/* Layout: one thumb-reach column (max 560px). A Nutrition-Facts style panel for the day's totals,
   meal ledgers below, and a fixed action bar with Scan as the main action. Sheets slide up for adding. */

@font-face {
  font-family: "Archivo";
  src: url("fonts/archivo-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Archivo";
  src: url("fonts/archivo-latin-ext.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Plex Mono";
  src: url("fonts/plex-mono-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* Themes: no data-theme = Automatic (White or Dark, following the iPhone setting);
   data-theme="light" = White, "dark" = Dark, "blue" = Light blue. */
:root {
  --ground: #ffffff;
  --panel: #ffffff;
  --ink: #121412;
  --muted: #5b615b;
  --rule: #121412;
  --hair: #e1e4df;
  --hair-strong: #b9bfb7;
  --accent: #d63c22;
  --accent-ink: #ffffff;
  --danger: #a8291a;
  --protein: #2b62c9;
  --carbs: #b98004;
  --fat: #18805a;
  --scrim: rgba(18, 20, 18, 0.38);
  --camera: #000000;
  --on-camera: #ffffff;

  --f-display: "Archivo", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Archivo", -apple-system, "Helvetica Neue", Arial, sans-serif;
  --f-mono: "Plex Mono", ui-monospace, Menlo, monospace;

  --radius: 14px;
  --bar-h: 76px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --ground: #000000;
    --panel: #151816;
    --ink: #eef1ec;
    --muted: #9ba29b;
    --rule: #eef1ec;
    --hair: #262a27;
    --hair-strong: #3d443e;
    --accent: #ff6a4d;
    --accent-ink: #1a0703;
    --danger: #ff8f80;
    --protein: #7ea8ff;
    --carbs: #f0bb45;
    --fat: #4fcf98;
    --scrim: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #000000;
  --panel: #151816;
  --ink: #eef1ec;
  --muted: #9ba29b;
  --rule: #eef1ec;
  --hair: #262a27;
  --hair-strong: #3d443e;
  --accent: #ff6a4d;
  --accent-ink: #1a0703;
  --danger: #ff8f80;
  --protein: #7ea8ff;
  --carbs: #f0bb45;
  --fat: #4fcf98;
  --scrim: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}
:root[data-theme="blue"] {
  --ground: #dcebf9;
  --panel: #ffffff;
  --ink: #0b2545;
  --muted: #4a6283;
  --rule: #0b2545;
  --hair: #c3d7ee;
  --hair-strong: #94b3d6;
  --accent: #1d63c9;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --protein: #7048c8;
  --carbs: #b07a00;
  --fat: #12805a;
  --scrim: rgba(11, 37, 69, 0.38);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
img { max-width: 100%; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.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;
}
.muted { color: var(--muted); }
.mono { font-family: var(--f-mono); letter-spacing: 0.06em; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- page ---------- */
.app {
  max-width: 560px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: calc(env(safe-area-inset-top, 0px) + 8px) calc(var(--bar-h) + env(safe-area-inset-bottom, 0px) + 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar { display: flex; align-items: center; gap: 4px; padding-top: 4px; }
.date-btn {
  flex: 1; min-width: 0; text-align: left;
  display: flex; flex-direction: column; padding: 2px 0;
}
.date-main {
  font-family: var(--f-display); font-stretch: 72%; font-weight: 850;
  font-size: 30px; line-height: 1; letter-spacing: -0.005em;
}
.date-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px;
  display: inline-grid; place-items: center;
}
.icon-btn:active { background: var(--hair); }
.icon-btn:disabled { opacity: 0.3; }
.settings-btn { margin-left: 6px; }

/* week strip */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day {
  display: grid; justify-items: center; gap: 3px;
  padding: 6px 0 7px; border-radius: 12px;
  font-size: 12px; color: var(--muted);
}
.day .dow { font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; font-size: 11px; }
.day .dnum { font-family: var(--f-display); font-stretch: 80%; font-weight: 750; font-size: 18px; color: var(--ink); line-height: 1.1; }
.day .track { width: 6px; height: 26px; border-radius: 3px; background: var(--hair); position: relative; overflow: hidden; }
.day .fill { position: absolute; left: 0; right: 0; bottom: 0; background: var(--ink); border-radius: 3px; }
.day.over .fill { background: var(--accent); }
.day.today .dow { color: var(--accent); }
.day[aria-current="date"] { background: var(--ink); }
.day[aria-current="date"] .dow, .day[aria-current="date"] .dnum { color: var(--ground); }
.day[aria-current="date"] .track { background: color-mix(in srgb, var(--ground) 25%, transparent); }
.day[aria-current="date"] .fill { background: var(--ground); }
.day[aria-current="date"].over .fill { background: var(--accent); }

.install-tip {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1.5px dashed var(--hair-strong); border-radius: var(--radius);
  padding: 12px 14px; font-size: 14px;
}
.install-tip p { margin: 0; flex: 1; min-width: 0; }

/* ---------- the Daily Facts panel ---------- */
.label {
  background: var(--panel);
  border: 1.5px solid var(--rule);
  padding: 8px 12px 10px;
}
.label-title {
  margin: 0;
  font-family: var(--f-display); font-stretch: 66%; font-weight: 900;
  font-size: clamp(42px, 13vw, 58px); line-height: 0.92; letter-spacing: -0.01em;
}
.label-sub { margin: 4px 0 6px; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.rule-thick { height: 10px; background: var(--rule); }
.rule-mid { height: 5px; background: var(--rule); }
.cal-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-top: 4px; }
.cal-word { font-family: var(--f-display); font-stretch: 72%; font-weight: 900; font-size: 30px; }
.cal-num { font-family: var(--f-display); font-stretch: 70%; font-weight: 900; font-size: 52px; line-height: 1; }
.meter { height: 8px; background: var(--hair); margin: 6px 0 4px; position: relative; overflow: hidden; }
.meter > span { position: absolute; inset: 0 auto 0 0; background: var(--ink); }
.meter.over > span {
  background: repeating-linear-gradient(135deg, var(--accent) 0 6px, var(--ink) 6px 9px);
}
.cal-left { margin: 0 0 6px; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.cal-left b { font-weight: 800; }
.dv-head { margin: 0; padding: 3px 0; text-align: right; font-size: 13px; font-weight: 800; }
.macro { border-top: 1px solid var(--rule); padding: 5px 0 6px; }
.macro-line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 15px; }
.macro-line b { font-weight: 800; }
.macro-line .of { color: var(--muted); font-size: 13px; }
.mbar { height: 4px; background: var(--hair); margin-top: 5px; position: relative; overflow: hidden; border-radius: 2px; }
.mbar > span { position: absolute; inset: 0 auto 0 0; background: var(--c); border-radius: 2px; }
.footnote { margin: 6px 0 0; font-size: 12px; line-height: 1.35; color: var(--ink); }

/* ---------- meals ---------- */
.meal { display: flex; flex-direction: column; }
.meal-head {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 6px; border-bottom: 2.5px solid var(--rule);
}
.meal-head h2 {
  margin: 0; flex: 1;
  font-family: var(--f-display); font-stretch: 75%; font-weight: 850;
  font-size: 22px; line-height: 1.1;
}
.meal-kcal { font-weight: 700; font-size: 15px; }
.meal-kcal small { font-weight: 500; color: var(--muted); font-size: 12px; }
.add-mini {
  width: 36px; height: 36px; border-radius: 10px; border: 1.5px solid var(--rule);
  display: grid; place-items: center;
}
.add-mini svg { width: 18px; height: 18px; }
.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  width: 100%; text-align: left;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--hair);
}
.entry:active { background: var(--hair); }
.e-main { min-width: 0; display: flex; flex-direction: column; }
.e-name { font-weight: 650; overflow-wrap: anywhere; }
.e-meta { font-size: 13px; color: var(--muted); }
.e-side { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.e-kcal { font-weight: 750; }
.e-kcal small { font-weight: 500; font-size: 12px; color: var(--muted); }
.e-macros { font-size: 12px; color: var(--muted); white-space: nowrap; }
.meal-empty { margin: 0; padding: 11px 0; color: var(--muted); font-size: 14px; border-bottom: 1px solid var(--hair); }

.first-run {
  border: 1.5px solid var(--rule); background: var(--panel);
  padding: 14px; display: grid; gap: 6px;
}
.first-run h3 { margin: 0; font-family: var(--f-display); font-stretch: 75%; font-weight: 850; font-size: 22px; }
.first-run p { margin: 0; font-size: 15px; }

.credit { margin: 6px 0 0; font-size: 12px; color: var(--muted); text-wrap: pretty; }

/* ---------- summary of the last days ---------- */
.summary { margin-top: 10px; }
.sum-range { margin: 10px 0; }
.sum-box { background: var(--panel); border: 1.5px solid var(--rule); padding: 8px 12px 10px; }
.sum-box .cal-left { margin: 6px 0 0; }
.sum-box .meal-empty { border: 0; padding: 6px 0; }
.sum-plot, .sum-axis { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); }
.sum-key { margin: 12px 0 0; display: flex; justify-content: flex-end; gap: 14px; font-size: 12px; color: var(--muted); }
.sum-key span { display: inline-flex; align-items: center; gap: 6px; }
.k-goal { width: 16px; border-top: 1.5px dashed var(--muted); }
.k-over { width: 9px; height: 9px; border-radius: 2px; background: var(--accent); }
.sum-plot { position: relative; height: 120px; margin-top: 6px; border-bottom: 1px solid var(--rule); }
.sbar { position: relative; height: 100%; border-radius: 4px 4px 0 0; }
.sbar .fill {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(22px, calc(100% - 2px)); border-radius: 3px 3px 0 0; background: var(--ink);
}
.sbar.over .fill { background: var(--accent); }
.sbar[aria-pressed="true"] { background: var(--hair); }
.sum-plot.has-sel .sbar:not([aria-pressed="true"]) .fill { opacity: 0.3; }
.sum-goal { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--muted); pointer-events: none; }
.sum-axis { margin-top: 4px; font-size: 11px; line-height: 1.2; color: var(--muted); text-align: center; }
.sum-axis span { display: flex; justify-content: center; white-space: nowrap; }
.sum-axis .today { color: var(--ink); font-weight: 800; }
.sum-readout { margin: 8px 0; min-height: 40px; font-size: 14px; }
.sum-readout b { font-weight: 800; margin-right: 4px; }
.sum-readout .link-btn { margin-left: 6px; white-space: nowrap; }

/* ---------- buttons ---------- */
.btn {
  min-height: 52px; padding: 0 18px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 750; font-size: 16px; line-height: 1.1; text-align: center;
  border: 1.5px solid transparent;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--panel); color: var(--ink); border-color: var(--rule); }
.btn.danger { background: transparent; color: var(--danger); border-color: currentColor; }
.btn.small { min-height: 46px; padding: 0 14px; font-size: 15px; }
.btn.wide { width: 100%; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; }
.text-btn { font-weight: 700; color: var(--accent); padding: 10px 4px; min-height: 44px; }
.link-btn { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; font-size: inherit; }
.link-btn.center { display: block; margin: 14px auto 0; padding: 8px; font-size: 14px; color: var(--muted); }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--ground) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--hair);
  display: grid; grid-template-columns: 1fr 1.35fr; gap: 10px;
}
@supports (width: max(1px, 2px)) {
  .actionbar { padding-left: max(16px, calc((100% - 560px) / 2 + 16px)); padding-right: max(16px, calc((100% - 560px) / 2 + 16px)); }
}

/* ---------- sheets ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
#recipeSheet { z-index: 55; }
#foodSheet { z-index: 60; }
.sheet-backdrop { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity 0.22s ease; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: 600px; margin-inline: auto;
  max-height: calc(100% - env(safe-area-inset-top, 0px) - 18px);
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: var(--ground);
  border-radius: 20px 20px 0 0;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#addSheet .sheet-panel, #recipeSheet .sheet-panel { height: calc(100% - env(safe-area-inset-top, 0px) - 18px); }
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: none; }
.sheet-head {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0 8px; background: var(--ground);
}
.sheet-head::before {
  content: ""; position: absolute; top: 6px; left: 50%; width: 38px; height: 5px; margin-left: -19px;
  border-radius: 3px; background: var(--hair-strong);
}
.sheet-head h2 { margin: 12px 0 0; font-family: var(--f-display); font-stretch: 72%; font-weight: 900; font-size: 28px; line-height: 1; }
.sheet-head .text-btn { margin-top: 10px; }
.sheet-kicker { margin-top: 10px; font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.head-spacer { width: 44px; }

.kicker { display: block; margin: 16px 0 6px; font-size: 12px; font-weight: 750; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }

/* segmented controls */
.meal-picker, .seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px;
  background: var(--hair); border-radius: 12px; padding: 3px;
}
.meal-picker { margin-top: 6px; }
.meal-picker button, .seg button {
  min-height: 40px; border-radius: 9px; padding: 0 6px;
  font-size: 14px; font-weight: 650; color: var(--muted);
}
.meal-picker button[aria-checked="true"], .seg button[aria-pressed="true"] {
  background: var(--panel); color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.tabs { display: flex; gap: 18px; margin: 14px 0 12px; border-bottom: 1px solid var(--hair); overflow-x: auto; }
.tabs button {
  padding: 8px 0 9px; margin-bottom: -1px; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; white-space: nowrap; min-height: 44px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 800; }

/* scanner */
.viewfinder {
  position: relative; width: 100%; max-width: 100%; aspect-ratio: 4 / 3;
  background: var(--camera); color: var(--on-camera);
  border-radius: 16px; overflow: hidden;
}
.viewfinder video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.reticle {
  position: absolute; left: 8%; right: 8%; top: 27%; bottom: 27%;
  border: 2px solid rgba(255, 255, 255, 0.92); border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.42);
}
.laser {
  position: absolute; left: 10px; right: 10px; top: 50%; height: 2px; margin-top: -1px;
  background: var(--accent); box-shadow: 0 0 10px var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }
.vf-msg {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 14px 12px; text-align: center; font-size: 14px; font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  display: grid; justify-items: center; gap: 10px;
}
.vf-msg p { margin: 0; max-width: 34ch; }
.viewfinder:not([data-state="live"]) .reticle { display: none; }
.viewfinder[data-state="denied"] .vf-msg,
.viewfinder[data-state="insecure"] .vf-msg,
.viewfinder[data-state="nocam"] .vf-msg,
.viewfinder[data-state="error"] .vf-msg,
.viewfinder[data-state="found"] .vf-msg,
.viewfinder[data-state="starting"] .vf-msg,
.viewfinder[data-state="paused"] .vf-msg,
.viewfinder[data-state="noscanner"] .vf-msg,
.viewfinder[data-state="idle"] .vf-msg {
  top: 0; align-content: center; text-shadow: none; font-weight: 500;
}
.viewfinder .btn.small { background: var(--on-camera); color: var(--camera); min-height: 42px; }

.row-form { display: flex; gap: 8px; margin-top: 12px; }
.row-form input { flex: 1; min-width: 0; }

input[type="text"], input[type="search"], select {
  width: 100%; height: 48px; padding: 0 12px;
  background: var(--panel); color: var(--ink);
  border: 1.5px solid var(--hair-strong); border-radius: 12px;
  font-size: 16px; appearance: none; -webkit-appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 16px top 21px, right 11px top 21px; background-size: 5px 5px; background-repeat: no-repeat;
  padding-right: 28px;
}
input:focus, select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
input::placeholder { color: var(--muted); opacity: 0.8; }

/* results */
.results { display: flex; flex-direction: column; }
.group-label { margin: 14px 0 2px; font-size: 12px; font-weight: 750; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.result { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--hair); }
.result-main {
  flex: 1; min-width: 0; text-align: left;
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px;
  padding: 10px 0;
}
.thumb {
  width: 44px; height: 44px; border-radius: 9px; object-fit: contain;
  background: var(--panel); border: 1px solid var(--hair);
  display: grid; place-items: center;
  font-family: var(--f-display); font-stretch: 75%; font-weight: 850; font-size: 18px; color: var(--muted);
}
.r-text { min-width: 0; display: flex; flex-direction: column; }
.r-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-meta { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-kcal { text-align: right; font-weight: 750; font-size: 15px; white-space: nowrap; }
.r-kcal small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }
.quick-add {
  width: 40px; height: 40px; border-radius: 10px; flex: none;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
}
.quick-add svg { width: 20px; height: 20px; }
.empty { padding: 26px 4px; text-align: center; color: var(--muted); font-size: 15px; }
.empty b { color: var(--ink); }
.loading { padding: 18px 0; color: var(--muted); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--hair-strong); border-top-color: var(--ink); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* forms */
.stack-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; border: 0; margin: 0; padding: 0; }
.field label, .field legend { font-size: 13px; font-weight: 650; padding: 0; }
.opt { font-weight: 500; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field-row.four input { padding: 0 8px; text-align: center; }
.suffix-input { position: relative; }
.suffix-input input { padding-right: 38px; }
.unit-suffix { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.note {
  margin: 0 0 12px; padding: 10px 12px; font-size: 14px;
  background: var(--panel); border-left: 4px solid var(--accent);
}
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.form-error { margin: 0; font-size: 14px; font-weight: 600; color: var(--danger); }

/* portion sheet */
.food-hero { display: flex; gap: 14px; align-items: flex-start; margin-top: 6px; }
.food-hero img {
  width: 76px; height: 76px; object-fit: contain; flex: none;
  background: #fff; border-radius: 12px; border: 1px solid var(--hair);
}
.food-id { min-width: 0; }
.food-id h2 {
  margin: 0; font-family: var(--f-display); font-stretch: 74%; font-weight: 850;
  font-size: 28px; line-height: 1.02; text-wrap: balance; overflow-wrap: anywhere;
}
.food-id p { margin: 4px 0 0; }
.barcode-digits { font-family: var(--f-mono); font-size: 13px; letter-spacing: 0.14em; color: var(--muted); }
.amount-row { display: flex; gap: 10px; align-items: stretch; }
.amount-row input {
  flex: 1; min-width: 0; height: 56px;
  font-family: var(--f-display); font-stretch: 80%; font-weight: 850; font-size: 30px;
}
.amount-row .seg { flex: none; min-width: 150px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  min-height: 36px; padding: 0 12px; border-radius: 18px;
  border: 1.5px solid var(--hair-strong); background: var(--panel);
  font-size: 14px; font-weight: 600;
}
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--panel); }
.portion .form-error { margin-top: 8px; }

.portion-facts {
  margin-top: 16px; background: var(--panel); border: 1.5px solid var(--rule);
  padding: 8px 12px 10px;
}
.pf-top { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 6px; border-bottom: 6px solid var(--rule); }
.pf-top span { font-family: var(--f-display); font-stretch: 72%; font-weight: 900; font-size: 24px; }
.pf-top b { font-family: var(--f-display); font-stretch: 70%; font-weight: 900; font-size: 40px; line-height: 1; }
.pf-macros { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 8px 0 6px; border-bottom: 1px solid var(--rule); }
.pf-macros div { display: flex; flex-direction: column; gap: 1px; }
.pf-macros div + div { border-left: 1px solid var(--hair); padding-left: 10px; }
.pf-macros b { font-size: 20px; font-weight: 800; }
.pf-macros span { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.pf-macros i { width: 8px; height: 8px; border-radius: 2px; background: var(--c); display: inline-block; }
.pf-per { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .primary { flex: 1; }

/* recipes */
.picking #addMealPicker, .picking #tab-recipes { display: none; }
.result-main.plain { grid-template-columns: 1fr auto; }
.recipe-top { grid-template-columns: 1fr 96px; }
#recipeForm .kicker { margin-top: 4px; }
#recipeIngredients .empty { padding: 14px 4px; }
#addIngredient { margin-top: 12px; }
#recipeFacts { margin-top: 0; }
#recipeForm .sheet-actions { margin-top: 6px; }

/* settings */
.settings-block { margin-top: 26px; padding-top: 4px; border-top: 2.5px solid var(--rule); }
.settings-block .hint { margin-bottom: 12px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row .btn { flex: 1 1 140px; }
.file-btn { cursor: pointer; }
.confirm { margin-top: 12px; padding: 12px; background: var(--panel); border: 1.5px solid var(--danger); border-radius: var(--radius); }
.confirm p { margin: 0 0 10px; }
.stats { margin: 12px 0 0; font-size: 13px; color: var(--muted); }
#settingsSheet .credit { margin-top: 26px; }

/* theme picker: each swatch previews its theme with fixed colors, whatever theme is active */
.themes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.theme-opt {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 6px 4px 8px; border-radius: 14px; border: 2px solid transparent;
  font-size: 13px; font-weight: 650; color: var(--muted);
}
.theme-opt[aria-checked="true"] { border-color: var(--accent); color: var(--ink); }
.swatch {
  position: relative; width: 100%; max-width: 100%; aspect-ratio: 3 / 4;
  border-radius: 10px; overflow: hidden;
  background: var(--sw-ground); border: 1px solid var(--hair-strong);
}
.swatch .sw-card {
  position: absolute; left: 14%; right: 14%; top: 14%; height: 38%;
  background: var(--sw-panel); border: 1.5px solid var(--sw-ink);
}
.swatch .sw-card::before, .swatch .sw-card::after {
  content: ""; position: absolute; left: 12%; height: 12%; background: var(--sw-ink);
}
.swatch .sw-card::before { top: 16%; width: 60%; }
.swatch .sw-card::after { top: 44%; width: 76%; height: 7%; }
.swatch .sw-btn {
  position: absolute; left: 14%; right: 14%; bottom: 12%; height: 16%;
  border-radius: 5px; background: var(--sw-accent);
}
.sw-light { --sw-ground: #ffffff; --sw-panel: #ffffff; --sw-ink: #121412; --sw-accent: #d63c22; }
.sw-dark { --sw-ground: #000000; --sw-panel: #151816; --sw-ink: #eef1ec; --sw-accent: #ff6a4d; }
.sw-blue { --sw-ground: #dcebf9; --sw-panel: #ffffff; --sw-ink: #0b2545; --sw-accent: #1d63c9; }
.sw-auto { --sw-ground: #ffffff; --sw-panel: #ffffff; --sw-ink: #121412; --sw-accent: #d63c22; }
.sw-auto .sw-half {
  position: absolute; inset: 0; clip-path: polygon(100% 0, 100% 100%, 0 100%);
  --sw-ground: #000000; --sw-panel: #151816; --sw-ink: #eef1ec; --sw-accent: #ff6a4d;
  background: var(--sw-ground);
}
.theme-hint { margin-top: 10px; }

/* toast */
.toast {
  position: fixed; z-index: 100; left: 16px; right: 16px;
  bottom: calc(var(--bar-h) + env(safe-area-inset-bottom, 0px) + 10px);
  max-width: 520px; margin-inline: auto;
  background: var(--ink); color: var(--ground);
  border-radius: 12px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px; font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast span { flex: 1; min-width: 0; }
.toast-action { color: var(--accent); font-weight: 800; padding: 6px 4px; }
body.locked .toast { bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); }

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