/* MELA — view-specific styles.
   A1 owns: the shared app frame (#app / #view-root layout) and .view-head stub chrome.
   A2–A4: append per-view sections below — one commented block per view. */

/* ============================================================
   A1 · app frame
   ============================================================ */

#view-root {
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--sp-4);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-5));
  max-width: 960px;
  margin: 0 auto;
}

@media (min-width: 769px) {
  #view-root {
    margin-left: var(--rail-w);
    padding: var(--sp-5) var(--sp-6);
    max-width: calc(var(--rail-w) + 1040px);
  }
}

/* ============================================================
   A1 · shared view header chrome (stubs use this; real views keep it)
   ============================================================ */

.view-head {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--line-0);
  margin-bottom: var(--sp-4);
}

.view-head .view-tagline {
  font-family: var(--font-serif);
  font-style: normal;
  font-size: 19px;
  color: var(--tx-0);
  line-height: 1.3;
}

.view-head .view-tagline em,
.view-head .view-tagline .num {
  color: var(--acc);
  font-style: normal;
}

.view-stub-note {
  margin-top: var(--sp-4);
  font-size: 12px;
  color: var(--tx-2);
}

/* ============================================================
   A2 Â· catalogue â€” sticky head, filter sidebar/sheet, virtual list
   ============================================================ */

.cat-view {
  display: flex;
  flex-direction: column;
  /* fill the viewport minus #view-root paddings (mobile: sp-4 top,
     tabbar + safe-area + sp-5 bottom) so the list scrolls internally */
  height: calc(100dvh - var(--tabbar-h) - env(safe-area-inset-bottom, 0px) - var(--sp-5) - var(--sp-4));
  min-height: 320px;
}

@media (min-width: 769px) {
  .cat-view {
    /* desktop: sp-5 top and bottom */
    height: calc(100dvh - var(--sp-5) - var(--sp-5));
  }
}

.cat-head {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--line-0);
  background: var(--ink-0);
}

.cat-head-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.cat-sort select {
  min-height: 36px;
  padding: 0 var(--sp-2);
  background: var(--ink-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-card);
  color: var(--tx-0);
  font-size: 12px;
  max-width: 130px;
}
.cat-sort select:focus-visible { outline: 1px solid var(--acc); outline-offset: 2px; }

.cat-filter-btn {
  position: relative;
  font-size: 12px;
  padding: var(--sp-2) var(--sp-3);
  flex: none;
}

.cat-filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  font-size: 10px;
  background: var(--acc);
  color: var(--ink-0);
  border-radius: var(--r-chip);
}

.cat-meta { padding-top: var(--sp-1); }
.cat-meta .num { color: var(--tx-0); font-size: 11px; }

.cat-body {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: var(--sp-5);
}

/* ---- filter surface: mobile = slide-up sheet ---- */
.cat-filter-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 13, 12, 0.6);
  z-index: calc(var(--z-sheet) - 1);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease);
}
.cat-filter-backdrop.open { opacity: 1; pointer-events: auto; }

.cat-filter-wrap {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-sheet);
  background: var(--ink-2);
  border-top: 1px solid var(--line-1);
  border-radius: var(--r-card) var(--r-card) 0 0;
  max-height: 82dvh;
  overflow-y: auto;
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom, 0px));
  transform: translateY(102%);
  visibility: hidden; /* offscreen sheet is not tabbable */
  transition: transform var(--dur-3) var(--ease), visibility 0s var(--dur-3);
}
.cat-filter-wrap.open {
  transform: translateY(0);
  visibility: visible;
  transition: transform var(--dur-3) var(--ease), visibility 0s 0s;
}

.cat-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--sp-2);
  margin-bottom: var(--sp-2);
  border-bottom: 1px solid var(--line-0);
}
.cat-sheet-done { font-size: 13px; color: var(--acc); padding: var(--sp-1) var(--sp-2); }

/* ---- desktop: filter sidebar column, no sheet chrome ---- */
@media (min-width: 769px) {
  .cat-filter-backdrop { display: none; }
  .cat-filter-btn { display: none; }
  .cat-filter-wrap {
    position: static;
    transform: none;
    transition: none;
    visibility: visible;
    width: 240px;
    flex: none;
    max-height: none;
    overflow-y: auto;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: var(--sp-4) 0 var(--sp-4);
    border-right: 1px solid var(--line-0);
    padding-right: var(--sp-4);
  }
  .cat-sheet-head { display: none; }
}

/* ---- virtual list ---- */
.cat-list {
  --row-h: 64px;
  flex: 1;
  min-width: 0;
  position: relative;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.cat-spacer { position: relative; width: 100%; }

/* accordion open/close: rows briefly transition their offsets */
.cat-spacer.cat-anim .cat-row { transition: top var(--dur-2) var(--ease); }

.cat-row {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--row-h);
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--line-0);
  cursor: pointer;
  background: var(--ink-0);
}

.cat-row:hover { background: var(--ink-1); }
.cat-row:focus-visible { outline: 1px solid var(--acc); outline-offset: -1px; }

.cat-row-open {
  height: auto;
  z-index: 1;
  background: var(--ink-1);
  border-bottom-color: var(--line-1);
}

.cat-row-oos .cr-main { opacity: 0.45; }

.cr-main {
  flex: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  /* row-h minus 3px strip minus 1px border = exact fit */
  height: calc(var(--row-h) - 4px);
  padding: 0 var(--sp-1);
  min-width: 0;
}

.cr-line1 {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  min-width: 0;
}

.cr-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--tx-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cr-price {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  font-size: 13px;
}
.cr-was { color: var(--tx-2); font-size: 11px; }
.cr-now { color: var(--acc); }

.cr-line2 {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 11px;
  color: var(--tx-1);
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
}

.cr-pack { color: var(--tx-2); flex: none; }
.cr-macros { flex: none; }
.cr-macros .num { font-size: 11px; }
.cr-mu { color: var(--tx-2); font-size: 9px; }
.cr-nomacro { color: var(--tx-2); font-style: normal; }

.cr-vdots { display: inline-flex; gap: 2px; flex: none; }
.cr-vdots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--tx-2);
}

/* ---- expanded row detail ---- */
.cat-expand {
  padding: var(--sp-2) var(--sp-1) var(--sp-4);
  border-top: 1px solid var(--line-0);
  cursor: default;
  animation: fade-in var(--dur-2) var(--ease);
}

.ce-top {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-2) 0 var(--sp-3);
}

.ce-img,
.ce-img-fb {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: var(--r-chip);
  object-fit: cover;
  background: var(--ink-3);
}

.ce-img-fb {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-style: normal;
  font-size: 24px;
  color: var(--tx-2);
}

.ce-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--tx-1);
  min-width: 0;
}

.ce-sub { text-transform: uppercase; letter-spacing: 0.06em; font-size: 10px; color: var(--tx-2); }
.ce-unit .num { color: var(--tx-0); }
.ce-src-label { color: var(--ok); }
.ce-src-est { color: var(--tx-2); }
.ce-byweight { color: var(--warn); font-style: normal; }

.ce-nutrition {
  width: 100%;
  max-width: 360px;
  border-collapse: collapse;
  font-size: 12px;
}
.ce-nutrition th { text-align: left; padding: 0 0 var(--sp-1); }
.ce-nutrition td {
  padding: 3px 0;
  border-top: 1px solid var(--line-0);
  color: var(--tx-1);
}
.ce-nutrition td.num { text-align: right; color: var(--tx-0); }

.ce-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding-top: var(--sp-3);
}
.ce-add:disabled { opacity: 0.4; cursor: not-allowed; }
.ce-oos { font-size: 11px; color: var(--bad); }

/* empty results */
.cat-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-4);
  padding: var(--sp-6) var(--sp-2);
}
.cat-empty-line { font-size: 18px; color: var(--tx-1); line-height: 1.4; }

/* ============================================================
   A3 · daily plan — date nav, target board, slot cards
   ============================================================ */

.dp-head { gap: var(--sp-1); }

.dp-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.dp-chev {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: var(--tx-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  flex: none;
}
.dp-chev:hover { color: var(--tx-0); background: var(--ink-3); }

.dp-datewrap {
  position: relative;
  flex: 1;
  min-width: 0;
  text-align: center;
}

.dp-date {
  font-family: var(--font-serif);
  font-style: normal;
  font-weight: 400;
  font-size: 22px;
  color: var(--tx-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* invisible native date input stretched over the label — tap = picker */
.dp-datepick {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
}
.dp-datewrap:has(.dp-datepick:focus-visible) { outline: 1px solid var(--acc); outline-offset: 2px; }

.dp-more {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  letter-spacing: 0.06em;
  color: var(--tx-1);
  border: 1px solid transparent;
  border-radius: var(--r-chip);
  flex: none;
}
.dp-more:hover { color: var(--tx-0); background: var(--ink-3); }

.dp-sub { text-align: center; }

/* target board */
.dp-board {
  padding: var(--sp-4) 0 var(--sp-4);
  border-bottom: 1px solid var(--line-0);
  margin-bottom: var(--sp-4);
}

.dp-gauges {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

@media (min-width: 769px) {
  .dp-gauges {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: var(--sp-3) var(--sp-5);
  }
  .dp-gauges .pgauge-big { grid-column: 1 / -1; }
}

.dp-remaining {
  margin-top: var(--sp-4);
  font-size: 17px;
  color: var(--tx-1);
  line-height: 1.4;
}
.dp-remaining .dp-mela { color: var(--acc); font-style: normal; }

/* slot cards */
.dp-slots {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.dp-slot {
  background: var(--ink-1);
  border: 1px solid var(--line-0);
  border-radius: var(--r-card);
  overflow: hidden;
  text-align: left;
}

.dp-slot-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-4);
}

.dp-slot-toggle { cursor: pointer; }
.dp-slot-toggle:hover { background: var(--ink-3); }

.dp-slot-head .microlabel { flex: 1; text-align: left; }
.dp-slot-kcal { font-size: 14px; color: var(--tx-0); }
.dp-ku { font-size: 10px; color: var(--tx-2); }

.dp-slot-chev {
  color: var(--tx-2);
  flex: none;
  transition: transform var(--dur-1) var(--ease);
}
.dp-slot-chev.open { transform: rotate(180deg); }

.dp-slot-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: 0 var(--sp-4) var(--sp-3);
}

.dp-slot-sum {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
}
.dp-slot-cost { font-size: 12px; color: var(--tx-1); }

.dp-items { display: flex; flex-direction: column; }

.dp-item {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--line-0);
  font-size: 12px;
}
.dp-item:last-child { border-bottom: none; }

.dp-item-name {
  flex: 1;
  min-width: 0;
  color: var(--tx-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dp-item-missing .dp-item-name { color: var(--tx-2); font-style: normal; }
.dp-item-g { color: var(--tx-2); font-size: 11px; flex: none; }
.dp-item-kcal { color: var(--tx-1); font-size: 11px; flex: none; min-width: 5ch; text-align: right; }
.dp-item-cost { color: var(--tx-1); font-size: 11px; flex: none; min-width: 6ch; text-align: right; }
.dp-slot-head .dp-slot-cost { flex: none; }

.dp-edit { align-self: flex-start; font-size: 12px; padding: var(--sp-1) var(--sp-3); min-height: 32px; }

/* empty slot: whole card is the button */
.dp-slot-empty {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding-bottom: var(--sp-3);
  cursor: pointer;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.dp-slot-empty:hover { border-color: var(--line-1); background: var(--ink-2); }
.dp-slot-empty .dp-slot-head { padding-bottom: 0; }

.dp-plan-prompt {
  padding: 0 var(--sp-4);
  font-size: 15px;
  color: var(--tx-2);
}
.dp-slot-empty:hover .dp-plan-prompt { color: var(--acc); }

/* day actions menu (inside modal) */
.dp-menu { display: flex; flex-direction: column; gap: var(--sp-2); }

.dp-menu-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--line-0);
  border-radius: var(--r-card);
  font-size: 13px;
  color: var(--tx-0);
  text-align: left;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.dp-menu-item:hover { border-color: var(--line-1); background: var(--ink-3); }
.dp-menu-hint { font-size: 11px; color: var(--tx-2); }
.dp-menu-danger { color: var(--bad); }
.dp-menu-danger:hover { border-color: var(--bad); }

.dp-date-input {
  width: 100%;
  margin-top: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  min-height: 36px;
  font-size: 13px;
  color: var(--tx-0);
  background: var(--ink-0);
  border: 1px solid var(--line-1);
  border-radius: var(--r-card);
  color-scheme: dark;
}
.dp-date-input:focus { border-color: var(--acc); }

/* ============================================================
   A3 · week view — day rows (mobile) / 7-column grid (desktop)
   ============================================================ */

.wk-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.wk-chev {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: var(--tx-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  flex: none;
}
.wk-chev:hover { color: var(--tx-0); background: var(--ink-3); }

.wk-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  text-align: center;
}
.wk-range { font-size: 21px; font-weight: 400; color: var(--tx-0); }
.wk-today-btn { font-size: 12px; flex: none; padding: var(--sp-1) var(--sp-2); }

/* mobile: vertical stack of day rows */
.wk-grid {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.wk-day {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  grid-template-areas:
    "head mid chips"
    "strip strip strip";
  align-items: center;
  gap: var(--sp-1) var(--sp-3);
  padding: var(--sp-2) var(--sp-3) var(--sp-2);
  background: var(--ink-1);
  border: 1px solid var(--line-0);
  border-radius: var(--r-card);
  cursor: pointer;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.wk-day:hover { border-color: var(--line-1); }
.wk-day:focus-visible { outline: 1px solid var(--acc); outline-offset: 1px; }

/* compliance tint: subtle status overlay on the surface */
.wk-tint-ok   { background: color-mix(in srgb, var(--ok) 6%, var(--ink-1)); }
.wk-tint-warn { background: color-mix(in srgb, var(--warn) 6%, var(--ink-1)); }
.wk-tint-bad  { background: color-mix(in srgb, var(--bad) 6%, var(--ink-1)); }

.wk-today { border-color: var(--acc); }

.wk-drop {
  border-color: var(--acc);
  background: color-mix(in srgb, var(--acc) 8%, var(--ink-1));
}

.wk-day-head {
  grid-area: head;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.wk-dnum { font-size: 15px; color: var(--tx-0); }

.wk-day-mid {
  grid-area: mid;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.wk-kcal { font-size: 17px; color: var(--tx-0); }
.wk-cost { font-size: 11px; color: var(--tx-1); }

.wk-macros {
  display: flex;
  gap: var(--sp-2);
  min-width: 0;
  flex-wrap: wrap;
}
.wk-m { display: inline-flex; align-items: baseline; gap: 2px; white-space: nowrap; }
.wk-mv { font-size: 11px; color: var(--tx-1); }
.wk-mt { font-size: 10px; color: var(--tx-2); }
.wk-m[data-status="ok"]   .wk-mv { color: var(--ok); }
.wk-m[data-status="warn"] .wk-mv { color: var(--warn); }
.wk-m[data-status="bad"]  .wk-mv { color: var(--bad); }

.wk-strip { grid-area: strip; }

.wk-chips {
  grid-area: chips;
  display: flex;
  gap: 3px;
  align-self: center;
}

.wk-chip {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--tx-2);
  border: 1px solid var(--line-0);
  border-radius: var(--r-chip);
  opacity: 0.45;
  user-select: none;
  -webkit-user-select: none;
}

.wk-chip-on {
  opacity: 1;
  color: var(--tx-0);
  border-color: var(--line-1);
  background: var(--ink-3);
}
.wk-chip-drag { border-color: var(--acc); color: var(--acc); }

@media (min-width: 769px) {
  .wk-chip-on { cursor: grab; }

  /* desktop: 7 columns, cells stack vertically */
  .wk-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: var(--sp-2);
    align-items: stretch;
  }

  .wk-day {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-2);
    min-height: 168px;
    padding: var(--sp-3);
  }

  .wk-day-head { flex-direction: row; align-items: baseline; justify-content: space-between; }
  .wk-day-mid { flex-direction: column; align-items: flex-start; gap: var(--sp-1); flex: 1; }
  .wk-kcal { font-size: 19px; }
  .wk-macros { flex-direction: column; gap: 2px; }
  .wk-chips { align-self: flex-start; }
}

/* averages: summary card (mobile) / bottom row (desktop) */
.wk-avg {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3) var(--sp-5);
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--ink-1);
  border: 1px solid var(--line-0);
  border-radius: var(--r-card);
}

.wk-avg-cell {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.wk-avg-val { font-size: 15px; color: var(--tx-0); }
.wk-avg-per { font-size: 10px; color: var(--tx-2); }
.wk-avg-delta { font-size: 10px; color: var(--tx-2); }
.wk-avg-cell[data-status="ok"]   .wk-avg-val { color: var(--ok); }
.wk-avg-cell[data-status="warn"] .wk-avg-val { color: var(--warn); }
.wk-avg-cell[data-status="bad"]  .wk-avg-val { color: var(--bad); }

.wk-avg-empty { font-size: 16px; color: var(--tx-1); }

/* ============================================================
   A3 · shopping list — generate bar, grouped rows, sticky footer
   ============================================================ */

.sl-genbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--line-0);
  margin-bottom: var(--sp-3);
}

.sl-presets { display: flex; gap: var(--sp-1); }

.sl-custom {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.sl-custom input {
  min-height: 32px;
  padding: 0 var(--sp-2);
  font-size: 12px;
  color: var(--tx-0);
  background: var(--ink-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  color-scheme: dark;
}
.sl-custom input:focus { border-color: var(--acc); }
.sl-arrow { color: var(--tx-2); font-size: 12px; }

.sl-generate { margin-left: auto; font-size: 12px; min-height: 32px; padding: var(--sp-1) var(--sp-3); }

/* groups */
.sl-group { margin-bottom: var(--sp-4); }

.sl-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-bottom: var(--sp-1);
  border-bottom: 1px solid var(--line-0);
}
.sl-group-sub { font-size: 11px; color: var(--tx-2); }

.sl-group-done { opacity: 0.75; }
.sl-group-done .sl-group-head .microlabel { color: var(--acc-dim); }

/* rows */
.sl-row {
  position: relative; /* anchors the visually-hidden real checkbox */
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  min-height: 44px;
  border-bottom: 1px solid var(--line-0);
}
.sl-row:last-child { border-bottom: none; }

/* custom checkbox: real input, visually replaced by .sl-box */
.sl-cb {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.sl-box {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  color: var(--ink-0);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.sl-box svg { opacity: 0; transition: opacity var(--dur-1) var(--ease); }
.sl-row:hover .sl-box { border-color: var(--acc-dim); }
.sl-cb:checked + .sl-box { background: var(--acc); border-color: var(--acc); }
.sl-cb:checked + .sl-box svg { opacity: 1; }
.sl-cb:focus-visible + .sl-box { outline: 1px solid var(--acc); outline-offset: 2px; }

.sl-main { flex: 1; min-width: 0; }

.sl-line1 {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  min-width: 0;
}

.sl-units { flex: none; font-size: 13px; color: var(--acc); min-width: 3ch; }
.sl-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--tx-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sl-price { flex: none; font-size: 13px; color: var(--tx-0); }

.sl-note { font-size: 11px; color: var(--tx-2); margin-top: 1px; }

.sl-checked .sl-name { text-decoration: line-through; color: var(--tx-2); }
.sl-checked .sl-units,
.sl-checked .sl-price { color: var(--tx-2); }

.sl-missing .sl-name { color: var(--tx-2); font-style: normal; }
.sl-missing .sl-note { color: var(--warn); }

/* sticky footer summary */
.sl-footer {
  position: sticky;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-2));
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--ink-2);
  border: 1px solid var(--line-1);
  border-radius: var(--r-card);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 5;
}

@media (min-width: 769px) {
  .sl-footer { bottom: var(--sp-3); }
}

.sl-foot-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.sl-foot-total {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  min-width: 0;
  flex-wrap: wrap;
}
.sl-total { font-size: 20px; color: var(--tx-0); }
.sl-count { font-size: 11px; color: var(--tx-2); }

.sl-copy { font-size: 12px; min-height: 32px; padding: var(--sp-1) var(--sp-3); flex: none; }

.sl-venues {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding-top: var(--sp-1);
  border-top: 1px solid var(--line-0);
}

.sl-vchip {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border: 1px solid var(--line-0);
  border-radius: var(--r-chip);
  font-size: 11px;
}
.sl-vchip .num { color: var(--tx-0); }
.sl-sup { color: var(--tx-2); font-size: 10px; }

.sl-foot-note { font-size: 10px; color: var(--tx-2); }

/* empty state */
.sl-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-4);
  padding: var(--sp-6) var(--sp-2);
}
.sl-empty-line { font-size: 18px; color: var(--tx-1); line-height: 1.4; }


/* ============================================================
   A4 · charts (dashboard SVG helpers)
   ============================================================ */

.chart { max-width: 100%; }
.ch-grid { stroke: var(--line-0); stroke-width: 1; }
.ch-target { stroke: var(--tx-2); stroke-width: 1; }
.ch-line { stroke: var(--acc); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ch-dot { fill: var(--acc); }
.ch-lab {
  fill: var(--tx-2);
  font-family: var(--font-num);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   A4 · dashboard — ledger stack
   ============================================================ */

.db-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-4);
  padding: var(--sp-6) var(--sp-2);
}
.db-empty-line { font-size: 18px; color: var(--tx-1); line-height: 1.4; }

.db-sec {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--line-0);
}
.db-sec:last-child { border-bottom: none; }

.db-live { display: flex; flex-direction: column; }

@media (min-width: 769px) {
  .db-live {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 0 var(--sp-6);
    align-items: start;
  }
  .db-live .db-today { grid-row: span 2; }
}

.db-today-body {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  flex-wrap: wrap;
}

.db-today-side {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-width: 0;
}

.db-today-legend {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  font-size: 12px;
  min-width: 150px;
}
.db-today-legend > span { display: flex; align-items: baseline; gap: var(--sp-2); }
.db-today-legend .num { margin-left: auto; color: var(--tx-0); }

.db-dot {
  width: 8px;
  height: 8px;
  flex: none;
  align-self: center;
  border-radius: var(--r-0);
}
.db-dot-p { background: var(--pro); }
.db-dot-c { background: var(--carb); }
.db-dot-f { background: var(--fat); }

.db-today-delta { font-size: 12px; color: var(--tx-1); }
.db-today-delta .num { color: var(--tx-0); }

.db-trend { max-width: 520px; }

/* heatmap: label column + 7 day columns */
.db-heat {
  display: grid;
  grid-template-columns: 34px repeat(7, minmax(0, 1fr));
  gap: 3px;
  max-width: 520px;
}
.db-heat-day { font-size: 10px; color: var(--tx-2); text-align: center; }
.db-heat-lab { align-self: center; font-size: 10px; }
.db-heat-cell {
  height: 22px;
  border-radius: var(--r-0);
  background: var(--ink-1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--tx-2);
}
.db-heat-none { color: var(--tx-2); }

/* top-product ledgers */
.db-tops {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4) var(--sp-5);
}
@media (min-width: 769px) {
  .db-tops { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.db-ledger { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.db-ledger .microlabel { padding-bottom: var(--sp-1); border-bottom: 1px solid var(--line-0); }

.db-lrow {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  width: 100%;
  min-height: 32px;
  padding: var(--sp-1) 0;
  border-bottom: 1px solid var(--line-0);
  font-size: 12px;
  color: var(--tx-1);
  text-align: left;
  transition: color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.db-lrow:last-child { border-bottom: none; }
.db-lrow:hover { color: var(--tx-0); background: var(--ink-1); }

.db-rank { flex: none; width: 2ch; font-size: 11px; color: var(--tx-2); }
.db-lname {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--tx-0);
}
.db-lstat { flex: none; font-size: 11px; color: var(--acc); }

.db-budget-line { font-size: 12px; color: var(--tx-1); }
.db-budget-line .num { color: var(--tx-0); }
.db-approx { color: var(--tx-2); font-size: 11px; }

/* ============================================================
   A4 · daily-plan suggest button (F7 entry point)
   ============================================================ */

.dp-suggest {
  margin-top: var(--sp-3);
  font-size: 12px;
  min-height: 32px;
  padding: var(--sp-1) var(--sp-3);
  align-self: flex-start;
}

/* ============================================================
   A4 · settings — ledger sections
   ============================================================ */

.st-sections { display: flex; flex-direction: column; }

.st-sec {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--line-0);
}
.st-sec:last-child { border-bottom: none; }

.st-hint { font-size: 11px; color: var(--tx-2); line-height: 1.5; max-width: 60ch; }
.st-body { display: flex; flex-direction: column; gap: var(--sp-3); }
.st-chips { display: flex; flex-wrap: wrap; gap: var(--sp-1); }

.st-targets {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-2);
  max-width: 420px;
}

.st-target {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.st-tlabel { flex: 1; font-size: 13px; color: var(--tx-1); }
.st-tunit { font-size: 11px; color: var(--tx-2); min-width: 3ch; }

.st-tinput {
  width: 76px;
  min-height: 32px;
  padding: 0 var(--sp-2);
  font-size: 13px;
  text-align: right;
  color: var(--tx-0);
  background: var(--ink-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  -moz-appearance: textfield;
  appearance: textfield;
}
.st-tinput::-webkit-outer-spin-button,
.st-tinput::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.st-tinput:focus { border-color: var(--acc); }

/* slots */
.st-slot {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 40px;
}
.st-slot-name {
  flex: 1;
  min-width: 0;
  min-height: 32px;
  padding: 0 var(--sp-2);
  font-size: 13px;
  color: var(--tx-0);
  background: var(--ink-1);
  border: 1px solid var(--line-0);
  border-radius: var(--r-chip);
}
.st-slot-name:focus { border-color: var(--acc); }
.st-slot-x:hover { color: var(--bad); }
.st-slot-add { align-self: flex-start; font-size: 12px; min-height: 32px; padding: var(--sp-1) var(--sp-3); }

/* segmented control */
/* Venue picker. Was an inline-flex segmented control, which worked at 5 venues
   but overflows the screen at 11 (the multi-store expansion). Now a wrapping
   chip group — same language as the filter-panel chips — so it reflows to any
   count on any width instead of forcing a horizontal scroll. */
.st-seg {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-self: flex-start;
}
.st-seg-btn {
  padding: var(--sp-2) var(--sp-3);
  min-height: 44px;
  font-size: 12px;
  color: var(--tx-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.st-seg-btn:hover { background: var(--ink-3); color: var(--tx-0); }
.st-seg-btn.st-seg-on { background: var(--ink-2); color: var(--acc); border-color: var(--acc); }

/* accent swatches */
.st-swatches { display: flex; gap: var(--sp-2); }
.st-swatch {
  width: 32px;
  height: 32px;
  border-radius: var(--r-chip);
  border: 2px solid transparent;
  transition: transform var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.st-swatch:hover { transform: translateY(-1px); }
.st-swatch-on { border-color: var(--tx-0); }

.st-key {
  width: 100%;
  max-width: 420px;
  min-height: 36px;
  padding: 0 var(--sp-3);
  font-size: 13px;
  color: var(--tx-0);
  background: var(--ink-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-card);
}
.st-key:focus { border-color: var(--acc); }

.st-row-btns { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.st-storage .num { color: var(--tx-1); }
.st-about { font-size: 13px; color: var(--tx-1); line-height: 1.7; }
.st-about .num { color: var(--tx-0); }
.st-credit { font-size: 11px; color: var(--tx-2); }

/* ============================================================
   A4 · AI advisor — chat layout
   ============================================================ */

.ai-view {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--tabbar-h) - env(safe-area-inset-bottom, 0px) - var(--sp-5) - var(--sp-4));
  min-height: 320px;
}
@media (min-width: 769px) {
  .ai-view { height: calc(100dvh - var(--sp-5) - var(--sp-5)); }
}

.ai-head { flex: none; margin-bottom: 0; }
.ai-head-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.ai-clear { font-size: 12px; padding: var(--sp-1) var(--sp-2); }

.ai-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4) 0;
}

.ai-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-2);
}
.ai-empty-line { font-size: 18px; color: var(--tx-1); line-height: 1.4; }
.ai-starters { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-2); }
.ai-starter { font-size: 13px; min-height: 32px; }

.ai-inputbar {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) 0;
  border-top: 1px solid var(--line-0);
  background: var(--ink-0);
}

.ai-input {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  max-height: 96px;
  padding: var(--sp-2) var(--sp-3);
  font-size: 13px;
  line-height: 20px;
  color: var(--tx-0);
  background: var(--ink-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-card);
  resize: none;
  overflow-y: auto;
}
.ai-input:focus { border-color: var(--acc); outline: none; }
.ai-input::placeholder { color: var(--tx-2); }

.ai-send { flex: none; min-height: 36px; }
.ai-send:disabled { opacity: 0.45; cursor: default; }

/* ============================================================
   A4 · onboarding overlay
   ============================================================ */

.ob-root {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--ink-0);
  display: flex;
  flex-direction: column;
  padding: var(--sp-5) var(--sp-4);
  padding-bottom: max(var(--sp-5), env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  animation: fade-in var(--dur-3) var(--ease);
}

.ob-top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.ob-wordmark { font-size: 26px; color: var(--acc); }
.ob-skip { font-size: 13px; }

.ob-body {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-5) 0;
}

.ob-h { font-size: 30px; font-weight: 400; color: var(--tx-0); line-height: 1.15; }
.ob-sub { font-size: 13px; color: var(--tx-1); line-height: 1.5; max-width: 44ch; }

.ob-presets { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.ob-targets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
  max-width: 360px;
}
@media (min-width: 480px) {
  .ob-targets { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: none; }
}

.ob-target { display: flex; flex-direction: column; gap: var(--sp-1); }
.ob-target input {
  min-height: 40px;
  padding: 0 var(--sp-2);
  font-size: 15px;
  text-align: right;
  color: var(--tx-0);
  background: var(--ink-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  width: 100%;
  -moz-appearance: textfield;
  appearance: textfield;
}
.ob-target input::-webkit-outer-spin-button,
.ob-target input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ob-target input:focus { border-color: var(--acc); }

.ob-showcase { display: flex; flex-direction: column; gap: var(--sp-3); }
.ob-row {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-3);
  border: 1px solid var(--line-0);
  border-radius: var(--r-card);
  background: var(--ink-1);
}
.ob-row-line { display: flex; align-items: baseline; gap: var(--sp-3); }
.ob-row-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--tx-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ob-row-price { flex: none; font-size: 13px; color: var(--acc); }
.ob-row-sub { display: flex; justify-content: space-between; gap: var(--sp-3); font-size: 11px; color: var(--tx-2); }
.ob-row-tag { color: var(--tx-1); }

.ob-cta { display: flex; flex-wrap: wrap; gap: var(--sp-3); }

.ob-nav {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.ob-dots { display: flex; gap: var(--sp-2); }
.ob-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-1);
  transition: background var(--dur-1) var(--ease);
}
.ob-dots i.ob-dot-on { background: var(--acc); }

/* A4 · large dashboard ring: scale the center numerals up */
.db-ring-slot .mr-kcal { font-size: 26px; }
.db-ring-slot .mr-unit { font-size: 10px; }

/* profiles section (settings) */
.st-prof-row { align-items: center; }
.st-prof-active {
  flex: none;
  color: var(--acc);
  border: 1px solid var(--line-1);
  border-radius: 2px;
  padding: 2px 8px;
}
.st-prof-switch { font-size: 12px; padding: var(--sp-1) var(--sp-3); min-height: 32px; flex: none; }
