@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg-primary: #09090b;
  --bg-secondary: #111114;
  --bg-tertiary: #18181b;
  --bg-card: #141417;
  --bg-card-hover: #1c1c22;
  --accent-primary: #fafafa;
  --accent-secondary: #d4d4d8;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-yellow: #eab308;
  --accent-blue: #3b82f6;
  --accent-pink: #ec4899;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border-color: #27272a;
  --border-focus: rgba(250, 250, 250, 0.35);
  --gradient-primary: linear-gradient(135deg, #fafafa 0%, #d4d4d8 100%);
  --gradient-green: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar-width: 260px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

[data-theme="light"] {
  --bg-primary: #fafafa;
  --bg-secondary: #f4f4f5;
  --bg-tertiary: #e4e4e7;
  --bg-card: #ffffff;
  --bg-card-hover: #f4f4f5;
  --accent-primary: #18181b;
  --accent-secondary: #52525b;
  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  --border-color: #e4e4e7;
  --border-focus: rgba(24, 24, 27, 0.25);
  --gradient-primary: linear-gradient(135deg, #18181b 0%, #52525b 100%);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.12);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  margin: 0;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.fade-in { animation: fadeIn 0.35s ease-out; }
.spin { animation: spin 0.8s linear infinite; }

.gradient-text {
  color: var(--text-primary);
  font-weight: 800;
}

.logo-icon,
.avatar-circle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

.sidebar-divider {
  border-color: var(--border-color) !important;
}

.page-content {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  width: var(--sidebar-width);
  min-height: 100vh;
  min-height: 100dvh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  padding-top: var(--safe-top);
}

.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1.5rem;
  padding-bottom: calc(5rem + var(--safe-bottom));
}

.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  margin: -1.5rem -1.5rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 20;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.875rem;
  transition: background 0.2s, color 0.2s;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.nav-link:hover,
.nav-link.active {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.nav-link.active { color: var(--accent-primary); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.card:hover {
  border-color: var(--border-focus);
}

.card-flat {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1.125rem;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
}

.stat-card.indigo::before { background: var(--gradient-primary); }
.stat-card.green::before { background: var(--gradient-green); }
.stat-card.blue::before { background: linear-gradient(90deg, #3b82f6, #06b6d4); }
.stat-card.yellow::before { background: linear-gradient(90deg, #eab308, #f97316); }
.stat-card.pink::before { background: linear-gradient(90deg, #ec4899, #f43f5e); }

.btn-primary,
.btn-secondary,
.btn-danger,
.btn-success {
  border-radius: var(--radius-sm);
  padding: 0.625rem 1.125rem;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-primary);
  color: var(--bg-primary);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  border-color: var(--border-focus);
  background: rgba(255, 255, 255, 0.06);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
}

.btn-success {
  background: var(--gradient-green);
  color: #fff;
}

.btn-sm {
  padding: 0.5rem 0.875rem;
  font-size: 0.8125rem;
}

.btn-icon {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-icon:hover {
  border-color: var(--border-focus);
  color: var(--text-primary);
}

.form-input,
.form-input select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.6875rem 0.875rem;
  width: 100%;
  font-size: 0.9375rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.form-input::placeholder { color: var(--text-muted); }

.form-label {
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  display: block;
}

.form-group { margin-bottom: 0.25rem; }

.search-input-wrap {
  position: relative;
}

.search-input-wrap .search-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input-wrap .form-input {
  padding-left: 2.5rem;
  padding-right: 2.5rem;
  min-height: 2.75rem;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 14rem;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.search-result-item {
  padding: 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.search-result-item:hover,
.search-result-item.selected {
  border-color: var(--border-focus);
  background: rgba(255, 255, 255, 0.04);
}

.spell-suggestion {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  margin-bottom: 0.75rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.spell-suggestion button {
  background: none;
  border: none;
  color: var(--accent-primary);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.progress-bar-bg {
  background: var(--bg-tertiary);
  border-radius: 999px;
  overflow: hidden;
  height: 8px;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s ease;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-green { background: rgba(34, 197, 94, 0.15); color: var(--accent-green); }
.badge-red { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); }
.badge-indigo { background: rgba(255, 255, 255, 0.08); color: var(--text-secondary); }
.badge-yellow { background: rgba(234, 179, 8, 0.15); color: var(--accent-yellow); }

.meal-breakfast { border-left: 3px solid var(--accent-yellow); }
.meal-lunch { border-left: 3px solid var(--accent-green); }
.meal-dinner { border-left: 3px solid var(--accent-primary); }
.meal-snack { border-left: 3px solid var(--accent-pink); }

.meal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 3rem;
  height: 3rem;
  margin: 0 auto 0.75rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state h3 {
  margin: 0 0 0.25rem;
  color: var(--text-primary);
  font-size: 0.9375rem;
}

.empty-state p {
  margin: 0;
  font-size: 0.8125rem;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
}

.modal-backdrop.hidden { display: none; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  z-index: 51;
  width: 100%;
  max-width: 42rem;
  max-height: min(90vh, 90dvh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.toast {
  position: fixed;
  bottom: calc(1rem + var(--safe-bottom));
  right: 1rem;
  left: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
  box-shadow: var(--shadow-lg);
  z-index: 1100;
  animation: fadeIn 0.25s ease-out;
  max-width: min(320px, calc(100vw - 2rem));
  font-size: 0.875rem;
}

.toast.success { border-left: 3px solid var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }
.toast.info { border-left: 3px solid var(--accent-primary); }

.theme-toggle {
  position: fixed;
  bottom: calc(1rem + var(--safe-bottom));
  right: 1rem;
  z-index: 1000;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.375rem;
  display: flex;
  gap: 0.25rem;
  box-shadow: var(--shadow-md);
}

.theme-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  border: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.theme-btn:hover,
.theme-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent-primary);
}

.theme-btn.active { border-color: var(--border-focus); }
.theme-btn svg { width: 16px; height: 16px; }

.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.625rem 0.875rem;
  text-align: left;
}
.data-table td {
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.875rem;
}
.data-table tr:hover td { background: rgba(255, 255, 255, 0.02); }

.hero-bg {
  background:
    radial-gradient(ellipse at top, rgba(255, 255, 255, 0.04) 0%, transparent 55%),
    var(--bg-primary);
}

.water-fill { position: relative; overflow: hidden; border-radius: var(--radius-md); }

.metric-badge {
  background: rgba(9, 9, 11, 0.85);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.6875rem;
  color: var(--text-primary);
  font-weight: 500;
  backdrop-filter: blur(4px);
}

.face-container,
.canvas-viewport {
  position: relative;
  width: 100%;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  overflow: hidden;
  touch-action: none;
}

.canvas-viewport {
  min-height: 280px;
  max-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#analysis-canvas,
#face-canvas {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  width: auto;
  height: auto;
  cursor: grab;
  border-radius: var(--radius-md);
}

#analysis-canvas:active { cursor: grabbing; }

.canvas-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.canvas-nav-btn.prev { left: 0.5rem; }
.canvas-nav-btn.next { right: 0.5rem; }

.canvas-view-label {
  position: absolute;
  bottom: 0.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.upload-zone {
  width: 100%;
  min-height: 11rem;
  border-radius: var(--radius-md);
  border: 2px dashed var(--border-color);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.info-banner {
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
}

.info-banner-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.info-banner ul {
  margin: 0;
  padding-left: 1rem;
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.info-banner li + li { margin-top: 0.25rem; }

.harmony-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
}

.guide-line {
  position: absolute;
  border: 1px dashed rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.guide-label {
  position: absolute;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  border: 1px solid var(--border-color);
}

.text-theme { color: var(--text-primary); }
.text-theme-secondary { color: var(--text-secondary); }
.text-theme-muted { color: var(--text-muted); }

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open { transform: translateX(0); }

  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-bottom: calc(5.5rem + var(--safe-bottom));
  }

  .mobile-header { display: flex; }

  .card { padding: 1rem; }

  .card:hover { transform: none; }

  .form-input { font-size: 16px; }

  .stat-card { padding: 0.875rem; }

  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-panel {
    max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    margin-top: auto;
  }

  .theme-toggle {
    bottom: calc(0.75rem + var(--safe-bottom));
    right: 0.75rem;
  }

  .toast {
    left: 1rem;
    right: 1rem;
    max-width: none;
  }

  .canvas-viewport {
    min-height: 240px;
    max-height: 55vh;
  }

  .btn-primary,
  .btn-secondary {
    min-height: 2.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
