/* SugarLog 2.0 — Designed by Graaphix (https://graaphix.com) */

/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Plus Jakarta Sans', var(--font-ui);

  --bg: #f4f6f8;
  --bg-tint: #eaf4f2;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --surface-3: #eef2f5;
  --border: #e3e8ee;
  --border-strong: #cfd7e0;
  --text: #0e1726;
  --text-2: #3f4b5c;
  --muted: #6b7788;
  --faint: #98a3b3;

  --brand: #0f766e;
  --brand-600: #0d6b64;
  --brand-500: #14918a;
  --brand-soft: #e3f3f1;
  --brand-ink: #ffffff;
  --accent: #e11d48;
  --accent-soft: #fde8ee;

  --ok: #15803d;      --ok-soft: #e4f6ea;
  --warn: #b45309;    --warn-soft: #fdf1dc;
  --high: #c81e1e;    --high-soft: #fde6e6;
  --low: #1d4ed8;     --low-soft: #e3ebfd;

  --m-fasting: #0f766e;
  --m-breakfast: #c2780c;
  --m-lunch: #15803d;
  --m-dinner: #7c3aed;
  --m-random: #4f46e5;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 16px -4px rgba(15, 23, 42, .08), 0 2px 6px -2px rgba(15, 23, 42, .05);
  --shadow-lg: 0 24px 48px -16px rgba(15, 23, 42, .22);
  --ring: 0 0 0 3px rgba(20, 145, 138, .25);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;

  --tabbar-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f1a;
    --bg-tint: #0d1a1f;
    --surface: #121a27;
    --surface-2: #162031;
    --surface-3: #1c283b;
    --border: #233046;
    --border-strong: #2f3f59;
    --text: #e8edf4;
    --text-2: #c2ccd9;
    --muted: #8d9aae;
    --faint: #64728a;
    --brand: #2bb3a8;
    --brand-600: #22a198;
    --brand-500: #36c2b6;
    --brand-soft: #0f2d2f;
    --brand-ink: #04211f;
    --accent: #fb5677;
    --accent-soft: #3a1621;
    --ok: #4ade80;     --ok-soft: #10301d;
    --warn: #fbbf24;   --warn-soft: #33270b;
    --high: #f87171;   --high-soft: #3a1515;
    --low: #7aa2ff;    --low-soft: #15224a;
    --m-fasting: #2bb3a8;
    --m-breakfast: #f0a53a;
    --m-lunch: #4ade80;
    --m-dinner: #a78bfa;
    --m-random: #818cf8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 6px 20px -6px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0f1a;
  --bg-tint: #0d1a1f;
  --surface: #121a27;
  --surface-2: #162031;
  --surface-3: #1c283b;
  --border: #233046;
  --border-strong: #2f3f59;
  --text: #e8edf4;
  --text-2: #c2ccd9;
  --muted: #8d9aae;
  --faint: #64728a;
  --brand: #2bb3a8;
  --brand-600: #22a198;
  --brand-500: #36c2b6;
  --brand-soft: #0f2d2f;
  --brand-ink: #04211f;
  --accent: #fb5677;
  --accent-soft: #3a1621;
  --ok: #4ade80;     --ok-soft: #10301d;
  --warn: #fbbf24;   --warn-soft: #33270b;
  --high: #f87171;   --high-soft: #3a1515;
  --low: #7aa2ff;    --low-soft: #15224a;
  --m-fasting: #2bb3a8;
  --m-breakfast: #f0a53a;
  --m-lunch: #4ade80;
  --m-dinner: #a78bfa;
  --m-random: #818cf8;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 6px 20px -6px rgba(0, 0, 0, .5);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ============================================================
   BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.02em; line-height: 1.2; }
p { margin: 0; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden], .hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
:focus-visible { outline: none; box-shadow: var(--ring); }

.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ============================================================
   BUTTONS & FORM CONTROLS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border: 1px solid transparent; border-radius: var(--r-md);
  font-weight: 600; font-size: 15px;
  background: var(--surface-3); color: var(--text);
  transition: transform .12s ease, background-color .15s ease, box-shadow .15s ease, opacity .15s;
  -webkit-user-select: none; user-select: none;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn-primary {
  background: linear-gradient(180deg, var(--brand-500), var(--brand));
  color: var(--brand-ink);
  box-shadow: 0 6px 16px -6px rgba(15, 118, 110, .55), inset 0 1px 0 rgba(255,255,255,.18);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--brand), var(--brand-600)); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-outline { background: var(--surface); border-color: var(--border-strong); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger { background: var(--high-soft); color: var(--high); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 16px; border-radius: 16px; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  transition: background-color .15s;
}
.icon-btn:hover { background: var(--surface-2); }

.field { display: grid; gap: 6px; }
.field + .field { margin-top: 14px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.field-hint { font-size: 12px; color: var(--muted); font-weight: 500; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 12px 14px;
  border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-size: 16px; /* prevents iOS zoom */
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--ring); }
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7788' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 40px;
}
input[type="date"].input, input[type="time"].input { min-width: 0; }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 48px; }
.input-wrap .input-action {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border: 0; background: none; color: var(--muted);
  display: grid; place-items: center; border-radius: 10px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-2 > .field + .field, .when-row > .field + .field { margin-top: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--border-strong); }
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip-row::-webkit-scrollbar { display: none; }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 4px; gap: 4px; border-radius: 14px; background: var(--surface-3);
}
.segmented button {
  min-height: 38px; border: 0; border-radius: 10px; background: transparent;
  font-weight: 600; font-size: 14px; color: var(--muted);
  transition: background-color .15s, color .15s, box-shadow .15s;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Status pill */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .01em; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.s-normal { color: var(--ok); background: var(--ok-soft); }
.pill.s-borderline { color: var(--warn); background: var(--warn-soft); }
.pill.s-high { color: var(--high); background: var(--high-soft); }
.pill.s-low { color: var(--low); background: var(--low-soft); }
.pill.s-neutral { color: var(--muted); background: var(--surface-3); }

/* ============================================================
   AUTH SCREEN
   ============================================================ */
.auth {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
}
.auth-hero {
  position: relative; overflow: hidden;
  padding: calc(32px + var(--safe-t)) 24px 72px;
  color: #fff;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(255,255,255,.18), transparent 55%),
    radial-gradient(90% 70% at 0% 100%, rgba(225, 29, 72, .35), transparent 60%),
    linear-gradient(150deg, #0f766e 0%, #0b5d57 55%, #083f3c 100%);
}
.auth-hero::after {
  content: ""; position: absolute; inset: auto -20% -60% auto; width: 420px; height: 420px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.12); box-shadow: 0 0 0 60px rgba(255,255,255,.04), 0 0 0 120px rgba(255,255,255,.03);
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  background: rgba(255,255,255,.16); backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.22);
}
.brand-mark img { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 20px; letter-spacing: -0.02em; }
.brand-tag { font-size: 12px; opacity: .8; font-weight: 500; }
.auth-hero h1 { margin-top: 36px; font-size: 30px; font-weight: 800; max-width: 16ch; }
.auth-hero p.lead { margin-top: 10px; font-size: 15px; opacity: .88; max-width: 38ch; }
.auth-points { display: none; list-style: none; padding: 0; margin: 32px 0 0; gap: 14px; }
.auth-points li { display: flex; gap: 12px; align-items: flex-start; font-size: 14px; opacity: .92; }
.auth-points .icon { margin-top: 1px; width: 22px; height: 22px; padding: 3px; border-radius: 8px; background: rgba(255,255,255,.14); }

.auth-panel { padding: 0 16px calc(24px + var(--safe-b)); margin-top: -48px; position: relative; z-index: 1; }
.auth-card {
  max-width: 440px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  padding: 20px 20px 24px;
}
.auth-card .segmented { margin-bottom: 20px; }
.auth-card h2 { font-size: 22px; font-weight: 800; }
.auth-card .sub { color: var(--muted); font-size: 14px; margin: 4px 0 20px; }
.auth-row { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 20px; }
.link-btn { border: 0; background: none; padding: 4px 0; color: var(--brand); font-weight: 600; font-size: 14px; }
.trust-note {
  display: flex; gap: 10px; align-items: flex-start; margin-top: 20px; padding: 12px 14px;
  border-radius: 14px; background: var(--brand-soft); color: var(--text-2); font-size: 12.5px; line-height: 1.45;
}
.trust-note .icon { color: var(--brand); margin-top: 1px; }
.footer-note { text-align: center; font-size: 12px; color: var(--muted); padding: 20px 0 4px; }
.footer-note a { color: var(--text-2); font-weight: 600; text-decoration: none; }

@media (min-width: 960px) {
  .auth { grid-template-columns: 1.05fr 1fr; }
  .auth-hero { padding: 56px 64px; display: flex; flex-direction: column; }
  .auth-hero h1 { font-size: 44px; margin-top: auto; }
  .auth-hero p.lead { font-size: 17px; }
  .auth-points { display: grid; margin-bottom: auto; }
  .auth-panel { margin: 0; display: grid; place-items: center; padding: 48px; }
  .auth-card { width: 100%; padding: 32px; box-shadow: var(--shadow-md); }
}

/* ============================================================
   APP SHELL
   ============================================================ */
.shell { min-height: 100dvh; }

.sidebar { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.topbar.scrolled { border-bottom-color: var(--border); }
.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: linear-gradient(150deg, #14918a, #0b5d57); color: #fff; overflow: hidden; }
.topbar-logo img { width: 100%; height: 100%; object-fit: cover; }
.topbar-title { font-family: var(--font-display); font-weight: 800; font-size: 17px; letter-spacing: -0.02em; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(150deg, var(--brand-500), var(--brand)); color: #fff;
  font-family: var(--font-display); font-weight: 800; font-size: 16px; border: 0;
}
.avatar-lg { width: 64px; height: 64px; font-size: 24px; }

.main {
  padding: 4px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
  max-width: 640px; margin: 0 auto;
}
.view { display: none; animation: viewIn .28s ease both; }
.view.active { display: block; }
@keyframes viewIn { from { transform: translateY(6px); } to { transform: none; } }

.page-head { margin: 8px 0 16px; }
.page-head .eyebrow { font-size: 13px; font-weight: 600; color: var(--muted); }
.page-head h1 { font-size: 26px; font-weight: 800; margin-top: 2px; }
.page-head p { color: var(--muted); font-size: 14px; margin-top: 4px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 0; background: none; color: var(--faint);
  font-size: 11px; font-weight: 600; position: relative;
  transition: color .15s;
}
.tab .icon { width: 22px; height: 22px; transition: transform .2s ease; }
.tab.active { color: var(--brand); }
.tab.active .icon { transform: translateY(-1px); }
.tab.active::before {
  content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--brand);
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  padding: 18px;
}
.card + .card, .stack > * + * { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-title { font-family: var(--font-display); font-size: 16px; font-weight: 700; }
.card-sub { font-size: 13px; color: var(--muted); }
.section-title { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 24px 4px 10px; }

/* ============================================================
   HOME / LOG VIEW
   ============================================================ */
.hello { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.hello h1 { font-size: 24px; font-weight: 800; }
.hello .eyebrow { font-size: 13px; color: var(--muted); font-weight: 600; }

/* Today strip */
.today-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.slot {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 4px 10px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); font-size: 11px; font-weight: 600; text-align: center;
  transition: transform .12s ease, border-color .15s;
}
.slot:active { transform: scale(.97); }
.slot .slot-ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--slot-c, var(--muted)); }
.slot .slot-ico .icon { width: 18px; height: 18px; }
.slot .slot-val { font-family: var(--font-display); font-size: 17px; font-weight: 800; color: var(--text); line-height: 1; }
.slot .slot-val.is-empty { color: var(--faint); font-size: 15px; }
.slot.filled { border-color: color-mix(in srgb, var(--slot-c) 35%, var(--border)); }
.slot.filled .slot-ico { background: color-mix(in srgb, var(--slot-c) 14%, transparent); }
.slot .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.slot .dot.s-normal { background: var(--ok); }
.slot .dot.s-borderline { background: var(--warn); }
.slot .dot.s-high { background: var(--high); }
.slot .dot.s-low { background: var(--low); }

/* Entry card */
.entry { padding: 20px 18px; }
.meal-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.meal {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 2px; border-radius: 14px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text-2);
  font-size: 11.5px; font-weight: 600; line-height: 1.15; text-align: center;
  transition: all .15s ease;
}
.meal .icon { width: 22px; height: 22px; color: var(--meal-c); }
.meal.active {
  border-color: var(--meal-c);
  background: color-mix(in srgb, var(--meal-c) 10%, var(--surface));
  color: var(--text);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--meal-c) 14%, transparent);
}
.m-fasting { --meal-c: var(--m-fasting); --slot-c: var(--m-fasting); }
.m-breakfast { --meal-c: var(--m-breakfast); --slot-c: var(--m-breakfast); }
.m-lunch { --meal-c: var(--m-lunch); --slot-c: var(--m-lunch); }
.m-dinner { --meal-c: var(--m-dinner); --slot-c: var(--m-dinner); }
.m-random { --meal-c: var(--m-random); --slot-c: var(--m-random); }

.reading {
  margin: 18px 0 6px; padding: 18px 16px 16px; border-radius: 20px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border);
  transition: background-color .25s, border-color .25s;
}
.reading label { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.reading-input { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin-top: 4px; }
.reading-input input {
  width: 5ch; border: 0; background: transparent; text-align: center; padding: 0;
  font-family: var(--font-display); font-weight: 800; font-size: 64px; line-height: 1.1; letter-spacing: -0.04em;
  color: var(--text); -moz-appearance: textfield; appearance: textfield;
}
.reading-input input::-webkit-outer-spin-button, .reading-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.reading-input input::placeholder { color: var(--border-strong); }
.reading-input input:focus, .reading-input input:focus-visible { outline: none; box-shadow: none; }
.reading:focus-within { border-color: var(--brand-500); }
.reading-unit { font-weight: 700; color: var(--muted); font-size: 15px; }
.reading-feedback { min-height: 44px; display: grid; gap: 6px; justify-items: center; }
.reading-feedback .advice { font-size: 13px; color: var(--text-2); max-width: 36ch; }
.reading.s-normal { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.reading.s-borderline { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.reading.s-high { background: var(--high-soft); border-color: color-mix(in srgb, var(--high) 30%, transparent); }
.reading.s-low { background: var(--low-soft); border-color: color-mix(in srgb, var(--low) 30%, transparent); }

.when { display: grid; gap: 12px; margin-top: 16px; }
.when-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.when .quick { display: flex; gap: 6px; flex-wrap: wrap; }
.time-tools { display: flex; gap: 6px; }
.time-tools .chip { min-height: 32px; padding: 0 10px; }

.entry .btn-save { margin-top: 18px; }

.targets {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px;
  background: var(--surface-2); border: 1px dashed var(--border-strong); font-size: 12.5px; color: var(--text-2);
}
.targets .icon { color: var(--brand); margin-top: 1px; }

/* Home insights (latest, averages) */
.latest { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.latest-val { font-family: var(--font-display); font-weight: 800; font-size: 36px; letter-spacing: -0.03em; line-height: 1; }
.latest-val small { font-size: 14px; color: var(--muted); font-weight: 700; margin-left: 4px; letter-spacing: 0; }
.latest-meta { font-size: 13px; color: var(--muted); margin-top: 6px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.kpi { padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.kpi-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kpi-val { font-family: var(--font-display); font-size: 20px; font-weight: 800; margin-top: 2px; }
.kpi-val small { font-size: 11px; color: var(--muted); font-weight: 700; }

/* Distribution bar */
.dist { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-3); gap: 2px; }
.dist span { display: block; height: 100%; transition: width .4s ease; }
.dist .d-normal { background: var(--ok); }
.dist .d-borderline { background: var(--warn); }
.dist .d-high { background: var(--high); }
.dist .d-low { background: var(--low); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; font-size: 12.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

/* ============================================================
   TRENDS
   ============================================================ */
.chart-wrap { position: relative; height: 260px; margin: 0 -6px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 14px; padding: 24px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { padding: 16px; min-width: 0; }
.stat-grid > .card + .card { margin-top: 0; }
.stat .stat-val { white-space: nowrap; }
.stat .stat-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.stat .stat-label .icon { width: 16px; height: 16px; color: var(--brand); }
.stat .stat-val { font-family: var(--font-display); font-size: 26px; font-weight: 800; margin-top: 8px; letter-spacing: -0.02em; }
.stat .stat-val small { font-size: 12px; color: var(--muted); font-weight: 700; margin-left: 2px; letter-spacing: 0; }
.stat .stat-foot { font-size: 12px; color: var(--muted); margin-top: 2px; }
.meal-avg { display: grid; gap: 10px; }
.meal-avg-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; align-items: center; }
.meal-avg-row .ico { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--meal-c) 14%, transparent); color: var(--meal-c); }
.meal-avg-row .ico .icon { width: 16px; height: 16px; }
.meal-avg-row .name { font-size: 14px; font-weight: 600; }
.meal-avg-row .bar { height: 6px; border-radius: 99px; background: var(--surface-3); margin-top: 6px; overflow: hidden; }
.meal-avg-row .bar span { display: block; height: 100%; border-radius: 99px; background: var(--meal-c); }
.meal-avg-row .val { font-family: var(--font-display); font-weight: 800; font-size: 16px; text-align: right; }
.meal-avg-row .val small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; font-family: var(--font-ui); }

/* ============================================================
   HISTORY
   ============================================================ */
.search {
  display: flex; align-items: center; gap: 10px; padding: 0 14px; min-height: 48px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--border);
}
.search .icon { color: var(--faint); }
.search input { flex: 1; border: 0; background: transparent; font-size: 16px; min-width: 0; padding: 12px 0; }
.search input:focus { outline: none; }
.search:focus-within { border-color: var(--brand-500); box-shadow: var(--ring); }
.history-tools { display: grid; gap: 12px; margin-bottom: 8px; }

.day-group { margin-top: 18px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 8px; }
.day-head h3 { font-size: 14px; font-weight: 700; color: var(--text-2); font-family: var(--font-ui); letter-spacing: 0; }
.day-head span { font-size: 12px; color: var(--muted); }
.day-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.entry-row {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center;
  width: 100%; padding: 14px 16px; border: 0; background: none; text-align: left;
  transition: background-color .12s;
}
.entry-row + .entry-row { border-top: 1px solid var(--border); }
.entry-row:hover { background: var(--surface-2); }
.entry-row .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--meal-c) 13%, transparent); color: var(--meal-c); }
.entry-row .title { font-weight: 600; font-size: 14.5px; }
.entry-row .meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 1px; }
.entry-row .note { font-size: 12.5px; color: var(--text-2); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.entry-row .right { text-align: right; display: grid; gap: 4px; justify-items: end; }
.entry-row .val { font-family: var(--font-display); font-weight: 800; font-size: 20px; line-height: 1; }
.entry-row .val small { font-size: 11px; color: var(--muted); font-weight: 700; margin-left: 2px; font-family: var(--font-ui); }
.row-actions { display: none; }

.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty .empty-ico { width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.empty h3 { color: var(--text); font-size: 17px; margin-bottom: 6px; }
.empty p { font-size: 14px; }
.empty .btn { margin-top: 16px; }

/* Skeleton */
.skeleton { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 12px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ============================================================
   PROFILE
   ============================================================ */
.profile-card { display: flex; align-items: center; gap: 16px; }
.profile-card h2 { font-size: 20px; font-weight: 800; }
.profile-card .handle { font-size: 13px; color: var(--muted); word-break: break-all; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.fact { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); min-width: 0; }
.fact.wide { grid-column: 1 / -1; }
.fact.is-preg { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 28%, transparent); }
.fact.is-preg .v { color: var(--accent); }
.fact .k { font-size: 11px; color: var(--muted); font-weight: 600; }
.fact .v { font-weight: 700; font-size: 14px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.menu { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.menu-item {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 14px; align-items: center;
  width: 100%; padding: 14px 16px; border: 0; background: none; text-align: left;
  transition: background-color .12s;
}
.menu-item + .menu-item { border-top: 1px solid var(--border); }
.menu-item:hover { background: var(--surface-2); }
.menu-item .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.menu-item .ico.rose { background: var(--accent-soft); color: var(--accent); }
.menu-item .ico.slate { background: var(--surface-3); color: var(--text-2); }
.menu-item .t { font-weight: 600; font-size: 14.5px; }
.menu-item .d { font-size: 12.5px; color: var(--muted); }
.menu-item .chev { color: var(--faint); }
.badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 99px; background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 700; }
.menu-item .segmented { min-width: 200px; }

/* ============================================================
   SHEETS / DIALOGS
   ============================================================ */
dialog.sheet {
  border: 0; padding: 0; margin: 0; max-width: none; max-height: none;
  width: 100%; height: 100%; background: transparent; color: var(--text);
  position: fixed; inset: 0;
}
dialog.sheet::backdrop { background: rgba(5, 10, 20, .5); backdrop-filter: blur(2px); animation: fadeIn .2s ease; }
dialog.sheet[open] { display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel {
  width: 100%; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(20px + var(--safe-b));
  box-shadow: var(--shadow-lg);
  animation: sheetUp .28s cubic-bezier(.2, .9, .3, 1) both;
}
.sheet-grab { width: 40px; height: 5px; border-radius: 99px; background: var(--border-strong); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.sheet-head h2 { font-size: 20px; font-weight: 800; }
.sheet-head p { font-size: 13.5px; color: var(--muted); margin-top: 3px; }
.sheet-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.sheet-foot.one { grid-template-columns: 1fr; }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.meal-picker.compact .meal { padding: 8px 2px; font-size: 11px; }
.trash-item { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 12px 0; }
.trash-item + .trash-item { border-top: 1px solid var(--border); }
.trash-item .t { font-weight: 600; font-size: 14px; }
.trash-item .d { font-size: 12.5px; color: var(--muted); }

.confirm-ico { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; background: var(--warn-soft); color: var(--warn); margin-bottom: 14px; }

/* ============================================================
   TOASTS
   ============================================================ */
.toasts {
  position: fixed; z-index: 100; left: 50%; transform: translateX(-50%);
  top: calc(12px + var(--safe-t)); width: min(440px, calc(100% - 24px));
  display: grid; gap: 8px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 14px;
  background: var(--text); color: var(--surface);
  box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  pointer-events: auto; animation: toastIn .25s cubic-bezier(.2, .9, .3, 1.2) both;
}
.toast .icon { flex: none; }
.toast.t-success .icon { color: #4ade80; }
.toast.t-error { background: var(--high); color: #fff; }
.toast.t-info .icon { color: #7dd3fc; }
.toast .toast-msg { flex: 1; }
.toast .toast-action { border: 0; background: rgba(255,255,255,.14); color: inherit; font-weight: 700; padding: 6px 10px; border-radius: 9px; font-size: 13px; }
.toast.leaving { animation: toastOut .2s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* Splash */
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 200; transition: opacity .3s; }
.splash .spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   TABLET / DESKTOP
   ============================================================ */
@media (min-width: 640px) {
  .main { max-width: 720px; padding-left: 24px; padding-right: 24px; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  dialog.sheet[open] { align-items: center; }
  .sheet-panel { max-width: 480px; border-radius: 24px; margin: 24px; padding: 24px; animation: popIn .22s cubic-bezier(.2, .9, .3, 1.1) both; }
  .sheet-grab { display: none; }
  .toasts { top: auto; bottom: 24px; }
}
@keyframes popIn { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }

@media (min-width: 1024px) {
  body { font-size: 15px; }
  .shell { display: grid; grid-template-columns: 264px 1fr; }
  .topbar, .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 24px;
    position: sticky; top: 0; height: 100dvh;
    padding: 24px 16px; border-right: 1px solid var(--border); background: var(--surface);
  }
  .sidebar .brand { padding: 0 8px; }
  .sidebar .brand-mark { background: linear-gradient(150deg, #14918a, #0b5d57); border: 0; }
  .sidebar .brand-name { color: var(--text); }
  .sidebar .brand-tag { color: var(--muted); opacity: 1; }
  .side-nav { display: grid; gap: 4px; }
  .side-link {
    display: flex; align-items: center; gap: 12px; padding: 11px 12px;
    border: 0; border-radius: 12px; background: none; color: var(--text-2);
    font-weight: 600; font-size: 14.5px; text-align: left;
    transition: background-color .12s, color .12s;
  }
  .side-link:hover { background: var(--surface-2); }
  .side-link.active { background: var(--brand-soft); color: var(--brand); }
  .side-cta { margin-top: 4px; }
  .side-user { margin-top: auto; display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); }
  .side-user .n { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .side-user .h { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .side-user > div { min-width: 0; flex: 1; }
  .side-foot { font-size: 11.5px; color: var(--muted); padding: 0 8px; }
  .side-foot a { color: var(--text-2); text-decoration: none; font-weight: 600; }

  .main { max-width: 1160px; padding: 32px 40px 48px; margin: 0; }
  .page-head h1, .hello h1 { font-size: 30px; }

  .home-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 24px; align-items: start; }
  .home-grid > .stack { margin-top: 0; }
  .home-grid .card + .card { margin-top: 0; }
  .home-side { display: grid; gap: 24px; position: sticky; top: 32px; }

  .trend-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 24px; align-items: start; }
  .trend-grid .card + .card { margin-top: 0; }
  .chart-wrap { height: 340px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  .history-tools { grid-template-columns: 1fr auto; align-items: center; }
  .entry-row { grid-template-columns: 44px 1fr auto auto; padding: 14px 20px; }
  .row-actions { display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
  .entry-row:hover .row-actions, .entry-row:focus-within .row-actions { opacity: 1; }

  .profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
  .profile-grid .section-title:first-child { margin-top: 0; }
  .footer-note.mobile-only { display: none; }
}

/* Pregnancy (mandatory for female members) */
.preg-block {
  margin-top: 14px; padding: 14px; border-radius: var(--r-md);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
}
.preg-block .field-label { margin-bottom: 8px; }
.preg-block .segmented { background: var(--surface); }
.preg-block .segmented button.active { background: var(--accent); color: #fff; }
.preg-block .due { margin-top: 12px; }
.preg-hint { margin-top: 10px; font-size: 12px; line-height: 1.45; color: var(--text-2); }
.req { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.preg-tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700;
}
.preg-tag .icon { width: 13px; height: 13px; }
.targets.is-preg { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.targets.is-preg .icon { color: var(--accent); }
.hours-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.hours-row .field-label { margin: 0; }
.hours-row .segmented { min-width: 168px; }
.hours-row .segmented button { min-height: 34px; font-size: 13px; }
.required-ico { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 14px; }
.sheet.locked .sheet-grab { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Graaphix */
