:root {
  color-scheme: light;
  --bg: #f4f0e6;
  --card: #ebe5d3;
  --card-border: #d8d2c2;
  --rule: #d8d2c2;
  --ink: #2a2620;
  --muted: #7a7468;
  --sage: #5b6e4d;
  --blush: #c6604a;
  --brass: #b8954a;

  --serif: "Instrument Serif", "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  font-family: var(--sans);
  font-feature-settings: "tnum" 1;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.shell {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(100vw, 430px);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

/* ─────────────── Topbar (header) ─────────────── */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: calc(38px + env(safe-area-inset-top)) 24px 0;
}

.topbar > div { display: grid; gap: 4px; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow {
  margin: 0;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1;
}

.topbar h1,
.section-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 38px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--ink);
}

/* ─────────────── Content ─────────────── */
.content {
  min-width: 0;
  overflow-y: auto;
  padding: 22px 24px 28px;
  scrollbar-width: none;
}

.content::-webkit-scrollbar { display: none; }

.view { display: none; }
.view.active { display: block; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.section-head > div { display: grid; gap: 4px; }

/* ─────────────── Period scrubber ─────────────── */
.period-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 4px 0 0;
  margin: 18px 0 12px;
}

.period-row strong {
  font-family: var(--serif);
  font-style: italic;
  font-size: 20px;
  font-weight: 400;
  color: var(--ink);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1;
}

.icon-btn:hover { background: rgba(42, 38, 32, 0.05); }

/* ─────────────── Hero (balance) ─────────────── */
.balance-hero {
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 22px 0 4px;
  text-align: center;
}

.hero-label { /* AVAILABLE BALANCE caption */ }

#runningBalance {
  font-family: var(--serif);
  font-size: 110px;
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: -0.04em;
  color: var(--ink);
  white-space: nowrap;
  font-feature-settings: "tnum" 1;
}

#runningBalance .cents,
#runningBalance .sym {
  font-size: 52px;
  color: var(--muted);
}

#runningBalance.balance-negative { color: var(--blush); }

#dailyBudgetLabel {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

#dailyBudgetLabel .per-day {
  color: var(--sage);
  font-weight: 600;
  font-feature-settings: "tnum" 1;
}

/* ─────────────── Rule ─────────────── */
.hairline {
  height: 1px;
  background: var(--rule);
  margin: 32px 0 22px;
}

/* ─────────────── Forecast row ─────────────── */
.forecast-section { display: grid; gap: 14px; }

.forecast {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.forecast-day {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 4px;
}

.bars {
  display: flex;
  align-items: end;
  gap: 3px;
  height: 24px;
}

.bars span {
  display: block;
  width: 3px;
  border-radius: 1px;
  background: var(--sage);
}

.forecast-day strong {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  font-weight: 400;
  color: var(--ink);
  line-height: 1;
}

.forecast-day span:last-child {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  font-feature-settings: "tnum" 1;
}

.forecast-day.negative .bars span { background: var(--blush); }
.forecast-day.negative span:last-child { color: var(--blush); }

/* ─────────────── Quick actions (+/-) ─────────────── */
.quick-actions {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  margin: 28px 0 4px;
}

.circle-action {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 999px;
  border: 1.5px solid currentColor;
  background: transparent;
  font-family: var(--serif);
  font-size: 24px;
  line-height: 1;
}

.circle-action.income { color: var(--sage); }
.circle-action.expense { color: var(--blush); }

.quick-actions-mid {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  color: var(--muted);
}

/* ─────────────── Summary cards (Repeat) ─────────────── */
.summary-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 22px;
}

.metric {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card);
  text-align: left;
}

.metric span {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.metric strong {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 400;
  font-feature-settings: "tnum" 1;
}

.metric strong::after {
  content: " / day";
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--muted);
}

.metric.income strong { color: var(--sage); }
.metric.expense strong { color: var(--blush); }
.metric.savings strong { color: var(--ink); }

/* ─────────────── Pill buttons ─────────────── */
.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn,
.link-btn {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  line-height: 1.2;
}

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

.danger-btn {
  border-color: var(--blush);
  color: var(--blush);
  background: transparent;
}

.primary-btn:hover { opacity: 0.92; }
.secondary-btn:hover, .ghost-btn:hover, .danger-btn:hover {
  background: rgba(42, 38, 32, 0.05);
}

.compact { padding: 8px 16px; }
.mini { padding: 6px 12px; font-size: 11px; }
.full { width: 100%; padding: 12px 16px; }

/* ─────────────── Tabs (Repeat filter / auth toggle) ─────────────── */
.tabs,
.auth-toggle {
  display: flex;
  gap: 18px;
  margin: 14px 0 16px;
  padding: 0 0 8px;
  border-bottom: 1px solid var(--rule);
}

.tab {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  font-weight: 400;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 0 0 6px;
  border-bottom: 1.5px solid transparent;
  margin-bottom: -9px;
}

.tab.active {
  color: var(--ink);
  border-color: var(--ink);
}

/* ─────────────── Lists / rows ─────────────── */
.list { display: grid; gap: 8px; }

.row-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  text-align: left;
  font-family: var(--sans);
}

.row-card .row-main { display: grid; gap: 4px; min-width: 0; }

.row-card b {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.row-card b::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sage);
  flex-shrink: 0;
}

.row-card.expense b::before { background: var(--blush); }

.row-card small {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
}

.row-card strong {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
  text-align: right;
  white-space: nowrap;
  font-feature-settings: "tnum" 1;
}

.row-card.income strong { color: var(--sage); }
.row-card.expense strong { color: var(--blush); }

.row-card strong small {
  display: block;
  margin-top: 2px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

/* ─────────────── Empty states ─────────────── */
.empty {
  padding: 28px 18px;
  border: 1px dashed var(--card-border);
  border-radius: 6px;
  background: rgba(235, 229, 211, 0.4);
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  text-align: center;
  line-height: 1.4;
}

.empty-rich {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 36px 24px;
  border: 1px dashed var(--card-border);
  border-radius: 6px;
  background: rgba(235, 229, 211, 0.4);
  text-align: center;
}

.empty-rich .glyph {
  font-family: var(--serif);
  font-style: italic;
  font-size: 64px;
  line-height: 1;
  color: var(--card-border);
}

.empty-rich .empty-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
  color: var(--ink);
}

.empty-rich .empty-body {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  max-width: 240px;
  line-height: 1.55;
}

/* ─────────────── Quick categories (Entries) ─────────────── */
.quick-categories {
  margin-top: 28px;
  display: grid;
  gap: 12px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: transparent;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink);
}

.chip::before {
  content: "+";
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--muted);
}

.chip:hover { background: rgba(42, 38, 32, 0.05); }

/* ─────────────── Panels / cards in Analysis & Settings ─────────────── */
.panel {
  padding: 16px 18px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card);
}

.panel h3 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  color: var(--ink);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-head h3 { margin: 0; }

.panel p {
  margin: 0 0 12px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

.danger-panel {
  border-color: rgba(198, 96, 74, 0.33);
}

.danger-panel h3 { color: var(--blush); }

/* ─────────────── Analysis: stat grid + bars ─────────────── */
.analysis-stack { display: grid; gap: 12px; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 14px;
}

.stat { display: grid; gap: 6px; }

.stat span {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat strong {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
  font-feature-settings: "tnum" 1;
}

.stat.income strong { color: var(--sage); }
.stat.income span { color: var(--sage); }
.stat.spend strong { color: var(--blush); }
.stat.spend span { color: var(--blush); }

.cat-breakdown { display: grid; gap: 10px; }

.cat-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 2fr) auto;
  align-items: center;
  gap: 12px;
  font-family: var(--sans);
  font-size: 13px;
}

.cat-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cat-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(42, 38, 32, 0.08);
  overflow: hidden;
}

.cat-bar-fill {
  height: 100%;
  background: var(--blush);
}

.cat-row strong {
  font-family: var(--serif);
  font-size: 16px;
  font-feature-settings: "tnum" 1;
  color: var(--ink);
}

.trend-chart {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  height: 90px;
  margin: 10px 0 12px;
}

.trend-col {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 6px;
  align-items: end;
  justify-items: center;
}

.trend-bars {
  display: flex;
  gap: 3px;
  align-items: end;
  height: 100%;
}

.trend-bars span {
  display: block;
  width: 8px;
  border-radius: 1px;
}

.t-income { background: var(--sage); }
.t-spend { background: var(--blush); }

.trend-col.past .trend-bars span { opacity: 0.5; }

.trend-label {
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.trend-quote {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

/* ─────────────── Settings ─────────────── */
.settings-stack { display: grid; gap: 12px; }

.slider-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.slider-row span:first-child {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.slider-row .slider-value {
  font-family: var(--serif);
  font-style: italic;
  font-size: 20px;
  color: var(--ink);
}

.field {
  display: grid;
  gap: 8px;
}

.field-group {
  padding: 18px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card);
}

.field-body {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
  margin-top: 8px;
}

.field input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--card-border);
  border-radius: 999px;
  outline: none;
  padding: 0;
  margin: 0;
}

.field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid var(--ink);
  cursor: pointer;
}

.field input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid var(--ink);
  cursor: pointer;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="date"],
.field select {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
}

.field input.invalid { border-color: var(--blush); }

.field span {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-error {
  min-height: 14px;
  font-family: var(--sans);
  font-size: 11px;
  color: var(--blush);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.button-row.right { justify-content: flex-end; }

.status-text {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
  line-height: 1.5;
}

.file-btn {
  display: inline-grid;
  place-items: center;
  position: relative;
}

.file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.version-footer {
  text-align: center;
  margin: 24px 0 8px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--muted);
}

/* ─────────────── Auth (account view) ─────────────── */
.auth-card {
  padding: 22px 20px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card);
}

.auth-card h2 {
  margin: 4px 0 6px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 28px;
  font-weight: 400;
  color: var(--ink);
}

.auth-copy {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.5;
}

.auth-form { display: grid; gap: 12px; }

/* ─────────────── Bottom nav rail ─────────────── */
.rail {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 12px 16px calc(28px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
  background: rgba(244, 240, 230, 0.92);
  backdrop-filter: blur(10px);
}

.nav-item {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 6px 0;
  background: transparent;
  border: 0;
  color: var(--muted);
}

.nav-icon {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  line-height: 1;
  padding-bottom: 1px;
  border-bottom: 1px solid transparent;
}

.nav-label {
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.nav-item.active {
  color: var(--ink);
}

.nav-item.active .nav-icon {
  border-bottom-color: var(--ink);
}

.nav-item.active .nav-label {
  font-weight: 700;
}

/* ─────────────── Dialogs ─────────────── */
dialog {
  width: min(420px, 100vw);
  max-height: min(86vh, 760px);
  margin: auto auto 0;
  padding: 0;
  border: 1px solid var(--card-border);
  border-radius: 12px 12px 0 0;
  background: var(--bg);
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(42, 38, 32, 0.45);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}

.dialog-card h2 {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 28px;
  color: var(--ink);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 4px 0;
}

.cat-tile {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 12px 6px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card);
}

.cat-tile:hover { background: rgba(42, 38, 32, 0.05); }

.cat-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg);
  font-size: 1.4rem;
}

.cat-name {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  color: var(--ink);
}

/* ─────────────── Landing ─────────────── */
.landing {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px 20px;
  background: var(--bg);
  color: var(--ink);
}

.landing-inner {
  display: grid;
  gap: 32px;
  width: min(100%, 940px);
}

.landing-hero h1 {
  margin: 6px 0 14px;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(2rem, 4vw, 2.8rem);
  font-weight: 400;
  line-height: 1.1;
  color: var(--ink);
}

.landing-copy {
  margin: 0 0 18px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--muted);
  line-height: 1.55;
}

.landing-points {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  line-height: 1.55;
}

.landing-points li {
  padding-left: 18px;
  position: relative;
}

.landing-points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sage);
}

.landing-points b { color: var(--ink); }

@media (min-width: 820px) {
  .landing-inner {
    grid-template-columns: 1.1fr 0.9fr;
    align-items: center;
    gap: 56px;
  }
}

@media (min-width: 520px) {
  .shell {
    height: min(932px, calc(100vh - 32px));
    min-height: 0;
    border: 1px solid var(--card-border);
    border-radius: 22px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), 0 18px 50px rgba(0, 0, 0, 0.04);
  }

  dialog {
    border-radius: 12px;
  }
}

@media (max-width: 370px) {
  #runningBalance { font-size: 84px; }
  #runningBalance .cents, #runningBalance .sym { font-size: 40px; }
  .topbar h1, .section-head h2 { font-size: 30px; }
}
