/* Shared components. Views may add their own CSS file but must use tokens only.
   Component index: .page / .nav-head(.nav-bar .page-head .large-title .nav-sub .nav-actions) / .back / .bar-btn / .menu / .edit-only / .chip-row .filter-chip / .flag-dot / .toolbar / .btn(-filled|-tinted|-plain|-destructive|-sm)
   .list(.row .row-icon .row-main .row-title .row-sub .row-detail .chev) / .segmented / .stepper / .field / .search / .switch
   .chip(.tint|.orange|.red|.blue) / .card / .grid-cards / .stats(.stat .v .u .l) / .macro-bar
   .empty(.empty-icon) / .banner(.error|.info) / .spinner / .skeleton / dialog.sheet / .toast */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg-grouped); color: var(--label);
  font: var(--t-body); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-appearance: none; appearance: none; }
a { color: var(--tint); text-decoration: none; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
dialog.sheet:focus, dialog.sheet:focus-visible { outline: none; }
/* Touch screens: a text field shows focus with its caret and a soft tint ring, not a heavy outline (U13). */
@media (pointer: coarse) {
  input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--tint-fill); }
}
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--label-2); }
.footnote { font: var(--t-footnote); color: var(--label-2); }
.caption { font: var(--t-caption); color: var(--label-2); }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App frame ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100%; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: var(--space-5) var(--space-3) var(--space-4);
  background: var(--sidebar-material);
  backdrop-filter: saturate(180%) blur(30px); -webkit-backdrop-filter: saturate(180%) blur(30px);
  border-right: 0.5px solid var(--separator);
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar .brand { display: flex; align-items: center; gap: var(--space-2); font: var(--t-title-3); padding: 0 var(--space-2) var(--space-5); }
.brand-icon { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; background: var(--tint); color: var(--label-on-tint); flex: none; }
.brand-icon svg { width: 17px; height: 17px; stroke-width: 2; }
.sidebar-label { font: var(--t-sidebar-label); color: var(--label-2); padding: 0 var(--space-3) var(--space-1); letter-spacing: 0.02em; }
#nav { display: grid; gap: 2px; }
#nav .sidebar-label:not(:first-child) { margin-top: var(--space-4); }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3); min-height: 36px;
  padding: 0 var(--space-3); border-radius: var(--radius-sm); color: var(--label); font: var(--t-callout);
  transition: background var(--dur-fast) var(--ease);
}
.nav-item svg { width: 20px; height: 20px; color: var(--tint); flex: none; }
.nav-item:hover { background: var(--fill); }
.nav-item[aria-current="page"] { background: var(--sidebar-selected); font-weight: 600; }
.sidebar .foot { margin-top: auto; padding: var(--space-3); font-variant-numeric: tabular-nums; display: grid; gap: var(--space-2); justify-items: start; }
/* Keyboard shortcuts (keys.js): key caps, the sidebar hint and the per-item number shown on hover. */
.kbd {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px;
  font: 600 11px/1 var(--font); color: var(--label-2); background: var(--fill); border-radius: 5px;
  box-shadow: inset 0 -1px 0 var(--separator);
}
.nav-key { margin-left: auto; font: 600 11px/1 var(--font); color: var(--label-3); opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
.nav-item:hover .nav-key, .nav-item:focus-visible .nav-key { opacity: 1; }
.keys-btn { display: inline-flex; align-items: center; gap: var(--space-2); padding: 0; background: none; border: 0; font: inherit; color: var(--label-2); cursor: pointer; }
.keys-btn:hover { color: var(--label); }
.keys-sheet .row .kbd { flex: none; min-width: 26px; height: 24px; font-size: 12px; }
main { min-width: 0; }
main:focus-visible { outline: none; }
.tabbar { display: none; }

@media (max-width: 899px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; inset: auto 0 0 0; z-index: 20;
    padding: var(--space-1) max(var(--space-1), env(safe-area-inset-right, 0px)) calc(var(--space-1) + env(safe-area-inset-bottom, 0px)) max(var(--space-1), env(safe-area-inset-left, 0px));
    background: var(--material); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid var(--separator);
  }
  .tabbar a { display: grid; justify-items: center; align-content: center; gap: 2px; min-width: 0; min-height: 49px; padding: var(--space-1) 0; color: var(--label-2); font: var(--t-tab); white-space: nowrap; }
  .tabbar svg { width: 26px; height: 26px; }
  .tabbar a[aria-current="page"] { color: var(--tint); }
  main { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
}
/* 320-374 px (iPhone SE / Display Zoom): "Boodschappen" must fit its fifth of the bar (U17). */
@media (max-width: 374px) {
  .tabbar a { font-size: 9.5px; letter-spacing: -0.02em; overflow: hidden; text-overflow: ellipsis; }
  .tabbar svg { width: 24px; height: 24px; }
}

/* ---------- Page ---------- */
.page { max-width: var(--content-max); margin: 0 auto; padding: var(--space-7) var(--space-6) var(--space-8); display: grid; gap: var(--space-6); grid-template-columns: minmax(0, 1fr); }
.page.detail { max-width: var(--detail-max); }
@media (max-width: 599px) { .page { padding: var(--space-4) var(--space-4) var(--space-8); gap: var(--space-5); } }
/* Notch / home-indicator safe areas (standalone PWA, landscape phones). */
@media (max-width: 899px) { .page { padding-left: max(var(--space-6), env(safe-area-inset-left, 0px)); padding-right: max(var(--space-6), env(safe-area-inset-right, 0px)); } }
@media (max-width: 599px) { .page { padding-left: max(var(--space-4), env(safe-area-inset-left, 0px)); padding-right: max(var(--space-4), env(safe-area-inset-right, 0px)); padding-top: max(var(--space-4), env(safe-area-inset-top, 0px)); } }
/* ---------- Navigation bar ----------
   Detail pages: [‹ Back ............ bar buttons] above the large title.
   Root pages:   [Large title ....... bar buttons] on one row. One quiet subtitle line below. */
.nav-head { display: grid; gap: var(--space-1); min-width: 0; }
.nav-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: var(--hit); margin: calc(-1 * var(--space-3)) 0 calc(-1 * var(--space-1)); }
.page-head { display: flex; align-items: flex-start; gap: var(--space-3); min-height: 41px; }
.page-head > .nav-actions { min-height: 41px; }
/* Phone: like iOS, root-page bar buttons sit in the bar above the large title. */
@media (max-width: 599px) {
  .page-head:has(> .nav-actions) { flex-direction: column-reverse; align-items: stretch; gap: 0; }
  .page-head > .nav-actions { justify-content: flex-end; min-height: var(--hit); margin-top: calc(-1 * var(--space-3)); }
  /* Root pages without bar buttons keep the same empty bar row, so the large title doesn't jump
     between tabs (U7). Detail pages have their back bar instead. */
  .nav-head:not(:has(> .nav-bar)) > .page-head:not(:has(> .nav-actions)) { padding-top: calc(var(--hit) - var(--space-3)); }
}
.large-title { font: var(--t-large-title); letter-spacing: var(--tracking-large); margin: 0; flex: 1; min-width: 0; text-wrap: balance; overflow-wrap: anywhere; }
.nav-sub { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); font: var(--t-subhead); color: var(--label-2); font-variant-numeric: tabular-nums; }
.nav-sub > * + :not(:empty)::before { content: "·"; margin-right: var(--space-2); color: var(--label-3); font-weight: 400; }
.nav-actions { display: flex; align-items: center; gap: var(--space-1); flex: none; margin-right: calc(-1 * var(--space-2)); }
.title-2 { font: var(--t-title-2); margin: 0; }
.title-3 { font: var(--t-title-3); margin: 0; }
.headline { font: var(--t-headline); margin: 0; }
.back {
  display: inline-flex; align-items: center; gap: 2px; min-height: var(--hit);
  margin-left: calc(-1 * var(--space-2)); padding: 0 var(--space-2) 0 0;
  border: 0; background: none; color: var(--tint); font: var(--t-body); cursor: pointer;
  transition: opacity var(--dur-fast) var(--ease);
}
.back svg { width: 24px; height: 24px; stroke-width: 2.2; }
.back:hover { opacity: 0.7; }
/* Bar buttons: tint text, no fill (UIBarButtonItem). */
.bar-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1); min-height: var(--hit); min-width: var(--hit);
  padding: 0 var(--space-2); border: 0; background: none; color: var(--tint); font: var(--t-body); cursor: pointer; white-space: nowrap;
  border-radius: var(--radius-sm); transition: opacity var(--dur-fast) var(--ease);
}
.bar-btn:hover { opacity: 0.7; }
.bar-btn:active { opacity: 0.45; }
.bar-btn:disabled { opacity: 0.35; cursor: default; }
.bar-btn.strong { font-weight: 600; }
.bar-btn svg { width: 22px; height: 22px; flex: none; }
.bar-btn.icon-only { padding: 0; }
.bar-btn.icon-only svg { width: 24px; height: 24px; }

/* Pull-down menu */
.menu-wrap { position: relative; display: inline-flex; }
.menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 30; min-width: 220px; max-width: min(300px, calc(100vw - 32px));
  padding: var(--space-1) 0; border-radius: var(--radius-lg); background: var(--menu-bg); box-shadow: var(--shadow-sheet);
  backdrop-filter: saturate(180%) blur(30px); -webkit-backdrop-filter: saturate(180%) blur(30px);
  display: grid;
}
.menu.start { right: auto; left: 0; }
.menu-item {
  display: flex; align-items: center; gap: var(--space-2); min-height: var(--hit); padding: 0 var(--space-4) 0 var(--space-2);
  border: 0; background: none; color: var(--label); font: var(--t-body); text-align: left; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--fill); outline: none; border-radius: 0; }
.menu-item.destructive { color: var(--red); }
.menu-item > svg { width: 20px; height: 20px; margin-left: auto; }
.menu-check { width: 20px; flex: none; display: grid; place-items: center; color: var(--label); }
.menu-check svg { width: 16px; height: 16px; stroke-width: 2.4; }
.menu-label { flex: 1; min-width: 0; }
.menu-sep { height: 8px; background: var(--fill); margin: var(--space-1) 0; }
@media (prefers-reduced-motion: no-preference) { .menu { animation: menu-in var(--dur) var(--ease-out); transform-origin: top right; } }
@keyframes menu-in { from { opacity: 0; scale: 0.92; } }

/* Edit mode (iOS "Wijzig"): controls marked .edit-only appear only while the page is editing. */
.edit-only { display: none !important; }
.editing .edit-only { display: inline-flex !important; }
.editing .view-only { display: none !important; }

/* Review flags: a small orange dot + secondary text. */
.flag-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--orange); flex: none; }
.flag-badge { display: inline-flex; align-items: center; gap: 6px; font: var(--t-footnote); color: var(--label-2); white-space: nowrap; }

/* Horizontal chip row (filters): one line, scrolls sideways. */
.chip-row { display: flex; gap: var(--space-2); overflow-x: auto; scrollbar-width: none; margin-inline: calc(-1 * var(--space-4)); padding: 2px var(--space-4); }
.chip-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex: none; min-height: 32px; padding: 0 var(--space-3); border-radius: var(--radius-pill); border: 0;
  background: var(--fill); color: var(--label); font: var(--t-subhead); cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.filter-chip:hover { background: var(--fill-2); }
.filter-chip[aria-pressed="true"] { background: var(--label); color: var(--bg-elevated); font-weight: 600; }
.filter-chip .n { color: inherit; opacity: 0.6; margin-left: 4px; font-variant-numeric: tabular-nums; }
@media (pointer: coarse) { .filter-chip { min-height: 36px; } }

.toolbar { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.section { display: grid; gap: var(--space-2); grid-template-columns: minmax(0, 1fr); }
.section-title, .section > .section-title { font: var(--t-footnote); text-transform: uppercase; letter-spacing: 0.04em; color: var(--label-2); padding: 0 var(--inset-list); margin: 0; }
.section-foot, .section > .section-foot { font: var(--t-footnote); color: var(--label-2); padding: 0 var(--inset-list); margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--hit); padding: 0 var(--space-4); border-radius: var(--radius-lg);
  border: 0; background: var(--fill); color: var(--tint); font: var(--t-headline); cursor: pointer; white-space: nowrap;
  transition: opacity var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--fill-2); }
.btn:active { opacity: 0.6; }
.btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }
.btn-filled { background: var(--tint); color: var(--label-on-tint); }
.btn-filled:hover { background: var(--tint); opacity: 0.88; }
.btn-tinted { background: var(--tint-fill); color: var(--tint); }
.btn-tinted:hover { background: var(--tint-fill); opacity: 0.8; }
.btn-plain { background: none; padding: 0 var(--space-2); font: var(--t-body); }
.btn-plain:hover { background: none; opacity: 0.7; }
.btn-destructive { color: var(--red); }
.btn-tinted.btn-destructive, .btn.btn-destructive:not(.btn-plain) { background: var(--red-fill); }
.btn-sm { min-height: 32px; padding: 0 var(--space-3); border-radius: var(--radius-pill); font: var(--t-button-sm); gap: var(--space-1); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-sm svg { width: 16px; height: 16px; }
@media (pointer: coarse) { .btn-sm { min-height: var(--hit); } }
.btn-block { width: 100%; }

/* ---------- Inset grouped list ---------- */
.list { background: var(--bg-elevated); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-card); margin: 0; padding: 0; list-style: none; }
.row {
  --sep-inset: var(--inset-list);
  position: relative; display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--hit); padding: var(--space-2) var(--space-4) var(--space-2) var(--inset-list);
  color: var(--label); background: none; border: 0; width: 100%; text-align: left; font: var(--t-body);
}
/* Hairlines start where the text starts (after a leading icon), never at the edge. */
.row:has(> .row-icon) { --sep-inset: calc(var(--inset-list) + var(--row-icon) + var(--space-3)); }
.row + .row::before, li + li > .row::before { content: ""; position: absolute; top: 0; right: 0; left: var(--sep-inset); border-top: 0.5px solid var(--separator); }
a.row, button.row, label.row { cursor: pointer; }
a.row, button.row { transition: background var(--dur-fast) var(--ease); }
a.row:hover, button.row:hover { background: var(--fill); }
a.row:active, button.row:active { background: var(--fill-2); }
.row-main { flex: 1; min-width: 0; display: grid; gap: 2px; grid-template-columns: minmax(0, 1fr); }
.row-title { font: var(--t-body); overflow-wrap: anywhere; }
.row-sub { font: var(--t-subhead); color: var(--label-2); overflow-wrap: anywhere; }
.row-detail { font: var(--t-body); color: var(--label-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chev { width: 20px; height: 20px; color: var(--label-3); flex: none; stroke-width: 2.6; margin-right: calc(-1 * var(--space-2)); }
.row-icon { width: var(--row-icon); height: var(--row-icon); border-radius: 7px; display: grid; place-items: center; background: var(--tint); color: var(--label-on-tint); flex: none; }
.row-icon svg { width: 18px; height: 18px; stroke-width: 2; }

/* ---------- Product picture / placeholder (ui.js thumb, docs/PLAN.md §13) ----------
   Always the same square per size, so every row of a list lines up whether it has a picture or not. */
.thumb {
  --thumb: 40px;
  position: relative; flex: none; width: var(--thumb); height: var(--thumb); border-radius: var(--radius-sm);
  overflow: hidden; display: grid; place-items: center; background: var(--fill); color: var(--label-3);
}
.thumb-glyph { width: 46%; height: 46%; stroke-width: 1.8; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; }
.thumb.has-img img { opacity: 1; background: #fff; }
.thumb.has-img::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 0.5px var(--fill-2); pointer-events: none; }
.thumb.has-img { background: #fff; }
.thumb.thumb-lg { --thumb: 64px; border-radius: var(--radius-lg); }
.thumb.thumb-sm { --thumb: 32px; border-radius: 7px; }
.thumb.thumb-xs { --thumb: 28px; border-radius: 6px; }
@media (max-width: 599px) { .thumb.thumb-md { --thumb: 36px; } }
.row:has(> .thumb) { --sep-inset: calc(var(--inset-list) + var(--thumb-w, 40px) + var(--space-3)); }
.row:has(> .thumb-md) { --thumb-w: 40px; }
.row:has(> .thumb-sm) { --thumb-w: 32px; }
.row:has(> .thumb-xs) { --thumb-w: 28px; }
.row:has(> .thumb-lg) { --thumb-w: 64px; }
@media (max-width: 599px) { .row:has(> .thumb-md) { --thumb-w: 36px; } }

/* ---------- Controls ---------- */
.segmented { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 2px; gap: 2px; border-radius: 9px; background: var(--fill); }
.segmented button {
  border: 0; background: none; min-height: 28px; padding: 0 var(--space-3); border-radius: 7px;
  font: var(--t-segment); color: var(--label); cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.segmented button:hover:not([aria-pressed="true"]) { background: var(--fill); }
.segmented button[aria-pressed="true"] { background: var(--segment-selected); box-shadow: var(--shadow-segment); font-weight: 600; }
@media (pointer: coarse) { .segmented button { min-height: 32px; } }

/* UIStepper: value label, then a − | + capsule. */
.stepper-wrap { display: inline-flex; align-items: center; gap: var(--space-3); flex: none; }
.stepper-value { font: var(--t-body); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.stepper { display: inline-flex; align-items: center; background: var(--fill); border-radius: var(--radius-pill); flex: none; }
.stepper > button {
  position: relative; width: 47px; height: 32px; border: 0; background: none; color: var(--label);
  display: grid; place-items: center; cursor: pointer; font: var(--t-stepper); padding: 0;
  transition: background var(--dur-fast) var(--ease);
}
.stepper > button:first-child { border-radius: var(--radius-pill) 0 0 var(--radius-pill); }
.stepper > button:last-child { border-radius: 0 var(--radius-pill) var(--radius-pill) 0; }
.stepper > button:first-child::after { content: ""; position: absolute; right: 0; top: 8px; bottom: 8px; border-right: 0.5px solid var(--separator); }
.stepper > button:hover:not(:disabled) { background: var(--fill); }
.stepper > button:active:not(:disabled) { background: var(--fill-2); }
.stepper > button:disabled { color: var(--label-3); cursor: default; }
.stepper > button svg { width: 16px; height: 16px; stroke-width: 2.2; }
@media (pointer: coarse) { .stepper > button { height: var(--hit); width: 50px; } }

.field { display: grid; gap: var(--space-1); }
.field > span { font: var(--t-footnote); color: var(--label-2); padding-left: var(--inset-list); }
.input, .field input, .field select, .field textarea {
  width: 100%; min-width: 0; min-height: var(--hit); padding: var(--space-2) var(--space-3);
  border-radius: var(--radius); border: 0; background: var(--fill); color: var(--label); font: var(--t-body);
}
/* Text fields on the grouped background read as cells, not wells. */
.field input, .field textarea { background: var(--bg-elevated); box-shadow: var(--shadow-card); padding-inline: var(--inset-list); border-radius: var(--radius-lg); }
.field textarea { min-height: 160px; resize: vertical; line-height: 1.4; padding-block: var(--space-3); }
::placeholder { color: var(--label-3); }
.search { position: relative; display: block; }
.search input {
  padding: 0 var(--space-2) 0 34px; min-height: 36px; border-radius: var(--radius); border: 0; background: var(--fill);
  width: 100%; font: var(--t-body); color: var(--label); -webkit-appearance: none; appearance: none;
}
@media (pointer: coarse) { .search input { min-height: 40px; } }
.search > svg { position: absolute; left: 10px; top: 50%; translate: 0 -50%; width: 17px; height: 17px; color: var(--label-2); pointer-events: none; stroke-width: 2.2; }
/* iOS clear button: a filled grey circle with a white x. */
.search input::-webkit-search-cancel-button {
  -webkit-appearance: none; appearance: none; width: 17px; height: 17px; margin-left: var(--space-2); cursor: pointer;
  background: var(--label-3);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill-rule='evenodd' d='M10 20a10 10 0 1 0 0-20 10 10 0 0 0 0 20zM6.5 5.4 10 8.9l3.5-3.5 1.1 1.1-3.5 3.5 3.5 3.5-1.1 1.1-3.5-3.5-3.5 3.5-1.1-1.1 3.5-3.5-3.5-3.5z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill-rule='evenodd' d='M10 20a10 10 0 1 0 0-20 10 10 0 0 0 0 20zM6.5 5.4 10 8.9l3.5-3.5 1.1 1.1-3.5 3.5 3.5 3.5-1.1 1.1-3.5-3.5-3.5 3.5-1.1-1.1 3.5-3.5-3.5-3.5z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.row input.inline { border: 0; background: none; min-height: 32px; text-align: right; font: var(--t-body); color: var(--label-2); width: 6em; }
.switch { appearance: none; -webkit-appearance: none; margin: 0; width: 51px; height: 31px; border-radius: 16px; background: var(--fill-2); position: relative; cursor: pointer; flex: none; transition: background var(--dur) var(--ease); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: var(--knob); box-shadow: var(--shadow-knob); transition: translate var(--dur) var(--ease-out); }
.switch:checked { background: var(--tint); }
.switch:checked::after { translate: 20px 0; }
.switch:disabled { opacity: 0.4; }

/* ---------- Chips, cards, stats ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-pill); font: var(--t-chip); background: var(--fill); color: var(--label-2); white-space: nowrap; }
.chip svg, .chip-icon { width: 12px; height: 12px; stroke-width: 2.4; }
.chip.tint { background: var(--tint-fill); color: var(--tint); }
.chip.orange { background: var(--orange-fill); color: var(--orange); }
.chip.red { background: var(--red-fill); color: var(--red); }
.chip.blue { background: var(--blue-fill); color: var(--blue); }
.card { background: var(--bg-elevated); border-radius: var(--radius-lg); padding: var(--space-4); box-shadow: var(--shadow-card); display: grid; gap: var(--space-2); min-width: 0; }
.card > p { margin: 0; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-4); }
/* Health-style summary tiles: label on top, big rounded number with a small unit. */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); }
.stat { background: var(--bg-elevated); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-1); box-shadow: var(--shadow-card); min-width: 0; }
.stat .l { order: -1; font: var(--t-footnote); font-weight: 600; color: var(--label-2); }
.stat .v { font: var(--t-metric); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v .u { font: var(--t-subhead); font-weight: 600; color: var(--label-2); margin-left: 3px; letter-spacing: 0; }
.stat.kcal .v { color: var(--c-kcal); }
.stat.protein .v { color: var(--c-protein); }
.stat.carbs .v { color: var(--c-carbs); }
.stat.fat .v { color: var(--c-fat); }
.macro-bar { display: block; height: 8px; border-radius: var(--radius-pill); background: var(--fill); overflow: hidden; }
.macro-bar > i { display: block; height: 100%; border-radius: var(--radius-pill); transition: width var(--dur-slow) var(--ease-out); }

/* ---------- States ---------- */
.empty { text-align: center; padding: var(--space-8) var(--space-5); color: var(--label-2); display: grid; gap: var(--space-3); justify-items: center; }
.empty p { margin: 0; max-width: 36ch; }
.empty .title-3 { color: var(--label); }
.empty .btn { margin-top: var(--space-2); }
.empty-icon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--tint-fill); color: var(--tint); margin-bottom: var(--space-1); }
.empty-icon svg { width: 30px; height: 30px; }
.banner { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); background: var(--orange-fill); color: var(--label); font: var(--t-subhead); }
.banner.error { background: var(--red-fill); }
.banner.info { background: var(--tint-fill); }
.banner > svg { width: 20px; height: 20px; flex: none; margin-top: 0; color: var(--orange); }
.banner.error > svg { color: var(--red); }
.banner.info > svg { color: var(--tint); }
.banner strong { font-weight: 600; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--fill-2); border-top-color: var(--label-2); animation: spin 0.8s linear infinite; }
@keyframes spin { to { rotate: 360deg; } }
.skeleton { background: var(--fill); border-radius: var(--radius-sm); min-height: 1em; }
.banner-main { display: grid; gap: var(--space-1); justify-items: start; min-width: 0; }
.banner-retry { margin-top: var(--space-1); }
/* Loading states (U3): a spinner only after a moment; skeleton rows while a page loads. */
.empty.late { animation: late-in 1ms linear 400ms both; }
@keyframes late-in { from { visibility: hidden; } to { visibility: visible; } }
.skeleton-page { pointer-events: none; }
.sk-block { height: 112px; border-radius: var(--radius-lg); }
.skeleton-list .row { min-height: 56px; }
.sk-line { height: 14px; width: 62%; }
.sk-line.short { width: 34%; height: 12px; }
@media (prefers-reduced-motion: no-preference) {
  .skeleton-page .skeleton { animation: sk-pulse 1.4s ease-in-out infinite; }
}
@keyframes sk-pulse { 50% { opacity: 0.5; } }

/* ---------- Sheet (modal) + toast ---------- */
dialog.sheet {
  border: 0; padding: 0; border-radius: var(--radius-xl); background: var(--bg-grouped); color: var(--label);
  width: min(560px, calc(100vw - 24px)); max-width: none; max-height: min(86vh, 900px); box-shadow: var(--shadow-sheet); overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; }
dialog.sheet::backdrop { background: var(--backdrop); }
.sheet-head {
  flex: none; z-index: 1; display: grid; grid-template-columns: minmax(max-content, 1fr) minmax(0, auto) minmax(max-content, 1fr); align-items: center; gap: var(--space-2);
  min-height: 56px; padding: 0 var(--space-2); background: var(--material);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-bottom: 0.5px solid var(--separator);
}
.sheet-head h2 { font: var(--t-headline); margin: 0; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 60vw; }
.sheet-head > :first-child { justify-self: start; }
.sheet-head > :last-child { justify-self: end; }
.sheet-head .btn-plain { padding: 0 var(--space-2); }
.sheet-head .sheet-primary { font-weight: 600; }
.sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--space-5) var(--space-4) var(--space-6); display: grid; gap: var(--space-5); align-content: start; grid-template-columns: minmax(0, 1fr); grid-auto-rows: max-content; }
.sheet-body > p { margin: 0; }
.sheet-body > .footnote { padding: 0 var(--inset-list); }
@media (max-width: 599px) {
  /* Phone: near full-screen, anchored to the bottom, top corners rounded. */
  dialog.sheet { width: 100vw; max-height: none; height: calc(100dvh - 10px); margin: auto 0 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .sheet-body { padding-bottom: calc(var(--space-7) + env(safe-area-inset-bottom, 0px)); }
}
.toast {
  position: fixed; left: 50%; bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px)); translate: -50% 0; z-index: 50;
  display: inline-flex; align-items: center; gap: var(--space-2); max-width: min(480px, calc(100vw - 32px)); width: max-content;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); background: var(--toast-bg); color: var(--toast-label);
  font: var(--t-subhead); font-weight: 600; box-shadow: var(--shadow-sheet); text-align: center;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
/* Long messages: at most two lines, the full text in the title (U18). */
.toast > span:first-child { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; min-width: 0; }
@media (max-width: 899px) { .toast { bottom: 88px; } }
@media (prefers-reduced-motion: no-preference) {
  dialog.sheet[open] { animation: sheet-in var(--dur-slow) var(--ease-out); }
  dialog.sheet[open]::backdrop { animation: fade-in var(--dur-slow) var(--ease); }
  .toast { animation: toast-in var(--dur-slow) var(--ease-out); }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 599px) {
  dialog.sheet[open] { animation: sheet-up 300ms var(--ease-out); }
}
@keyframes sheet-in { from { opacity: 0; translate: 0 16px; scale: 0.98; } }
@keyframes sheet-up { from { translate: 0 100%; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes toast-in { from { opacity: 0; translate: -50% 12px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  .spinner { animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
}

/* ---------- Sign-in (shown when the API answers 401) ---------- */
body.locked { overflow: hidden; }
.login {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--space-5);
  padding-top: max(var(--space-5), env(safe-area-inset-top, 0px)); background: var(--bg-grouped);
}
.login-card { width: min(380px, 100%); display: grid; justify-items: center; gap: var(--space-3); text-align: center; }
.login-icon { width: 72px; height: 72px; border-radius: 16px; display: grid; place-items: center; background: var(--tint); color: var(--label-on-tint); margin-bottom: var(--space-2); box-shadow: var(--shadow-card); }
.login-icon svg { width: 40px; height: 40px; stroke-width: 1.9; }
.login-text { margin: 0 0 var(--space-3); font: var(--t-subhead); color: var(--label-2); max-width: 30ch; }
.login-field {
  width: 100%; display: flex; align-items: center; gap: var(--space-2); min-height: 50px; padding: 0 var(--space-4);
  background: var(--bg-elevated); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); cursor: text;
}
.login-field svg { width: 20px; height: 20px; color: var(--label-2); flex: none; }
.login-field input { flex: 1; min-width: 0; border: 0; background: none; font: var(--t-body); color: var(--label); min-height: 48px; }
.login-field:focus-within { box-shadow: 0 0 0 3px var(--focus); }
.login-field input:focus-visible { outline: none; }
.login-err { margin: 0; min-height: 18px; font: var(--t-footnote); color: var(--red); }
.login-card .btn { min-height: 50px; }
.login-err:empty { display: none; }
