/* ============================================================
   Nourish — warm, organic nutrition tracker
   Design tokens + base styles
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Hanken+Grotesk:ital,wght@0,400;0,500;0,600;0,700;0,800&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;1,6..72,400&display=swap');

:root {
  /* --- warm earth surfaces --- */
  --bg:         oklch(0.962 0.014 72);
  --bg-2:       oklch(0.944 0.018 68);
  --surface:    oklch(0.995 0.006 84);
  --surface-2:  oklch(0.978 0.012 76);
  --surface-3:  oklch(0.958 0.016 70);

  /* --- ink (warm dark browns) --- */
  --ink:    oklch(0.30 0.022 52);
  --ink-2:  oklch(0.47 0.026 52);
  --ink-3:  oklch(0.62 0.022 58);
  --ink-4:  oklch(0.74 0.018 64);

  /* --- hairlines --- */
  --line:   oklch(0.905 0.014 70);
  --line-2: oklch(0.86 0.018 68);

  /* --- terracotta primary --- */
  --primary:      oklch(0.625 0.142 41);
  --primary-deep: oklch(0.52 0.132 39);
  --primary-ink:  oklch(0.40 0.10 38);
  --primary-soft: oklch(0.93 0.038 52);
  --primary-soft2:oklch(0.89 0.052 50);

  /* --- macro hues (earthy, ~equal chroma/lightness, varied hue) --- */
  --cal:    oklch(0.64 0.142 42);   /* terracotta  */
  --cal-bg: oklch(0.92 0.05 46);
  --protein:    oklch(0.59 0.13 22);   /* clay red    */
  --protein-bg: oklch(0.92 0.045 26);
  --fiber:    oklch(0.62 0.092 138);   /* sage olive  */
  --fiber-bg: oklch(0.93 0.04 138);
  --fat:    oklch(0.72 0.116 76);   /* ochre amber */
  --fat-bg: oklch(0.93 0.05 80);
  --carb:    oklch(0.66 0.10 58);
  --carb-bg: oklch(0.93 0.04 60);

  /* --- type --- */
  --sans: 'Hanken Grotesk', system-ui, sans-serif;
  --serif: 'Newsreader', Georgia, serif;

  /* --- shape --- */
  --r-sm: 12px;
  --r:    18px;
  --r-lg: 26px;
  --r-xl: 34px;

  /* --- shadow (warm, soft) --- */
  --sh-sm: 0 1px 2px oklch(0.4 0.04 50 / 0.06), 0 2px 8px oklch(0.4 0.04 50 / 0.05);
  --sh:    0 2px 6px oklch(0.4 0.04 50 / 0.06), 0 10px 28px oklch(0.4 0.04 50 / 0.08);
  --sh-lg: 0 8px 22px oklch(0.4 0.04 50 / 0.10), 0 28px 60px oklch(0.4 0.04 50 / 0.12);

  --maxw: 1240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
*::-webkit-scrollbar { width: 0; height: 0; }
* { scrollbar-width: none; }

html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;
}

#root { height: 100vh; }

button { font-family: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; color: inherit; }
::selection { background: var(--primary-soft2); }

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

/* tap feedback */
.tap { transition: transform .12s ease, background .15s ease, box-shadow .2s ease, border-color .15s ease, opacity .15s ease; }
.tap:active { transform: scale(0.97); }

/* ============================================================
   APP SHELL — responsive: mobile (bottom nav) -> desktop (sidebar)
   ============================================================ */
.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

/* scrolling content region */
.scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.page { padding: 0 20px 140px; max-width: 540px; margin: 0 auto; }

/* soft animated entrance for screens */
@keyframes riseIn { from { transform: translateY(12px); } to { transform: none; } }
/* transform-only entrance — content is always opaque even if the animation
   timeline is frozen (e.g. backgrounded tab), so nothing ever gets stuck hidden */
@media (prefers-reduced-motion: no-preference) {
  .screen { animation: riseIn .42s cubic-bezier(.2,.7,.3,1); }
}

/* ---- bottom tab bar (mobile) ---- */
.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: stretch; justify-content: space-around;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: oklch(0.995 0.006 84 / 0.86);
  backdrop-filter: blur(18px) saturate(1.3);
  border-top: 1px solid var(--line);
  z-index: 40;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 4px; color: var(--ink-3); border-radius: 14px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .01em;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--primary); }
.tab .tab-fab {
  width: 52px; height: 52px; margin-top: -22px; border-radius: 50%;
  background: var(--primary); color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 20px oklch(0.625 0.142 41 / 0.4); border: 4px solid var(--bg);
}
.tab .tab-fab svg { width: 26px; height: 26px; }

/* ---- desktop sidebar (hidden on mobile) ---- */
.sidebar { display: none; }

/* top bar inside scroll */
.topbar { padding: 18px 0 10px; display: flex; align-items: center; justify-content: space-between; }

/* ============================================================
   PRIMITIVES
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
}

.eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3);
}
.h-title { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; line-height: 1.1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 700; font-size: 15px; border-radius: 99px; padding: 13px 20px;
  background: var(--primary); color: #fff; box-shadow: var(--sh-sm);
}
.btn svg { width: 18px; height: 18px; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line-2); box-shadow: none; }
.btn.soft  { background: var(--primary-soft); color: var(--primary-deep); box-shadow: none; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px;
  border-radius: 99px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.pill.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px;
  border-radius: 99px; font-size: 12px; font-weight: 700;
}

.divider { height: 1px; background: var(--line); border: none; }

/* segmented control */
.seg { display: inline-flex; background: var(--surface-3); border-radius: 99px; padding: 4px; gap: 2px; max-width: 100%; }
.seg button { padding: 8px 13px; border-radius: 99px; font-size: 12.5px; font-weight: 700; color: var(--ink-3); white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--sh-sm); }

/* sheet / modal */
.scrim { position: absolute; inset: 0; background: oklch(0.3 0.03 50 / 0.42); z-index: 60; animation: fade .25s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 61;
  background: var(--bg); border-radius: 28px 28px 0 0;
  box-shadow: var(--sh-lg); max-height: 92%; display: flex; flex-direction: column;
  animation: sheetUp .34s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 99px; background: var(--line-2); margin: 10px auto 4px; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 20px 12px; flex: none; }
.sheet-body { overflow-y: auto; padding: 0 20px 24px; }

.iconbtn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); }
.iconbtn svg { width: 19px; height: 19px; }

/* progress bar */
.bar-track { height: 9px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; transition: width .7s cubic-bezier(.2,.8,.2,1); }

/* ============================================================
   DESKTOP  (>= 980px)  -> dashboard with sidebar
   ============================================================ */
@media (min-width: 980px) {
  body { overflow: hidden; }
  .app { flex-direction: row; }

  .tabbar { display: none; }

  .sidebar {
    display: flex; flex-direction: column; width: 248px; flex: none;
    background: var(--surface); border-right: 1px solid var(--line);
    padding: 26px 16px; gap: 4px;
  }
  .sidebar .brand { display: flex; align-items: center; gap: 11px; padding: 4px 12px 22px; }
  .sidebar .brand .mark { width: 38px; height: 38px; border-radius: 12px; background: var(--primary); color: #fff; display: grid; place-items: center; }
  .sidebar .brand .mark svg { width: 22px; height: 22px; }
  .sidebar .brand b { font-family: var(--serif); font-weight: 500; font-size: 22px; letter-spacing: -.01em; }
  .navitem {
    display: flex; align-items: center; gap: 13px; padding: 11px 14px; border-radius: 14px;
    color: var(--ink-2); font-weight: 600; font-size: 15px;
  }
  .navitem svg { width: 21px; height: 21px; }
  .navitem:hover { background: var(--surface-2); }
  .navitem.active { background: var(--primary-soft); color: var(--primary-deep); }
  .navitem.cta { margin-top: 8px; background: var(--primary); color: #fff; justify-content: center; box-shadow: var(--sh-sm); }
  .navitem.cta:hover { background: var(--primary-deep); }
  .sidebar .spring { flex: 1; }

  .scroll { padding: 0; }
  .page { max-width: var(--maxw); padding: 0 48px 64px; margin: 0; }
  .topbar { padding: 30px 0 6px; }

  /* desktop dashboard grid for Today */
  .dash { display: grid; grid-template-columns: 1.15fr 1fr; gap: 28px; align-items: start; }
  .dash-wide { grid-column: 1 / -1; }

  .stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; align-items: start; }

  .hide-desktop { display: none !important; }
}
@media (max-width: 979px) {
  .hide-mobile { display: none !important; }
}

/* ---- range slider ---- */
.slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 8px; border-radius: 99px;
  background: var(--surface-3); outline: none; cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; border: 3px solid var(--c, var(--primary)); box-shadow: var(--sh-sm); cursor: grab;
  transition: transform .12s ease;
}
.slider::-webkit-slider-thumb:active { transform: scale(1.12); cursor: grabbing; }
.slider::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%; background: #fff;
  border: 3px solid var(--c, var(--primary)); box-shadow: var(--sh-sm); cursor: grab;
}

/* ---- skeleton loaders ---- */
@keyframes shimmer { 0% { background-position: -200px 0; } 100% { background-position: 320px 0; } }
.skel {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 40%, var(--surface-2) 80%);
  background-size: 400px 100%; animation: shimmer 1.2s infinite linear;
}

/* ---- scan beam ---- */
@keyframes beam { 0% { top: 0; } 100% { top: 100%; } }
.scan-beam {
  position: absolute; left: 0; right: 0; height: 60px;
  background: linear-gradient(to bottom, transparent, oklch(0.7 0.14 50 / 0.5), transparent);
  animation: beam 1.4s ease-in-out infinite alternate;
}

/* ---- meals layout ---- */
.meals-cols { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 980px) {
  .meals-cols { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
}

/* ---- inline spinner ---- */
@keyframes spin { to { transform: rotate(360deg); } }
.spin {
  width: 16px; height: 16px; border-radius: 50%; display: inline-block; vertical-align: -3px;
  border: 2.5px solid oklch(1 0 0 / 0.4); border-top-color: #fff; animation: spin .7s linear infinite;
}

/* ---- method picker (icon segmented) ---- */
.methods { display: flex; gap: 5px; background: var(--surface-3); border-radius: 16px; padding: 5px; }
.methods button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 9px 3px; border-radius: 11px; font-size: 10.5px; font-weight: 700; color: var(--ink-3); letter-spacing: .01em;
}
.methods button.on { background: var(--surface); color: var(--primary); box-shadow: var(--sh-sm); }

/* ---- barcode / QR scan viewfinder ---- */
.viewfinder {
  position: relative; height: 188px; border-radius: 22px; overflow: hidden;
  background: oklch(0.28 0.02 52); display: grid; place-items: center;
}
.viewfinder .frame { position: absolute; inset: 26px; border-radius: 14px; }
.viewfinder .frame::before, .viewfinder .frame::after,
.viewfinder .corner::before, .viewfinder .corner::after { content: ''; position: absolute; width: 26px; height: 26px; border: 3px solid #fff; }
.viewfinder .frame::before { top: 0; left: 0; border-right: none; border-bottom: none; border-radius: 8px 0 0 0; }
.viewfinder .frame::after  { top: 0; right: 0; border-left: none;  border-bottom: none; border-radius: 0 8px 0 0; }
.viewfinder .corner::before{ bottom: 0; left: 0; border-right: none; border-top: none; border-radius: 0 0 0 8px; }
.viewfinder .corner::after { bottom: 0; right: 0; border-left: none;  border-top: none; border-radius: 0 0 8px 0; }
.barcode {
  width: 132px; height: 70px;
  background: repeating-linear-gradient(90deg, #fff 0 3px, transparent 3px 5px, #fff 5px 7px, transparent 7px 12px, #fff 12px 14px, transparent 14px 19px);
  opacity: .92; border-radius: 3px;
}
.viewfinder .laser {
  position: absolute; left: 30px; right: 30px; top: 50%; height: 2.5px; border-radius: 99px;
  background: oklch(0.72 0.16 45); box-shadow: 0 0 12px 2px oklch(0.72 0.16 45 / 0.8);
}
@media (prefers-reduced-motion: no-preference) {
  .viewfinder .laser { animation: laser 1.2s ease-in-out infinite alternate; }
}
@keyframes laser { from { top: 34px; } to { top: 150px; } }

/* image-slot tuning */
image-slot { --is-bg: var(--surface-2); border-radius: 22px; }

/* ---- language toggle ---- */
.langtoggle {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; padding: 3px;
}
.langtoggle button {
  padding: 5px 11px; border-radius: 99px; font-size: 12px; font-weight: 800; letter-spacing: .04em;
  color: var(--ink-3);
}
.langtoggle button.on { background: var(--primary); color: #fff; box-shadow: var(--sh-sm); }
.langtoggle.floating {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 18px; z-index: 45;
  background: oklch(0.995 0.006 84 / 0.82); backdrop-filter: blur(12px) saturate(1.3); box-shadow: var(--sh-sm);
}

/* tab labels: fit 6 columns with longer PT words */
.tab { font-size: 9.5px; letter-spacing: 0; padding: 7px 2px; white-space: nowrap; }
@media (min-width: 980px) {
  .sidebar .brand b { font-size: 19px; line-height: 1.1; }
}
