/* FitBite: app design (Oct 2026) on Brand Kit v1.0. Forest green base, gold accent, warm
   neutrals; serif for short headings, Arial for UI. Mobile-first: the base styles are the
   390px phone design; tablet (768px+) and desktop (1024px+) layouts are added at the end
   through min-width queries only. */
:root {
  --forest: #0F3D32; --forest-2: #164B3E; --header: #14332D; --olive: #90A63B; --gold: #C6A05B; --beige: #D3B996; --off-white: #CFCDCB; --warm: #F3F0E7;
  --ink: #1E2622; --muted: #4F5752; --muted-2: #5B625D; --eyebrow: #6B5A33; --gold-ink: #86672F;
  --card: #FFFDF8; --sand: #ECE6D8; --line: #E4DCCB; --line-2: #D8CFBC;
  --notice-bg: #F1E7D3; --notice: #6B4E1E; --err: #9B2C1F; --err-bg: #FBEDEA;
  /* non-text UI must reach 3:1 (WCAG 1.4.11): focus ring 4.2:1+ and field borders 3.2:1+ on every light surface */
  --focus: var(--gold-ink); --field-border: #958566;
  --serif: "Times New Roman", Times, Georgia, serif; --sans: Arial, Helvetica, sans-serif;
  --tap: 44px; --nav-h: 84px; --bar-h: 76px; --safe-b: env(safe-area-inset-bottom, 0px); --col: 560px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; background: var(--warm); }
body { margin: 0; font: 16px/1.45 var(--sans); color: var(--ink); background: var(--warm); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; } /* headings that receive focus programmatically */

.app { max-width: var(--col); margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- header ---------- */
.appbar { position: sticky; top: 0; z-index: 20; height: calc(64px + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) 16px 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--header); }
.wordmark { height: 36px; width: auto; }
.appbar-right { display: flex; align-items: center; gap: 10px; }
.user-button { display: flex; align-items: center; min-width: 0; }
.user-button:empty { display: none; }
.badge { font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; padding: 6px 10px; border-radius: 999px; border: 1px solid rgba(198, 160, 91, .55); color: var(--beige); white-space: nowrap; }

main { flex: 1; padding: 24px 20px calc(var(--nav-h) + var(--safe-b) + 32px); }
.view { display: flex; flex-direction: column; gap: 18px; }
#view-groceries { padding-bottom: calc(var(--bar-h) + 8px); }
#home-empty, #home-plan, .home-grid, .home-col, .groceries-layout, .checkout-panel { display: flex; flex-direction: column; gap: 18px; }

.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; padding: 10px 14px; border-radius: 10px; background: var(--gold); color: var(--forest); font-weight: 700; text-decoration: none; }
.skip-link:focus { top: 12px; }
main:focus { outline: none; }

/* ---------- type ---------- */
.display { margin: 0; font-family: var(--serif); font-weight: 400; color: var(--forest); line-height: 1.1; }
h1.display { font-size: 36px; }
.eyebrow { margin: 0; font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--eyebrow); }
.eyebrow.gold { color: var(--gold); }
.lede { margin: 0; color: var(--muted); font-size: 15px; }
.fine { margin: 0; font-size: 12px; line-height: 1.5; color: var(--muted-2); }
.summary { margin: 0; font-size: 15px; color: var(--ink); border-left: 3px solid var(--gold); padding: 2px 0 2px 12px; }
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.title-row > div { display: flex; flex-direction: column; gap: 6px; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 18px; border-radius: 14px; border: 0; font-weight: 700; font-size: 16px; text-decoration: none; }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--forest); color: var(--warm); min-height: 52px; }
.btn-primary:hover { background: var(--forest-2); }
.btn-gold { background: var(--gold); color: var(--forest); min-height: 48px; }
.btn-gold:hover { background: #D0AD6C; }
.btn-outline { background: transparent; color: var(--forest); border: 1px solid var(--line-2); min-height: 52px; font-weight: 400; }
.btn-quiet { height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--card); color: var(--forest); font-size: 14px; flex-shrink: 0; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: progress; }

/* ---------- home ---------- */
.hero { background: var(--header); border-radius: 20px; overflow: hidden; line-height: 0; }
.hero img { width: 100%; height: auto; }
@media (max-width: 359px) { .hero { margin-inline: -20px; border-radius: 0; } } /* keep the logo >=320px, never cropped */

.chips-static { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-static span { font-size: 13px; padding: 6px 12px; border-radius: 999px; background: var(--sand); color: var(--ink); }
.notice { margin: 0; background: var(--notice-bg); color: var(--notice); padding: 10px 12px; border-radius: 12px; font-size: 14px; border-left: 4px solid var(--gold); }
#plan-notices { display: flex; flex-direction: column; gap: 8px; }
.notice p { margin: 0; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }
.notice.ok { background: #E6EDD3; color: #3E4C17; border-left-color: var(--olive); }
#plan-notices:empty { display: none; }

.totals { background: var(--forest); color: var(--warm); border-radius: 24px; padding: 22px; display: flex; gap: 20px; align-items: center; }
.ring { position: relative; width: 116px; height: 116px; flex-shrink: 0; }
.ring svg { width: 116px; height: 116px; }
.ring-track, .ring-fill { fill: none; stroke-width: 9; }
.ring-track { stroke: rgba(243, 240, 231, .14); }
.ring-fill { stroke: var(--gold); stroke-linecap: round; transition: stroke-dasharray .4s ease; }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-label span { font-family: var(--serif); font-size: 28px; line-height: 1; }
.ring-label small { font-size: 11px; color: var(--beige); margin-top: 4px; }
.macros { flex: 1; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.macro { display: flex; flex-direction: column; gap: 5px; }
.macro-top { display: flex; justify-content: space-between; font-size: 13px; }
.macro-top span { color: var(--off-white); }
.bar { height: 6px; border-radius: 3px; background: rgba(243, 240, 231, .14); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; transition: width .4s ease; }

.day-picker { display: grid; grid-template-columns: repeat(var(--days, 7), minmax(0, 1fr)); gap: 6px; }
.day-btn { height: 56px; border-radius: 14px; border: 1px solid var(--line-2); background: var(--card); color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0; }
.day-btn small { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.day-btn b { font-size: 17px; }
.day-btn[aria-selected="true"] { border-color: var(--forest); background: var(--forest); color: var(--warm); }

.meals { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 6px 18px; }
.meal { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 14px 0; }
.meal-open { flex: 1 1 100%; display: flex; gap: 14px; align-items: center; padding: 0; border: 0; background: none; text-align: left; color: inherit; border-radius: 12px; }
.meal-open:hover .meal-name { text-decoration: underline; text-decoration-color: var(--gold); text-underline-offset: 3px; }
.meal-notes { font-size: 12px; color: var(--eyebrow); }
.meal-warn { font-size: 12px; color: var(--err); }
.btn-chip { margin-left: 58px; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--warm); color: var(--forest); font-size: 13px; font-weight: 700; }
.btn-chip:hover { border-color: var(--forest); }
.day-title { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 22px; color: var(--forest); }
.meal + .meal { border-top: 1px solid var(--sand); }
.tile-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--sand); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.tile-icon svg { width: 22px; height: 22px; fill: none; stroke: var(--forest); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tile-icon.dark { background: var(--forest); }
.tile-icon.dark svg { stroke: var(--gold); stroke-width: 1.8; }
.meal-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.meal-slot { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--eyebrow); }
.meal-name { display: block; margin: 0; font-family: var(--serif); font-weight: 400; font-size: 19px; line-height: 1.2; color: var(--forest); }
.meal-meta { font-size: 13px; color: var(--muted); }

.groceries-link { display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-radius: 20px; background: var(--sand); border: 0; color: var(--ink); text-align: left; width: 100%; }
.gl-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.gl-text b { font-size: 16px; color: var(--forest); }
.gl-text small { font-size: 13px; color: var(--muted); }
.chev { width: 20px; height: 20px; fill: none; stroke: var(--forest); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- groceries ---------- */
#grocery-list { display: flex; flex-direction: column; gap: 14px; }
.aisle { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 14px 18px 6px; }
.aisle-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.aisle-head h2 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 21px; color: var(--forest); }
.aisle-head small { font-size: 12px; color: var(--muted); }
.item { display: flex; flex-direction: row; align-items: center; gap: 14px; font-size: 15px; color: var(--ink); min-height: 58px; padding: 8px 0; border-top: 1px solid var(--sand); cursor: pointer; }
.aisle-head + .item { border-top: 0; }
.item input { appearance: none; -webkit-appearance: none; margin: 0; width: 22px; height: 22px; flex-shrink: 0; border: 1.5px solid var(--field-border); border-radius: 5px; background: #fff; display: grid; place-content: center; cursor: pointer; }
.item input:checked { background: var(--forest); border-color: var(--forest); }
.item input:checked::after { content: ""; width: 11px; height: 6px; border: solid var(--warm); border-width: 0 0 2.5px 2.5px; transform: translateY(-2px) rotate(-45deg); }
.item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.item-name { font-size: 15px; }
.item-qty { font-size: 12px; color: var(--muted); }
.item-price { font-size: 15px; font-weight: 700; }
.item.off .item-name { color: var(--muted); text-decoration: line-through; }
.item.off .item-price { color: var(--muted); font-weight: 400; }
.more { display: block; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--sand); background: none; padding: 14px 6px; font-size: 14px; font-weight: 700; color: var(--forest); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.checkoutbar { position: fixed; z-index: 25; left: 50%; transform: translateX(-50%); width: min(calc(100% - 24px), calc(var(--col) - 24px));
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px); min-height: var(--bar-h); padding: 12px 12px 12px 20px; border-radius: 18px; background: var(--forest); color: var(--warm);
  display: flex; align-items: center; gap: 12px; box-shadow: 0 8px 24px rgba(15, 61, 50, .25); }
.total { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.total small { font-size: 12px; color: var(--beige); }
.total strong { font-family: var(--serif); font-weight: 400; font-size: 26px; }
.checkoutbar :focus-visible { outline-color: var(--gold); }

.cost-summary { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 4px 18px; }
.cost-summary div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 12px 0; }
.cost-summary div + div { border-top: 1px solid var(--sand); }
.cost-summary dt { display: flex; flex-direction: column; gap: 2px; font-size: 14px; color: var(--ink); }
.cost-summary dt small { font-size: 12px; color: var(--muted); }
.cost-summary dd { margin: 0; font-weight: 700; white-space: nowrap; }
.cost-summary .over dd, .cost-summary .over dt { color: var(--err); }
.done-item { cursor: default; }
.pill { flex-shrink: 0; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 4px 8px; border-radius: 999px; background: #E6EDD3; color: #3E4C17; }
.link-btn { border: 0; background: none; color: var(--forest); font-weight: 700; font-size: 14px; text-decoration: underline; min-height: var(--tap); padding: 0 4px; }

/* ---------- meal panel ---------- */
.sheet h2.panel-title { font-size: 28px; margin: 4px 0 12px; }
.panel-body { display: flex; flex-direction: column; gap: 12px; }
.panel-h { margin: 8px 0 0; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--eyebrow); }
.nut-grid { margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.nut-grid div { background: var(--warm); border-radius: 12px; padding: 10px; text-align: center; }
.nut-grid dt { font-size: 11px; color: var(--muted); }
.nut-grid dd { margin: 2px 0 0; font-family: var(--serif); font-size: 20px; color: var(--forest); }
.ingredients, .steps, .tips { margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.ingredients { list-style: none; }
.ingredients li { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--sand); }
.ingredients b { min-width: 64px; color: var(--forest); }
.steps, .tips { padding-left: 20px; }
.tips { font-size: 14px; color: var(--muted); }
.reason-list { display: flex; flex-direction: column; gap: 8px; }
.reason { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line-2); background: #fff; color: var(--forest); font-size: 16px; text-align: left; }
.reason:hover { border-color: var(--forest); }
.alt-list { display: flex; flex-direction: column; gap: 10px; }
.alt { position: relative; display: block; }
.alt input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.alt-card { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line-2); background: #fff; cursor: pointer; }
.alt-card b { font-family: var(--serif); font-weight: 400; font-size: 19px; color: var(--forest); }
.alt-card small { font-size: 13px; color: var(--ink); }
.alt input:checked + .alt-card { border: 2px solid var(--forest); background: var(--warm); padding: 11px 13px; }
.alt input:focus-visible + .alt-card { outline: 3px solid var(--focus); outline-offset: 2px; }
.sheet-foot.single { grid-template-columns: 1fr; }

/* ---------- tab bar ---------- */
.tabbar { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: 0; width: min(100%, var(--col));
  height: calc(var(--nav-h) + var(--safe-b)); padding: 0 12px calc(16px + var(--safe-b)); background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tabbar > .tab[data-view="home"] { grid-column: 1; grid-row: 1; }
.tabbar > .fab-wrap { grid-column: 2; grid-row: 1; }
.tabbar > .tab[data-view="groceries"] { grid-column: 3; grid-row: 1; }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 0; border-top: 3px solid transparent; background: none; font-size: 12px; color: var(--muted-2); }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--forest); font-weight: 700; border-top-color: var(--gold); }
.tab:disabled { opacity: .4; cursor: default; }
.fab-wrap { display: flex; justify-content: center; }
.fab { margin-top: -22px; width: 60px; height: 60px; border-radius: 50%; background: var(--gold); border: 4px solid var(--warm); display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 16px rgba(15, 61, 50, .25); padding: 0; }
.fab svg { width: 26px; height: 26px; fill: none; stroke: var(--forest); stroke-width: 2.4; stroke-linecap: round; }
.fab-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } /* visible on desktop */

/* ---------- sign in ---------- */
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.signin { position: fixed; inset: 0; z-index: 45; background: var(--header); color: var(--warm); overflow-y: auto; }
.signin-inner { max-width: 440px; min-height: 100%; margin: 0 auto; padding: calc(28px + env(safe-area-inset-top, 0px)) 16px calc(28px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 16px; }
.signin-logo { width: 100%; max-width: 400px; min-width: 320px; height: auto; } /* brand rule: logo with slogan >=320px */
.clerk-signin { width: 100%; display: flex; justify-content: center; }
.clerk-signin:empty { display: none; }
.signin-status { margin: 0; color: var(--off-white); font-size: 14px; text-align: center; }
.signin-status.error { color: #FFB4A8; background: none; padding: 0; }
.signin .slogan { margin-top: auto; padding-top: 24px; }

/* ---------- cart ready ---------- */
.done { position: fixed; inset: 0; z-index: 40; background: var(--header); color: var(--warm); overflow-y: auto; }
.done-inner { max-width: 440px; margin: 0 auto; padding: calc(56px + env(safe-area-inset-top, 0px)) 28px calc(32px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; }
.done-icon { position: relative; width: 96px; height: 96px; margin-bottom: 10px; }
.done-icon img { width: 96px; height: 96px; }
.check { position: absolute; right: -8px; bottom: -8px; width: 34px; height: 34px; border-radius: 50%; background: var(--gold); display: flex; align-items: center; justify-content: center; }
.check svg { width: 18px; height: 18px; fill: none; stroke: var(--forest); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.display.light { color: var(--warm); font-size: 36px; }
.done-sub { margin: 0; color: var(--off-white); font-size: 15px; }
.done-card { width: 100%; margin: 20px 0 10px; padding: 4px 20px; border: 1px solid rgba(243, 240, 231, .18); border-radius: 18px; text-align: left; }
.done-card div { display: flex; justify-content: space-between; align-items: baseline; padding: 16px 0; }
.done-card div + div { border-top: 1px solid rgba(243, 240, 231, .12); }
.done-card dt { color: var(--off-white); font-size: 15px; }
.done-card dd { margin: 0; font-weight: 700; }
.done-card .money { font-family: var(--serif); font-weight: 400; font-size: 26px; color: var(--gold); }
.done-actions { width: 100%; display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.done-actions .btn { width: 100%; min-height: 54px; }
.done-actions .btn-outline { color: var(--warm); border-color: rgba(243, 240, 231, .35); }
.done :focus-visible { outline-color: var(--gold); }
.done-details { width: 100%; text-align: left; color: var(--off-white); font-size: 14px; }
.done-details summary { cursor: pointer; padding: 8px 0; color: var(--warm); }
.done-details table { width: 100%; border-collapse: collapse; }
.done-details td { padding: 6px 0; border-top: 1px solid rgba(243, 240, 231, .12); }
.done-details td:last-child { text-align: right; }
.slogan { margin: 18px 0 0; font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--gold); }

/* ---------- wizard sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15, 30, 25, .55); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease; }
.sheet { width: min(100%, var(--col)); max-height: calc(100% - 24px - env(safe-area-inset-top, 0px)); background: var(--card); border-radius: 28px 28px 0 0;
  display: flex; flex-direction: column; padding: 10px 24px calc(16px + var(--safe-b)); animation: rise .25s ease; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } .ring-fill, .bar i { transition: none; } }
.handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 0 auto 14px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.icon-btn { width: 44px; height: 44px; margin-right: -10px; border: 0; background: none; color: var(--ink); display: flex; align-items: center; justify-content: center; border-radius: 12px; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.progress { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; margin: 10px 0 20px; }
.progress span { height: 5px; border-radius: 3px; background: var(--sand); }
.progress span.on { background: var(--gold); }
.sheet h2.display { font-size: 30px; }
.sheet > .lede { margin: 6px 0 18px; }
.sheet-body { flex: 1; overflow-y: auto; margin: 0 -24px; padding: 2px 24px 16px; }
.step { display: flex; flex-direction: column; gap: 14px; }
.sheet-foot { display: grid; grid-template-columns: auto 1fr; gap: 12px; padding-top: 14px; border-top: 1px solid var(--line); margin: 0 -24px; padding-inline: 24px; }
.sheet-foot .btn-outline { padding: 0 22px; }
.error { margin: 0; color: var(--err); background: var(--err-bg); padding: 10px 12px; border-radius: 12px; font-weight: 700; font-size: 14px; }
.sheet > .error { margin-bottom: 10px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input[type="number"], input:not([type]), input[type="text"], select, textarea { min-height: 48px; padding: 10px 14px; border: 1px solid var(--field-border); border-radius: 12px; background: #fff; color: var(--ink); width: 100%; font-size: 16px; }
textarea { min-height: 72px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--forest); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span2 { grid-column: 1 / -1; }
.height { display: flex; flex-direction: column; gap: 6px; }
.lbl { font-size: 14px; color: var(--muted); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.suffix { position: relative; }
.suffix input { padding-right: 34px; }
.suffix span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 13px; color: var(--muted); pointer-events: none; }
.prefix { display: block; }
.prefix input { padding-left: 28px; padding-right: 14px; }
.prefix span { left: 14px; right: auto; font-size: 16px; }
.weekdays label span, .carry-opts span { padding: 0 14px; }
#pantry span { min-height: 40px; font-size: 13px; padding: 0 12px; }
fieldset { border: 0; margin: 0; padding: 0; }
legend { font-weight: 700; font-size: 14px; color: var(--ink); margin-bottom: 10px; }
legend small { font-weight: 400; color: var(--muted); }

/* Native inputs stay in the DOM (keyboard + screen readers), visually replaced by the span after them. */
.seg label, .choices label, .chips label, .diet-grid label { position: relative; display: block; }
.seg input, .choices input, .chips input, .diet-grid input { position: absolute; inset: 0; width: 1px; height: 1px; min-height: 0; margin: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.seg input:focus-visible + span, .choices input:focus-visible + span, .chips input:focus-visible + span, .diet-grid input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; background: var(--sand); border-radius: 12px; padding: 4px; }
.seg span { display: flex; align-items: center; justify-content: center; height: 44px; border-radius: 9px; color: var(--muted); font-size: 15px; cursor: pointer; }
.seg input:checked + span { background: var(--forest); color: var(--warm); font-weight: 700; }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choices label > span { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; padding: 12px 16px; border-radius: 14px; border: 1px solid var(--line-2); background: #fff; cursor: pointer; color: var(--ink); }
.choices label > span > span { display: flex; flex-direction: column; gap: 2px; }
.choices b { font-family: var(--serif); font-weight: 400; font-size: 19px; color: var(--forest); }
.choices small { font-size: 13px; color: var(--muted); }
.dot { width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; border: 2px solid #8F8061; }
.choices input:checked + span { border: 2px solid var(--forest); background: var(--warm); padding: 11px 15px; }
.choices input:checked + span .dot { border: 6px solid var(--forest); background: var(--gold); }

.diet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.diet-grid span { display: flex; align-items: center; justify-content: center; min-height: 52px; border-radius: 14px; border: 1px solid var(--line-2); background: #fff; font-size: 15px; cursor: pointer; }
.diet-grid input:checked + span { border: 2px solid var(--forest); background: var(--warm); color: var(--forest); font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line-2); background: #fff; font-size: 14px; color: var(--ink); cursor: pointer; }
.chips input:checked + span { background: var(--forest); border-color: var(--forest); color: var(--warm); }
.chips input:checked + span::before { content: "✓"; margin-right: 6px; font-size: .9em; color: var(--gold); }
#allergies input:checked + span::before { content: "✕"; font-size: .8em; } /* allergies are kept out */

.row-setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 6px 0; border-bottom: 1px solid var(--sand); font-size: 16px; color: var(--ink); }
.row-setting label { flex-direction: row; font-size: 16px; color: var(--ink); }
.stepper { display: flex; align-items: center; gap: 6px; }
.step-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--field-border); background: #fff; font-size: 22px; line-height: 1; color: var(--forest); }
.step-btn:disabled { opacity: .4; cursor: default; }
#days-out { min-width: 32px; text-align: center; font-family: var(--serif); font-size: 24px; color: var(--forest); }
.switch { appearance: none; -webkit-appearance: none; margin: 0; width: 52px; height: 32px; border-radius: 999px; background: #8F8061; position: relative; cursor: pointer; flex-shrink: 0; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .15s; }
.switch:checked { background: var(--forest); }
.switch:checked::after { transform: translateX(20px); }
.plan-uses { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-radius: 14px; background: var(--warm); }
#plan-uses { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--ink); }

.loading { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; padding: 40px 0; }
.loading .display { font-size: 26px; }
.spinner { width: 56px; height: 56px; border-radius: 50%; border: 5px solid var(--sand); border-top-color: var(--gold); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- short screens (landscape phones, high zoom) ---------- */
/* Keep the content area usable when height is scarce: the header scrolls away, the
   checkout bar sits in the page after the list, and the tab bar shrinks to icons. */
@media (max-height: 520px) {
  :root { --nav-h: 56px; }
  .appbar { position: static; }
  main { padding-top: 16px; }
  #view-groceries { padding-bottom: 0; }
  .checkoutbar { position: static; transform: none; width: auto; min-height: 0; box-shadow: none; }
  .sheet { padding-top: 6px; }
  .handle { margin-bottom: 6px; }
  .progress { margin: 6px 0 10px; }
  .sheet h2.display { font-size: 24px; }
  .sheet > .lede { margin: 2px 0 8px; font-size: 14px; }
  .sheet-foot { padding-top: 10px; }
  .btn-primary, .btn-outline { min-height: 46px; }
}
/* Icon-only tab bar on short screens while it's at the bottom (labels stay for screen readers). */
@media (max-height: 520px) and (max-width: 1023px) {
  .tab .tab-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .tabbar { padding-bottom: var(--safe-b); }
  .fab { width: 48px; height: 48px; margin-top: -12px; }
  .fab svg { width: 22px; height: 22px; }
}

/* ---------- tablet: 768px and up ---------- */
@media (min-width: 768px) {
  .app { max-width: none; }
  .appbar { padding-inline: max(24px, calc((100% - 1160px) / 2 + 32px)); }
  main { width: 100%; max-width: 1160px; margin: 0 auto; padding: 32px 32px calc(var(--nav-h) + var(--safe-b) + 40px); }
  h1.display { font-size: 42px; }
  #home-empty { max-width: 560px; }

  /* Home: overview + totals on the left, the selected day on the right; HTML order is
     overview, then day, then the full-width groceries card, matching how it reads. */
  .home-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 24px; align-items: start; }

  /* Groceries: aisles flow down two columns (top-to-bottom, then the next column). */
  #grocery-list { display: block; columns: 2; column-gap: 16px; }
  #grocery-list .aisle { break-inside: avoid; margin-bottom: 16px; }
  .checkout-panel .field { max-width: 420px; }

  /* Bottom bars span the screen but keep their content centered. */
  .tabbar { left: 0; transform: none; width: 100%; padding-inline: max(12px, calc((100% - 560px) / 2)); }
  .checkoutbar { width: min(calc(100% - 64px), 1096px); }

  /* Wizard becomes a centered dialog instead of a bottom sheet. */
  .sheet-backdrop { align-items: center; padding: 24px; }
  .sheet { border-radius: 28px; max-height: 100%; padding-bottom: 20px; box-shadow: 0 24px 60px rgba(0, 0, 0, .3); }
  .sheet-foot { border-radius: 0 0 28px 28px; }
  .handle { display: none; }
}
@media (min-width: 768px) and (max-height: 520px) {
  .sheet-backdrop { padding: 8px 24px; }
  .checkoutbar { width: auto; } /* in the page flow here, so match the panel width */
}

/* ---------- desktop: 1024px and up ---------- */
@media (min-width: 1024px) {
  :root { --nav-h: 0px; }
  .appbar { height: 72px; gap: 28px; }

  /* The tab bar joins the top bar: Home and Groceries as links, "+ New plan" as a button. */
  .tabbar { position: static; transform: none; width: auto; height: 100%; padding: 0; background: none; border: 0; display: flex; align-items: stretch; gap: 4px; flex: 1; }
  .tab { flex-direction: row; gap: 8px; padding: 0 14px; border-top: 0; border-bottom: 3px solid transparent; font-size: 15px; color: var(--off-white); }
  .tab svg { width: 20px; height: 20px; }
  .tab[aria-current="page"] { color: var(--warm); border-top: 0; border-bottom-color: var(--gold); }
  .tab:focus-visible, .fab:focus-visible { outline-color: var(--gold); outline-offset: -3px; }
  .fab-wrap { margin-left: auto; align-items: center; }
  .fab { margin: 0; width: auto; height: 44px; padding: 0 18px 0 14px; gap: 8px; border: 0; border-radius: 12px; box-shadow: none; }
  .fab svg { width: 20px; height: 20px; }
  .fab-label { position: static; width: auto; height: auto; overflow: visible; clip: auto; font-weight: 700; font-size: 15px; color: var(--forest); }
  .user-button :focus-visible { outline-color: var(--gold); }

  main { padding-bottom: 56px; }
  .home-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 32px; }

  /* Groceries: list on the left, a sticky checkout panel on the right (no floating bar). */
  .groceries-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start; }
  #view-groceries { padding-bottom: 0; }
  .checkout-panel { position: sticky; top: 96px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 20px; gap: 14px; }
  .checkout-panel .field { max-width: none; }
  .checkoutbar { position: static; transform: none; width: auto; min-height: 0; flex-direction: column; align-items: stretch; gap: 14px; padding: 18px; box-shadow: none; }
  .checkoutbar .btn { width: 100%; }
}

/* Short desktop windows: the header scrolls away, so the sticky panel can sit near the top.
   (After the desktop block so it wins.) */
@media (min-width: 1024px) and (max-height: 520px) {
  .checkout-panel { top: 16px; }
}
