/* Nutriful — mobile-first PWA styling. No framework, no build step. */

:root {
  /* Mint — used ONLY for app chrome (top nav, tabs, selected states) */
  --mint: #a7efc5;
  --mint-deep: #42b883;     /* primary buttons, links, active accents */
  --mint-deep-h: #36a874;
  --mint-tint: #e6f7ee;
  /* Spectrum accents — buttons, charts, badges (used sparingly) */
  --teal: #4db6ac;
  --coral: #ff6b6b;
  --mango: #ffb547;
  --mango-h: #f59e0b;
  --lavender: #8b7cf8;
  --lavender-h: #7965f2;
  --sky: #64b5f6;
  /* Neutrals */
  --ink: #233238;
  --muted: #6b7b78;
  --disabled: #b8c5c1;
  --line: #e6f0ec;
  --bg: #fafcfb;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  /* Status bands (traffic-light, drawn from the spectrum) */
  --band-excellent: #42b883;
  --band-good: #5bc66a;
  --band-ok: #ffb547;
  --band-over: #ff6b6b;
  /* Legacy aliases → mint family, so untouched rules adopt the new palette */
  --green: var(--mint-deep);
  --green-deep: var(--mint-deep);
  --green-tint: var(--mint-tint);
  --green-leaf: var(--mint);
  /* layout */
  --rail-h: 30px;
  --appbar-h: 58px;
  --safe-top: env(safe-area-inset-top);
  --topbar-h: calc(var(--rail-h) + var(--appbar-h) + var(--safe-top));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Enforce the `hidden` attribute even on elements whose class sets `display`
   (a class selector otherwise ties [hidden] on specificity and wins on order).
   The drawer is the one exception — it stays in the box to animate off-screen. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
  padding-top: var(--topbar-h);
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h3 { font-size: 1rem; }
p { margin: .3em 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mt8 { margin-top: 8px; }
.center { text-align: center; }

/* ───────── Top bar (food rail + nav) ───────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  padding-top: var(--safe-top); background: var(--mint);
  box-shadow: var(--shadow);
}
.food-rail {
  height: var(--rail-h); overflow: hidden; background: var(--mint);
  border-bottom: 1px solid rgba(0, 0, 0, .06); display: flex; align-items: center;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}
.rail-track {
  white-space: nowrap; font-size: 17px; letter-spacing: 6px; line-height: 1;
  padding-left: 10px; will-change: transform;
  animation: rail 48s linear infinite;
}
@keyframes rail { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .rail-track { animation: none; } }

.appbar {
  height: var(--appbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: var(--mint); color: var(--ink);
}
.brand { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.logo-badge {
  width: 38px; height: 38px; border-radius: 50%; background: #fff;
  display: grid; place-items: center; flex: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}
.logo-badge img { width: 32px; height: 32px; }
.brand-name { font-weight: 800; font-size: 1.2rem; letter-spacing: .2px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }

.appbar-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.icon-btn {
  background: transparent; border: 0; color: inherit; font-size: 1.35rem;
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { background: rgba(0, 0, 0, .08); }
.chip {
  background: var(--mint-deep); color: #fff; border: 0;
  padding: 5px 11px; border-radius: 999px; font-size: .8rem; font-weight: 700;
  white-space: nowrap; display: inline-flex; align-items: center; gap: 4px;
}
.chip .crown { font-size: .85rem; }

/* ───────── Buttons / inputs ───────── */
.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 12px 16px;
  font-size: .95rem; font-weight: 600; cursor: pointer; width: 100%;
  transition: transform .04s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--mint-deep); color: #fff; }            /* Reveal Nutrition */
.btn-primary:active, .btn-primary:hover { background: var(--mint-deep-h); }
.btn-ghost { background: var(--mint-tint); color: var(--mint-deep); }   /* secondary / cancel */
.btn-sm { padding: 8px 12px; font-size: .85rem; width: auto; }
.btn-danger { background: #ffecec; color: var(--coral); }
.btn-mango { background: var(--mango); color: var(--ink); }            /* On my plate */
.btn-mango:active, .btn-mango:hover { background: var(--mango-h); color: #fff; }
.btn-lavender { background: var(--lavender); color: #fff; }            /* Ate this today */
.btn-lavender:active, .btn-lavender:hover { background: var(--lavender-h); }
.btn[disabled] { opacity: .5; pointer-events: none; }

.input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px;
  font-size: 16px; /* ≥16px stops iOS zoom-on-focus */ background: #fff; color: var(--ink);
  font-family: inherit;
}
.input:focus { outline: 2px solid var(--green); border-color: var(--green); }
textarea.input { resize: vertical; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px; background-size: 5px 5px; background-repeat: no-repeat; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.check input { width: 18px; height: 18px; accent-color: var(--green); }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin: 12px;
}

/* ───────── Segmented control ───────── */
.seg { display: flex; background: var(--bg); border-radius: 11px; padding: 3px; gap: 3px; }
.seg-btn {
  flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px;
  font-weight: 600; font-size: .88rem; color: var(--muted); cursor: pointer;
}
.seg-btn.active { background: #fff; color: var(--green-deep); box-shadow: var(--shadow); }
.seg-sm .seg-btn { padding: 7px 4px; font-size: .8rem; }

/* ───────── Auth ───────── */
.auth-screen {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  padding-top: calc(env(safe-area-inset-top) + 16px);
  overflow-y: auto;
}
.auth-card { width: 100%; max-width: 400px; margin: 0; }
.auth-hero { text-align: center; margin-bottom: 16px; }
.auth-hero img { width: 64px; height: 64px; border-radius: 16px; }
.auth-hero h1 { font-size: 1.4rem; margin: 8px 0 2px; }
.auth-hero p { color: var(--muted); margin: 0; }
.auth-card .seg { margin-bottom: 14px; }
.divider { display: flex; align-items: center; text-align: center; color: var(--muted); margin: 16px 0; font-size: .8rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.divider span { padding: 0 12px; }

/* ───────── Drawer ───────── */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 45; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50; width: min(86vw, 360px);
  background: var(--bg); box-shadow: 2px 0 16px rgba(0, 0, 0, .2);
  overflow-y: auto; padding-bottom: 40px;
  transform: translateX(0); transition: transform .22s ease;
}
.drawer[hidden] { display: block !important; transform: translateX(-100%); pointer-events: none; }
.drawer-head {
  position: sticky; top: 0; background: var(--mint); color: var(--ink); z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; padding-top: calc(env(safe-area-inset-top) + 14px);
}
.drawer-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.drawer-logo { width: 38px; height: 38px; background: #fff; border-radius: 50%; padding: 3px; flex: none; }
.drawer-title { font-weight: 800; font-size: 1.05rem; line-height: 1.1; }
.drawer-tag { font-size: .66rem; opacity: .9; line-height: 1.2; }
.drawer-sec { padding: 14px 16px; border-bottom: 8px solid var(--bg); background: #fff; }
.drawer-sec h3 { margin-bottom: 8px; }
details summary { cursor: pointer; color: var(--green-deep); font-weight: 600; font-size: .9rem; }
.src-panel { margin-top: 4px; }

.chips-select { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-toggle {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 5px 10px; border-radius: 999px; font-size: .8rem; cursor: pointer;
}
.chip-toggle.on { background: var(--green); color: #fff; border-color: var(--green); }

/* dish list in drawer */
.dish-list { display: flex; flex-direction: column; gap: 8px; }
.dish-item { border: 1px solid var(--line); border-radius: 11px; overflow: hidden; }
.dish-item summary { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; font-weight: 600; }
.dish-item .dish-body { padding: 0 12px 12px; font-size: .85rem; color: var(--muted); }
.dish-item .dish-body li { margin: 2px 0; }
.owner-tag { font-weight: 400; color: var(--muted); font-size: .78rem; }

/* ───────── Tabs ───────── */
.tabs {
  position: sticky; top: var(--topbar-h); z-index: 20;
  display: flex; background: var(--card); box-shadow: var(--shadow);
}
.tab {
  flex: 1; border: 0; background: transparent; padding: 13px 6px; font-weight: 600;
  color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; font-size: .92rem;
}
.tab.active { color: var(--green-deep); border-bottom-color: var(--green); }
.tab-panel { padding: 4px 0 80px; }
.empty { text-align: center; color: var(--muted); padding: 40px 24px; }

/* ───────── Result rendering ───────── */
.macro-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.metric { background: var(--green-tint); border-radius: 11px; padding: 10px 6px; text-align: center; }
.metric .v { font-size: 1.15rem; font-weight: 700; color: var(--green-deep); }
.metric .l { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
/* Distinct colour per macro so the summary isn't all-green. */
.metric.m-cal  { background: #fff3dd; }  .metric.m-cal .v  { color: #c98a12; }  /* mango */
.metric.m-pro  { background: #e9f0ff; }  .metric.m-pro .v  { color: #2f6be6; }  /* blue   */
.metric.m-carb { background: #ffefd6; }  .metric.m-carb .v { color: #b9760a; }  /* orange */
.metric.m-fat  { background: #fcf6da; }  .metric.m-fat .v  { color: #9a7b00; }  /* yellow */

/* Dish emoji icons */
.dish-ic { margin-right: 6px; }
.dish-ic-lg { font-size: 1.7rem; line-height: 1; }
.name-row { display: flex; align-items: center; gap: 8px; }
.name-row .input { flex: 1; }

.conf { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.conf-dot { width: 9px; height: 9px; border-radius: 50%; }

.section-title { font-weight: 700; margin: 16px 4px 8px; }

table.ntab { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.ntab th { text-align: left; color: var(--muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; padding: 6px 6px; border-bottom: 1px solid var(--line); }
table.ntab td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.ntab td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.band-pill { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.cat-dot { display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 7px; vertical-align: middle; }
.star { color: var(--mango-h); }
.legend { font-size: .76rem; color: var(--muted); margin-top: 8px; display: flex; flex-wrap: wrap; gap: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }

.note { border-radius: 11px; padding: 10px 12px; margin-top: 8px; font-size: .87rem; }
.note-info { background: #f0edfe; border-left: 3px solid var(--lavender); }  /* AI insight */
.note-good { background: var(--mint-tint); border-left: 3px solid var(--mint-deep); }
.note-warn { background: #fff4e0; border-left: 3px solid var(--mango); }
.note-bad { background: #ffecec; border-left: 3px solid var(--coral); }

/* ───────── Day wheel ───────── */
.wheel-card { padding: 14px 8px 12px; }
.wheel-head { padding: 0 8px 2px; }
.wheel-svg { width: 100%; max-width: 340px; height: auto; display: block; margin: 2px auto 0; }
.wheel-svg .wedge { cursor: pointer; }
.wheel-svg .wedge:active { opacity: .72; }
.wlab { font-size: 12px; }
.wemoji { font-size: 14px; }
.wpct { font-size: 9px; font-weight: 700; fill: var(--ink); }
.wscore { font-size: 27px; font-weight: 800; fill: var(--mint-deep); }
.wscore-l { font-size: 8.5px; fill: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.wscore-m { font-size: 8.5px; fill: var(--mint-deep); font-weight: 700; }
.wheel-detail { margin: 8px; max-height: 0; overflow: hidden; transition: none; }
.wheel-detail.open { max-height: none; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.wd-title { font-weight: 800; margin-bottom: 6px; }
.wd-item { font-size: .9rem; padding: 3px 0; display: flex; align-items: center; gap: 7px; }
.wd-item .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.wd-need { margin-top: 8px; font-weight: 700; color: var(--mango-h); }
.wd-sug { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.wd-chip { font-size: .8rem; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; background: #fff; }
.wheel-legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px; }
.wleg { display: inline-flex; align-items: center; gap: 5px; font-size: .76rem; border: 1px solid var(--line); border-radius: 999px; padding: 4px 9px; background: #fff; cursor: pointer; }
.wleg .dot { width: 9px; height: 9px; border-radius: 50%; }
.wleg b { font-weight: 800; }
.wleg-h { width: 100%; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 6px 0 0; font-weight: 700; }

/* ───────── Plate (food groups) ───────── */
.plate-toggle { margin: 8px 4px 0; }
.plate-view { margin-top: 2px; }
.plate-note { text-align: center; margin: 4px 8px 2px; }
.plate-svg { width: 100%; max-width: 300px; height: auto; display: block; margin: 8px auto 0; filter: drop-shadow(0 2px 5px rgba(0, 0, 0, .1)); }
.plate-svg .slice { cursor: pointer; }
.plate-svg .slice:active { opacity: .72; }
.slice-emoji { font-size: 15px; }
.slice-emoji-lg { font-size: 21px; }                 /* bigger icons */
.slice-num { font-size: 10px; font-weight: 700; fill: var(--ink); }
.slice-count { font-size: 14px; font-weight: 800; fill: #fff; }
.plate-score { font-size: 25px; font-weight: 800; }
.plate-score-l { font-size: 8.5px; fill: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
/* Colours = rainbow of stacked arcs */
.rainbow-svg { width: 100%; max-width: 300px; height: auto; display: block; margin: 10px auto 2px; }
.rainbow-svg .rband { cursor: pointer; }
.rainbow-svg .rband:active { opacity: .65; }
.rainbow-count { font-size: 11px; fill: var(--muted); font-weight: 700; }

.ing-line { display: flex; justify-content: space-between; gap: 12px; padding: 7px 6px; border-bottom: 1px solid var(--line); font-size: .87rem; }
.ing-line .prep { color: var(--muted); font-size: .8rem; }

.list-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; background: #fff; border-radius: 11px; box-shadow: var(--shadow); margin-bottom: 8px; }

/* editable draft table */
.draft h2 { font-size: 1.1rem; }
.draft-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.draft-row { display: grid; grid-template-columns: 1fr; gap: 6px; border: 1px solid var(--line); border-radius: 11px; padding: 10px; }
.draft-row .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.draft-row .grid3 { display: grid; grid-template-columns: 2fr 1fr auto; gap: 6px; align-items: center; }
.draft-row .input { font-size: 15px; padding: 8px 10px; }
.rm-row { background: #fdecec; color: var(--band-over); border: 0; border-radius: 9px; width: 38px; height: 38px; font-size: 1rem; cursor: pointer; }
.dish-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ing-search { margin-top: 4px; }
.ing-results { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.ing-result { font-size: .82rem; border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; background: #fff; cursor: pointer; color: var(--ink); text-align: left; }
.ing-result:active { background: var(--mint-tint); border-color: var(--mint-deep); }

.inline-field { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.inline-field label { font-size: .85rem; color: var(--muted); }
.inline-field .input { width: 90px; }
.row-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.row-actions .btn { width: auto; flex: 1; white-space: nowrap; }

/* ───────── Nutrient list (rich rows) ───────── */
.ntable { margin-top: 4px; }
.nrow { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.nrow:last-child { border-bottom: 0; }
.nicon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; flex: none; }
.nmain { min-width: 0; }
.nname { font-weight: 700; font-size: .95rem; display: flex; align-items: center; gap: 6px; }
.nsub { color: var(--muted); font-size: .72rem; margin-top: 1px; }
.nprog { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.npct { font-weight: 800; font-size: .78rem; min-width: 42px; }
.nbar { flex: 1; height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.nbar-fill { height: 100%; border-radius: 999px; min-width: 3px; }
.nvals { text-align: right; min-width: 72px; }
.nconsumed { font-weight: 700; font-size: .9rem; white-space: nowrap; }
.ntarget { color: var(--muted); font-size: .72rem; white-space: nowrap; }
.nstar { color: var(--disabled); font-size: .82rem; }
.nstar.on { color: var(--mango-h); }
.nnote { font-size: .72rem; color: var(--mango-h); background: #fff4e0; border-radius: 8px; padding: 5px 8px; margin-top: 6px; line-height: 1.35; }

/* ───────── Collapsible ingredient lists ───────── */
.ing-details { margin: 12px 0 4px; }
.ing-details > summary {
  list-style: none; cursor: pointer; font-weight: 700; padding: 4px 2px;
  display: flex; align-items: center; gap: 6px;
}
.ing-details > summary::-webkit-details-marker { display: none; }
.ing-details > summary::before { content: "▸"; color: var(--muted); font-size: .75rem; }
.ing-details[open] > summary::before { content: "▾"; }
.day-item { border: 1px solid var(--line); border-radius: 11px; background: #fff; box-shadow: var(--shadow); margin-bottom: 8px; }
.day-item > summary {
  list-style: none; cursor: pointer; font-weight: 600;
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
}
.day-item > summary::-webkit-details-marker { display: none; }
.day-item > summary::before { content: "▸"; color: var(--muted); font-size: .8rem; }
.day-item[open] > summary::before { content: "▾"; }
.day-item .day-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-item .btn { flex: none; }
.ing-collapse { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px 30px; }
.ing-chip { font-size: .8rem; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; background: var(--bg); }

/* ───────── Toast / loading ───────── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 60;
  background: #1c2024; color: #fff; padding: 11px 16px; border-radius: 11px;
  font-size: .88rem; box-shadow: 0 4px 16px rgba(0, 0, 0, .25); max-width: 90vw; text-align: center;
}
.toast.err { background: var(--band-over); }
.toast.ok { background: var(--green-deep); }

.loading { position: fixed; inset: 0; z-index: 70; background: rgba(255, 255, 255, .55); display: grid; place-items: center; }
.spinner { width: 38px; height: 38px; border: 4px solid var(--green-tint); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 640px) {
  main, .auth-screen { max-width: 720px; margin-left: auto; margin-right: auto; }
}
