/* LedgerBite — minimal teal system */

:root {
  --ink: #13241e;
  --muted: #5f736b;
  --paper: #f3f6f4;
  --surface: #ffffff;
  --surface-soft: #eef2f0;
  --line: rgba(26, 58, 50, 0.11);
  --line-strong: rgba(26, 58, 50, 0.2);
  --teal: #1a3a32;
  --teal-mid: #2f6b5c;
  --teal-soft: rgba(47, 107, 92, 0.11);
  --amber: #b86a2d;
  --ok: #2f7a4a;
  --warn: #b45309;
  --bad: #a33b2c;
  --field: #ffffff;
  --field-2: #f7faf8;
  --elevated: #ffffff;
  --control-border: rgba(26, 58, 50, 0.16);
  --btn-primary-bg: #1a3a32;
  --btn-primary-fg: #f5f8f6;
  --btn-primary-border: #122c26;
  --btn-primary-hover: #143029;
  --btn-secondary-bg: #ffffff;
  --btn-secondary-fg: #1a3a32;
  --btn-secondary-border: rgba(26, 58, 50, 0.16);
  --btn-secondary-hover-bg: var(--teal-soft);
  --btn-secondary-hover-fg: #143029;
  --check-mark: #f5f8f6;
  --ring-hole: #ffffff;
  --wash: rgba(26, 58, 50, 0.045);
  --hairline: rgba(26, 58, 50, 0.09);
  --sheet-divider: rgba(26, 58, 50, 0.09);
  --heat: rgba(184, 106, 45, 0.45);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
  --text-title: 1.15rem;
  --text-body: 0.95rem;
  --text-meta: 0.8rem;
  --text-tiny: 0.72rem;
  --radius: 12px;
  --radius-sm: 10px;
  --shadow: 0 6px 20px rgba(20, 35, 30, 0.06);
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --section-gap: 0.75rem;
  --block-pad: 1rem;
  --touch: 2.75rem;
  --nav-h: 3.85rem;
  --top-h: 3.15rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --panel: var(--surface);
  --inset-shine: transparent;
  --bg-grad-1: #e8f0ec;
  --bg-grad-2: #f3f6f4;
  --bg-grad-3: #f3f6f4;
  --bg-grad-4: #f3f6f4;
  --bg-grad-5: #eef2f0;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 140ms;
}

html[data-theme="dark"] {
  --ink: #eaf2ed;
  --muted: #a7b8b0;
  --paper: #101815;
  --surface: #18231f;
  --surface-soft: #141e1a;
  --line: rgba(210, 228, 218, 0.14);
  --line-strong: rgba(210, 228, 218, 0.26);
  --teal: #8bc4b2;
  --teal-mid: #5aab94;
  --teal-soft: rgba(90, 171, 148, 0.18);
  --amber: #e4a468;
  --ok: #68c288;
  --warn: #e5ac5a;
  --bad: #e5887a;
  --field: #1a2722;
  --field-2: #15201c;
  --elevated: #1c2a25;
  --control-border: rgba(210, 228, 218, 0.22);
  --btn-primary-bg: #3f947c;
  --btn-primary-fg: #07110d;
  --btn-primary-border: #2f6b5c;
  --btn-primary-hover: #4f9a84;
  --btn-secondary-bg: #18231f;
  --btn-secondary-fg: #eaf2ed;
  --btn-secondary-border: rgba(210, 228, 218, 0.22);
  --btn-secondary-hover-bg: var(--teal-soft);
  --btn-secondary-hover-fg: #eaf2ed;
  --check-mark: #07110d;
  --ring-hole: #18231f;
  --wash: rgba(210, 228, 218, 0.07);
  --hairline: rgba(210, 228, 218, 0.12);
  --sheet-divider: rgba(210, 228, 218, 0.12);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --panel: var(--surface);
  --bg-grad-1: #141e1a;
  --bg-grad-2: #101815;
  --bg-grad-3: #101815;
  --bg-grad-4: #101815;
  --bg-grad-5: #141e1a;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.45;
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

.bg-atmosphere {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

/* ——— App shell ——— */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-top {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(var(--top-h) + var(--safe-top));
  padding: var(--safe-top) max(var(--s4), var(--safe-right)) 0 max(var(--s4), var(--safe-left));
  background: var(--paper);
  border-bottom: 1px solid var(--hairline);
}

.app-top-title {
  margin: 0;
  padding: 0.65rem 0;
  width: min(100%, 44rem);
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--teal);
}

.app-main,
main.shell {
  flex: 1;
  width: min(100%, 44rem);
  margin: 0 auto;
  padding: var(--s4) max(var(--s4), var(--safe-right)) calc(var(--nav-h) + var(--safe-bottom) + var(--s5))
    max(var(--s4), var(--safe-left));
}

.page {
  display: none;
}

.page.active {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
}

/* ——— Bottom nav ——— */
.page-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  min-height: calc(var(--nav-h) + var(--safe-bottom));
  padding: 0.35rem 0.25rem calc(0.35rem + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.page-nav-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: 2.75rem;
  padding: 0.2rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.page-nav-btn .nav-icon {
  width: 1.35rem;
  height: 1.35rem;
  display: grid;
  place-items: center;
}

.page-nav-btn .nav-icon svg {
  width: 1.2rem;
  height: 1.2rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.page-nav-btn .nav-emoji {
  display: none;
}

.page-nav-btn.active {
  color: var(--teal);
}

.page-nav-btn.active .nav-icon svg {
  stroke-width: 2.15;
}

/* ——— Blocks / panels ——— */
.block,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4);
  margin: 0 0 var(--s3);
  box-shadow: none;
  backdrop-filter: none;
}

.hub-shell,
.meals-hub {
  background: transparent;
  border: 0;
  padding: 0 0 var(--s2);
  margin: 0 0 var(--s2);
}

.hub-shell h2,
.meals-hub h2,
.history-panel > .section-head h2,
.block > h2,
.panel > h2,
.section-head h2,
.section-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--teal);
  letter-spacing: -0.02em;
}

.panel-lead,
.expense-lead,
.meta {
  margin: 0.25rem 0 0.65rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.subhead {
  margin: var(--s4) 0 var(--s2);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s3);
}

.section-head h2,
.section-head h3 {
  margin: 0;
}

/* ——— Segmented control ——— */
.seg-control,
.hub-tabs,
.meals-hub-tabs,
.history-mode,
.event-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.3rem;
  margin: 0 0 var(--s4);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.seg-btn,
.hub-tab,
.meals-hub-tab,
.history-mode-btn,
.event-filter {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  min-height: 2.2rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex: 1 1 auto;
  text-align: center;
}

.seg-btn.active,
.hub-tab.active,
.meals-hub-tab.active,
.history-mode-btn.active,
.event-filter.active {
  background: var(--surface);
  color: var(--teal);
  box-shadow: 0 1px 0 var(--line);
}

.history-mode-btn span[aria-hidden] {
  display: none;
}

/* ——— Forms & buttons ——— */
label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--muted);
}

input,
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  min-height: var(--touch);
  padding: 0.55rem 0.7rem;
  width: 100%;
  accent-color: var(--teal-mid);
}

::placeholder {
  color: var(--muted);
  opacity: 1;
}

input:focus,
select:focus,
textarea:focus,
.entry-box:focus,
.compact-note:focus,
.compact-amount:focus {
  outline: none;
  border-color: var(--teal-mid);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.btn,
button.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: var(--touch);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.btn.primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  border-color: var(--btn-primary-border);
}

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

.btn.secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-fg);
  border-color: var(--btn-secondary-border);
}

.btn.secondary:hover {
  background: var(--btn-secondary-hover-bg);
  color: var(--btn-secondary-hover-fg);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.btn-inline {
  min-height: 2.15rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  width: auto;
}

.link-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--teal-mid);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.25rem 0;
  cursor: pointer;
  text-decoration: none;
}

.btn-row,
.form-actions-row,
.settings-actions,
.settings-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  align-items: center;
  margin-top: var(--s3);
}

.field-grid,
.expense-more-grid,
.settings-grid,
.mini-form,
.meal-filters,
.meal-advanced-grid {
  display: grid;
  gap: var(--s3);
}

@media (min-width: 560px) {
  .field-grid,
  .expense-more-grid,
  .settings-grid,
  .mini-form,
  .meal-filters,
  .meal-advanced-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.meal-filters-span {
  grid-column: 1 / -1;
}

/* ——— Home: expense ——— */
.expense-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s3);
}

.expense-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--teal);
}

.expense-ocr {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.2rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--teal-mid);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.expense-sheet {
  display: grid;
  grid-template-columns: 5.5rem 1fr var(--touch);
  gap: 0.45rem;
  align-items: stretch;
}

.expense-amount-field {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  background: var(--field);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  padding: 0 0.55rem;
  min-height: var(--touch);
}

.expense-currency {
  color: var(--muted);
  font-weight: 700;
}

.compact-amount,
.compact-note {
  border: 0;
  background: transparent;
  box-shadow: none;
  min-height: 2.4rem;
  padding: 0.35rem 0;
  width: 100%;
}

.expense-amount-field:focus-within,
.compact-note:focus {
  box-shadow: none;
}

.expense-amount-field:focus-within {
  border-color: var(--teal-mid);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.compact-note {
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  background: var(--field);
  padding: 0.55rem 0.7rem;
}

.expense-add {
  width: 100%;
  min-height: var(--touch);
  padding: 0.55rem 1rem;
  font-size: 1rem;
  line-height: 1.2;
}

.expense-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s2);
  margin-top: var(--s3);
}

.expense-cat {
  flex: 1 1 10rem;
}

.compact-select {
  min-height: 2.4rem;
}

.expense-status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.draft-hint,
.category-hint,
.submit-flash {
  font-size: 0.78rem;
  font-weight: 700;
}

.draft-hint {
  color: var(--warn);
}

.category-hint {
  color: var(--teal-mid);
}

.submit-flash {
  color: var(--ok);
}

.expense-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: var(--s3);
}

.expense-more-toggle {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--teal-mid);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  min-height: 2.2rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
}

.expense-more,
.recurring-inline {
  margin-top: var(--s3);
  padding-top: var(--s3);
  border-top: 1px solid var(--hairline);
}

.expense-emergency-title {
  margin: 0 0 var(--s2);
  font-weight: 700;
  font-size: 0.88rem;
}

.expense-emergency-row {
  display: grid;
  grid-template-columns: 4.5rem 1fr auto;
  gap: 0.4rem;
}

.ocr-status {
  margin: var(--s2) 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Habits / chips */
.habit-chips,
.recurring-chips,
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: var(--s3) 0 0;
}

.habit-chip,
.recurring-chip,
.check-chip span,
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
}

.habit-chip,
.recurring-chip {
  appearance: none;
  cursor: pointer;
}

.habit-chip:hover,
.recurring-chip:hover {
  border-color: var(--teal-mid);
  color: var(--teal);
}

.chip-amt {
  color: var(--muted);
  font-weight: 600;
}

.recurring-chip-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
}

.recurring-chip-wrap .chip-x {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  font-size: 1rem;
}

.check-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
}

.check-chip input {
  width: auto;
  min-height: auto;
}

.chip-fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}

.chip-fieldset legend {
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

/* Shortcuts */
.home-shortcuts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin: 0 0 var(--s3);
}

.home-shortcut {
  appearance: none;
  min-height: 2.55rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.home-shortcut:hover {
  border-color: var(--teal-mid);
  color: var(--teal);
}

/* Funds / money heroes */
.funds-today-line {
  margin: 0 0 var(--s3);
  font-size: 0.9rem;
  color: var(--muted);
}

.funds-today-line strong {
  color: var(--ink);
}

.period-rail {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: var(--s4);
  padding: var(--s3);
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
}

.period-rail-step {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.period-rail-step strong {
  font-size: 0.88rem;
  color: var(--ink);
}

.period-rail-step.is-accent strong {
  color: var(--teal);
}

.period-rail-line {
  height: 1px;
  background: var(--line);
  min-width: 0.75rem;
}

.funds-overview,
.money-grid {
  display: grid;
  gap: var(--s4);
  align-items: center;
}

@media (min-width: 520px) {
  .funds-overview {
    grid-template-columns: auto 1fr;
  }
}

.funds-ring {
  --spent: 0;
  --fixed: 0;
  --left: 100;
  width: 9.5rem;
  height: 9.5rem;
  margin: 0 auto;
  border-radius: 50%;
  background: conic-gradient(
    var(--teal-mid) 0 calc(var(--spent) * 1%),
    var(--amber) calc(var(--spent) * 1%) calc((var(--spent) + var(--fixed)) * 1%),
    var(--surface-soft) calc((var(--spent) + var(--fixed)) * 1%) 100%
  );
  display: grid;
  place-items: center;
}

.funds-ring-hole {
  width: 6.6rem;
  height: 6.6rem;
  border-radius: 50%;
  background: var(--ring-hole);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  text-align: center;
}

.funds-ring-label {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}

.funds-ring-hole strong {
  font-size: 1.05rem;
  color: var(--teal);
}

.funds-ring.is-over .funds-ring-hole strong {
  color: var(--bad);
}

.funds-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.funds-legend li {
  display: grid;
  grid-template-columns: 0.7rem 1fr;
  gap: 0.55rem;
  align-items: start;
}

.funds-swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  margin-top: 0.25rem;
  background: var(--muted);
}

.funds-legend [data-key="spent"] .funds-swatch {
  background: var(--teal-mid);
}
.funds-legend [data-key="fixed"] .funds-swatch {
  background: var(--amber);
}
.funds-legend [data-key="carry"] .funds-swatch {
  background: var(--ok);
}

.funds-legend span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.funds-legend strong {
  font-size: 0.95rem;
}

.funds-progress {
  margin-top: var(--s4);
}

.funds-progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.meter {
  height: 0.45rem;
  background: var(--surface-soft);
  border-radius: 999px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  background: var(--teal-mid);
  border-radius: inherit;
}

.money-hero,
.money-hero-sm {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: var(--s3);
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
  margin-bottom: var(--s3);
}

.money-hero span,
.money-hero-sm span {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.money-hero strong,
.money-hero-sm strong {
  font-size: 1.35rem;
  color: var(--teal);
}

.money-hero-sm strong {
  font-size: 1.1rem;
}

.funds,
.event-summary,
.info-pills {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin: 0 0 var(--s3);
}

@media (min-width: 520px) {
  .funds,
  .event-summary,
  .info-pills {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.funds > div,
.event-summary > div,
.info-pill {
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.funds span,
.event-summary span,
.info-pill span {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}

.funds strong,
.event-summary strong,
.info-pill strong {
  font-size: 0.95rem;
}

.forecast-pill {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: var(--s3);
  background: var(--teal-soft);
  border-radius: var(--radius-sm);
  margin-bottom: var(--s3);
}

.forecast-pill-kicker {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 650;
}

.projection-card {
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: var(--s3);
}

.projection-card.is-warn {
  border-color: var(--warn);
}
.projection-card.is-bad {
  border-color: var(--bad);
}

.projection-main {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--teal);
}

.home-more,
.meal-advanced {
  margin-top: var(--s3);
  border-top: 1px solid var(--hairline);
  padding-top: var(--s2);
}

.home-more > summary,
.meal-advanced > summary {
  cursor: pointer;
  list-style: none;
  min-height: 2.4rem;
  display: flex;
  align-items: center;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--teal-mid);
}

.home-more > summary::-webkit-details-marker,
.meal-advanced > summary::-webkit-details-marker {
  display: none;
}

.home-more > summary::before,
.meal-advanced > summary::before {
  content: "▸";
  margin-right: 0.35rem;
}

.home-more[open] > summary::before,
.meal-advanced[open] > summary::before {
  content: "▾";
}

/* Lists */
.entry-list,
.payday-list,
.soft-list,
.reminder-list,
.wish-list,
.goal-list,
.leftover-list,
.pantry-list,
.night-expense-list,
.cal-event-list,
.spend-bars {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entry-list > li,
.payday-list > li,
.soft-list > li,
.reminder-list > li,
.wish-list > li,
.goal-list > li,
.leftover-list > li,
.pantry-list > li,
.night-expense-list > li,
.cal-event-list > li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s3);
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--hairline);
}

.entry-list > li:last-child,
.payday-list > li:last-child {
  border-bottom: 0;
}

.empty,
li.empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: var(--s3) 0;
  border: 0 !important;
  display: block !important;
}

.entry-actions {
  display: flex;
  gap: 0.25rem;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
  width: 2.2rem;
  height: 2.2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  display: grid;
  place-items: center;
}

.icon-btn.edit {
  color: var(--teal-mid);
}

.month-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--teal-mid);
  background: var(--teal-soft);
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}

.soft-alerts,
.insight-warnings {
  list-style: none;
  margin: 0 0 var(--s3);
  padding: 0;
}

.soft-alerts li,
.insight-warn {
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  background: rgba(180, 83, 9, 0.1);
  color: var(--warn);
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

/* Spend bars / donut */
.spend-groups-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}

.spend-donut {
  width: 2.8rem;
  height: 2.8rem;
  border-radius: 50%;
}

.spend-bar-head {
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
  font-size: 0.82rem;
  margin-bottom: 0.25rem;
}

.spend-bar-track {
  height: 0.35rem;
  background: var(--surface-soft);
  border-radius: 999px;
  overflow: hidden;
}

.spend-bar-fill {
  height: 100%;
  background: var(--teal-mid);
}

.spend-bars > li {
  margin-bottom: 0.65rem;
}

/* Wish afford ring */
.wish-afford-wrap {
  display: grid;
  gap: var(--s3);
}

.wish-ring {
  width: 8.5rem;
  height: 8.5rem;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.wish-ring-hole {
  width: 5.8rem;
  height: 5.8rem;
  border-radius: 50%;
  background: var(--ring-hole);
  display: grid;
  place-items: center;
  text-align: center;
}

/* Calendar */
.cal-nav {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.25rem;
  margin: 0.2rem 0 0.15rem;
}

.cal-weekdays span {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.25rem;
  margin: var(--s3) 0;
}

.cal-dow {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  padding: 0.25rem 0;
}

.cal-day {
  appearance: none;
  border: 0;
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
  min-height: 2.6rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  cursor: pointer;
  color: var(--ink);
  position: relative;
}

.cal-day.is-muted {
  opacity: 0.4;
}

.cal-day.is-today {
  outline: 1px solid var(--teal-mid);
}

.cal-day.is-selected {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
}

.cal-day.has-heat::after {
  content: "";
  position: absolute;
  left: 20%;
  right: 20%;
  bottom: 0.25rem;
  height: 3px;
  border-radius: 999px;
  background: var(--heat);
}

/* Meals */
.meal-plan-panel .btn.primary,
.meal-plan-panel #runMealPlan,
#savedMealPanel > .btn.secondary,
#regenMealSchedule {
  width: 100%;
  margin-top: 0.45rem;
}

.meal-filter-pills {
  margin-bottom: var(--s3);
}

.meal-draft-list,
.meal-shopping-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.meal-draft-list li,
.meal-shopping-list li {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--hairline);
}

.ai-notice {
  margin: var(--s2) 0;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 0.85rem;
}

.ai-output,
.report-body {
  white-space: pre-wrap;
  font-size: 0.9rem;
  line-height: 1.5;
}

.night-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
}

/* History search */
.history-search {
  display: grid;
  grid-template-columns: 1fr minmax(8rem, 11rem);
  gap: 0.45rem;
  margin: 0 0 var(--s3);
}

@media (max-width: 430px) {
  .history-search {
    grid-template-columns: 1fr;
  }
}

.history-subhead {
  margin-top: 0;
}

.history-range {
  margin: 0 0 0.15rem;
  font-weight: 700;
  color: var(--ink);
}

.history-meta {
  margin: 0 0 0.65rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.history-meta:empty {
  display: none;
}

.history-month-nav {
  justify-content: space-between;
  margin: 0 0 0.55rem;
}

.history-month-nav strong {
  font-size: 0.95rem;
}

/* FAB */
.fab-expense {
  position: fixed;
  right: max(1rem, var(--safe-right));
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 0.75rem);
  z-index: 45;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  border: 0;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  font-size: 1.6rem;
  font-weight: 700;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.fab-expense:hover {
  background: var(--btn-primary-hover);
}

/* Toasts / pull refresh */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 1rem);
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: min(92vw, 24rem);
  pointer-events: none;
}

.toast {
  pointer-events: none;
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-sm);
  background: var(--teal);
  color: var(--btn-primary-fg);
  font-weight: 650;
  box-shadow: var(--shadow);
  animation: toastIn 0.28s ease;
}

.toast.ok {
  background: var(--ok);
}
.toast.err {
  background: var(--bad);
}

.toast.toast-undo {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
}

.toast-undo-btn {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.22);
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.pull-refresh {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: var(--pull, 0px);
  max-height: 120px;
  pointer-events: none;
  overflow: hidden;
  background: linear-gradient(180deg, var(--teal-soft), transparent);
}

.pull-refresh span {
  margin-bottom: 0.45rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--teal-mid);
}

.pull-refresh.is-loading {
  height: 52px !important;
}

/* Overlay report */
.report-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(10, 20, 16, 0.45);
  display: grid;
  place-items: end center;
  padding: var(--s4);
}

.report-sheet {
  width: min(100%, 40rem);
  max-height: min(88vh, 52rem);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--s4);
}

.report-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s3);
}

.report-toolbar h2 {
  margin: 0;
  font-family: var(--font-display);
  color: var(--teal);
}

/* Settings / misc */
.preview-toggle-row,
.settings-tools {
  margin-top: var(--s3);
}

.ai-status-line {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.ai-status-line.is-online {
  color: var(--ok);
}
.ai-status-line.is-offline {
  color: var(--bad);
}

.period-line {
  font-size: 0.85rem;
  color: var(--muted);
}

.copy-row {
  display: flex;
  gap: 0.4rem;
}

.copy-row input {
  flex: 1;
}

.shortcut-steps,
.category-ref-list,
.home-setup-steps {
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.9rem;
}

code {
  font-size: 0.82em;
  background: var(--surface-soft);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

.live-pulse {
  animation: flashIn 0.9s ease;
}

@keyframes flashIn {
  from {
    opacity: 0.4;
  }
  to {
    opacity: 1;
  }
}

/* Login page */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: max(1rem, var(--safe-top)) max(1rem, var(--safe-right)) max(1rem, var(--safe-bottom))
    max(1rem, var(--safe-left));
  background: var(--paper);
}

.login-page .login-card,
.login-card {
  width: min(100%, 24rem);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s5);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--teal);
}

.login-card .lead {
  margin: 0 0 var(--s4);
  color: var(--muted);
  font-size: 0.9rem;
}

.login-card form {
  display: grid;
  gap: var(--s3);
}

.login-error {
  margin: 0;
  color: var(--bad);
  font-size: 0.85rem;
  font-weight: 650;
}

/* Desktop: nav can sit as bottom still for consistency */
@media (min-width: 720px) {
  .app-main,
  main.shell {
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--s6));
  }
}

@media print {
  .page-nav,
  .fab-expense,
  .toast-host,
  .pull-refresh,
  .app-top,
  .no-print {
    display: none !important;
  }
  .app-main,
  main.shell {
    padding: 0;
    width: 100%;
  }
  .report-overlay {
    position: static;
    background: none;
    padding: 0;
  }
  .report-sheet {
    max-height: none;
    box-shadow: none;
    border: none;
    width: 100%;
    margin: 0;
  }
}

/* Extra layout helpers for money/meals/wishlist */
.check-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.55rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
}
.check-row input {
  width: auto;
  min-height: auto;
  margin-top: 0.2rem;
}
.income-grid,
.wish-settings-grid {
  display: grid;
  gap: var(--s3);
  margin-top: var(--s3);
}
.workday-toggle {
  display: inline-flex;
  margin: 0.2rem 0.35rem 0.2rem 0;
}
.wish-afford-overview {
  display: grid;
  gap: var(--s4);
  align-items: center;
  margin-bottom: var(--s3);
}
@media (min-width: 520px) {
  .wish-afford-overview {
    grid-template-columns: auto 1fr;
  }
}
.wish-afford-ring {
  width: 9rem;
  height: 9rem;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.wish-afford-hole {
  width: 6.2rem;
  height: 6.2rem;
  border-radius: 50%;
  background: var(--ring-hole);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.1rem;
}
.wish-afford-label {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 650;
}
.wish-afford-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}
.wish-afford-legend li {
  display: grid;
  grid-template-columns: 0.7rem 1fr;
  gap: 0.5rem;
  align-items: start;
  border: 0;
  padding: 0;
}
.wish-swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  margin-top: 0.25rem;
  background: var(--muted);
}
.wish-afford-caption {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.wish-afford-caption.muted {
  opacity: 0.85;
}
.goal-meter,
.progress-track {
  height: 0.4rem;
  background: var(--surface-soft);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.35rem;
}
.goal-meter > span,
.progress-fill {
  display: block;
  height: 100%;
  background: var(--teal-mid);
}
.carry-card,
.projection-meta {
  margin-top: var(--s3);
}
.hub-panel {
  display: block;
}
.meals-tab-panel {
  display: block;
}
.history-view {
  display: block;
}
.meal-save-row,
.meal-howto-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: var(--s3);
}
.category-hint {
  color: var(--teal-mid);
}

/* ——— JS-injected / dynamic UI (from inventory) ——— */
.editing {
  background: var(--teal-soft);
  border-radius: var(--radius-sm);
  outline: 1px solid var(--teal-mid);
}

.list-actions,
.wish-actions,
.reminder-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  flex-shrink: 0;
}

.log-fixed,
.log-scheduled,
.log-payday {
  /* inherits entry-list row */
}

.urgency {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  margin-bottom: 0.25rem;
}
.urgency.overdue {
  background: rgba(163, 59, 44, 0.12);
  color: var(--bad);
}
.urgency.today {
  background: rgba(180, 83, 9, 0.12);
  color: var(--warn);
}
.urgency.upcoming {
  background: var(--teal-soft);
  color: var(--teal-mid);
}

.wish-safe .wish-badge {
  background: rgba(47, 122, 74, 0.12);
  color: var(--ok);
}
.wish-unsafe .wish-badge {
  background: rgba(163, 59, 44, 0.12);
  color: var(--bad);
}
.wish-badge {
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  margin-top: 0.25rem;
}
.wish-safe {
  border-left: 3px solid var(--ok);
  padding-left: 0.55rem;
}
.wish-unsafe {
  border-left: 3px solid var(--bad);
  padding-left: 0.55rem;
}

/* Calendar cells (JS uses .cal-cell, not .cal-day) */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.25rem;
  margin: var(--s3) 0;
}
.cal-cell {
  appearance: none;
  border: 0;
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
  min-height: 2.75rem;
  padding: 0.25rem 0.15rem 0.35rem;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.15rem;
}
.cal-cell:disabled {
  opacity: 0.25;
  cursor: default;
}
.cal-cell .day-num {
  font-size: 0.85rem;
  font-weight: 650;
}
.cal-cell .dots {
  display: flex;
  gap: 0.15rem;
  min-height: 0.35rem;
}
.cal-cell .dots i {
  width: 0.28rem;
  height: 0.28rem;
  border-radius: 50%;
  background: var(--muted);
  display: block;
}
.cal-cell .dots i.payday { background: var(--ok); }
.cal-cell .dots i.income { background: var(--ok); }
.cal-cell .dots i.fixed { background: var(--amber); }
.cal-cell .dots i.scheduled { background: var(--teal-mid); }
.cal-cell .dots i.entry { background: var(--ink); }

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  margin: 0 0 var(--s3);
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}
.cal-legend .dot,
.cal-legend i.dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  margin-right: 0.25rem;
  vertical-align: middle;
  background: var(--ink);
}
.cal-legend .dot.payday,
.cal-legend .dot.income { background: var(--ok); }
.cal-legend .dot.fixed { background: var(--amber); }
.cal-legend .dot.scheduled { background: var(--teal-mid); }
.cal-legend .dot.entry { background: var(--ink); }
.cal-legend .heat-swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  margin-right: 0.25rem;
  vertical-align: middle;
  background: color-mix(in srgb, var(--heat) 55%, var(--surface-soft));
}
.cal-cell.today {
  outline: 1px solid var(--teal-mid);
}
.cal-cell.selected {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
}
.cal-cell.selected .dots i {
  background: var(--btn-primary-fg);
  opacity: 0.85;
}
.cal-cell.heat-1 { background: color-mix(in srgb, var(--heat) 12%, var(--surface-soft)); }
.cal-cell.heat-2 { background: color-mix(in srgb, var(--heat) 22%, var(--surface-soft)); }
.cal-cell.heat-3 { background: color-mix(in srgb, var(--heat) 34%, var(--surface-soft)); }
.cal-cell.heat-4 { background: color-mix(in srgb, var(--heat) 48%, var(--surface-soft)); }
.cal-cell.heat-5 { background: color-mix(in srgb, var(--heat) 62%, var(--surface-soft)); }
.cal-cell.selected.heat-1,
.cal-cell.selected.heat-2,
.cal-cell.selected.heat-3,
.cal-cell.selected.heat-4,
.cal-cell.selected.heat-5 {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
}

.type-tag {
  display: inline-flex;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  margin-right: 0.25rem;
}
.type-tag.payday { color: var(--ok); }
.type-tag.fixed { color: var(--amber); }
.type-tag.scheduled { color: var(--teal-mid); }
.type-tag.entry { color: var(--ink); }

/* Meals dynamic lists */
.meal-day-group {
  margin-bottom: var(--s4);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--hairline);
}
.meal-day-group h4 {
  margin: 0 0 var(--s2);
  font-size: 0.9rem;
  color: var(--teal);
}
.meal-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 0.4rem;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--hairline);
}
.meal-item:last-child {
  border-bottom: 0;
}
.meal-item-body strong {
  font-size: 0.92rem;
}
.meal-howto-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--teal-mid);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  min-height: 2rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.meal-howto-btn.alt {
  color: var(--amber);
}

/* Goals / category budgets / leftovers */
.goal-item,
.cat-budget-item,
.leftover-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--hairline);
}
.goal-item-head,
.cat-budget-item-head,
.leftover-item-head {
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
  align-items: flex-start;
}
.cat-budget-progress {
  height: 0.4rem;
  background: var(--surface-soft);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.4rem 0;
}
.cat-budget-progress > i {
  display: block;
  height: 100%;
  background: var(--teal-mid);
}
.cat-budget-progress.warn > i { background: var(--warn); }
.cat-budget-progress.bad > i { background: var(--bad); }

.leftover-item.is-soon {
  border-left: 3px solid var(--warn);
  padding-left: 0.55rem;
}
.leftover-item.is-expired {
  border-left: 3px solid var(--bad);
  padding-left: 0.55rem;
  opacity: 0.85;
}

.report-kv {
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 0.9rem;
}
.report-kv span {
  color: var(--muted);
}
.report-kv strong {
  color: var(--ink);
}

.is-loading {
  opacity: 0.7;
}
.muted {
  color: var(--muted);
}

/* ——— Redesigned Home ——— */
.home-balance {
  margin: 0 0 var(--s3);
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.home-balance-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s3);
}
.home-balance-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.home-balance-value {
  margin: 0.05rem 0 0;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.05;
  color: var(--teal);
  letter-spacing: -0.03em;
}
.home-balance-meta {
  margin: 0.3rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.45rem;
  font-size: 0.86rem;
  color: var(--muted);
  font-weight: 500;
}
.home-balance-meta strong {
  color: var(--ink);
  font-weight: 700;
}
.home-balance-sep {
  opacity: 0.5;
}
.home-balance-meter {
  margin-top: 0.45rem;
}
.home-balance {
  padding: 0.75rem 0.85rem;
}

.home-log .expense-head {
  margin-bottom: 0.35rem;
}
.home-log.panel {
  padding: 0.75rem 0.85rem;
}
.entry-kind-switch {
  margin: 0 0 0.45rem;
}
.log-compact {
  display: grid;
  grid-template-columns: 1fr 6.5rem;
  gap: 0.4rem;
}
.log-compact .home-log-note {
  grid-column: 1;
  margin: 0;
  min-height: 2.35rem;
  font-size: 0.95rem;
}
.log-compact .log-amount {
  grid-column: 2;
  min-height: 2.35rem;
}
.log-compact input,
.log-compact select,
.log-compact .expense-amount-field {
  min-height: 2.35rem;
}
.log-compact #entryDate,
.log-compact #entryTime,
.log-compact #entryCategory {
  grid-column: auto;
}
.log-compact #entryCategory {
  grid-column: 1 / -1;
}
.habit-label {
  margin: 0.55rem 0 0.15rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
}
.home-log .habit-chips {
  margin-top: 0.15rem;
}
.home-log .expense-add {
  width: 100%;
  margin-top: 0.45rem;
  min-height: 2.35rem;
  font-size: 0.95rem;
  padding: 0.4rem 0.8rem;
}
.home-recent.panel {
  padding: 0.7rem 0.85rem 0.35rem;
}
.home-recent .section-head {
  margin-bottom: 0.15rem;
}
.home-recent-list > li {
  padding: 0.4rem 0;
}
.home-recent-list .entry-actions {
  align-items: center;
}
.home-log-sheet {
  grid-template-columns: 1fr var(--touch);
}
.home-log-more {
  margin-top: 0.45rem;
  border-top: 1px solid var(--hairline);
  padding-top: 0.15rem;
}
.home-log-more > summary {
  cursor: pointer;
  list-style: none;
  min-height: 2rem;
  display: flex;
  align-items: center;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--teal-mid);
}
.home-log-more > summary::-webkit-details-marker {
  display: none;
}
.home-log-more > summary::before {
  content: "▸";
  margin-right: 0.35rem;
}
.home-log-more[open] > summary::before {
  content: "▾";
}
.home-log-more .expense-more {
  border-top: 0;
  margin-top: var(--s2);
  padding-top: 0;
}
.home-log-more .recurring-inline {
  margin-top: var(--s4);
  padding-top: var(--s3);
  border-top: 1px solid var(--hairline);
}

.home-funds-details {
  padding: 0;
  overflow: hidden;
}
.home-funds-details > summary.home-funds-summary-row {
  cursor: pointer;
  list-style: none;
  padding: var(--s4);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--teal-mid);
}
.home-funds-details > summary::-webkit-details-marker {
  display: none;
}
.home-funds-details > summary::before {
  content: "▸ ";
}
.home-funds-details[open] > summary::before {
  content: "▾ ";
}
.home-funds-details > :not(summary) {
  padding-left: var(--s4);
  padding-right: var(--s4);
}
.home-funds-details > :last-child {
  padding-bottom: var(--s4);
}
.home-funds-details .period-rail {
  margin-top: 0;
}

/* ========== UI polish pack ========== */
body {
  font-size: var(--text-body);
}

.app-main,
main.shell {
  display: block;
  padding-top: var(--s3);
}

.page.active {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
  animation: pageIn var(--dur) var(--ease);
}

@keyframes pageIn {
  from { opacity: 0.01; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.app-top-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.block,
.panel,
.home-balance {
  padding: var(--block-pad);
  margin: 0;
  transition: border-color var(--dur) var(--ease);
}

.hub-panel,
.meals-tab-panel {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  box-shadow: none;
}

.hub-shell,
.meals-hub {
  margin: 0;
  padding: 0 0 var(--s1);
}

.hub-shell h2,
.meals-hub h2,
.history-panel > .section-head h2,
.block > h2,
.panel > h2,
.section-head h2,
.expense-head h2 {
  font-family: var(--font-body);
  font-size: var(--text-title);
  font-weight: 700;
  letter-spacing: -0.015em;
}

.section-head h3,
.subhead {
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
}

.panel-lead,
.expense-lead,
.meta {
  font-size: var(--text-meta);
  line-height: 1.4;
}

/* Segmented control — teal pill active */
.seg-control,
.hub-tabs,
.meals-hub-tabs,
.history-mode,
.event-filters {
  gap: 0.2rem;
  padding: 0.25rem;
  background: var(--wash);
  border-color: transparent;
}

.seg-btn,
.hub-tab,
.meals-hub-tab,
.history-mode-btn,
.event-filter {
  flex: 1 1 0;
  min-width: 0;
  min-height: 2.35rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 9px;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.seg-btn.active,
.hub-tab.active,
.meals-hub-tab.active,
.history-mode-btn.active,
.event-filter.active {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  box-shadow: none;
}

.entry-kind-switch {
  margin: 0 0 var(--s3);
}

.home-log.is-income .expense-amount-field {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--control-border));
}
.home-log.is-income .expense-add {
  background: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 70%, #000);
}
.chip.income,
.entry-list > li.is-income .chip.amount-chip {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 14%, transparent);
}
.amount-pos {
  color: var(--ok);
  font-weight: 700;
}

/* Buttons */
.btn {
  min-height: var(--touch);
  border-radius: var(--radius-sm);
  transition: background var(--dur) var(--ease), transform 80ms var(--ease), opacity var(--dur) var(--ease);
}
.btn:active {
  transform: scale(0.98);
}
.btn.secondary {
  background: transparent;
  border-color: var(--line-strong);
}
.btn.secondary:hover {
  background: var(--teal-soft);
}

@media (max-width: 560px) {
  .meal-plan-panel .btn.primary,
  .meal-plan-panel #runMealPlan,
  #savedMealPanel > .btn.secondary,
  #regenMealSchedule {
    width: 100%;
  }
  .home-log-sheet {
    grid-template-columns: 1fr auto;
  }
  .home-log .expense-add {
    width: 100%;
    min-width: 0;
    min-height: 2.35rem;
    padding: 0.4rem 0.8rem;
    font-size: 0.95rem;
  }
  .log-compact {
    grid-template-columns: 1fr 5.5rem;
  }
}

/* Lists — polished rows */
.entry-list > li,
.payday-list > li,
.soft-list > li,
.reminder-list > li,
.wish-list > li,
.goal-list > li,
.leftover-list > li,
.pantry-list > li,
.night-expense-list > li,
.cal-event-list > li {
  align-items: center;
  padding: 0.85rem 0;
  gap: var(--s3);
}

.entry-list > li > div:first-child,
.payday-list > li > div:first-child,
.wish-list > li > div:first-child {
  min-width: 0;
  flex: 1;
}

.entry-list > li > div:first-child > div:first-child,
.payday-list > li > div:first-child > div:first-child,
.wish-list > li > div:first-child > div:first-child,
.pantry-list > li > div:first-child > div:first-child {
  font-weight: 650;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.chip {
  margin-top: 0.3rem;
  background: var(--wash);
  border-color: transparent;
  color: var(--muted);
  font-size: var(--text-tiny);
  font-weight: 700;
}

.meta {
  margin-top: 0.15rem;
}

/* Empty states */
.empty,
li.empty,
p.empty {
  display: flex !important;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
  margin: 0;
  padding: var(--s4) !important;
  border: 1px dashed var(--line) !important;
  border-radius: var(--radius-sm);
  background: var(--wash);
  color: var(--muted);
  font-size: var(--text-meta);
  font-weight: 550;
  line-height: 1.45;
}
.empty .link-btn,
li.empty .link-btn,
.empty .btn {
  margin-top: 0.15rem;
}

/* Nav polish */
.page-nav {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.page-nav-btn {
  transition: color var(--dur) var(--ease);
  position: relative;
}
.page-nav-btn.active::after {
  content: "";
  position: absolute;
  top: 0.2rem;
  left: 50%;
  width: 1rem;
  height: 2px;
  border-radius: 999px;
  background: var(--teal);
  transform: translateX(-50%);
}

/* Forms */
input,
select,
textarea,
.compact-note,
.expense-amount-field {
  border-radius: var(--radius-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.home-balance-value {
  font-size: 1.85rem;
}
.home-balance {
  margin: 0;
}

.home-shortcuts {
  margin: 0;
}
.home-shortcut {
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.home-shortcut:active {
  background: var(--teal-soft);
}

.toast {
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.toast.ok {
  background: var(--ok);
  color: var(--btn-primary-fg);
}

.fab-expense {
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.fab-expense:active {
  transform: scale(0.96);
}

.history-search {
  position: sticky;
  top: calc(var(--top-h) + var(--safe-top));
  z-index: 5;
  background: var(--paper);
  padding: 0.35rem 0 0.55rem;
  margin-bottom: var(--s2);
}

.funds-legend li[data-key="extra"] .funds-swatch {
  background: var(--ok);
}

.cal-cell .dots i.income,
.dot.income {
  background: var(--ok);
}
.type-tag.income {
  color: var(--ok);
}

.page.active {
  gap: 0.5rem;
}
.app-main,
main.shell {
  padding-top: 0.5rem;
}
.home-recent .entry-list > li {
  padding: 0.4rem 0;
}
.seg-control.entry-kind-switch {
  margin: 0 0 0.4rem;
}
.seg-control.entry-kind-switch .seg-btn {
  min-height: 2.15rem;
}

#page-history .event-filter {
  font-size: 0.76rem;
  min-height: 2.05rem;
  padding: 0.32rem 0.4rem;
}

#moneyHubTabs .hub-tab {
  flex: 1 1 calc(33.33% - 0.3rem);
  font-size: 0.74rem;
  min-height: 2.05rem;
  padding: 0.32rem 0.28rem;
}

.money-fold {
  margin-top: 0.7rem;
  border-top: 1px solid var(--line);
  padding-top: 0.55rem;
}

.money-fold > summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 0.86rem;
  color: var(--ink);
  list-style: none;
}

.money-fold > summary::-webkit-details-marker {
  display: none;
}

.money-fold > summary::before {
  content: "+ ";
  color: var(--muted);
  font-weight: 700;
}

.money-fold[open] > summary {
  margin-bottom: 0.6rem;
}

.money-fold[open] > summary::before {
  content: "– ";
}

.funds > div.is-left strong {
  color: var(--ink);
}

@media (min-width: 520px) {
  #page-money .funds {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .page.active,
  .btn,
  .seg-btn,
  .fab-expense,
  .toast {
    animation: none !important;
    transition: none !important;
  }
}
