/* Calm slate and blue. Green = good, red = needs attention, always with a symbol. */
:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --on-accent: #ffffff;
  --good: #15803d;
  --good-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --auto: #94a3b8;
  --radius: 12px;
  --tap: 44px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #131c2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --line: #23314a;
    --accent: #60a5fa;
    --accent-soft: #1e3a5f;
    --on-accent: #0b1220;
    --good: #4ade80;
    --good-soft: #14321f;
    --bad: #f87171;
    --bad-soft: #3b1515;
    --auto: #64748b;
  }
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 1.1rem; margin: 0; }
.chip {
  border: 0; border-radius: 999px; padding: 6px 12px; min-height: 32px;
  background: var(--accent-soft); color: var(--accent); font-size: 0.85rem; font-weight: 600;
}

main { max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; outline: none; }
.loading, .notice { color: var(--muted); text-align: center; padding: 32px 0; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 2;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; min-height: 56px; border: 0; background: none; color: var(--muted); font-weight: 600;
}
.tabs button[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; }
.card h2 { font-size: 1rem; margin: 0 0 4px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h2 .count { font-size: 0.8rem; font-weight: 600; }
.card p.help { margin: 0 0 8px; color: var(--muted); font-size: 0.875rem; }

/* Month switcher */
.switcher { display: flex; gap: 8px; align-items: center; }
.switcher select { flex: 1; min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: var(--card); font-weight: 600; }
.icon-btn { min-width: var(--tap); min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 1.2rem; }
.icon-btn:disabled { opacity: 0.35; }

.status { margin: 10px 0 0; padding: 8px 12px; border-radius: 10px; font-weight: 600; font-size: 0.95rem; }
.tone-good { background: var(--good-soft); color: var(--good); }
.tone-bad { background: var(--bad-soft); color: var(--bad); }
.tone-info { background: var(--accent-soft); color: var(--accent); }
.tone-muted { background: var(--line); color: var(--muted); }
.count.tone-bad, .count.tone-good { background: none; }

/* Fields */
.field { display: grid; grid-template-columns: 1fr minmax(120px, 44%); gap: 4px 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.field:first-of-type { border-top: 0; }
.field label { font-weight: 500; }
.field .hint { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.field .req { color: var(--bad); font-size: 0.75rem; font-weight: 700; margin-left: 4px; }
.input-wrap { position: relative; display: flex; }
.input-wrap input {
  width: 100%; min-height: var(--tap); padding: 0 34px 0 10px; text-align: right;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-variant-numeric: tabular-nums;
}
.input-wrap input::placeholder { color: var(--auto); font-style: italic; }
.input-wrap input:focus { outline: 2px solid var(--accent); outline-offset: 0; background: var(--card); }
.input-wrap input[aria-invalid="true"] { border-color: var(--bad); }
.input-wrap input:read-only { color: var(--muted); }
.clear { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border: 0; background: none; color: var(--muted); font-size: 1rem; }
.field .error { grid-column: 1 / -1; color: var(--bad); font-size: 0.85rem; }
.sub { padding-left: 14px; }

textarea { width: 100%; min-height: 72px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }

/* Results */
.results { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; }
.results dt { color: var(--muted); }
.results dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Buttons */
.btn { min-height: var(--tap); padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--bad); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.file-label { display: inline-flex; align-items: center; }
.file-label input { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* Giving */
.form-grid { display: grid; gap: 10px; }
.form-grid label { display: grid; gap: 4px; font-weight: 500; font-size: 0.9rem; }
.form-grid input, .form-grid select { min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: var(--bg); }
.gift-month { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.85rem; font-weight: 600; margin: 14px 2px 4px; }
.gift { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin: 4px 0; }
.gift small { display: block; color: var(--muted); }
.gift .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* Dashboard */
.as-of { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.as-of p { margin: 0; font-weight: 600; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 2px; min-width: 0; }
.tile-label { color: var(--muted); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.tile-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-line { font-size: 0.8rem; color: var(--muted); }
.tone-text-good { color: var(--good); }
.tone-text-bad { color: var(--bad); }
.tone-text-info { color: var(--accent); }
.tone-text-muted { color: var(--muted); }
.big { font-size: 1.6rem; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.flow { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.flow th, .flow td { padding: 6px 0 6px 6px; text-align: right; border-top: 1px solid var(--line); }
.flow thead th { border-top: 0; color: var(--muted); font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.flow tbody th { text-align: left; font-weight: 500; padding-left: 0; }
.flow .sub-row th { padding-left: 12px; color: var(--muted); font-weight: 400; }
.flow td { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.bar { display: block; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 6px 0; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar-fill.good { background: var(--good); }
.bar-fill.bad { background: var(--bad); }
.goal { padding: 6px 0; border-top: 1px solid var(--line); }
.goal:first-of-type { border-top: 0; }
.goal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.goal-short { font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.goal-detail { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.goal-name { font-weight: 600; }
.goal .help { margin: 0; }
.results dt .hint { display: block; font-size: 0.8rem; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.checks li { padding: 8px 10px; border-radius: 10px; font-size: 0.9rem; }
.results.accounts dt { color: var(--text); }
.form-grid label.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.form-grid label.check input { width: 22px; height: 22px; min-height: 0; }
.results dt.sub-dt { padding-left: 12px; }

/* Banners: update ready, export reminder */
.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: var(--radius); margin: 12px 0; font-weight: 600; font-size: 0.95rem; }
.banner .btn { flex: none; }

/* The ± button on fields that can be negative */
.input-wrap.has-sign input { padding-left: 40px; }
.sign { position: absolute; left: 2px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-size: 1.1rem; font-weight: 700; }

/* Phone turned sideways (short screen): let the top bar scroll away and slim the tabs. */
@media (max-height: 480px) {
  .top { position: static; }
  .tabs button { min-height: 44px; }
  body { padding-bottom: calc(52px + env(safe-area-inset-bottom)); }
}
.link-btn { min-height: var(--tap); margin: -8px -8px -8px 0; padding: 0 8px; border: 0; background: none; color: var(--accent); font-weight: 600; flex: none; }

/* Top bar: the Workbook chip */
.top h1 { margin-right: auto; }
.chip.quiet { background: var(--good-soft); color: var(--good); }
.chip[aria-current="page"] { outline: 2px solid var(--accent); }

/* Dashboard: one screen */
.dashboard .card { margin: 6px 0; padding: 10px 12px; }
.dashboard .as-of { padding: 6px 8px 6px 12px; }
.dashboard .as-of .btn { min-height: 38px; padding: 0 12px; }
.check-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; border-radius: 10px; padding: 6px 10px; margin: 6px 0; font-size: 0.85rem; line-height: 1.3; }
.more-count { white-space: nowrap; font-weight: 600; }
.dashboard .tiles { gap: 6px; margin: 6px 0; }
.dashboard .tile { padding: 7px 10px; gap: 0; }
button.tile { text-align: left; font: inherit; color: inherit; }
.dashboard .tile-value { font-size: 1.2rem; }
.dashboard .tile-line { font-size: 0.75rem; line-height: 1.3; }
.go { color: var(--muted); font-weight: 600; }
.line-card { display: block; width: 100%; text-align: left; font: inherit; color: inherit; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.line-title { font-weight: 700; }
.row-value { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-sub { font-size: 0.85rem; color: var(--muted); font-weight: 600; text-align: right; }
.line-sub { display: block; font-size: 0.8rem; line-height: 1.3; color: var(--muted); }
.line-card .bar, .goal .bar { height: 6px; margin: 4px 0; }
.results.compact { gap: 2px 12px; font-size: 0.9rem; }
.dashboard #accounts h2 { margin-bottom: 2px; }
.results.compact dt .hint { display: inline; margin-left: 6px; font-size: 0.75rem; color: var(--muted); }
.goal-detail p.help { margin: 0; font-size: 0.8rem; }

/* Ledger */
.next-fill { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.next-fill > div { display: grid; }
.sub-head { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; }
.sub-head h2 { font-size: 1.05rem; margin: 0; }
.back-btn { border: 0; background: none; color: var(--accent); font-weight: 600; min-height: var(--tap); padding: 0 8px 0 0; }
.month-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: left; min-height: var(--tap); border: 1px solid var(--line); background: var(--card); border-radius: 10px; margin: 6px 0; padding: 8px 12px; }
.month-row small { display: block; color: var(--muted); font-size: 0.85rem; }
.month-name { font-weight: 600; }
.month-row .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Adding, renaming and closing accounts, investments and income sources */
.field-name { display: flex; align-items: flex-start; gap: 2px; min-width: 0; }
.field-name label { flex: 1; min-width: 0; }
.manage { flex: none; border: 0; background: none; color: var(--muted); font-size: 1.1rem; line-height: 1; min-width: 32px; min-height: 32px; margin: -4px 0; border-radius: 8px; }
.manage-panel { grid-column: 1 / -1; padding: 6px 0 2px; }
.manage-panel .btn-row { margin-top: 4px; }
.manage-panel .rename input { width: 100%; min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: var(--bg); }
.setup { padding-top: 8px; border-top: 1px solid var(--line); margin-top: 4px; }
.add-btn { margin: 0; padding: 0; }
.setup-form { padding-top: 4px; }
.setup-form .form-grid { margin-bottom: 6px; }
.setup-full { margin: 8px 0 0; }
