/* Sift styles. Warm sand palette, light and dark, following the agreed mockups. */

:root {
  --bg: #F6EFE3; --card: #FBF6EC; --line: #ECE0CA; --line2: #E3D5C1;
  --text: #2C2118; --text2: #5C4E3F; --muted: #8A7A68;
  --accent: #C1592E; --on-accent: #FBF6EC; --soft: #F1E2CE; --ink: #8A4A2A;
  --protein: #C1592E; --protein-t: #EAC4B0;
  --carbs: #D9A441; --carbs-t: #F0DDB0;
  --fat: #6B7A4F; --fat-t: #D7DCC3;
  --fibre: #5B7C8A; --fibre-t: #C9DCE0;
  --alcohol: #8B5A6B;
  --over: #A6402A; --over-soft: #F3DCD2;
  --shadow: 0 6px 14px rgba(193, 89, 46, 0.35);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #211A15; --card: #2A221B; --line: #3A2F26; --line2: #3A2F26;
  --text: #F3EAD9; --text2: #D9CBB8; --muted: #A89985;
  --accent: #E5824C; --on-accent: #211A15; --soft: #3A2A1E; --ink: #F1C79C;
  --protein: #E5824C; --protein-t: #4A3626;
  --carbs: #E8B75A; --carbs-t: #4C4126;
  --fat: #93A56E; --fat-t: #37402A;
  --fibre: #6FA0AF; --fibre-t: #26363B;
  --alcohol: #B57E90;
  --over: #E9997E; --over-soft: #3A241C;
  --shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg: #211A15; --card: #2A221B; --line: #3A2F26; --line2: #3A2F26;
    --text: #F3EAD9; --text2: #D9CBB8; --muted: #A89985;
    --accent: #E5824C; --on-accent: #211A15; --soft: #3A2A1E; --ink: #F1C79C;
    --protein: #E5824C; --protein-t: #4A3626;
    --carbs: #E8B75A; --carbs-t: #4C4126;
    --fat: #93A56E; --fat-t: #37402A;
    --fibre: #6FA0AF; --fibre-t: #26363B;
    --alcohol: #B57E90;
    --over: #E9997E; --over-soft: #3A241C;
    --shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: 'Public Sans', system-ui, sans-serif; font-size: 14px; line-height: 1.35;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
input, select { font: inherit; color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1, h2 { font-family: 'Fraunces', Georgia, serif; font-weight: 600; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }
.h-sm { font-size: 19px; }

#app { max-width: 480px; margin: 0 auto; min-height: 100vh; }
.screen {
  padding: calc(22px + env(safe-area-inset-top)) 22px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; min-height: 100vh;
}
.screen.with-nav { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.screen.centred { justify-content: center; }
.loading { padding: 40vh 0; text-align: center; color: var(--muted); }

.num { font-family: 'Fraunces', Georgia, serif; font-weight: 600; }
.num.sm { font-size: 14px; }
.big { font-size: 36px; line-height: 1; }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.muted { color: var(--muted); }
.over { color: var(--over); }
.centre { text-align: center; }
.indent { padding: 0 4px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hidden { display: none; }
.spacer { flex: 1; }
.rule { height: 1px; background: var(--line); margin: 4px 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.note { color: var(--muted); font-size: 13px; margin: 0; }
.note.warn { color: var(--ink); background: var(--soft); border-radius: 12px; padding: 10px 12px; }
.brand { font-size: 44px; text-align: center; margin-bottom: 18px; }

/* header */
.head { display: flex; justify-content: space-between; align-items: flex-start; }
.head-simple { display: flex; align-items: center; gap: 12px; }
.kicker { font-size: 12px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.title-row { display: flex; align-items: center; gap: 6px; margin: 2px 0 8px -6px; }
.arrow { width: 26px; height: 26px; display: grid; place-items: center; color: var(--muted); border-radius: 13px; }
.arrow:disabled { opacity: 0.25; }
.round {
  width: 36px; height: 36px; flex: none; border-radius: 18px; border: 1px solid var(--line2);
  background: var(--card); display: grid; place-items: center; color: var(--text2);
}

.pill {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 7px; padding: 4px 10px;
  border-radius: 12px; background: var(--soft); color: var(--ink); font-size: 12px; font-weight: 600;
}
.pill-over { background: var(--over-soft); color: var(--over); }
.streak { margin-top: 0; }
.flame { fill: var(--accent); stroke: none; }

.banner {
  position: sticky; top: 0; z-index: 5; text-align: center; font-size: 12px; font-weight: 600;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px; background: var(--soft); color: var(--ink);
}

/* ring */
.ring-wrap { position: relative; width: 204px; height: 204px; margin: 0 auto; }
.ring { width: 100%; height: 100%; }
.ring-centre { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.arc { fill: none; stroke-width: 15; }
.t-protein { stroke: var(--protein-t); } .f-protein { stroke: var(--protein); }
.t-carbs { stroke: var(--carbs-t); } .f-carbs { stroke: var(--carbs); }
.t-fat { stroke: var(--fat-t); } .f-fat { stroke: var(--fat); }
.f-alcohol { stroke: var(--alcohol); }

/* macro grid */
.macro-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.macro-top { display: flex; align-items: baseline; gap: 5px; }
.macro-name { font-weight: 600; font-size: 12px; }
.macro-val { margin-left: auto; font-size: 11px; color: var(--text2); }
.dot { width: 8px; height: 8px; border-radius: 4px; display: inline-block; margin-right: 4px; vertical-align: 1px; }
.d-protein { background: var(--protein); } .d-carbs { background: var(--carbs); }
.d-fat { background: var(--fat); } .d-fibre { background: var(--fibre); } .d-alcohol { background: var(--alcohol); }
.bar { height: 6px; border-radius: 3px; overflow: hidden; margin: 5px 0 3px; }
.bar > div { height: 100%; border-radius: 3px; }
.bar.t-protein { background: var(--protein-t); } .bar > .f-protein { background: var(--protein); }
.bar.t-carbs { background: var(--carbs-t); } .bar > .f-carbs { background: var(--carbs); }
.bar.t-fat { background: var(--fat-t); } .bar > .f-fat { background: var(--fat); }
.bar.t-fibre { background: var(--fibre-t); } .bar > .f-fibre { background: var(--fibre); }
.bar.track-plain { background: var(--line); margin-top: 8px; }
.bar > .f-over { background: var(--over); }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 11px 14px; width: 100%; }
.meal { display: flex; align-items: center; gap: 12px; }
.mini-ring { width: 40px; height: 40px; flex: none; }
.mr-track { fill: none; stroke: var(--protein-t); stroke-width: 5; }
.mr-fill { fill: none; stroke: var(--protein); stroke-width: 5; stroke-linecap: round; }
.mr-fill.is-over { stroke: var(--over); }
.meal-mid { flex: 1; min-width: 0; }
.meal-name { font-weight: 600; font-size: 13px; }
.meal-kcal { text-align: right; flex: none; }
.minis { display: flex; gap: 3px; margin-top: 5px; }
.mini { flex: 1; height: 4px; border-radius: 2px; overflow: hidden; }
.mini > div { height: 100%; }
.mini.t-protein { background: var(--protein-t); } .mini > .f-protein { background: var(--protein); }
.mini.t-carbs { background: var(--carbs-t); } .mini > .f-carbs { background: var(--carbs); }
.mini.t-fat { background: var(--fat-t); } .mini > .f-fat { background: var(--fat); }
.small-card { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; min-width: 0; }

/* bottom nav */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; max-width: 480px; margin: 0 auto;
  display: flex; justify-content: space-around; align-items: center;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px; color: var(--muted); font-size: 10px; font-weight: 600; }
.nav-item.on { color: var(--ink); }
.nav-add {
  width: 52px; height: 52px; border-radius: 26px; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; margin-top: -26px; box-shadow: var(--shadow);
}
.nav-add svg { stroke-width: 2.4; }

/* chips, pills, segments */
.chip-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.chips-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  text-align: center; font-size: 12px; font-weight: 600; padding: 8px 12px; border-radius: 11px;
  background: var(--card); border: 1px solid var(--line2); color: var(--text2);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pills { align-items: stretch; }
.pill-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px; font-weight: 600; font-size: 13px;
  border-radius: 13px; background: var(--card); border: 1px solid var(--line2); color: var(--text2); padding: 11px;
}
.search {
  display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line2);
  border-radius: 13px; padding: 0 12px; color: var(--muted);
}
.search input { border: 0; background: transparent; outline: none; width: 100%; padding: 11px 0; color: var(--text); }
.seg { display: flex; background: var(--line); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { padding: 5px 11px; border-radius: 7px; font-size: 11px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); }
.tag { font-size: 9px; font-weight: 700; color: var(--ink); background: var(--soft); padding: 2px 6px; border-radius: 6px; text-transform: uppercase; }
.link { color: var(--ink); font-weight: 600; font-size: 12px; }
.link.centre { align-self: center; padding: 8px; }

/* results */
.section-label { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin-top: 6px; }
.result { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); width: 100%; }
.result-main { flex: 1; padding: 11px 0; min-width: 0; display: block; }
button.result { padding: 11px 0; flex-direction: column; align-items: flex-start; }
.result-name { font-size: 13px; font-weight: 600; }
.quick { width: 30px; height: 30px; border-radius: 15px; background: var(--soft); color: var(--ink); display: grid; place-items: center; flex: none; }
.quick svg { stroke-width: 2.4; }

/* amount */
.macro-row { display: flex; justify-content: space-between; text-align: center; }
.mcell { flex: 1; }
.mcell .num { font-size: 16px; }
.mcell + .mcell { border-left: 1px solid var(--line); }
.select { background: transparent; border: 0; font-weight: 600; color: var(--text2); text-align: right; max-width: 60%; }
.select.wide { background: var(--card); border: 1px solid var(--line2); border-radius: 11px; padding: 9px 12px; max-width: none; text-align: left; }
.stepper { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; }
.step-mid { text-align: center; flex: 1; }
.qty { width: 120px; text-align: center; border: 0; background: transparent; font-size: 24px; outline: none; }

/* forms */
.flabel { display: flex; flex-direction: column; gap: 5px; font-size: 11px; font-weight: 600; color: var(--muted); }
.flabel.missing .field { border-color: var(--accent); }
.field {
  background: var(--card); border: 1px solid var(--line2); border-radius: 11px; padding: 10px 12px;
  font-size: 14px; font-weight: 500; color: var(--text); width: 100%; outline: none;
}
.field:focus { border-color: var(--accent); }
.field.readonly { color: var(--muted); min-height: 41px; }
.cta {
  width: 100%; text-align: center; background: var(--accent); color: var(--on-accent);
  font-size: 15px; font-weight: 600; padding: 14px; border-radius: 16px;
}
.cta.slim { padding: 10px; font-size: 13px; border-radius: 12px; }

/* sheet and toast */
.overlay { position: fixed; inset: 0; z-index: 10; background: rgba(28, 20, 14, 0.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 480px; max-height: 80vh; overflow-y: auto; background: var(--bg);
  border-radius: 20px 20px 0 0; padding: 20px 22px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px;
}
.sheet .cta { margin-top: 12px; }
.entry { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.entry-main { flex: 1; padding: 10px 0; min-width: 0; }
.entry-name { font-size: 13px; font-weight: 600; }
.icon-btn { width: 30px; height: 30px; display: grid; place-items: center; color: var(--muted); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(100px + env(safe-area-inset-bottom)); z-index: 20;
  width: calc(100% - 44px); max-width: 436px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: 12px; font-size: 13px;
}
.toast button { color: var(--accent); font-weight: 700; }

/* scanner */
.viewfinder { position: relative; border-radius: 16px; overflow: hidden; background: #17130F; aspect-ratio: 4 / 3; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; }
.frame { position: absolute; inset: 22% 12%; border: 3px solid var(--accent); border-radius: 12px; }
