/* ==========================================================================
   What Am I Eating? — Editorial Botanical Apothecary Design System
   Perceptually uniform OKLCH palette, Major Third type scale, 8px rhythm.
   ========================================================================== */

:root {
  /* Perceptual OKLCH Palette — Warm Apothecary Linen (Light Mode Default) */
  --color-bg:           oklch(96.6% 0.012 85);
  --color-surface:      oklch(99.3% 0.005 85);
  --color-surface-alt:  oklch(93.8% 0.015 82);
  --color-surface-inv:  oklch(22% 0.035 152);
  --color-border:       oklch(86.5% 0.016 78);
  --color-border-strong:oklch(75% 0.02 74);

  --color-text:         oklch(20% 0.018 55);
  --color-text-soft:    oklch(34% 0.018 58);
  --color-muted:        oklch(47% 0.018 65);

  /* Brand & Semantic Roles */
  --color-accent:       oklch(38% 0.092 154);   /* Deep botanical forest sage */
  --color-accent-hover: oklch(32% 0.096 154);
  --color-accent-soft:  oklch(92.5% 0.032 150);
  --color-accent-ink:   oklch(98% 0.006 85);

  --color-positive:     oklch(42% 0.115 150);
  --color-positive-bg:  oklch(93.5% 0.036 148);

  --color-caution:      oklch(50% 0.135 72);
  --color-caution-bg:   oklch(94.5% 0.048 82);

  --color-warning:      oklch(49% 0.165 34);    /* Terracotta / persimmon */
  --color-warning-bg:   oklch(94% 0.042 38);

  --color-danger:       oklch(43% 0.165 20);    /* Apothecary crimson */
  --color-danger-bg:    oklch(93.5% 0.045 22);

  /* Typography */
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-sans:    'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;

  /* Major Third Type Scale */
  --text-xs:   0.75rem;
  --text-sm:   0.85rem;
  --text-base: 0.96rem;
  --text-lg:   1.15rem;
  --text-xl:   1.42rem;
  --text-2xl:  1.82rem;
  --text-3xl:  2.35rem;

  /* 8px Spacing Grid */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Radii */
  --radius-sm:   6px;
  --radius-md:   12px;
  --radius-lg:   18px;
  --radius-xl:   24px;
  --radius-full: 9999px;

  /* Motion */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out:   cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 150ms;
  --dur-base: 260ms;
  --dur-slow: 420ms;

  /* Soft Paper Shadows */
  --shadow-xs: 0 1px 2px oklch(20% 0.02 60 / 6%);
  --shadow-sm: 0 2px 8px oklch(20% 0.02 60 / 6%), 0 1px 2px oklch(20% 0.02 60 / 5%);
  --shadow-md: 0 8px 24px oklch(20% 0.02 60 / 9%), 0 2px 6px oklch(20% 0.02 60 / 5%);
  --shadow-lg: 0 20px 44px oklch(18% 0.02 60 / 14%), 0 4px 12px oklch(18% 0.02 60 / 6%);

  --rail-width: 248px;
  --bottom-nav-h: 66px;
}

/* Warm Espresso Dark Mode */
[data-theme="dark"] {
  --color-bg:           oklch(15.5% 0.012 60);
  --color-surface:      oklch(20.5% 0.013 60);
  --color-surface-alt:  oklch(25% 0.015 62);
  --color-surface-inv:  oklch(28% 0.045 152);
  --color-border:       oklch(31% 0.015 62);
  --color-border-strong:oklch(42% 0.018 65);

  --color-text:         oklch(93% 0.012 85);
  --color-text-soft:    oklch(82% 0.012 82);
  --color-muted:        oklch(66% 0.015 76);

  --color-accent:       oklch(68% 0.11 152);
  --color-accent-hover: oklch(74% 0.115 152);
  --color-accent-soft:  oklch(27% 0.04 152);
  --color-accent-ink:   oklch(15% 0.02 152);

  --color-positive:     oklch(72% 0.125 148);
  --color-positive-bg:  oklch(25% 0.045 148);

  --color-caution:      oklch(77% 0.13 80);
  --color-caution-bg:   oklch(27% 0.045 78);

  --color-warning:      oklch(72% 0.155 38);
  --color-warning-bg:   oklch(26% 0.055 34);

  --color-danger:       oklch(70% 0.16 22);
  --color-danger-bg:    oklch(25% 0.06 20);

  --shadow-sm: 0 2px 10px oklch(0% 0 0 / 28%);
  --shadow-md: 0 10px 28px oklch(0% 0 0 / 38%);
  --shadow-lg: 0 24px 48px oklch(0% 0 0 / 50%);
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* Subtle paper grain background texture on desktop */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(1200px 600px at 85% -10%, oklch(88% 0.04 148 / 22%), transparent 60%),
    radial-gradient(900px 500px at -10% 90%, oklch(88% 0.04 65 / 20%), transparent 55%);
}
[data-theme="dark"] body::before {
  background:
    radial-gradient(1000px 500px at 85% -10%, oklch(32% 0.05 152 / 22%), transparent 60%),
    radial-gradient(800px 500px at -10% 90%, oklch(30% 0.04 50 / 18%), transparent 55%);
}

h1, h2, h3, .font-display {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0;
}

p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
a { color: var(--color-accent); text-underline-offset: 3px; }

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.skip-link {
  position: fixed; top: -100px; left: 16px; z-index: 9999;
  background: var(--color-accent); color: var(--color-accent-ink);
  padding: 10px 16px; border-radius: var(--radius-md); font-weight: 600;
  transition: top var(--dur-fast) var(--ease-out-expo);
}
.skip-link:focus { top: 12px; }

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   App Shell Layout (Mobile-first bottom nav -> Desktop editorial left rail)
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100dvh;
}

/* Desktop Sidebar Rail */
.side-rail {
  display: none;
}

/* Mobile Top Header */
.mobile-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 12px 16px;
  background: color-mix(in oklch, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--color-border);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--color-text);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}

.brand-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.7rem;
  color: var(--color-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}

/* Main Content Region */
.main-content {
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  padding: var(--space-4) var(--space-4) calc(var(--bottom-nav-h) + var(--space-8));
}

/* Mobile Bottom Tab Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in oklch, var(--color-surface) 94%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--color-border);
}

.bottom-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--color-muted);
  font-size: 0.72rem;
  font-weight: 600;
  min-height: 48px;
  transition: color var(--dur-fast) var(--ease-out-expo), transform var(--dur-fast) var(--ease-out-expo);
}

.bottom-nav-btn i { font-size: 1.35rem; }
.bottom-nav-btn.active { color: var(--color-accent); }
.bottom-nav-btn:active { transform: scale(0.95); }

/* Desktop Breakpoint */
@media (min-width: 960px) {
  .app-shell {
    grid-template-columns: var(--rail-width) 1fr;
  }
  .mobile-header,
  .bottom-nav {
    display: none;
  }
  .side-rail {
    position: sticky;
    top: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: var(--space-6) var(--space-4);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
  }
  .main-content {
    padding: var(--space-8) var(--space-8) var(--space-12);
  }
}

/* Rail Nav Buttons */
.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: var(--space-6);
}

.rail-nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-soft);
  font-weight: 600;
  font-size: 0.92rem;
  text-align: left;
  transition: background var(--dur-fast) var(--ease-out-expo), color var(--dur-fast) var(--ease-out-expo);
}
.rail-nav-btn i { font-size: 1.2rem; opacity: 0.85; }
.rail-nav-btn:hover { background: var(--color-surface-alt); color: var(--color-text); }
.rail-nav-btn.active {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}
.rail-nav-btn.active i { opacity: 1; }

.rail-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--color-surface-alt);
  color: var(--color-text-soft);
}
.rail-nav-btn.active .rail-badge {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}

.rail-footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.rail-credit {
  font-size: 0.72rem;
  color: var(--color-muted);
  line-height: 1.45;
}

/* ==========================================================================
   Shared Primitives: Buttons, Pills, Cards, Inputs, Badges
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: transform var(--dur-fast) var(--ease-out-expo),
              background var(--dur-fast) var(--ease-out-expo),
              border-color var(--dur-fast) var(--ease-out-expo),
              box-shadow var(--dur-fast) var(--ease-out-expo);
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.52; cursor: not-allowed; }

.btn-primary {
  background: var(--color-accent);
  color: var(--color-accent-ink);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--color-surface-alt);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-soft);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.btn-sm {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
  border-radius: 9px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  transition: background var(--dur-fast) var(--ease-out-expo);
}
.icon-btn:hover { background: var(--color-surface-alt); }

.surface-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.section-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-accent);
}

.view-panel { display: none; animation: fadeSlideUp 260ms var(--ease-out-expo); }
.view-panel.active { display: block; }

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Tone Badges */
.tone-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  flex-shrink: 0;
}
.tone-positive { background: var(--color-positive-bg); color: var(--color-positive); }
.tone-caution  { background: var(--color-caution-bg);  color: var(--color-caution); }
.tone-warning  { background: var(--color-warning-bg);  color: var(--color-warning); }
.tone-danger   { background: var(--color-danger-bg);   color: var(--color-danger); }
.tone-neutral  { background: var(--color-surface-alt); color: var(--color-text-soft); }

/* Toast Notifications */
.toast-rack {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 14px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}
@media (min-width: 960px) {
  .toast-rack { bottom: 24px; left: auto; right: 24px; transform: none; }
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--color-surface-inv);
  color: var(--color-accent-ink);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: fadeSlideUp 220ms var(--ease-out-expo);
}
