/* Colour tokens: design/tokens.json is the contract (shared with iOS); tests/test_design_tokens.py keeps them in sync. */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1f1c;
  --muted: #6b6f68;
  --border: #e3e1da;
  --accent: #2f6f4f;
  --energy: #2f6f4f;
  --protein: #3a7bd5;
  --carbs: #d39b1c;
  --fat: #8a6fd0;
  --over: #e0703a;
  --accent-contrast: #ffffff;
  --danger: #b3261e;
  --warn-bg: #fff4d6;
  --warn-text: #7a5a00;
  --ok-bg: #e3f1e8;
  --ok-text: #245c3f;
  --row-bad: #fdecea;
  --card-border: var(--border);
  --segment-track: color-mix(in srgb, var(--muted) 14%, transparent);
  --segment-selected: var(--surface);
  --radius: 16px;
  --radius-control: 12px;
  --font: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

[hidden] { display: none !important; }

/* The dark values exist twice: once for the system setting, once for an explicit data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121412;
    --surface: #1c1f1c;
    --text: #ecede8;
    --muted: #9ca198;
    --border: #2e322d;
    --accent: #6fbf8f;
    --energy: #6fbf8f;
    --protein: #7fb0f0;
    --carbs: #f0c35a;
    --fat: #b7a3ee;
    --over: #f29a6b;
    --accent-contrast: #0f1a13;
    --danger: #f2b8b5;
    --warn-bg: #352e16;
    --warn-text: #f3d98a;
    --ok-bg: #1c3526;
    --ok-text: #a8dcbc;
    --row-bad: #351f1e;
    --card-border: transparent;
    --segment-track: color-mix(in srgb, var(--muted) 18%, transparent);
    --segment-selected: color-mix(in srgb, var(--muted) 32%, var(--surface));
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121412;
  --surface: #1c1f1c;
  --text: #ecede8;
  --muted: #9ca198;
  --border: #2e322d;
  --accent: #6fbf8f;
  --energy: #6fbf8f;
  --protein: #7fb0f0;
  --carbs: #f0c35a;
  --fat: #b7a3ee;
  --over: #f29a6b;
  --accent-contrast: #0f1a13;
  --danger: #f2b8b5;
  --warn-bg: #352e16;
  --warn-text: #f3d98a;
  --ok-bg: #1c3526;
  --ok-text: #a8dcbc;
  --row-bad: #351f1e;
  --card-border: transparent;
  --segment-track: color-mix(in srgb, var(--muted) 18%, transparent);
  --segment-selected: color-mix(in srgb, var(--muted) 32%, var(--surface));
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h1 { font-size: 1.75rem; line-height: 1.2; font-weight: 700; margin: 0 0 .5rem; }
h2 { font-size: 1.25rem; line-height: 1.3; font-weight: 600; margin: 0 0 .75rem; }

/* type scale: large title 28/34 bold, caption 12 uppercase-tracked */
.large-title { font-size: 1.75rem; line-height: 2.125rem; font-weight: 700; letter-spacing: .01em; margin: 0 0 .5rem; }
.caption { font-size: .75rem; line-height: 1rem; font-weight: 500; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.icon { width: 1.25rem; height: 1.25rem; flex: none; stroke: currentColor; fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.25em; }
/* navigation: a slim top bar everywhere; its links and logout only from 720px, the tab bar only below */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .75rem max(16px, env(safe-area-inset-right)) .75rem max(16px, env(safe-area-inset-left)); padding-top: max(.75rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topnav, .topbar-end { display: none; }
.topnav { gap: 1rem; flex-wrap: wrap; flex: 1; }
.topnav a { text-decoration: none; color: var(--muted); }
.topnav a:hover, .topnav a[aria-current=page] { color: var(--text); }
.topnav a[aria-current=page] { font-weight: 600; }
.topbar-end { align-items: center; gap: 1rem; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: flex;
  padding: 0 max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
  background: var(--surface); border-top: .5px solid var(--border);
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .tabbar {
    background: color-mix(in srgb, var(--surface) 78%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  }
}
.tab {
  flex: 1 1 0; min-width: 0; min-height: 3.125rem; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: .125rem; padding: .375rem 0 .25rem; color: var(--muted); text-decoration: none;
  font-size: .7rem; font-weight: 500; line-height: 1; -webkit-tap-highlight-color: transparent;
}
.tab .icon { width: 1.5rem; height: 1.5rem; vertical-align: 0; }
.tab[aria-current=page] { color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 8px; }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 719.98px) {
  .topbar { justify-content: center; padding-top: max(.6rem, env(safe-area-inset-top)); padding-bottom: .6rem; }
}
@media (min-width: 720px) {
  .topnav, .topbar-end { display: flex; }
  .tabbar { display: none; }
  button.block.logout-block { width: 100%; }
}

/* /more: an inset grouped list, rows at least 44px with icon, label and chevron */
ul.grouped { list-style: none; margin: 0 0 1rem; }
.grouped li + li::before { content: ""; display: block; margin-left: 3.125rem; border-top: .5px solid var(--border); }
.grouped-row {
  display: flex; align-items: stretch; gap: .875rem; padding-left: 1rem; color: var(--text); text-decoration: none;
}
.grouped-row > .icon { align-self: center; color: var(--accent); }
.grouped-row span { flex: 1; display: flex; align-items: center; min-height: 2.75rem; padding: .375rem 0; }
.grouped-row .chevron { align-self: center; padding: 0 1rem 0 .25rem; box-sizing: content-box; color: var(--muted); }
.grouped-row:active { background: var(--segment-track); }
.grouped-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.more-build { margin: 0 0 1rem 1rem; text-transform: none; letter-spacing: 0; }
button.block.danger { color: var(--danger); }

.container { max-width: 1000px; margin: 1.5rem auto; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); }
.container.narrow { max-width: 420px; margin-top: 10vh; }
/* Room for the fixed phone tab bar. main.container (0,1,1) outranks .container's padding shorthand above. */
@media (max-width: 719.98px) {
  main, main.container { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
}

/* cards: 16px radius and padding, hairline in light mode, borderless in dark mode (--card-border) */
.card {
  background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
.card.flush { padding: 0; overflow: hidden; }
.card .pad { padding: 1rem 1rem 0; }

.heading-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.heading-row > div:first-child { min-width: 0; }
.actions { display: flex; gap: .5rem; }

label { display: block; font-weight: 500; margin-bottom: .75rem; }
/* Fields stay at 1rem (16px) or more: iOS Safari zooms in on focus below that. */
input, textarea, select {
  width: 100%; margin-top: .25rem; padding: .625rem .75rem; font: inherit; font-size: 1rem; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; accent-color: var(--accent);
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1rem; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.row { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 200px; margin: 0; }
.row .grow { flex: 1; min-width: 200px; }
.row .small-field { width: 120px; }

/* 1.5rem line + .625rem padding each side + border: at least 44px tall */
button, .button {
  display: inline-block; padding: .625rem 1rem; font: inherit; font-weight: 500; cursor: pointer;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; white-space: nowrap;
}
button:active, .button:active { opacity: .7; }
button:focus-visible, .button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--muted); padding: 0; }
button:disabled { opacity: .6; cursor: progress; }
/* primary actions: full width on phones, at least 48px tall, 12px radius */
button.block, .button.block {
  display: flex; align-items: center; justify-content: center; gap: .5rem; width: 100%; min-height: 3rem;
  border-radius: var(--radius-control); font-weight: 600; white-space: normal; text-align: center;
}
@media (min-width: 720px) {
  button.block, .button.block { display: inline-flex; width: auto; min-width: 12rem; }
}

/* segmented control: a group of buttons, the selected one has aria-pressed or aria-selected="true" */
.segmented, .tabs {
  display: flex; flex-wrap: wrap; gap: 2px; padding: 3px; border-radius: 11px; background: var(--segment-track);
}
.segmented button, .tabs button {
  flex: 1 1 0; min-height: 2.375rem; padding: .375rem .875rem; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); font-weight: 500;
}
.segmented button[aria-pressed=true], .segmented button[aria-selected=true],
.tabs button[aria-pressed=true], .tabs button[aria-selected=true] {
  background: var(--segment-selected); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.muted { color: var(--muted); }
.small { font-size: .85em; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.ellipsis { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.error { color: var(--danger); }
.warning { color: var(--muted); margin: .5rem 0 0; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .3rem 0; }

.tag {
  display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 99px;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted); vertical-align: middle;
}
.tag.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.tag.ok { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.nutrition tbody th { font-weight: 500; white-space: nowrap; }

.summary-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.summary-head label { display: flex; align-items: center; gap: .5rem; margin: 0; font-weight: 400; }
.summary-head input { width: 80px; margin: 0; }

table.ingredients tr.unmatched td { background: var(--row-bad); }
table.ingredients tr.ignored td { color: var(--muted); }
input.grams { width: 80px; text-align: right; margin: 0; padding: .3rem .45rem; }
.food-cell { min-width: 260px; }
.food-name { margin-right: .25rem; }
details.swap { margin-top: .3rem; }
details.swap summary { cursor: pointer; color: var(--accent); font-size: .85em; }
details.swap input { margin-top: .4rem; }
.food-options { list-style: none; margin: .4rem 0 0; padding: 0; max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.food-options li + li { border-top: 1px solid var(--border); }
button.option {
  width: 100%; display: flex; justify-content: space-between; gap: .75rem; text-align: left;
  border: 0; border-radius: 0; white-space: normal; padding: .45rem .6rem;
}
button.option:hover { background: var(--bg); }

.login h1 { margin-bottom: 0; }
.login form { margin-top: 1rem; }
.login button { width: 100%; }

pre.json {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .75rem;
  overflow-x: auto; font-size: 12.5px; max-height: 480px;
}
pre.log-message {
  margin: 0; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; max-height: 240px; overflow-y: auto;
}
.key-reveal { font-family: ui-monospace, Menlo, monospace; padding: .75rem; background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; word-break: break-all; }
.status-ok { color: var(--ok-text); }
.status-error { color: var(--danger); }

@media (max-width: 640px) {
  .actions { width: 100%; }
}

/* admin */
.subnav, .filters { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 1rem; }
.subnav a, .filters a { padding: .3rem .7rem; border-radius: 99px; text-decoration: none; color: var(--muted); }
.subnav a.active, .filters a.active { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.filters { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stats .card { margin: 0; }
.stat .value { font-size: 1.8rem; font-weight: 600; font-variant-numeric: tabular-nums; }
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; min-width: 0; }
.url-cell { max-width: 420px; }
.pager { display: flex; gap: 1rem; }
details.card summary { cursor: pointer; font-weight: 600; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; }

/* progress + save feedback */
.progress { display: flex; align-items: center; gap: .9rem; margin-top: 1rem; padding: .9rem 1rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.progress[hidden] { display: none; }
.progress-step { font-weight: 500; }
.spinner { width: 22px; height: 22px; flex: none; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.toast { position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10;
  max-width: calc(100% - 2rem); padding: .75rem 1.125rem; border-radius: var(--radius-control); font-weight: 500;
  background: var(--text); color: var(--bg); box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }
.toast[hidden] { display: none; }
.toast.ok { background: var(--ok-bg); color: var(--ok-text); border: 1px solid var(--ok-text); }
.toast.error { background: var(--row-bad); color: var(--danger); border: 1px solid var(--danger); }

.hint { margin: .25rem 0 1rem; max-width: 70ch; }
.card .pad h2 { margin-bottom: .25rem; }
tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--ok-bg); } to { background: transparent; } }
form.htmx-request input.grams, button.option.htmx-request { opacity: .5; cursor: progress; }

.recovery-key { display: block; margin: .75rem 0; padding: .75rem; font: 1.15rem/1.6 ui-monospace, monospace;
  letter-spacing: .05em; background: var(--ok-bg); border-radius: 6px; user-select: all; word-break: break-all; }
label.check { display: flex; gap: .5rem; align-items: center; }
label.check input { width: auto; flex: none; margin: 0; }
p.ok { color: var(--ok-text); }
button.danger { color: var(--danger); }

/* catalog refs list */
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; padding: .35rem 0; border-top: 1px solid var(--border); }
ul.plain li:first-child { border-top: 0; }

/* food log ("Dagbok", log-page.js): date title, "‹ Idag ›" segmented control, meal cards, compact day totals */
.log { max-width: 44rem; margin: 0 auto; font-variant-numeric: tabular-nums; }
.log-head { margin: .5rem 0 1rem; }
.log-title { margin: 0 0 .5rem; }
.segmented.log-nav { display: inline-flex; flex-wrap: nowrap; }
.log-nav button { flex: none; min-height: 2.75rem; min-width: 2.75rem; padding: 0 1.25rem; }
nav.row.log-nav { align-items: center; } /* Statistik period nav; Dagbok uses .segmented */
.log-nav .log-step { display: inline-flex; align-items: center; justify-content: center; padding: 0 .75rem; }
.icon.flip { transform: scaleX(-1); }
.meal { margin-bottom: 1rem; }
.meal-head { display: flex; align-items: center; gap: .5rem; padding: .25rem .25rem .25rem 1rem; min-height: 3rem; }
.meal-head h2 { margin: 0; font-size: 1.0625rem; font-weight: 600; flex: 1; }
.meal-kcal { font-size: .9375rem; }
button.meal-add {
  display: inline-flex; align-items: center; gap: .25rem; min-height: 2.75rem; padding: 0 .75rem;
  border: 0; background: none; color: var(--accent); font-weight: 600;
}
ul.entries li { padding: .125rem 1rem .125rem .25rem; align-items: center; flex-wrap: wrap; gap: 0 .5rem; min-height: 2.75rem; }
ul.entries li.selected { background: var(--ok-bg); }
label.entry-check-hit { display: flex; align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem;
  margin: 0; flex: none; cursor: pointer; }
.entry-check { margin: 0; width: 1.125rem; height: 1.125rem; flex: none; }
button.entry-toggle { flex: 1; min-width: 0; min-height: 2.75rem; text-align: left; color: var(--text); white-space: normal; font-weight: 400; }
button.entry-edit { min-height: 2.75rem; padding: 0 .25rem 0 .5rem; color: var(--accent); }
.entry-details { flex-basis: 100%; margin: 0 0 .5rem; padding-left: 3.25rem; }
dl.totals-grid.entry-details { grid-template-columns: repeat(4, minmax(0, 1fr)); } /* dt/dd sit in rows 1 and 2 */
dl.entry-details dt { overflow: hidden; text-overflow: ellipsis; }
dl.entry-details dt, dl.entry-details dd { font-size: .85rem; font-weight: 400; }
.totals .caption { margin: 0; }
.totals-body { display: flex; align-items: flex-start; gap: 1rem 1.25rem; margin-top: .75rem; }
.totals-rings { flex: none; width: 4.5rem; height: 4.5rem; }
.totals-rings .rings { width: 100%; height: 100%; }
dl.totals-grid.day-totals { flex: 1; min-width: 0; margin: 0; grid-template-columns: repeat(auto-fill, minmax(6.75rem, 1fr)); gap: .5rem 1rem; }
.day-totals .total-kcal { grid-column: 1 / -1; } /* "1 392 / 2 200 kcal" needs the full width on phones */
.day-totals dt { display: flex; align-items: center; gap: .4rem; font-size: .8125rem; color: var(--muted); }
dl.day-totals dd { margin: 0 0 0 .9rem; white-space: nowrap; font-size: 1rem; font-weight: 650; }
.day-totals .of, .day-totals .unit { color: var(--muted); font-weight: 500; }
.day-totals .unit { font-size: .875rem; }
.day-totals .dot { width: .5rem; height: .5rem; border-radius: 50%; flex: none; background: var(--muted); }
.total-kcal .dot { background: var(--energy); }
.total-protein .dot { background: var(--protein); }
.total-fat .dot { background: var(--fat); }
.total-carbs .dot { background: var(--carbs); }
.select-bar { position: sticky; bottom: 1rem; z-index: 4; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .15); }
/* The phone tab bar is fixed at the bottom: keep the sticky select bar above it. */
@media (max-width: 719.98px) { .select-bar { bottom: calc(4.5rem + env(safe-area-inset-bottom)); } }
.select-bar [data-role=select-count] { flex: 1; white-space: nowrap; }
ul.collection-items li { border: 0; padding: .1rem 0; }
ul.collection-edit li { align-items: center; gap: .5rem; }
ul.collection-edit .item-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
ul.collection-edit label { display: flex; align-items: center; gap: .35rem; margin: 0; font-weight: 400; }
fieldset.add-item { border: 1px solid var(--border); border-radius: 8px; padding: .5rem .75rem .75rem; margin: 0; }
fieldset.add-item .combo { margin: 0; }
fieldset.add-item .row { align-items: center; }
fieldset.add-item .row label { display: flex; align-items: center; gap: .35rem; margin: 0; }
.entry-name { min-width: 0; overflow-wrap: anywhere; }
dl.totals-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: .5rem 1rem; }
.totals-grid dt { grid-row: 1; }
.totals-grid dd { grid-row: 2; font-size: 1.1rem; font-weight: 600; }
.footer-note { margin-top: 1.5rem; }
/* .card's margin-bottom would override the UA's margin:auto and push modals to the bottom of the screen. */
dialog.card { max-width: 34rem; width: calc(100% - 2rem); max-height: calc(100dvh - 2rem); margin: auto; box-sizing: border-box;
  padding: 1.25rem; background: var(--surface); color: var(--text); border: 1px solid var(--card-border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .2); }
/* In a modal (which scrolls) an absolute list is clipped: keep it in the flow so the dialog grows instead. */
dialog ul.suggestions { position: static; margin-top: .25rem; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.close-row { display: flex; justify-content: space-between; align-items: center; }
.close-row h2 { margin: 0; }
.tabs { margin: .75rem 0; }
@media (max-width: 719.98px) { #add-dialog .tabs button { flex-basis: 40%; } } /* four add-dialog tabs wrap as an even 2x2 on phones */
.tabs button[hidden] { display: none; }
.combo { position: relative; margin: .75rem 0; }
.combo input { width: 100%; box-sizing: border-box; }
ul.suggestions { position: absolute; left: 0; right: 0; z-index: 5; margin: 0; padding: 0; list-style: none;
  max-height: 16rem; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
ul.suggestions[hidden] { display: none; }
ul.suggestions li { padding: .45rem .75rem; cursor: pointer; }
ul.suggestions li[aria-selected=true], ul.suggestions li:hover { background: var(--ok-bg); }
.amount { margin-top: .75rem; }
.preview { flex-basis: 100%; }
/* Picked item: name, then its nutrition, then amount + Add on one line. */
form.row.amount > :first-child { flex-basis: 100%; order: -2; }
form.row.amount > .preview { order: -1; }
.preview > div { margin: 0; }
.stack { display: flex; flex-direction: column; gap: .75rem; }

/* statistics */
.stats-controls { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; }
.stats-controls .tabs { margin: 0; }
.chart-card { margin-top: 1rem; }
.chart { width: 100%; min-height: 240px; }
.chart .u-legend { color: var(--text); }
.chart-card table { font-size: .9rem; }
.chart-card td, .chart-card th { text-align: right; padding: .2rem .5rem; }
.chart-card td:first-child, .chart-card th:first-child { text-align: left; }
.scan-video { width: 100%; max-width: 24rem; border-radius: .5rem; background: #000; }
.scan-video[hidden] { display: none; }

/* user guide */
.help { max-width: 46rem; }
.help .lead { font-size: 1.05rem; color: var(--muted); }
.help section { margin-top: 2rem; scroll-margin-top: 1rem; }
.help h3 { font-size: 1rem; margin: 1.25rem 0 .4rem; }
.help li { margin-bottom: .35rem; }
.help-toc ol { margin: .5rem 0 0; padding-left: 1.4rem; columns: 2 14rem; }
.help .note { margin-top: 1rem; }
.help-terms dt { font-weight: 600; margin-top: .75rem; }
.help-terms dd { margin: .2rem 0 0 0; }

/* charts (charts-core.js): today's rings and the week bars. Tracks are the nutrient colour mixed down. */
:root { --chart-track: 15%; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --chart-track: 22%; } }
:root[data-theme="dark"] { --chart-track: 22%; }
.rings, .week-chart { display: block; font-family: var(--font); font-variant-numeric: tabular-nums; }
.rings { max-width: 100%; height: auto; }
.rings circle { fill: none; }
.rings .track-kcal { stroke: color-mix(in srgb, var(--energy) var(--chart-track), transparent); }
.rings .track-protein { stroke: color-mix(in srgb, var(--protein) var(--chart-track), transparent); }
.rings .track-carbs { stroke: color-mix(in srgb, var(--carbs) var(--chart-track), transparent); }
.rings .track-split { stroke: color-mix(in srgb, var(--muted) var(--chart-track), transparent); }
.rings .ring-kcal { stroke: var(--energy); }
.rings .ring-kcal.over { stroke: var(--over); }
.rings .ring-protein { stroke: var(--protein); }
.rings .ring-carbs { stroke: var(--carbs); }
.rings .arc-protein { stroke: var(--protein); }
.rings .arc-fat { stroke: var(--fat); }
.rings .arc-carbs { stroke: var(--carbs); }
.rings .ring.zero { visibility: hidden; } /* a zero-length round-capped dash would still draw a dot */
.rings .ring, .rings .arc { animation: ring-in 600ms ease-out both; }
@keyframes ring-in { from { stroke-dasharray: 0 100; } }
.rings .center-value { fill: var(--text); font-weight: 650; letter-spacing: -.02em; }
.rings .center-unit { fill: var(--muted); font-weight: 500; }
/* animate on the first render only; the page modules set .rings-seen after the first paint */
.rings-seen .rings .ring, .rings-seen .rings .arc { animation: none; }
@media (prefers-reduced-motion: reduce) { .rings .ring, .rings .arc { animation: none; } }

.week-chart { width: 100%; height: auto; overflow: visible; }
.week-chart .hit { fill: transparent; }
.week-chart a:focus { outline: none; }
.week-chart a:focus-visible .hit { stroke: var(--accent); stroke-width: 2; }
.week-chart a:hover .hit { fill: color-mix(in srgb, var(--muted) 8%, transparent); }
.week-chart .bar { fill: color-mix(in srgb, var(--muted) var(--chart-track), transparent); }
.week-chart .bar.logged { fill: color-mix(in srgb, var(--energy) 50%, transparent); }
.week-chart .bar.logged.today { fill: var(--energy); }
.week-chart .bar.logged.over { fill: var(--over); }
.week-chart .bar.today:not(.logged) { fill: color-mix(in srgb, var(--energy) 35%, transparent); }
.week-chart .bar.prev { fill: color-mix(in srgb, var(--muted) 26%, transparent); }
.week-chart .target { stroke: var(--muted); stroke-width: 1.25; stroke-dasharray: 4 4; stroke-linecap: round; pointer-events: none; }
.week-chart .letter { fill: var(--muted); font-size: 11px; font-weight: 500; }
.week-chart .letter.today { fill: var(--text); font-weight: 700; }

/* start page ("Idag", start-page.js): greeting, today's rings with a legend, the week bars and the log button */
.start { max-width: 40rem; margin: 0 auto; }
.start-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin: .5rem 0 1rem; }
.start-head .large-title { margin: 0; }
.start-date { margin: .125rem 0 0; color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: .375rem; min-height: 2.75rem; padding: 0 1rem; flex: none;
  border-radius: 999px; border: 1px solid var(--card-border); background: var(--surface); color: var(--accent); font-weight: 600;
}
.pill:disabled { cursor: default; }
.today-card .caption, .week-card .caption { margin: 0; }
.today-body { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem; margin-top: .75rem; }
.today-rings { flex: none; width: 9rem; height: 9rem; }
.today-rings .rings { width: 100%; height: 100%; }
.today-side { flex: 1 1 9rem; min-width: 0; }
.legend { display: grid; gap: .5rem; margin: 0; }
.legend-row dt { display: flex; align-items: center; gap: .4rem; font-size: .8125rem; line-height: 1.1rem; color: var(--muted); }
.legend-row dd { margin: 0 0 0 .9rem; font-size: 1.0625rem; line-height: 1.4rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.legend-row .of, .legend-row .unit { color: var(--muted); font-weight: 500; }
.legend-row .unit { font-size: .875rem; }
.legend-row .share { margin-left: .5rem; color: var(--muted); font-size: .8125rem; font-weight: 500; }
.legend .dot { width: .5rem; height: .5rem; border-radius: 50%; flex: none; background: var(--muted); }
.legend-kcal .dot { background: var(--energy); }
.legend-protein .dot { background: var(--protein); }
.legend-carbs .dot { background: var(--carbs); }
.legend-fat .dot { background: var(--fat); }
.today-status {
  display: inline-block; margin: .75rem 0 0; padding: .25rem .75rem; border-radius: 999px; font-weight: 600;
  font-variant-numeric: tabular-nums; color: var(--energy); background: color-mix(in srgb, var(--energy) 12%, transparent);
}
/* --over itself is too light for text on white, so the text is the over colour mixed towards --text */
.today-status.over { color: color-mix(in srgb, var(--over) 60%, var(--text)); background: color-mix(in srgb, var(--over) 16%, transparent); }
.empty-title { font-size: 1.25rem; line-height: 1.3; font-weight: 600; margin: 0 0 .25rem; }
.today-side p { margin: 0 0 .5rem; }
.week-head { display: flex; justify-content: space-between; align-items: baseline; gap: .25rem 1rem; flex-wrap: wrap; }
.week-summary { margin: 0; color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; }
.week-plot { margin-top: .75rem; }
.week-key { display: flex; align-items: center; gap: .375rem; margin: .5rem 0 0; color: var(--muted); font-size: .75rem; }
.key-swatch { width: .625rem; height: .625rem; border-radius: 2px; background: color-mix(in srgb, var(--muted) 26%, transparent); }
.log-cta { margin-top: .5rem; }
@media (min-width: 720px) {
  .start .log-cta { display: flex; width: 100%; }
  .start .week-chart { max-height: 13rem; } /* the viewBox keeps its ratio and centres; letters stay readable */
}
.targets-form label { margin-bottom: 0; }
/* The phone tab bar is fixed at the bottom: lift toasts above it. */
@media (max-width: 719.98px) { .toast { bottom: calc(4.5rem + env(safe-area-inset-bottom)); } }
.close-row .close { min-width: 2.75rem; min-height: 2.75rem; }

/* add / remove ingredient lines */
button.remove { background: none; border: 0; color: var(--muted, inherit); cursor: pointer; padding: .2rem .45rem; }
button.remove:hover { color: var(--danger); }
.add-line label { display: block; font-weight: 600; margin-bottom: .3rem; }
.add-line-row { display: flex; gap: .5rem; }
.add-line-row input { flex: 1; min-width: 0; }
