/* Sage for Home redesign v2.
   Visual layer over the existing app shell. Tokens live in index.html :root.
   Phone command center, raised Talk control, full-screen voice, week calendar,
   meals board, budget overview, and the laptop sidebar all use real mounts. */

:root {
  --ink-green: #15803D;
  --ink-amber: #92400E;
  --m-jordan: #1E54C8;
  --m-jordan-tint: #EFF6FF;
  --m-mia: #0F766E;
  --m-mia-tint: #E3F5F1;
  --m-leo: #5A4FCF;
  --m-leo-tint: #ECE9FB;
  --m-family: #92400E;
  --m-family-tint: #FFF4DC;
  --target: 48px;
  --mic: 68px;
}
[data-theme="dark"] {
  --ink-green: #56D17F;
  --ink-amber: #F3CE6B;
  --m-jordan: #8AB0F0;
  --m-jordan-tint: #16243C;
  --m-mia: #3FD3C0;
  --m-mia-tint: #12302B;
  --m-leo: #B9B2F0;
  --m-leo-tint: #221E3C;
  --m-family: #F3CE6B;
  --m-family-tint: #2A2410;
  --amber: #F3CE6B;
}

/* Type floor and target floor. Larger display type is set explicitly below. */
html { font-size: 16px; }
body { font-size: 17px; line-height: 1.45; }
button, input, select, textarea { font-size: 16px; }
button { min-height: var(--target); }
button.small { min-height: var(--target); font-size: 16px; padding: 10px 14px; }
.theme-toggle, .auth-theme-toggle, .icon-btn {
  width: var(--target); height: var(--target); min-width: var(--target); min-height: var(--target);
}

/* Cookie banner sits in normal flow at the top so it cannot cover Sign up or the tab bar. */
#cookie-banner {
  position: relative !important;
  top: auto !important;
  bottom: auto !important;
  left: auto !important;
  right: auto !important;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  z-index: 80;
  font-size: 16px;
  flex-wrap: wrap;
}
#cookie-banner p { margin: 0; color: #fff; font-size: 16px; line-height: 1.4; }
#cookie-banner a { color: #fff; font-weight: 700; }
#cookie-banner button { min-height: 44px; padding: 0 16px; border-radius: 999px; font-size: 16px; font-weight: 800; }
#cookie-banner button[data-args*="accept"] { background: #fff; color: var(--ink); }
#cookie-banner button[data-args*="decline"] { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.55); }
.cal-mobile-view-toggle { display: flex; flex-wrap: nowrap; gap: 4px; }
.cal-mobile-view-btn { flex: 1 1 0; min-height: 44px; }

/* Keep the legacy hero in the DOM (voice ids, tests) without the tall phone hero. */
#section-home .home-layout {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
#section-home .home-day-summary,
#section-home #quickAccessGrid,
#section-home .modern-section-title { display: none; }
/* Keep the Home composer palette paired; generic sage-bar rules set a
   different background and must not leave bright text on a light panel. */
#appShell #section-home form.home-sage-bar {
  --ask-surface: #fff;
  --ask-ink: #14253d;
  --ask-placeholder: #475569;
  --ask-border: #b5c4d2;
  --ask-accent: #155e56;
  --ask-control-ink: #fff;
  --ask-focus: #1d4ed8;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--ask-surface);
  color: var(--ask-ink);
  border: 1px solid var(--ask-border);
  border-radius: var(--radius-lg);
  min-height: 64px;
  box-shadow: var(--shadow);
}
html[data-theme="dark"] #appShell #section-home form.home-sage-bar {
  --ask-surface: #17253a;
  --ask-ink: #f1f5f9;
  --ask-placeholder: #b8c7dd;
  --ask-border: #526781;
  --ask-accent: #99f1dc;
  --ask-control-ink: #0c4039;
  --ask-focus: #93c5fd;
}
#appShell #section-home form.home-sage-bar input {
  background: transparent;
  border: 0;
  color: var(--ask-ink);
  min-width: 0;
  min-height: 48px;
  padding-inline: 8px;
  font-size: 16px;
}
#appShell #section-home form.home-sage-bar input::placeholder { color: var(--ask-placeholder); opacity: 1; }
#appShell #section-home form.home-sage-bar :is(.sb-ic, .sb-send) {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  min-width: 48px;
  min-height: 48px;
  padding: 0 10px;
  border: 0;
  border-radius: 14px;
  background: var(--ask-accent);
  color: var(--ask-control-ink);
}
#appShell #section-home form.home-sage-bar .sb-ic { padding: 0; }
#appShell #section-home form.home-sage-bar .sb-ic .ic { stroke: currentColor; }
#appShell #section-home form.home-sage-bar .sb-ic.listening { background: #b91c1c; color: #fff; }
#appShell #section-home form.home-sage-bar .sb-ic.speaking { background: #174f65; color: #fff; }
#appShell #section-home form.home-sage-bar :is(input, button):focus-visible {
  outline: 2px solid var(--ask-focus);
  outline-offset: 2px;
}

html[data-sage-ui="modern"] .modern-voice-description {
  white-space: normal;
  overflow-wrap: anywhere;
  max-width: min(520px, 100%);
}
.cmd { display: flex; flex-direction: column; gap: 12px; }
.cmd-top { display: flex; align-items: center; gap: 12px; padding: 4px 0 4px; }
.cmd-top img { width: 44px; height: 44px; border-radius: 50%; }
.cmd-greet { flex: 1; min-width: 0; }
.cmd-hello {
  font-family: var(--font-display); font-weight: 600; font-size: 26px; line-height: 1.1;
  letter-spacing: -0.01em; margin: 0;
}
.cmd-sub { display: flex; flex-wrap: wrap; column-gap: 8px; color: var(--muted); font-size: 16px; line-height: 1.35; }
.cmd-sub span { white-space: nowrap; }
.cmd-people-mini { display: none; }
.cmd-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 8px 16px;
}
.cmd-card-title, .cmd-card h3 {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 17px; font-weight: 800; margin: 8px 0;
}
.cmd-card-title button, .cmd-link {
  background: none; color: var(--ink-teal); font-weight: 700; font-size: 16px;
  min-height: var(--target); padding: 0 4px;
}
.cmd-row {
  display: flex; align-items: center; gap: 12px; min-height: 56px; width: 100%;
  background: none; color: inherit; text-align: left; border-radius: 12px; padding: 4px 0;
}
.cmd-row + .cmd-row { border-top: 1px solid var(--line); }
.cmd-bar { width: 4px; align-self: stretch; border-radius: 4px; margin: 8px 0; flex-shrink: 0; }
.cmd-time { width: auto; min-width: 76px; flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.cmd-when { font-size: 16px; font-weight: 700; color: var(--muted); }
.cmd-grow { flex: 1; min-width: 0; }
.cmd-t1 { display: block; font-weight: 700; font-size: 17px; line-height: 1.3; overflow-wrap: break-word; }
.cmd-t2 { display: block; color: var(--muted); font-size: 16px; line-height: 1.35; overflow-wrap: break-word; }
.cmd-grid > * { min-width: 0; }
.cmd-ride { color: var(--ink-teal); font-weight: 700; }
.cmd-h { font-size: 16px; font-weight: 700; color: var(--muted); margin: 10px 2px 6px; }
.cmd-where { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.cmd-who {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: 8px; display: grid; grid-template-columns: 32px minmax(0, 1fr); column-gap: 8px;
  align-items: center; text-align: left; color: inherit; min-height: 56px;
}
.cmd-where-card { background: transparent; border: 0; box-shadow: none; padding: 0; }
.cmd-av {
  width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; grid-row: 1 / 3;
}
.av-teal { background: var(--m-mia-tint); color: var(--m-mia); }
.av-purple { background: var(--m-leo-tint); color: var(--m-leo); }
.av-blue { background: var(--m-jordan-tint); color: var(--m-jordan); }
.av-amber { background: var(--m-family-tint); color: var(--m-family); }
.bar-teal { background: var(--m-mia); }
.bar-purple { background: var(--m-leo); }
.bar-blue { background: var(--m-jordan); }
.bar-amber { background: var(--m-family); }
.cmd-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cmd-tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 4px;
  align-items: flex-start; text-align: left; color: inherit; min-height: 112px;
}
.cmd-k { display: flex; align-items: center; gap: 6px; max-width: 100%; font-weight: 800; font-size: 16px; color: var(--muted-strong); }
.cmd-k .ic { width: 20px; height: 20px; flex: 0 0 20px; }
.cmd-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  font-size: 16px; font-weight: 700; line-height: 1.2;
}
.cmd-badge.warn { background: var(--tint-warn); color: var(--ink-amber); border: 1px solid var(--tint-warn-line); }
.cmd-badge.rose { background: var(--tint-rose); color: var(--tint-rose-text); border: 1px solid var(--tint-rose-line); }
.cmd-badge.ok { background: var(--tint-success); color: var(--ink-green); border: 1px solid var(--tint-success-line); }
.cmd-badge.blue { background: var(--tint-blue); color: var(--ink-navy); border: 1px solid var(--tint-blue-line); }
.cmd-needs, .cmd-week, .cmd-dinner { display: none; }
.cmd-empty { color: var(--muted); font-size: 16px; padding: 8px 0 12px; }

/* Phone tab bar: Today, Calendar, raised Talk, Meals, More. */
@media (max-width: 899px) {
  .tabbar {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr);
    height: auto;
    min-height: 84px;
    align-items: start;
    padding: 8px 4px calc(8px + var(--safe-bottom));
    background: var(--panel);
    border-top: 1px solid var(--line);
  }
  .tabbar button {
    background: none; color: var(--muted); box-shadow: none; border: 0; border-radius: 12px;
    min-height: 56px; font-size: 16px; font-weight: 700; padding: 4px 2px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  }
  .tabbar button.active { color: var(--ink-navy); }
  [data-theme="dark"] .tabbar button.active { color: var(--ink-teal); }
  .tabbar button .tab-ico .ic, .tabbar button .ic { width: 26px; height: 26px; }
  .tabbar button.tab-mic {
    margin-top: -28px; color: var(--ink); font-weight: 800; background: none; min-height: 0;
  }
  .tabbar button.tab-mic .mic {
    width: var(--mic); height: var(--mic); border-radius: 50%;
    background: linear-gradient(135deg, var(--navy), var(--teal)); color: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 10px 24px rgba(15, 118, 110, .38), 0 0 0 5px var(--panel);
  }
  .tabbar button.tab-mic .mic .ic { width: 30px; height: 30px; }
  main { padding-bottom: calc(108px + var(--safe-bottom)); }
  .cmd-up .cmd-row:nth-child(n+3) { display: none; }
}

/* Calendar week treatment. */
.rd-cal-search { margin: 0 0 12px; }
.rd-cal-search input { min-height: var(--target); border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 0 14px; width: 100%; }
.cal-person-row { display: flex; gap: 8px; overflow: auto; padding: 8px 0 4px; }
.cal-person-row button, .rd-seg button {
  min-height: 44px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); box-shadow: none;
}
.cal-person-row button.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
html body .tabbar button { font-size: 16px; }
.cal-day-dots { display: flex; gap: 3px; justify-content: center; min-height: 8px; }
.cal-day-dots i { width: 7px; height: 7px; border-radius: 50%; display: block; }
.cal-agenda-card { position: relative; }
.cal-agenda-bar { width: 4px; align-self: stretch; border-radius: 4px; flex-shrink: 0; }
.rd-dayhead { display: flex; justify-content: space-between; gap: 8px; font-weight: 800; font-size: 17px; margin: 14px 2px 8px; }
.rd-dayhead span { color: var(--muted); font-weight: 700; }

/* Meals board. */
.rd-seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin: 0 0 12px; }
.rd-seg button { flex: 1; min-height: 44px; border-radius: 999px; background: transparent; color: var(--muted-strong); font-weight: 700; font-size: 16px; box-shadow: none; }
.rd-seg button.on, .rd-seg button[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
#section-meals[data-meal-view="week"] .mb-board,
#section-meals[data-meal-view="groceries"] .mb-board { display: none; }
.meal-draft-banner {
  display: flex; gap: 12px; align-items: center; background: var(--qt-g2); border: 1px solid var(--qt-g2-line);
  border-radius: var(--radius-lg); padding: 12px 14px; margin-bottom: 12px;
}
@media (max-width: 899px) {
  .meal-draft-banner { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 12px; align-items: start; }
  .meal-draft-banner > button { grid-column: 1 / -1; justify-self: start; min-height: 44px; }
}
.meal-day { display: flex; gap: 12px; align-items: center; min-height: 64px; width: 100%; background: none; color: inherit; text-align: left; border-radius: 12px; }
.meal-day + .meal-day { border-top: 1px solid var(--line); }
.meal-day .d { width: 52px; text-align: center; flex-shrink: 0; }
.meal-day .d b { display: block; font-size: 19px; }
.meal-day .d span { font-size: 16px; color: var(--muted); font-weight: 700; }
.meal-thumb { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0; }
.gi { display: flex; align-items: center; gap: 12px; min-height: 52px; width: 100%; background: none; color: inherit; text-align: left; }
.gi + .gi { border-top: 1px solid var(--line); }
.gi .box { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--muted); flex-shrink: 0; }
.gi.on .box { background: var(--teal); border-color: var(--teal); }
.gi.on .cmd-t1 { text-decoration: line-through; color: var(--muted); }

/* Budget overview. */
.rd-budget-hero, .rd-budget-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 16px;
}
.rd-budget-hero { margin-bottom: 12px; }
.rd-big { font-family: var(--font-display); font-weight: 600; font-size: 44px; line-height: 1.05; margin: 4px 0; }
.rd-progress { height: 10px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); overflow: hidden; }
.rd-progress > i { display: block; height: 100%; background: var(--teal); }
.rd-progress > i.over { background: var(--rose); }
.rd-sample { display: flex; gap: 10px; align-items: center; background: var(--tint-blue); border: 1px solid var(--tint-blue-line); border-radius: var(--radius-md); padding: 12px; margin: 12px 0; font-size: 16px; }
.rd-spend-meta { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-top: 8px; }
.rd-cat { padding: 12px 0; }
.rd-cat + .rd-cat { border-top: 1px solid var(--line); }
.rd-cat .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.budget-subnav { display: flex; gap: 8px; overflow: auto; padding: 4px 0 12px; }
.budget-subnav button { min-height: 44px; border-radius: 999px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); padding: 0 14px; white-space: nowrap; }
.budget-subnav button.active { background: var(--ink); color: var(--panel); }

/* Web checkout offers the existing monthly and yearly plans. */
.paywall { background: var(--panel); }
.paywall-card { max-width: 440px; }
.pw-step { color: var(--muted); font-weight: 700; font-size: 16px; }
.pw-ticks { margin: 14px 0; display: flex; flex-direction: column; gap: 8px; }
.pw-ticks div { display: flex; gap: 10px; align-items: center; font-size: 17px; }
.pw-ticks .ic { color: var(--ink-green); }
.pw-stripe { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 16px; margin: 8px 0; }
.pw-plan-annual[hidden] { display: none !important; }
.pw-fine { color: var(--muted); font-size: 16px; text-align: center; }
.auth-trust span { font-size: 16px; min-height: 32px; }

/* Laptop / tablet dashboard. */
@media (min-width: 900px) {
  #appShell.app-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 100vh;
    align-items: start;
  }
  #appShell .app-top {
    grid-column: 1; grid-row: 1 / span 2; position: sticky; top: 0; height: 100vh;
    border-right: 1px solid var(--line); border-bottom: 0; background: var(--panel); color: var(--ink);
    padding: 20px 16px; display: flex;
  }
  #appShell .top-inner { display: flex !important; flex-direction: column; align-items: stretch; height: 100%; width: 100%; gap: 8px; }
  #appShell .app-brand { padding: 0 8px 12px; }
  #appShell .app-brand strong { font-family: var(--font-display); font-size: 22px; font-weight: 600; color: var(--ink); }
  #appShell .app-brand span { color: var(--muted); font-size: 16px; }
  #appShell .nav {
    display: flex !important; flex-direction: column; align-items: stretch; gap: 4px; width: 100%;
    overflow: visible; justify-content: flex-start;
  }
  #appShell .nav button {
    display: flex; align-items: center; gap: 12px; min-height: 48px; width: 100%; padding: 0 12px; border-radius: 12px;
    background: none; color: var(--muted-strong); font-weight: 700; font-size: 17px; text-align: left;
    box-shadow: none; justify-content: flex-start; white-space: normal;
  }
  #appShell .nav button.active { background: var(--tint-blue); color: var(--ink-navy); }
  #appShell #headTalk.head-talk {
    display: inline-flex !important; flex-direction: row; margin-top: auto; min-height: 64px; width: 100%; justify-content: center;
    border-radius: 18px; background: linear-gradient(135deg, var(--navy), var(--teal)); color: #fff;
    font-size: 18px; font-weight: 800; white-space: nowrap;
  }
  #appShell #timezoneChangeBanner, #appShell main { grid-column: 2; }
  #appShell main { max-width: none !important; margin: 0 !important; justify-self: stretch; padding: calc(24px + var(--safe-top)) calc(28px + var(--safe-right)) 48px calc(28px + var(--safe-left)); }
  html #section-home.active,
  html[data-sage-ui="modern"] #section-home.active {
    display: block !important; max-width: none !important; grid-template-columns: none !important;
  }
  #section-home .home-primary { display: flex; flex-direction: column; width: 100%; max-width: none; }
  .cmd-hello { font-size: 34px; }
  .cmd-people-mini { display: flex; gap: 8px; align-items: center; }
  .cmd-people-mini .cmd-av { width: 40px; height: 40px; }
  #appShell #section-home form.home-sage-bar { border-radius: 999px; }
  #appShell #section-home form.home-sage-bar :is(.sb-ic, .sb-send) { border-radius: 999px; }
  .cmd-grid {
    display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 16px; align-items: stretch;
  }
  .cmd-up, .cmd-where-card, .cmd-needs { align-self: stretch; height: auto; }
  .cmd-up { grid-column: 1; grid-row: 1; }
  .cmd-where-card {
    grid-column: 2; grid-row: 1; background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 8px 16px;
  }
  .cmd-where { display: flex; flex-direction: column; }
  .cmd-who { border: 0; border-radius: 0; box-shadow: none; grid-template-columns: 40px minmax(0, 1fr); min-height: 56px; }
  .cmd-who + .cmd-who { border-top: 1px solid var(--line); }
  .cmd-needs { display: block; grid-column: 3; grid-row: 1; }
  .cmd-tiles { display: none; }
  .cmd-week { display: block; grid-column: 1 / -1; grid-row: 2; }
  .cmd-dinner { display: block; grid-column: 1 / -1; grid-row: 3; }
  .cmd-week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
  .cmd-week-day { border: 1px solid var(--line); border-radius: 12px; padding: 8px; min-height: 140px; }
  .cmd-week-day b { display: block; color: var(--muted); font-size: 16px; font-weight: 700; }
  .cmd-chip {
    display: block; font-style: normal; font-size: 16px; font-weight: 700; border-radius: 8px;
    padding: 2px 6px; margin-top: 4px; line-height: 1.25; white-space: normal; overflow-wrap: break-word; max-width: 100%;
  }
  .tabbar { display: none !important; }
}

@media (max-width: 899px) {
  #appShell .app-top { display: none; }
  #appShell main { padding-top: calc(12px + var(--safe-top)); }
  #section-home { max-width: none; margin: 0; }
}

/* Every section uses the same page header, cards, fields, and empty states. */
html[data-sage-ui="modern"] #appShell main > .section > .page-head,
html[data-sage-ui="modern"] :is(#section-carpool, #section-reminders, #section-groceries, #section-sports, #section-family, #section-wallet, #section-kids, #section-school, #section-nutrition, #section-memory, #section-more) > .page-head,
#appShell main > .section > .page-head {
  background: transparent !important;
  color: var(--ink) !important;
  border: 0 !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  padding: 4px 0 12px !important;
  margin: 0 0 8px !important;
}
html[data-sage-ui="modern"] #appShell .page-title,
#appShell .page-title {
  color: var(--ink) !important;
  font-family: var(--font-display) !important;
  font-weight: 600 !important;
  font-size: 30px !important;
  letter-spacing: -0.02em;
}
html[data-sage-ui="modern"] #appShell .page-copy,
#appShell .page-copy { color: var(--muted) !important; font-size: 16px !important; }
html[data-sage-ui="modern"] #appShell .page-head .row-actions > button:not(.secondary):not(.ghost) {
  background: linear-gradient(135deg, var(--navy), var(--teal)) !important;
  color: #fff !important;
  border: 0 !important;
  border-radius: 999px;
}
#appShell :is(.panel, .mb-draft, .mb-week, .mb-groc, .mb-profile, .mb-scan, .cal-mini, .cal-week, .cal-sync, .cal-agenda-card, .scan-hint, .mr-card, .budget-modal, dialog) {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  color: var(--ink);
}
#appShell :is(input, select, textarea) {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 16px;
}
#appShell textarea { min-height: 96px; }
#appShell .sage-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  min-height: 64px;
  padding: 8px;
  box-shadow: var(--shadow);
}
#appShell .sage-bar input {
  border: 0;
  background: transparent;
  box-shadow: none;
  min-height: 48px;
}
#appShell .sage-bar .sb-ic {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 50%;
  background: var(--qt-g2);
  color: var(--teal);
  border: 0;
}
#appShell .sage-bar .sb-send { min-height: 48px; border-radius: 999px; background: transparent; color: var(--ink-teal); }
#appShell .empty, #appShell .cal-agenda-empty, #appShell .budget-empty {
  font-size: 16px;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 16px;
}
#appShell .row-item, #appShell .budget-row, #appShell .gro-row, #appShell .reminder-swipe {
  min-height: 56px;
  font-size: 16px;
}
#appShell .row-title, #appShell .mr-tile-name, #appShell .panel-title { font-size: 17px; color: var(--ink); }
#appShell .row-meta, #appShell .mr-tile-cap, #appShell .panel-sub { font-size: 16px; color: var(--muted); }
#appShell .mr-tile {
  min-height: 72px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: left;
}
#appShell .mr-label { font-size: 16px; color: var(--muted); letter-spacing: 0; text-transform: none; font-weight: 800; }
#appShell .cal-filter-pill, #appShell .chip, #appShell .carpool-mobile-tab, #appShell .cp-mode-tab {
  min-height: 44px;
  border-radius: 999px;
  font-size: 16px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
}
#appShell .cal-filter-pill.is-active, #appShell .carpool-mobile-tab.is-active {
  background: var(--ink);
  color: var(--panel);
  border-color: var(--ink);
}
#appShell .scan-hint, #appShell .cal-sync, #appShell .cal-scanhint { padding: 14px; }
#appShell .cp-ride-head { flex-wrap: wrap; align-items: center; }
#appShell .cp-ride-name { flex: 1 1 160px; min-width: 140px; overflow-wrap: break-word; }
#appShell .cp-ride-lane-tag { margin-left: 0; }
#appShell dialog, #appShell .budget-modal {
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 16px;
}
#sageInline .suggestion {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
  margin-top: 8px;
  text-align: left;
}
.auth-shell {
  background: var(--soft) !important;
  color: var(--ink);
}
.auth-panel {
  background: var(--panel) !important;
  color: var(--ink) !important;
  box-shadow: none !important;
  backdrop-filter: none;
}
.auth-panel :is(.brand-title, .brand-sub, label, .page-copy, .auth-trust) { color: var(--ink); }
.auth-panel .brand-sub, .auth-panel .page-copy, .auth-panel label { color: var(--muted); }
.auth-panel .brand-home { color: var(--ink) !important; background: var(--panel-2) !important; }
.auth-panel input, .auth-panel select {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  min-height: 48px;
}
.auth-tabs button { min-height: 48px; font-size: 16px; color: var(--muted-strong); background: transparent; }
.auth-tabs button.active { background: var(--panel); color: var(--ink); }
.paywall { background: var(--soft) !important; }
.paywall-card { border: 1px solid var(--line); }

@media (prefers-reduced-motion: reduce) {
  .tabbar button.tab-mic .mic { transition: none; }
}

/* v2 mobile correctness.
   v1 raised every label to 16px inside boxes that were still sized for 10–13px
   type. Month cells used a fixed 16px + 16px grid, so the day number and the
   count painted outside the cell and into the next week. Phone gutters also
   disagreed (12px, 14px, and full-bleed headers). This block sizes the boxes
   to the type, keeps one 16px page gutter, and clears the notch and tab bar. */

#appShell.app-shell > main,
#appShell main {
  padding: calc(12px + var(--safe-top)) calc(16px + var(--safe-right)) calc(148px + var(--safe-bottom)) calc(16px + var(--safe-left));
}
/* The schedule is the page. Filters and tools follow it, so the month
   grid is on screen instead of under a stack of forms. */
@media (max-width: 899px) {
  #section-calendar.active { display: flex; flex-direction: column; gap: 8px; }
  #section-calendar > .page-head { display: contents; }
  #section-calendar > .page-head > div:first-child { order: 1; }
  #section-calendar > .page-head .page-copy { display: none; }
  #section-calendar > #calendarMobileControls { order: 2; }
  #section-calendar > #calendarFilters { order: 3; }
  #section-calendar > .cal-planner { order: 4; }
  #section-calendar > .sage-bar { order: 5; }
  #section-calendar > .page-head > .row-actions { order: 6; display: flex; flex-wrap: wrap; gap: 8px; }
  #section-calendar > .form-grid { order: 7; }
  #section-calendar > .rd-cal-search { order: 8; }
  #section-calendar > #scanReview,
  #section-calendar > #captureReviewCalendar,
  #section-calendar > .add-card { order: 9; }
  .legal-foot { padding-bottom: calc(28px + 120px + var(--safe-bottom)); }
}
#appShell main > .section,
#appShell .section.active { min-width: 0; }
#appShell img, #appShell svg, #appShell video, #appShell canvas { max-width: 100%; height: auto; }
#appShell .cmd-time { width: auto; flex: 0 0 auto; white-space: normal; }
#appShell .cmd-up .cmd-row {
  display: grid;
  grid-template-columns: 4px 104px minmax(0, 1fr);
  column-gap: 10px;
  align-items: start;
  padding: 8px 4px 8px 0;
}
#appShell .cmd-up .cmd-time { width: 104px; min-width: 104px; max-width: 104px; }
#appShell .cmd-row, #appShell .cmd-who, #appShell .cmd-tile, #appShell .meal-day, #appShell .gi { min-width: 0; }
#appShell :is(.cmd-who,.cmd-tile) :is(.cmd-t1,.cmd-t2,.cmd-k),
#appShell :is(.row-title,.row-meta,.cal-agenda-title,.cal-agenda-meta,.mb-title,.mb-meta,.mb-groc-name,.ntr-row-name,.ntr-row-meta,.gro-name,.gro-meal-title) {
  min-width: 0;
  overflow-wrap: anywhere;
}
@media (max-width: 899px) {
  #section-calendar #calendarFilters {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
  }
  #section-calendar #calendarFilters .cal-person-row,
  #section-calendar #calendarFilters > .cal-filter-pill {
    flex: 0 0 auto;
    width: auto;
    max-width: none;
  }
}
#appShell .cal-day-btn .cal-day-btn-dot { display: none; }
#appShell > #calEventDetail { position: absolute; width: 0; height: 0; overflow: visible; }

/* Phone rhythm: who's-where is a list, tiles share a row, calendar chrome stays short. */
@media (max-width: 899px) {
  .cmd-top { align-items: center; }
  .cmd-hello { font-size: clamp(20px, 6.4vw, 28px); overflow-wrap: anywhere; line-height: 1.15; }
  .cmd-where-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 4px 16px 8px;
  }
  .cmd-where { display: flex; flex-direction: column; gap: 0; }
  .cmd-who {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    padding: 10px 0;
    min-height: 64px;
    grid-template-columns: 40px minmax(0, 1fr);
  }
  .cmd-who + .cmd-who { border-top: 1px solid var(--line); }
  .cmd-tile { min-height: 120px; padding: 14px 16px; }
  .cmd-k { max-width: 100%; }
  .budget-stats { grid-template-columns: 1fr 1fr; }
  .budget-stat-label { letter-spacing: 0; text-transform: none; }
  .cp-event-meta, .cp-thread-title, .cp-thread-last, .cp-member-name, .mb-draft-sub, .mb-draft-title {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    overflow-wrap: break-word;
  }
  #section-budget label { white-space: normal; min-width: 0; }
  #section-budget label:has(input[type="checkbox"]) { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; }
  .ntr-add-link, .mb-add-link, .gro-add-link { white-space: normal; max-width: 100%; }
  .cmd-card { padding: 8px 16px 12px; }
  #section-meals > .page-head,
  html[data-sage-ui="modern"] #section-meals > .page-head { align-items: stretch; }
  #section-meals > .page-head .row-actions,
  html[data-sage-ui="modern"] #section-meals > .page-head .row-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    gap: 8px;
  }
  html[data-sage-ui="modern"] #appShell #section-meals > .page-head .row-actions > button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    white-space: nowrap;
    justify-content: center;
    padding: 8px 10px;
    line-height: 1.2;
  }
  .rd-seg button { white-space: nowrap; padding: 0 8px; }
  #section-calendar .cal-title-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 0;
  }
  #section-calendar .page-title { font-size: 28px !important; line-height: 1.1; white-space: nowrap; margin: 0; width: auto; flex: 1 1 auto; }
  #section-calendar .cal-title-meta { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
  #section-calendar .cal-mobile-period { white-space: nowrap; font-size: 16px; font-weight: 800; }
  #section-calendar .cal-mobile-today { min-height: 44px; padding: 0 12px; }
  #section-calendar .cal-mobile-controls { gap: 0; margin: 0; padding: 0; }
  #section-calendar .cal-mobile-toolbar {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 4px;
    align-items: center;
    min-height: 44px;
  }
  #section-calendar .cal-mobile-view-toggle { min-width: 0; box-sizing: border-box; padding: 4px; gap: 2px; min-height: 52px; }
  #section-calendar .cal-mobile-view-btn { white-space: nowrap; padding: 0 2px; min-height: 44px; letter-spacing: -0.02em; }
  #section-calendar .cal-type-all { display: none; }
  #section-calendar #calendarFilters {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    max-width: 100%;
    margin: 0;
    padding: 0;
    min-height: 44px;
    max-height: 44px;
  }
  #section-calendar .cal-person-row,
  #section-calendar .cal-type-row {
    display: contents;
  }
  #section-calendar .cal-person-chip,
  #section-calendar .cal-person-row button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 12px;
    white-space: nowrap;
    flex: 0 0 auto;
  }
  #section-calendar .cal-person-row .cmd-av {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 16px;
    grid-row: auto;
  }
  #section-calendar .cal-filter-pill { flex: 0 0 auto; }
  #section-calendar .cal-mobile-month { margin-top: 4px; }
}
.form-grid > * { min-width: 0; }
.form-grid :is(input, select, textarea) { min-width: 0; max-width: 100%; }
input[type="date"], input[type="time"], input[type="datetime-local"] { min-width: 0; max-width: 100%; }
.form-grid > label:has(input[type="checkbox"]),
.form-grid > label:has(input[type="radio"]) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  grid-column: 1 / -1;
  white-space: normal;
}
.mb-rail .form-grid { grid-template-columns: 1fr; }
@media (min-width: 901px) {
  #section-meals .mb-row {
    grid-template-columns: 96px 44px minmax(0, 1fr);
    grid-template-areas: "day tile body" "day tile actions";
  }
  #section-meals .mb-actions { flex-wrap: wrap; min-width: 0; max-width: 100%; }
}
.ntr-foot { flex-wrap: wrap; }
.ntr-add-link { white-space: normal; overflow-wrap: anywhere; max-width: 100%; }
.rd-spend-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.rd-spend-label { color: var(--muted); font-size: 16px; font-weight: 700; min-width: 0; }
.rd-spend-month { font-size: 17px; font-weight: 800; white-space: nowrap; }
.cmd-week, .cmd-week-grid { width: 100%; }
@media (min-width: 900px) {
  #calendarTitleMeta { display: none; }
  .cmd-week-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .cmd-week-day { min-width: 0; }
}
#appShell .cal-detail-close, #appShell .vd-close {
  width: 44px; height: 44px; min-width: 44px; min-height: 44px;
}
#section-calendar .cal-mobile-view-toggle { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
#section-calendar .cal-filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  overflow: visible;
  max-width: 100%;
}
#section-calendar .cal-person-row {
  flex: 1 0 100%;
  display: flex;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
#section-budget .budget-subnav {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
#appShell :is(button, summary),
#authShell :is(button, summary),
#paywallShell button {
  min-height: 44px;
}
#appShell button.footer-action { min-height: 48px; padding: 8px 12px; }
#appShell :is(.mb-add-link, .mb-binder-link, .gro-add-link, .gro-meals-link, .ntr-goal-edit-link, .link-sm, .ntr-add-link) {
  display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; font-size: 16px;
}
#section-budget .budget-target-btn { min-height: 44px; min-width: 48px; padding: 8px 4px; }
.auth-panel a, .auth-form a { display: inline-flex; align-items: center; min-height: 44px; font-size: 16px; }
#appShell button.cal-mobile-month-day,
#appShell button.cal-day-btn,
#appShell button.cal-mini-day { min-width: 0; }

@media (max-width: 899px) {
  #appShell .app-top { display: none; }
  #tabbar.tabbar {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
    height: auto;
    min-height: 0;
    gap: 0;
    padding: 6px max(2px, var(--safe-right)) calc(8px + var(--safe-bottom)) max(2px, var(--safe-left));
  }
  #tabbar.tabbar button {
    min-width: 0;
    width: 100%;
    min-height: 48px;
    padding: 2px 0 0;
    font-size: 16px;
    line-height: 1.05;
  }
  #tabbar.tabbar button .tab-label {
    display: block;
    max-width: 100%;
    font-size: 16px;
    line-height: 1.05;
    letter-spacing: -0.06em;
    font-weight: 650;
    text-align: center;
    white-space: nowrap;
  }
  #tabbar.tabbar button.tab-mic {
    margin-top: -12px;
    min-height: 0;
    padding-top: 0;
  }
  #tabbar.tabbar button.tab-mic .mic {
    width: 52px;
    height: 52px;
    box-shadow: 0 8px 18px rgba(15, 118, 110, .32), 0 0 0 4px var(--panel);
  }
  /* The month grid and week strip go to the safe-area edge so seven 16px
     labels still have a 44px track at 320px. The page title stays at 16px. */
  #section-calendar .cal-mobile-month,
  #section-calendar .cal-daystrip {
    margin-left: -16px;
    margin-right: -16px;
    width: calc(100% + 32px);
  }
  #section-calendar .cal-mobile-month {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
    padding-left: 0;
    padding-right: 0;
  }
  html[data-sage-ui="modern"]:not([data-theme="dark"]) #appShell main,
  html[data-sage-ui="modern"][data-theme="dark"] #appShell main {
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    padding-bottom: calc(148px + var(--safe-bottom));
  }
  .auth-panel {
    padding: calc(20px + var(--safe-top)) calc(16px + var(--safe-right)) calc(28px + var(--safe-bottom)) calc(16px + var(--safe-left));
  }
  .paywall { padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(16px + var(--safe-left)); }
}



@media (min-width: 900px) {
  #appShell.app-shell > main,
  #appShell main {
    padding: calc(24px + var(--safe-top)) calc(28px + var(--safe-right)) 48px calc(28px + var(--safe-left));
  }
  #section-calendar .cal-mobile-controls { display: grid; }
  #section-calendar[data-cal-view="month"] .cal-mobile-month { display: block; }
  #section-calendar[data-cal-view="month"] .cal-week,
  #section-calendar[data-cal-view="month"] .cal-mini,
  #section-calendar[data-cal-view="month"] .cal-daystrip,
  #section-calendar[data-cal-view="month"] .cal-agenda,
  #section-calendar[data-cal-view="month"] .cal-dayhead-row { display: none !important; }
  #section-calendar[data-cal-view="day"] .cal-week { display: none !important; }
  #section-calendar[data-cal-view="day"] .cal-daystrip { display: grid; }
  #section-calendar[data-cal-view="day"] .cal-agenda { display: grid; }
  #section-calendar[data-cal-view="day"] .cal-dayhead-row { display: flex; }
  #section-calendar .cal-mobile-month,
  #section-calendar .cal-daystrip {
    margin-left: 0;
    margin-right: 0;
    width: 100%;
  }
}

/* Review pass: legible secondary buttons, one ask bar, stacked draft header, budget panes. */
.home-account-footer { display: none !important; }
#budgetOverview[hidden],
#section-budget > [id^="budget"][hidden] { display: none !important; }
#appShell button.secondary,
html[data-sage-ui="modern"] #appShell :is(#section-carpool, #section-groceries, #section-sports) > .page-head button.secondary {
  background: var(--panel) !important;
  color: var(--ink) !important;
  border: 1.5px solid var(--ink) !important;
  opacity: 1 !important;
}
#appShell button:disabled {
  opacity: 1 !important;
  background: var(--panel-2) !important;
  color: #334155 !important;
  border: 1.5px solid #64748b !important;
}
html[data-sage-ui="modern"] #appShell .sage-bar,
html[data-sage-ui="modern"] #appShell :is(#section-family, #section-wallet, #section-kids, #section-school, #section-memory) > .sage-bar {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
html[data-sage-ui="modern"] #appShell .sage-bar input,
html[data-sage-ui="modern"] #appShell :is(#section-family, #section-wallet, #section-kids, #section-school, #section-memory) > .sage-bar input {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  width: auto;
  flex: 1;
  min-width: 0;
  color: var(--ink);
}
#calendarEventEditor.calendar-composer {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
}
#calendarEventEditor.calendar-composer::backdrop { background: rgba(15, 23, 42, 0.45); }
#calendarEventEditor .calendar-composer-head { border-bottom: 1px solid var(--line); }
#calendarEventEditor .calendar-composer-head h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
}
#calendarEventEditor .calendar-composer-head button:first-child {
  background: var(--panel);
  color: var(--ink);
  border: 1.5px solid var(--line);
}
#calendarEventEditor .calendar-composer-head button:last-child {
  background: var(--navy);
  color: #fff;
}
#calendarEventEditor .calendar-composer label { color: var(--muted); }
#calendarEventEditor :is(input:not([type="checkbox"]), select, textarea) {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
}
#calendarEventEditor .calendar-composer-hint,
#calendarEventEditor .calendar-composer-more summary { color: var(--muted); }
#calendarEventEditor .calendar-composer-more { border-top-color: var(--line); }
#section-nutrition select {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 12px;
}
#authShell button.secondary,
#paywallShell button.secondary {
  background: var(--panel) !important;
  color: var(--ink) !important;
  border: 1.5px solid var(--ink) !important;
  opacity: 1 !important;
}
#authShell button[type="submit"]:not(.secondary) {
  background: var(--navy);
  color: #fff;
  border-radius: 14px;
}
.auth-headline {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0 0 8px;
  line-height: 1.15;
}
.auth-hint { display: block; font-size: 16px; font-weight: 600; color: var(--muted); line-height: 1.4; }
.auth-panel .brand-title { font-family: var(--font-display); font-size: 28px; font-weight: 600; color: var(--ink) !important; }
.auth-panel .brand-home {
  background: transparent !important;
  color: var(--ink) !important;
  border-radius: 12px;
  box-shadow: none;
}
.auth-theme-toggle { box-shadow: none; }
.paywall { background: var(--soft) !important; }
.pw-lead, .pw-title { font-family: var(--font-display); color: var(--ink); }
.pw-lead { font-size: 32px; font-weight: 600; letter-spacing: -0.02em; }
@media (max-width: 899px) {
  .mb-draft-head { flex-direction: column; align-items: stretch; }
  .mb-draft-title, .mb-draft-sub { overflow-wrap: break-word; word-break: normal; }
  .mb-approve, .mb-kept-chip { align-self: flex-start; }
  #section-nutrition > .page-head .row-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
  }
  #section-nutrition > .page-head .row-actions button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    height: auto;
    white-space: normal;
    padding: 8px;
    line-height: 1.2;
  }
  #appShell main {
    padding-bottom: calc(168px + var(--safe-bottom)) !important;
  }
}


@media (max-width: 899px) {
  /* Prevent min-content widths from pushing the mobile Home cards past the viewport. */
  #section-home .home-primary { min-width: 0; grid-template-columns: minmax(0, 1fr); }
  #section-home .home-primary > * { min-width: 0; }
}
