/* MELA — component styles.
   A1 owns: .nav-* (rail + tab bar + more-sheet), .modal-*, .toast-*, .btn.
   A2–A4: append your component sections below the A1 block — do not restyle A1 selectors. */

/* ============================================================
   A1 · buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  min-height: 36px;
  border-radius: var(--r-card);
  border: 1px solid var(--line-1);
  color: var(--tx-0);
  font-weight: 500;
  font-size: 13px;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}

.btn:hover { background: var(--ink-3); }

.btn-primary {
  background: var(--acc);
  border-color: var(--acc);
  color: var(--ink-0);
}

.btn-primary:hover { background: var(--acc-dim); border-color: var(--acc-dim); }

.btn-ghost { border-color: transparent; color: var(--tx-1); }
.btn-ghost:hover { color: var(--tx-0); }

/* ============================================================
   A1 · nav — left rail ≥769px / bottom tab bar ≤768px
   ============================================================ */

.nav-rail {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--rail-w);
  display: none;
  flex-direction: column;
  border-right: 1px solid var(--line-0);
  background: var(--ink-0);
  z-index: var(--z-nav);
  padding: var(--sp-5) 0 var(--sp-4);
}

.nav-rail .nav-wordmark {
  font-family: var(--font-serif);
  font-style: normal;
  font-size: 26px;
  color: var(--acc);
  padding: 0 var(--sp-4) var(--sp-5);
}

.nav-rail .nav-links {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-rail a {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  min-height: 40px;
  font-size: 13px;
  font-weight: 500;
  color: var(--tx-1);
  border-left: 2px solid transparent;
  transition: color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}

.nav-rail a:hover { color: var(--tx-0); background: var(--ink-1); }

.nav-rail a[aria-current="page"] {
  color: var(--acc);
  border-left-color: var(--acc);
  background: var(--ink-1);
}

.nav-rail a svg { flex: none; stroke: currentColor; }

.nav-snapshot {
  padding: var(--sp-3) var(--sp-4) 0;
  border-top: 1px solid var(--line-0);
  font-size: 11px;
  color: var(--tx-2);
  line-height: 1.6;
}

/* active profile indicator above the snapshot line (rail only) */
.nav-profile {
  padding: var(--sp-3) var(--sp-4) var(--sp-2);
  border-top: 1px solid var(--line-0);
  color: var(--acc);
}

/* tab bar (mobile) */
.nav-tabbar {
  position: fixed;
  inset: auto 0 0 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: var(--ink-1);
  border-top: 1px solid var(--line-0);
  z-index: var(--z-nav);
}

.nav-tabbar a,
.nav-tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--tx-2);
  border-top: 2px solid transparent;
  transition: color var(--dur-1) var(--ease);
}

.nav-tabbar a[aria-current="page"],
.nav-tabbar button[aria-expanded="true"] {
  color: var(--acc);
  border-top-color: var(--acc);
}

.nav-tabbar svg { stroke: currentColor; }

@media (min-width: 769px) {
  .nav-rail { display: flex; }
  .nav-tabbar { display: none; }
}

/* more-sheet (mobile overflow) */
.nav-more-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 13, 12, 0.6);
  z-index: calc(var(--z-sheet) - 1);
}

.nav-more-sheet {
  position: fixed;
  inset: auto 0 calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)) 0;
  background: var(--ink-2);
  border-top: 1px solid var(--line-1);
  z-index: var(--z-sheet);
  padding: var(--sp-2) 0 var(--sp-2);
  animation: sheet-up var(--dur-2) var(--ease);
}

.nav-more-sheet a {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  min-height: 44px;
  font-size: 14px;
  font-weight: 500;
  color: var(--tx-1);
}

.nav-more-sheet a:hover { background: var(--ink-3); color: var(--tx-0); }
.nav-more-sheet a[aria-current="page"] { color: var(--acc); }
.nav-more-sheet a svg { stroke: currentColor; }

@keyframes sheet-up {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ============================================================
   A1 · modal — centered desktop / sheet-from-bottom mobile
   ============================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 13, 12, 0.8);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in var(--dur-2) var(--ease);
}

.modal-panel {
  background: var(--ink-2);
  border: 1px solid var(--line-1);
  border-bottom: none;
  border-radius: var(--r-card) var(--r-card) 0 0;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: sheet-up var(--dur-2) var(--ease);
}

@media (min-width: 769px) {
  .modal-backdrop { align-items: center; }
  .modal-panel {
    width: min(520px, calc(100vw - var(--sp-6)));
    border-bottom: 1px solid var(--line-1);
    border-radius: var(--r-card);
    max-height: 80vh;
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4);
  border-bottom: 1px solid var(--line-0);
}

.modal-title { font-size: 15px; font-weight: 600; }

.modal-close {
  color: var(--tx-1);
  padding: var(--sp-1);
  line-height: 0;
  border-radius: var(--r-chip);
}
.modal-close:hover { color: var(--tx-0); background: var(--ink-3); }

.modal-body {
  padding: var(--sp-4);
  overflow-y: auto;
  flex: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-0);
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ============================================================
   A1 · toast
   ============================================================ */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-4));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: none;
}

@media (min-width: 769px) {
  .toast-region { bottom: var(--sp-5); left: calc(50% + var(--rail-w) / 2); }
}

.toast {
  background: var(--ink-2);
  border: 1px solid var(--line-1);
  border-radius: var(--r-card);
  padding: var(--sp-2) var(--sp-4);
  font-size: 13px;
  color: var(--tx-0);
  max-width: min(360px, calc(100vw - var(--sp-6)));
  animation: sheet-up var(--dur-2) var(--ease);
  border-left: 2px solid var(--line-1);
}

.toast[data-kind="ok"]   { border-left-color: var(--ok); }
.toast[data-kind="warn"] { border-left-color: var(--warn); }
.toast[data-kind="bad"]  { border-left-color: var(--bad); }
.toast[data-kind="acc"]  { border-left-color: var(--acc); }

.toast.toast-out { opacity: 0; transition: opacity var(--dur-2) var(--ease); }

/* ============================================================
   A2 Â· macro strip â€” the signature element (3px stacked P/C/F)
   ============================================================ */

.macro-bar {
  display: flex;
  gap: 1px;
  width: 100%;
  height: 3px;
  border-radius: var(--r-0);
  overflow: hidden;
}

.macro-seg {
  flex: 0 1 0%;
  height: 100%;
  transition: flex-basis var(--dur-2) var(--ease);
}

.macro-seg-zero { display: none; }
.macro-seg-p { background: var(--pro); }
.macro-seg-c { background: var(--carb); }
.macro-seg-f { background: var(--fat); }

.macro-bar-empty { background: var(--line-1); }
.macro-bar-empty .macro-seg { display: none; }

/* compact legend: "1,842 kcal Â· P 132 Â· C 210 Â· F 58" */
.macro-legend {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-1);
  font-size: 12px;
  color: var(--tx-1);
  white-space: nowrap;
}

.macro-legend .ml-kcal { color: var(--tx-0); }
.macro-legend .ml-unit,
.macro-legend .ml-sep { color: var(--tx-2); font-size: 11px; }

.ml-key {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.ml-key-p { color: var(--pro); }
.ml-key-c { color: var(--carb); }
.ml-key-f { color: var(--fat); }

/* ============================================================
   A2 Â· macro ring â€” SVG donut of the P/C/F split
   ============================================================ */

.macro-ring { position: relative; flex: none; }
.macro-ring svg { transform: rotate(-90deg); }

.macro-ring circle {
  transition:
    stroke-dasharray var(--dur-3) var(--ease),
    stroke-dashoffset var(--dur-3) var(--ease);
}

.mr-track { stroke: var(--line-0); }
.mr-arc-p { stroke: var(--pro); }
.mr-arc-c { stroke: var(--carb); }
.mr-arc-f { stroke: var(--fat); }

.mr-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  pointer-events: none;
}

.mr-center .mr-kcal { font-size: 16px; color: var(--tx-0); }
.mr-center .mr-unit { font-size: 9px; color: var(--tx-2); }

/* ============================================================
   A2 Â· search field
   ============================================================ */

.search-field {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 36px;
  padding: 0 var(--sp-3);
  background: var(--ink-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-card);
  flex: 1;
  min-width: 0;
  transition: border-color var(--dur-1) var(--ease);
}

.search-field:focus-within { border-color: var(--acc); }
.search-field .sf-icon { color: var(--tx-2); line-height: 0; flex: none; }

.search-field input {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  font-size: 13px;
  color: var(--tx-0);
}
.search-field input::placeholder { color: var(--tx-2); }
.search-field input::-webkit-search-cancel-button { display: none; }
.search-field input:focus-visible { outline: none; }

.search-field .sf-clear {
  color: var(--tx-2);
  line-height: 0;
  padding: var(--sp-1);
  border-radius: var(--r-chip);
  flex: none;
}
.search-field .sf-clear:hover { color: var(--tx-0); background: var(--ink-3); }

/* match highlight: accent text, no box */
mark {
  background: transparent;
  color: var(--acc);
}

/* ============================================================
   A2 Â· chips (filter chips, micro category chip, status chips)
   ============================================================ */

.fchip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px var(--sp-2);
  min-height: 26px;
  font-size: 12px;
  color: var(--tx-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  transition: color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
    background var(--dur-1) var(--ease);
}

.fchip:hover { color: var(--tx-0); background: var(--ink-3); }

.fchip-on {
  color: var(--acc);
  border-color: var(--acc);
  background: var(--ink-1);
}

.fchip-count { font-size: 10px; color: var(--tx-2); }
.fchip-on .fchip-count { color: var(--acc-dim); }

/* tiny inline category microchip on product rows */
.mchip {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--tx-2);
  border: 1px solid var(--line-0);
  border-radius: var(--r-chip);
  padding: 0 var(--sp-1);
  line-height: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 12ch;
  flex: none;
}

.chip-sale,
.chip-est,
.chip-out {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  border-radius: var(--r-chip);
  padding: 1px var(--sp-1);
  line-height: 13px;
  flex: none;
}

.chip-sale { color: var(--ink-0); background: var(--acc); }
.chip-est  { color: var(--tx-2); border: 1px solid var(--line-1); }
.chip-out  { color: var(--bad); border: 1px solid var(--bad); }

/* ============================================================
   A2 Â· filter panel
   ============================================================ */

.filter-panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  font-size: 13px;
}

.fp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--line-0);
}

.fp-clear { font-size: 12px; padding: var(--sp-1) var(--sp-2); }

.fp-group { display: flex; flex-direction: column; gap: var(--sp-2); }
.fp-glabel { display: block; }
.fp-glabel-row { display: flex; align-items: baseline; justify-content: space-between; }
.fp-price-out { font-size: 12px; color: var(--tx-1); }

.fp-chips { display: flex; flex-wrap: wrap; gap: var(--sp-1); }

.fp-cats {
  max-height: 220px;
  overflow-y: auto;
  padding-right: var(--sp-1);
}

/* price slider â€” hairline track, chip-radius thumb */
.fp-price {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
}
.fp-price::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--line-1);
}
.fp-price::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -6px;
  border-radius: var(--r-chip);
  background: var(--acc);
  border: none;
}
.fp-price::-moz-range-track {
  height: 2px;
  background: var(--line-1);
}
.fp-price::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: var(--r-chip);
  background: var(--acc);
  border: none;
}

/* macro-min steppers */
.fp-stepper {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.fp-stepper-label { flex: 1; color: var(--tx-1); font-size: 12px; }
.fp-step {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  color: var(--tx-1);
  font-family: var(--font-num);
}
.fp-step:hover { color: var(--tx-0); background: var(--ink-3); }
.fp-step-val { min-width: 5ch; text-align: center; font-size: 12px; color: var(--tx-0); }

/* switch toggles */
.fp-toggles { gap: 0; }
.fp-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  width: 100%;
  min-height: 40px;
  padding: var(--sp-2) 0;
  font-size: 13px;
  color: var(--tx-1);
  border-bottom: 1px solid var(--line-0);
  text-align: left;
}
.fp-toggle:last-child { border-bottom: none; }
.fp-toggle:hover { color: var(--tx-0); }

.fp-switch {
  flex: none;
  width: 28px;
  height: 14px;
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  position: relative;
  transition: border-color var(--dur-1) var(--ease);
}
.fp-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 8px;
  height: 8px;
  background: var(--tx-2);
  transition: transform var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.fp-toggle[aria-checked="true"] .fp-switch { border-color: var(--acc); }
.fp-toggle[aria-checked="true"] .fp-switch::after {
  transform: translateX(14px);
  background: var(--acc);
}

/* ============================================================
   A2 Â· meal builder â€” sheet (mobile) / right panel (desktop)
   ============================================================ */

.mb-root {
  pointer-events: none;
  visibility: hidden; /* offscreen panel is not tabbable */
  transition: visibility 0s var(--dur-3);
}
.mb-root.open {
  visibility: visible;
  transition: visibility 0s 0s;
}

.mb-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 13, 12, 0.6);
  z-index: calc(var(--z-sheet) - 1);
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease);
}

.mb-panel {
  position: fixed;
  z-index: var(--z-sheet);
  background: var(--ink-1);
  border-top: 1px solid var(--line-1);
  display: flex;
  flex-direction: column;
  /* mobile: bottom sheet */
  inset: auto 0 0 0;
  max-height: 88dvh;
  border-radius: var(--r-card) var(--r-card) 0 0;
  transform: translateY(102%);
  transition: transform var(--dur-3) var(--ease);
}

.mb-root.open { pointer-events: auto; }
.mb-root.open .mb-backdrop { opacity: 1; }
.mb-root.open .mb-panel { transform: translateY(0); }

@media (min-width: 769px) {
  .mb-backdrop { display: none; }
  .mb-panel {
    inset: 0 0 0 auto;
    width: 420px;
    max-height: none;
    border-radius: 0;
    border-top: none;
    border-left: 1px solid var(--line-1);
    transform: translateX(102%);
  }
  .mb-root.open .mb-panel { transform: translateX(0); }
}

.mb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line-0);
  flex: none;
}

.mb-title { font-size: 15px; font-weight: 600; margin-top: 2px; }

.mb-close {
  color: var(--tx-1);
  padding: var(--sp-2);
  line-height: 0;
  border-radius: var(--r-chip);
}
.mb-close:hover { color: var(--tx-0); background: var(--ink-3); }

.mb-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3) var(--sp-4);
  min-height: 120px;
}

/* template quick-pick */
.mb-templates { display: flex; flex-direction: column; gap: var(--sp-2); }

.mb-tpl {
  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-0);
  text-align: left;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.mb-tpl:hover { border-color: var(--line-1); background: var(--ink-2); }
.mb-tpl-name { font-size: 13px; font-weight: 500; color: var(--tx-0); }

.mb-scratch { align-self: flex-start; margin-top: var(--sp-2); }

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

/* item rows */
.mb-items { display: flex; flex-direction: column; }

.mb-item {
  position: relative;
  border-bottom: 1px solid var(--line-0);
  overflow: hidden;
}

.mb-under {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: var(--sp-4);
  background: var(--bad);
  color: var(--ink-0);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease);
}

.mb-swiping .mb-under,
.mb-swipe-armed .mb-under { opacity: 1; }

.mb-item-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) 0;
  min-height: 56px;
  background: var(--ink-1);
  transition: transform var(--dur-2) var(--ease);
}
.mb-item.mb-swiping .mb-item-inner { transition: none; }

.mb-item.mb-dragging {
  z-index: 2;
  overflow: visible;
}
.mb-item.mb-dragging .mb-item-inner {
  background: var(--ink-3);
  border: 1px solid var(--line-1);
  transition: none;
}
.mb-item:not(.mb-dragging) { transition: transform var(--dur-2) var(--ease); }

.mb-grip {
  color: var(--tx-2);
  padding: var(--sp-2) var(--sp-1);
  cursor: grab;
  touch-action: none;
  flex: none;
  line-height: 0;
}
.mb-grip:hover { color: var(--tx-1); }
.mb-dragging .mb-grip { cursor: grabbing; }

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

.mb-item-name {
  font-size: 13px;
  color: var(--tx-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mb-item-macros {
  font-size: 11px;
  color: var(--tx-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mb-mu { color: var(--tx-2); font-size: 10px; }
.mb-icost { color: var(--tx-2); margin-left: var(--sp-1); }

.mb-gram-ctl {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.mb-step {
  width: 28px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-1);
  border-radius: var(--r-chip);
  color: var(--tx-1);
  font-family: var(--font-num);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.mb-step:hover { color: var(--tx-0); background: var(--ink-3); }

.mb-gram {
  min-width: 58px;
  height: 32px;
  padding: 0 var(--sp-1);
  font-size: 13px;
  color: var(--tx-0);
  border: 1px solid transparent;
  border-radius: var(--r-chip);
  text-align: center;
}
.mb-gram:hover { border-color: var(--line-1); }
.mb-gram-u { font-size: 10px; color: var(--tx-2); margin-left: 2px; }

.mb-gram-input {
  width: 58px;
  height: 32px;
  font-size: 13px;
  text-align: center;
  color: var(--tx-0);
  background: var(--ink-0);
  border: 1px solid var(--acc);
  border-radius: var(--r-chip);
}

.mb-remove {
  color: var(--tx-2);
  padding: var(--sp-2);
  line-height: 0;
  border-radius: var(--r-chip);
  flex: none;
}
.mb-remove:hover { color: var(--bad); background: var(--ink-3); }

.mb-add-more {
  margin-top: var(--sp-3);
  font-size: 12px;
  padding: var(--sp-2) 0;
}

/* summary */
.mb-summary {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--line-0);
  background: var(--ink-2);
}

.mb-sum-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.mb-tot-row {
  display: flex;
  gap: var(--sp-4);
}
.mb-tot { display: flex; flex-direction: column; gap: 1px; }
.mb-tot-val { font-size: 15px; color: var(--tx-0); }

.mb-cost-row {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
}
.mb-cost { font-size: 13px; color: var(--tx-0); }

/* number tick: quick transform pop on change */
@keyframes num-tick {
  0%   { transform: translateY(4px); opacity: 0.35; }
  100% { transform: translateY(0);   opacity: 1; }
}
.tick { animation: num-tick var(--dur-2) var(--ease); display: inline-block; }

.mb-actions {
  flex: none;
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-0);
}
.mb-actions .btn { font-size: 12px; padding: var(--sp-2) var(--sp-3); }
.mb-actions .mb-done { margin-left: auto; }

/* quick-add sheet (inside modal) */
.mb-quickadd { display: flex; flex-direction: column; gap: var(--sp-2); }

.mb-qa-product {
  font-size: 13px;
  color: var(--tx-1);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--line-0);
}

.mb-qa-slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  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);
}
.mb-qa-slot:hover { border-color: var(--acc); background: var(--ink-3); }
.mb-qa-count { font-size: 11px; color: var(--tx-2); }
.mb-qa-tpl { border-style: dashed; }

.mb-tpl-name-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);
}
.mb-tpl-name-input:focus { border-color: var(--acc); }

/* ============================================================
   A3 · progress gauge — ledger-style target bar (F3 hero)
   ============================================================ */

.pgauge {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.pg-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
}

.pg-nums { font-size: 13px; color: var(--tx-0); }
.pg-of { color: var(--tx-2); font-size: 11px; }

.pg-track {
  position: relative;
  height: 6px;
  background: var(--ink-2);
  border-radius: var(--r-0);
  overflow: visible;
}

.pg-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  border-radius: var(--r-0);
  transition: width var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
}

/* fill color: macro identity while under/on target */
.pgauge[data-macro="kcal"]    .pg-fill { background: var(--acc);  }
.pgauge[data-macro="protein"] .pg-fill { background: var(--pro);  }
.pgauge[data-macro="carbs"]   .pg-fill { background: var(--carb); }
.pgauge[data-macro="fat"]     .pg-fill { background: var(--fat);  }
/* status overrides: amber when warn, red when over */
.pgauge[data-status="warn"] .pg-fill { background: var(--warn); }
.pgauge[data-status="bad"]  .pg-fill { background: var(--bad);  }

/* hairline tick at 100% of target (overflow renders past it, capped 130%) */
.pg-tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 1px;
  background: var(--line-1);
}

.pg-delta {
  font-size: 11px;
  align-self: flex-end;
  color: var(--tx-2);
}
.pgauge[data-status="under"] .pg-delta { color: var(--tx-1); }
.pgauge[data-status="ok"]    .pg-delta { color: var(--ok);   }
.pgauge[data-status="warn"]  .pg-delta { color: var(--warn); }
.pgauge[data-status="bad"]   .pg-delta { color: var(--bad);  }

/* the kcal hero gauge: taller track, larger numerals */
.pgauge-big .pg-track { height: 10px; }
.pgauge-big .pg-nums { font-size: 17px; }
.pgauge-big .pg-of { font-size: 12px; }
.pgauge-big .pg-delta { font-size: 12px; }


/* ============================================================
   A4 · suggest sheet — fill-my-macros / swaps / cheapest-day rows
   ============================================================ */

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

.sg-remaining {
  font-size: 14px;
  color: var(--tx-0);
  display: flex;
  align-items: baseline;
  gap: var(--sp-1);
  flex-wrap: wrap;
}
.sg-sep { color: var(--tx-2); }

.sg-swap-orig {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
}

.sg-list { display: flex; flex-direction: column; }

.sg-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  min-height: 56px;
  border-bottom: 1px solid var(--line-0);
}
.sg-row:last-child { border-bottom: none; }

.sg-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

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

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

.sg-grams { flex: none; font-size: 12px; color: var(--acc); }

.sg-line2 {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  font-size: 11px;
  color: var(--tx-1);
  white-space: nowrap;
  overflow: hidden;
}
.sg-line2 .num { font-size: 11px; }
.sg-mu { color: var(--tx-2); font-size: 10px; }
.sg-kcal { color: var(--tx-0); }
.sg-cost { margin-left: auto; color: var(--tx-1); }
.sg-saves { color: var(--ok); }

.sg-add { flex: none; font-size: 12px; min-height: 32px; padding: var(--sp-1) var(--sp-3); }
.sg-add:disabled { opacity: 0.45; cursor: default; }

.sg-empty { font-size: 16px; color: var(--tx-1); line-height: 1.4; padding: var(--sp-3) 0; }
.sg-mela { color: var(--acc); }

/* cheapest-day rows */
.sg-cd-sum { font-size: 13px; color: var(--tx-1); }
.sg-cd-from {
  font-size: 12px;
  color: var(--tx-2);
  text-decoration: line-through;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sg-cd-to {
  font-size: 13px;
  color: var(--tx-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sg-cd-arrow { color: var(--acc); }

/* ============================================================
   A4 · meal-builder swap affordance (⇄ per item row)
   ============================================================ */

.mb-swapbtn {
  color: var(--tx-2);
  padding: var(--sp-2) var(--sp-1);
  font-size: 13px;
  line-height: 1;
  border-radius: var(--r-chip);
  flex: none;
}
.mb-swapbtn:hover { color: var(--acc); background: var(--ink-3); }

/* ============================================================
   A4 · budget gauge variant (dashboard)
   ============================================================ */

.pgauge[data-macro="budget"] .pg-fill { background: var(--acc); }
.pgauge[data-macro="budget"][data-status="warn"] .pg-fill { background: var(--warn); }
.pgauge[data-macro="budget"][data-status="bad"] .pg-fill { background: var(--bad); }

/* ============================================================
   A4 · AI advisor chat pieces
   ============================================================ */

.ai-msg {
  max-width: 85%;
  padding: var(--sp-2) var(--sp-3);
  font-size: 13px;
  line-height: 1.5;
  border-radius: var(--r-card);
  overflow-wrap: break-word;
}

.ai-msg-user {
  align-self: flex-end;
  background: var(--ink-2);
  color: var(--tx-0);
  white-space: pre-wrap;
}

.ai-msg-assistant {
  align-self: flex-start;
  background: var(--ink-1);
  border-left: 2px solid var(--acc);
  border-radius: 0 var(--r-card) var(--r-card) 0;
  color: var(--tx-0);
}

.ai-msg-assistant p { margin: 0 0 var(--sp-2); }
.ai-msg-assistant p:last-child { margin-bottom: 0; }
.ai-msg-assistant ul,
.ai-msg-assistant ol { margin: 0 0 var(--sp-2); padding-left: var(--sp-4); }
.ai-msg-assistant ul { list-style: disc; }
.ai-msg-assistant ol { list-style: decimal; }
.ai-msg-assistant li { margin-bottom: 2px; }
.ai-msg-assistant strong { font-weight: 600; }

.ai-chip {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-1);
  padding: 1px var(--sp-2);
  margin: 0 1px;
  font-size: 12px;
  color: var(--tx-0);
  border: 1px solid var(--acc);
  border-radius: var(--r-chip);
  background: var(--ink-2);
  transition: background var(--dur-1) var(--ease);
  vertical-align: baseline;
}
.ai-chip:hover { background: var(--ink-3); }
.ai-chip .num { color: var(--acc); font-size: 11px; }

.ai-notice {
  align-self: flex-start;
  font-size: 12px;
  color: var(--tx-1);
  border: 1px solid var(--line-0);
  border-left: 2px solid var(--warn);
  border-radius: var(--r-card);
  padding: var(--sp-2) var(--sp-3);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.ai-notice a { color: var(--acc); }
.ai-fallback-btn { font-size: 12px; min-height: 30px; padding: var(--sp-1) var(--sp-3); }

/* typing: 3-dot pulse */
.ai-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  min-height: 34px;
}
.ai-typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--tx-2);
  animation: ai-pulse 1s var(--ease) infinite;
}
.ai-typing i:nth-child(2) { animation-delay: 0.15s; }
.ai-typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-pulse {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .ai-typing i { animation: none; opacity: 0.6; }
}
