/* ─── Type ──────────────────────────────────────────────────────
   Geist (SIL OFL 1.1, fonts/Geist-OFL.txt), self-hosted: the CSP allows
   same-origin fonts only, and it keeps the app readable offline. */
@font-face {
  font-family: 'Geist';
  src: url('../fonts/Geist-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ─── Design Tokens ─────────────────────────────────────────────
   One layout, two themes: Midnight (dark, the default) and Paper
   (body.light). Colour is only for meaning: green = up / saved,
   red = owed / over, gold = warning; everything else is text colour
   plus one accent. */
:root {
  color-scheme: dark;
  --bg:     #070B14;
  --surf:   #0E1522;
  --surf2:  #131C2C;
  --surf3:  #1A2436;
  --text:   #F3F5FA;
  --muted:  #8C96AA;
  --faint:  #7A8599;
  --border: #172033;
  --brig:   #26324A;
  --hair:   #1A2233;

  --accent:      #4C86FF;
  --on-accent:   #070B14;
  --accent-soft: rgba(76,134,255,.14);
  --accent-text: #8DB2FF;

  --green:  #3EE0A1;
  --green-soft: rgba(62,224,161,.12);
  --red:    #FF8574;
  --red-soft: rgba(255,133,116,.12);
  --blue:   #8DB2FF;
  --orange: #FFA25C;
  --gold:   #FFC44D;
  --gold-soft: rgba(255,196,77,.12);
  --purple: #B9A2FF;
  --pink:   #F59AC6;
  --teal:   #5EE0D0;

  --nav-h: 60px;
  --tabbar-h: 62px;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: none;
  --shadow-lg: 0 16px 40px rgba(0,0,0,.45);
  --nav-bg: rgba(7,11,20,.92);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.light {
  color-scheme: light;
  --bg:     #F4F3EF;
  --surf:   #FFFFFF;
  --surf2:  #F7F6F2;
  --surf3:  #EFEDE7;
  --text:   #15171C;
  --muted:  #62676F;
  --faint:  #6B7078;
  --border: #E8E5DE;
  --brig:   #D9D5CC;
  --hair:   #F0EDE7;

  --accent:      #1D5FD1;
  --on-accent:   #FFFFFF;
  --accent-soft: #E8F0FE;
  --accent-text: #1D5FD1;

  --green:  #0B7A55;
  --green-soft: #E3F3EB;
  --red:    #B4410C;
  --red-soft: #FDEEE4;
  --blue:   #1D5FD1;
  --orange: #B45309;
  --gold:   #8A5A00;
  --gold-soft: #FDF3DC;
  --purple: #6D3FC0;
  --pink:   #B8306F;
  --teal:   #0E7C7B;

  --shadow: 0 1px 2px rgba(20,20,15,.04), 0 8px 24px rgba(20,20,15,.05);
  --shadow-lg: 0 16px 40px rgba(20,20,15,.14);
  --nav-bg: rgba(255,255,255,.94);
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
html, body { max-width: 100%; overflow-x: clip; overscroll-behavior-x: none; }
body {
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent-text); text-decoration: none; }
button { font-family: inherit; cursor: pointer; color: inherit; }
input, select, textarea { font-family: inherit; }

/* ─── Skip Link ──────────────────────────────────────────────── */
.skip-link {
  position: absolute; top: -99px; left: 8px; z-index: 9999;
  padding: 8px 14px; background: var(--accent); color: var(--on-accent);
  border-radius: var(--radius-sm); font-weight: 600; font-size: 13px;
}
.skip-link:focus { top: calc(8px + var(--safe-top)); }

/* ─── Nav ──────────────────────────────────────────────────────
   Desktop: one calm top bar (brand · tabs · theme). Phones: the brand
   bar stays on top and the tabs become a bottom tab bar (see the
   phone block at the end of this file). */
#nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: calc(var(--nav-h) + var(--safe-top));
  padding: var(--safe-top) max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 18px;
}

.nav-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px; letter-spacing: -.2px;
  white-space: nowrap; flex-shrink: 0;
}
/* The brand mark: an accent tile with a rising line (was a pulsing dot). */
.dot {
  width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23070B14' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 16l5-5 4 4 7-8'/%3E%3C/svg%3E") center / 15px no-repeat;
}
body.light .dot {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FFFFFF' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 16l5-5 4 4 7-8'/%3E%3C/svg%3E");
}

#nav [role="tablist"] {
  display: flex; gap: 2px; flex: 1; overflow-x: auto;
  scrollbar-width: none;
}
#nav [role="tablist"]::-webkit-scrollbar { display: none; }

[role="tab"] {
  display: inline-flex; align-items: center; gap: 7px;
  height: 40px; padding: 0 14px;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 500;
  white-space: nowrap;
  transition: color .15s, background-color .15s;
}
[role="tab"] svg { width: 18px; height: 18px; flex-shrink: 0; }
[role="tab"]:hover { color: var(--text); background: var(--surf2); }
[role="tab"][aria-selected="true"] { color: var(--text); background: var(--surf2); font-weight: 600; }
[role="tab"][aria-selected="true"] svg { color: var(--accent); }

#theme-toggle {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--surf);
  border: 1px solid var(--border);
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: color .15s, border-color .15s;
}
#theme-toggle svg { width: 19px; height: 19px; }
#theme-toggle:hover { color: var(--text); border-color: var(--brig); }

/* ─── Main Layout ────────────────────────────────────────────── */
main {
  margin-top: calc(var(--nav-h) + var(--safe-top));
  padding: 28px 20px 48px;
  max-width: 960px; margin-left: auto; margin-right: auto;
}

.sec { display: none; }
.sec.on { display: block; }

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 16px; font-weight: 600; letter-spacing: -.1px;
  color: var(--text);
  margin-bottom: 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
/* The one-line explainer next to a title ("Key ratios from your data"). */
.card-title > span { font-size: 13px !important; font-weight: 400 !important; color: var(--muted) !important; }

/* ─── Summary Cards Grid ─────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.kpi-value { font-size: 20px; font-weight: 600; letter-spacing: -.4px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--faint); margin-top: 4px; }

/* ─── Form Elements ──────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group[hidden] { display: none; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--muted); }
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  min-height: 44px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--surf2) inset;
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
}

select option { background: var(--surf2); color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 44px; padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, opacity .15s, transform .1s;
}
.btn:hover { opacity: .92; }
.btn:active { transform: scale(.98); }

/* Primary actions use the accent (the class names are kept for the JS). */
.btn-green  { background: var(--accent); color: var(--on-accent); }
.btn-blue   { background: var(--accent); color: var(--on-accent); }
.btn-red    { background: var(--red-soft); color: var(--red); border-color: transparent; }
.btn-ghost  { background: var(--surf); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--brig); opacity: 1; }
.btn-sm     { min-height: 40px; padding: 8px 14px; font-size: 13px; }

/* ─── Account Balance Form ───────────────────────────────────── */
.account-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.account-field-group { display: flex; flex-direction: column; gap: 4px; }
.acct-label {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  display: flex; align-items: center; gap: 6px;
}
.acct-badge {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
}
.acct-input {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
.acct-input:focus { border-color: var(--green); }
.acct-input.debt-input:focus { border-color: var(--red); }

/* ─── Balance History ────────────────────────────────────────── */
.history-table {
  width: 100%; border-collapse: collapse;
  font-size: 12px;
}
.history-table th {
  text-align: left; padding: 6px 10px;
  font-size: 10px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.history-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.history-table tr:last-child td { border-bottom: none; }
.history-table tr:hover td { background: var(--surf2); }

/* ─── Tracker Filter Bar ─────────────────────────────────────── */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 14px;
}
.filter-bar select,
.filter-bar input[type="date"] {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 7px 10px;
  font-size: 12px;
  outline: none;
  transition: border-color .15s;
}
.filter-bar select:focus,
.filter-bar input[type="date"]:focus { border-color: var(--green); }
.filter-label { font-size: 11px; color: var(--muted); font-weight: 600; }

/* ─── Tracker Summary Cards ──────────────────────────────────── */
.tracker-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.ts-card {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
}
.ts-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.ts-value { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ts-note { margin: -8px 0 16px; font-size: 12px; color: var(--green); }
.ts-note--carry { color: var(--blue); }
.ts-note.muted { color: var(--muted); }
.savings-change-note { margin: -6px 0 16px; font-size: 12px; color: var(--green); }
.savings-change-note.muted { color: var(--muted); }

/* ─── Category Breakdown ─────────────────────────────────────── */
.cat-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.cat-label { font-size: 12px; font-weight: 600; min-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-bar-wrap { flex: 1; height: 8px; background: var(--surf2); border-radius: 4px; overflow: hidden; }
.cat-bar { height: 100%; border-radius: 4px; transition: width .3s; }
.cat-amount { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 70px; text-align: right; color: var(--text); }
.cat-pct { font-size: 10px; color: var(--muted); min-width: 36px; text-align: right; }

/* ─── Daily Chart ────────────────────────────────────────────── */
.daily-chart {
  display: flex; align-items: flex-end; gap: 4px;
  height: 70px; overflow-x: auto;
  padding-bottom: 4px;
}
.day-col { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 28px; height: 100%; justify-content: flex-end; }
.day-bar { width: 20px; border-radius: 3px 3px 0 0; background: var(--blue); opacity: .8; min-height: 2px; }
.day-lbl { font-size: 8px; color: var(--muted); }

/* ─── Transaction Log ────────────────────────────────────────── */
.txn-search { width: 100%; margin-bottom: 12px; }

.txn-list { display: flex; flex-direction: column; gap: 1px; }
.txn-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--surf2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  transition: background .15s;
}
.txn-item:hover { background: var(--surf3); }
.txn-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.txn-info { flex: 1; min-width: 0; }
.txn-desc { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-meta { font-size: 10px; color: var(--muted); margin-top: 1px; }
.txn-amount { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.txn-actions { display: flex; gap: 6px; flex-shrink: 0; }
.txn-btn {
  border: none; background: none; cursor: pointer;
  padding: 3px 6px; border-radius: 4px;
  font-size: 11px; color: var(--muted);
  transition: color .15s, background .15s;
}
.txn-btn:hover.edit { color: var(--blue); background: rgba(96,165,250,.12); }
.txn-btn:hover.del  { color: var(--red);  background: rgba(248,113,113,.12); }

.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--muted); font-size: 13px;
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 10px; }

/* ─── Account Group Labels ───────────────────────────────────── */
.group-header {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted);
  margin: 16px 0 8px;
  padding-bottom: 4px; border-bottom: 1px solid var(--border);
}

/* ─── Net Worth Trend (Accounts Tab) ────────────────────────── */
.nw-trend { display: flex; align-items: flex-end; gap: 5px; height: 60px; margin-top: 8px; }
.nw-bar-col { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1; height: 100%; justify-content: flex-end; }
.nw-bar { width: 100%; border-radius: 3px 3px 0 0; background: var(--green); opacity: .75; min-height: 2px; }
.nw-lbl { font-size: 8px; color: var(--muted); white-space: nowrap; }

/* ─── Badges / Tags ──────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 7px;
  border-radius: 10px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
}

/* ─── Scrollbar ──────────────────────────────────────────────── */
body { scrollbar-width: thin; scrollbar-color: var(--brig) transparent; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--brig); border-radius: 3px; }

/* ─── Focus ring ─────────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ─── Utilities ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-blue   { color: var(--blue); }
.text-muted  { color: var(--muted); }
.text-orange { color: var(--orange); }
.mono { font-variant-numeric: tabular-nums; }
.fw-bold { font-weight: 700; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.flex  { display: flex; }
.gap-8 { gap: 8px; }
.ai-center { align-items: center; }
.jc-sb { justify-content: space-between; }
.section-title {
  font-size: 18px; font-weight: 800; letter-spacing: -.3px;
  margin-bottom: 4px;
}
.section-sub {
  font-size: 12px; color: var(--muted); margin-bottom: 16px;
}

/* ─── Analysis Grid (responsive 2-col) ──────────────────────── */
.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* ─── Analysis Tab ───────────────────────────────────────────── */
.an-controls {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.an-modes {
  display: flex; gap: 2px; padding: 3px;
  background: var(--surf2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.an-mode {
  border: none; background: transparent; color: var(--muted);
  font-size: 12px; font-weight: 700; padding: 6px 16px; border-radius: 6px;
}
.an-mode.on { background: var(--surf); color: var(--text); box-shadow: var(--shadow); }
.an-nav { display: flex; align-items: center; gap: 10px; }
.an-arrow {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surf2);
  color: var(--text); font-size: 16px; line-height: 1;
}
.an-arrow:disabled { opacity: .35; cursor: default; }
.an-period-label { font-size: 13px; font-weight: 700; min-width: 150px; text-align: center; }

.an-badge-row { margin-top: 4px; min-height: 14px; }
.an-delta { font-size: 10px; font-weight: 700; white-space: nowrap; }
.an-delta.good  { color: var(--green); }
.an-delta.bad   { color: var(--red); }
.an-delta.muted { color: var(--muted); }
.an-delta-cell  { min-width: 52px; text-align: right; }

.an-rhythm { height: 96px; }
.an-bar-amt { font-size: 8px; color: var(--muted); font-variant-numeric: tabular-nums; }

.an-big-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.an-big-row:last-child { border-bottom: none; }
.an-big-rank {
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
  background: var(--surf2); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800;
}
.an-big-main { flex: 1; min-width: 0; }
.an-big-desc { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.an-big-meta { font-size: 10px; color: var(--muted); }
.an-big-amt { font-size: 13px; font-weight: 800; color: var(--red); font-variant-numeric: tabular-nums; }

.an-pulse-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.an-pulse-row:last-child { border-bottom: none; }
.an-pulse-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.an-pulse-value { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.an-pulse-value .an-delta { margin-right: 6px; font-size: 10px; }
.an-pulse-net { border-top: 1px solid var(--brig); }
.an-pulse-net .an-pulse-label { color: var(--text); }
.an-pulse-net .an-pulse-value { font-size: 16px; }

.an-insight {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 0; border-bottom: 1px solid var(--border);
  font-size: 12.5px; line-height: 1.55;
}
.an-insight:last-child { border-bottom: none; }
.an-insight-icon { font-size: 15px; flex-shrink: 0; }

/* ─── Budget vs Actual ───────────────────────────────────────── */
.budget-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 4px; margin-bottom: 6px;
}
.budget-bar-wrap {
  flex: 1; height: 5px; background: var(--surf3);
  border-radius: 3px; overflow: hidden;
}
.budget-bar { height: 100%; border-radius: 3px; transition: width .3s; }
.budget-label { font-size: 10px; min-width: 130px; text-align: right; font-weight: 600; }
.budget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.budget-field-group { display: flex; flex-direction: column; gap: 4px; }

/* ─── Debt Details ───────────────────────────────────────────── */
.debt-card {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.debt-card-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
}
.debt-balance { margin-left: auto; font-size: 16px; font-weight: 800; }
.debt-meta-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px;
}
.debt-stats {
  display: flex; gap: 16px; flex-wrap: wrap;
  padding: 10px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.debt-stat { display: flex; flex-direction: column; gap: 2px; }
.debt-stat-label { font-size: 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.debt-stat-value { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ─── Loans Out ─────────────────────────────────────────────── */
.loan-item {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.loan-item:last-child { border-bottom: none; }
.loan-name { font-weight: 700; font-size: 13px; }
.loan-meta { font-size: 10px; color: var(--muted); margin-top: 2px; }
.loan-amount { font-size: 14px; font-weight: 800; color: var(--teal); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.loan-paid-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.loan-paid-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.loan-paid-item {
  display: flex; gap: 8px; align-items: center;
  padding: 6px 0; font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.loan-paid-item:last-child { border-bottom: none; }
.loan-detail { flex-basis: 100%; padding: 6px 0 2px 14px; }
.loan-pay-row {
  display: flex; gap: 12px; align-items: center; font-size: 12px;
  padding: 3px 0; border-top: 1px dashed var(--surf2); font-variant-numeric: tabular-nums;
}
.loan-pay-row > span:first-child { color: var(--muted); }

/* ─── Recurring Badge ────────────────────────────────────────── */
.recurring-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 8px;
  font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  background: var(--surf3); color: var(--muted);
}

/* ─── Balance Trend Chart ────────────────────────────────────── */
.trend-tabs { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:14px; }
.trend-tab {
  padding:4px 12px; border-radius:14px;
  font-size:11px; font-weight:700;
  border:1px solid var(--border);
  background:var(--surf2); color:var(--muted);
  cursor:pointer; transition:color .15s, background .15s, border-color .15s;
}
.trend-tab:hover { color:var(--text); }
.trend-tab.active { background:var(--green); color:#000; border-color:transparent; }
.trend-chart-wrap { width:100%; overflow-x:auto; }
.trend-chart-wrap svg { display:block; width:100%; }
.trend-dot { stroke:var(--surf); stroke-width:1.5; }
.trend-legend {
  display:flex; flex-wrap:wrap; gap:12px;
  margin-top:12px; padding-top:10px;
  border-top:1px solid var(--border);
}
.trend-legend-item { display:flex; align-items:center; gap:5px; font-size:11px; color:var(--muted); }
.trend-legend-dot { width:8px; height:8px; border-radius:50%; flex-shrink:0; }

/* ─── Manage Accounts ───────────────────────────────────────── */
.acct-mgmt-item {
  display:flex; align-items:center; gap:10px;
  padding:8px 0; border-bottom:1px solid var(--border);
}
.acct-mgmt-item:last-child { border-bottom:none; }
.acct-color-swatch {
  width:12px; height:12px; border-radius:50%; flex-shrink:0;
}
.acct-mgmt-name { flex:1; font-size:13px; font-weight:600; color:var(--text); }
.acct-mgmt-group {
  font-size:10px; font-weight:700; padding:2px 7px;
  border-radius:10px; background:var(--surf2); color:var(--muted);
  text-transform:uppercase; letter-spacing:.4px;
}
.add-acct-form {
  padding:14px 0 4px; border-top:1px solid var(--border); margin-top:12px;
}

/* ─── Google Drive Sync ──────────────────────────────────────── */
.gdrive-sync {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.gdrive-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); margin-bottom: 8px;
}
.gdrive-status {
  font-size: 11px; color: var(--muted);
}
.sync-help { margin: 0 0 10px; font-size: 12px; color: var(--muted); line-height: 1.45; }
.sync-alert { margin: 0 0 16px; padding: 12px 14px; border: 1px solid var(--warn-border); border-radius: 12px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; }
.sync-setup { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin: 0 0 16px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surf); color: var(--muted); font-size: 13px; }

/* ─── Login Gate ─────────────────────────────────────────────── */
#login-overlay {
  position: fixed; inset: 0; z-index: 9000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
#login-overlay.hidden { display: none; }

.login-box {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%; max-width: 340px;
  box-shadow: var(--shadow);
}
.login-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 18px; letter-spacing: -.3px;
  margin-bottom: 6px;
}
.login-sub {
  font-size: 12px; color: var(--muted);
  margin-bottom: 20px;
}
.login-error {
  font-size: 12px; color: var(--red);
  min-height: 18px; margin-top: 6px;
}
/* Email-code lock screen (js/email-login.js) */
.login-box [hidden] { display: none !important; }
.el-wide { width: 100%; margin-top: 12px; justify-content: center; }
.el-code { font-size: 20px; letter-spacing: .45em; text-align: center; }
.el-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 12px; font-size: 12px; }
.el-link { background: none; border: 0; padding: 0; color: var(--green); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.el-hint { color: var(--muted); }
/* Lock button: same look as the theme toggle next to it */
#lock-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surf2); border: 1px solid var(--border);
  color: var(--text); font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-left: 4px;
  transition: background .15s, border-color .15s, transform .15s;
}
#lock-btn:hover { background: var(--brig); transform: scale(1.1); }

/* ─── Financial Ratios ──────────────────────────────────────── */
.ratios-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.ratio-card {
  background: var(--surf2);
  border-radius: 8px;
  padding: 12px 14px;
}
.ratio-label {
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
  margin-bottom: 4px;
}
.ratio-value {
  font-size: 20px; font-weight: 800; letter-spacing: -.3px;
  margin-bottom: 2px;
}
.ratio-sub { font-size: 10px; color: var(--muted); }

/* ─── Bill Reminders ─────────────────────────────────────────── */
.bill-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.bill-item:last-child { border-bottom: none; }
.bill-info  { flex: 1; min-width: 0; }
.bill-name  { font-size: 13px; font-weight: 600; color: var(--text); }
.bill-meta  { font-size: 11px; color: var(--muted); }
.bill-amount { font-size: 13px; font-weight: 600; color: var(--text); flex-shrink: 0; }
.bill-due   { font-size: 11px; font-weight: 600; flex-shrink: 0; color: var(--muted); }
.bill-overdue .bill-due,
.bill-urgent  .bill-due { color: var(--red); }
.bill-soon    .bill-due { color: var(--gold); }

/* ─── Savings Goals ──────────────────────────────────────────── */
.goal-item {
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.goal-item:last-child { border-bottom: none; }
.goal-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.goal-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--text); }
.goal-pct  { font-size: 12px; font-weight: 700; }
.goal-progress-wrap {
  height: 8px; background: var(--surf2);
  border-radius: 4px; overflow: hidden;
}
.goal-progress-bar {
  height: 100%; background: var(--green);
  border-radius: 4px; transition: width .4s ease;
}

/* ─── Things Tracker ────────────────────────────────────────────── */
.things-controls-bar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 14px;
}

.things-item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.things-item-card {
  background: var(--surf); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow);
  transition: border-color .2s, transform .2s;
}
.things-item-card:hover { border-color: var(--brig); transform: translateY(-1px); }
.things-item-name  { font-size: 14px; font-weight: 700; color: var(--text); }
.things-cat-badge  {
  display: inline-block; font-size: 10px; font-weight: 700; padding: 2px 7px;
  border-radius: 10px; background: var(--surf2); color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
}
.things-unit-cost  { font-size: 18px; font-weight: 700; color: var(--green); }
.things-trend-up   { color: var(--red); }
.things-trend-down { color: var(--green); }
.things-trend-flat { color: var(--muted); }
.things-insight {
  font-size: 12px; color: var(--muted); font-style: italic;
  padding: 8px 10px; background: var(--surf2);
  border-radius: 6px; margin: 4px 0 10px;
}
.things-diff-badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 1px 5px; border-radius: 5px; margin-left: 4px;
}
.things-diff-badge.up   { background: rgba(248,113,113,.15); color: var(--red); }
.things-diff-badge.down { background: rgba(74,222,128,.15);  color: var(--green); }
.things-chart { width: 100%; height: 80px; overflow: visible; display: block; }

/* ─── Things — section nav ───────────────────────────────────── */
.things-section-nav {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 20px;
  padding: 10px 14px;
  background: var(--surf2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.things-sec-link {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-decoration: none; padding: 4px 10px;
  border-radius: 20px; border: 1px solid transparent;
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap;
}
.things-sec-link:hover {
  color: var(--text);
  border-color: var(--brig);
  background: var(--surf3);
}

/* ─── Things — section headings ─────────────────────────────── */
.things-section-head {
  display: flex; align-items: center; gap: 8px;
}
.things-section-icon { font-size: 16px; }
.things-analysis-sub-title {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  margin: 18px 0 8px; padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ─── Things — analysis filters ─────────────────────────────── */
.things-analysis-filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  padding: 12px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.things-filter-group { display: flex; flex-direction: column; gap: 4px; }
.things-filter-label {
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.things-filter-select {
  background: var(--surf2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  padding: 6px 10px; font-size: 12px; outline: none;
  min-width: 140px;
}

/* ─── Things — timing grid ───────────────────────────────────── */
.things-timing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px; margin: 10px 0;
}
.things-timing-card {
  background: var(--surf2); border-radius: 8px; padding: 10px 12px;
}
.things-timing-label {
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px;
}
.things-timing-value { font-size: 15px; font-weight: 700; }

/* ─── Things — review / stores ───────────────────────────────── */
.things-unknown-badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 10px;
  background: rgba(251,146,60,.15); color: var(--orange);
  text-transform: uppercase; letter-spacing: .4px;
}
.things-review-link { color: var(--blue); text-decoration: none; }
.things-review-link:hover { text-decoration: underline; }
.things-review-section {
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.things-review-section:first-child { margin-top: 4px; border-top: none; }
.things-review-section-title {
  font-size: 13px; font-weight: 700; margin-bottom: 6px;
  display: flex; align-items: center; gap: 8px;
}
.things-review-count {
  font-size: 11px; font-weight: 400; color: var(--orange);
}
.things-item-link {
  color: var(--green); text-decoration: none; cursor: pointer;
}
.things-item-link:hover { text-decoration: underline; }

/* ─── Things — table utility ─────────────────────────────────── */
.text-right { text-align: right; }

@media (max-width: 600px) {
  .things-item-grid { grid-template-columns: 1fr; }
  .things-section-nav { gap: 4px; }
  .things-timing-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Wealth tab ─────────────────────────────────────────── */
.wl-sub { color: var(--muted); font-size: 12px; line-height: 1.5; }
.wl-head-line { font-size: 14px; }
.wl-callout { background: var(--surf2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 12.5px; margin-top: 10px; }
.wl-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.wl-row:last-child { border-bottom: none; padding-bottom: 2px; }
.wl-row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; }
.wl-row-head .amt { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.wl-left { font-weight: 600; font-variant-numeric: tabular-nums; }
.wl-left.over { color: var(--red); }
.wl-bar { height: 6px; background: var(--surf3); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.wl-bar-fill { height: 100%; border-radius: 3px; background: var(--green); }
.wl-bar-fill.warn { background: var(--gold); }
.wl-bar-fill.over { background: var(--red); }
.wl-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.wl-chip { font-size: 11px; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); }
.wl-chip.paid { color: var(--green); border-color: var(--green); }
.wl-stage { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.wl-stage-n { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); flex: none; }
.wl-stage.done .wl-stage-n { background: var(--green); color: var(--bg); border-color: var(--green); }
.wl-stage.active .wl-stage-n { border-color: var(--gold); color: var(--gold); }
.wl-stage-body { flex: 1; min-width: 0; }
.wl-grade { font-size: 30px; font-weight: 700; width: 52px; text-align: center; flex: none; }
.wl-grade.a, .wl-grade.b { color: var(--green); }
.wl-grade.c { color: var(--teal); }
.wl-grade.d { color: var(--gold); }
.wl-grade.e { color: var(--orange); }
.wl-grade.f { color: var(--red); }
.wl-studio-read { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.wl-sl-lab { display: flex; justify-content: space-between; font-size: 12px;
  color: var(--muted); margin: 12px 0 4px; }
.wl-corr { display: flex; height: 24px; border-radius: var(--radius-sm);
  overflow: hidden; margin-top: 14px; }
.wl-corr-key { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11px;
  color: var(--muted); margin-top: 8px; }
.wl-corr-key i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
.wl-proj-head { display: flex; justify-content: space-between; align-items: flex-end; margin: 16px 0 8px; }
.wl-proj-val { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.wl-ctrl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

/* ── Wealth v2: window toggle + charts ─────────────────────── */
.wl-mode { display: flex; gap: 6px; margin: 14px 0; }
.wl-mode button { background: var(--surf); border: 1px solid var(--border); color: var(--muted);
  border-radius: var(--radius-sm); padding: 6px 14px; font-size: 12px; cursor: pointer; }
.wl-mode button:hover { color: var(--text); }
.wl-mode button.on { background: var(--surf3); color: var(--text); border-color: var(--brig); font-weight: 600; }
.wl-varrow { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 12px; }
.wl-var-label { flex: 0 0 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wl-var-track { flex: 1; position: relative; height: 12px; background: var(--surf3);
  border-radius: 3px; overflow: hidden; }
.wl-var-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--green); opacity: .85; }
.wl-var-fill.over { background: var(--red); }
.wl-var-ref { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--brig); }
.wl-var-clip { position: absolute; right: 2px; top: -1px; color: var(--red); font-size: 10px; }
.wl-var-delta { flex: 0 0 110px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.wl-var-delta.over { color: var(--red); font-weight: 600; }
.wl-ch-under, .wl-ch-over { fill: none; stroke-width: 2; }
.wl-ch-under { stroke: var(--green); }
.wl-ch-over  { stroke: var(--red); }
.wl-ch-pace  { stroke: var(--gold); stroke-dasharray: 4 3; stroke-width: 1.5; fill: none; }
.wl-ch-col   { fill: var(--green); opacity: .8; }
.wl-ch-col.short { fill: var(--gold); }
.wl-ch-col.over  { fill: var(--red); }
.wl-ch-col.negative { fill: var(--red); }
.wl-ch-zero { stroke: var(--border); stroke-width: 1; }
.wl-ch-target { stroke: var(--gold); stroke-dasharray: 4 3; stroke-width: 1.5; }
@media (max-width: 560px) { .wl-var-label { flex-basis: 90px; } .wl-var-delta { flex-basis: 88px; } }

/* ─── Reduced Motion ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .dot { animation: none; }
}

/* ── Africa tab ─────────────────────────────────────────────── */
.af-sumline { margin: 4px 0; }
.af-est { margin-top: 8px; font-size: 15px; }
.af-country { margin: 14px 0 4px; font-size: 12px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.af-item { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--surf2); }
.af-item:last-child { border-bottom: none; }
.af-name { font-weight: 600; }
.af-meta { font-size: 12px; color: var(--muted); flex-basis: 100%; }
.af-gain { color: var(--green); }
.af-loss { color: var(--red); }
.af-val-input { width: 110px; }
.af-row-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.af-hist { flex-basis: 100%; padding: 8px 0 4px; }
.af-hist-link { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
.af-hist-analysis { font-size: 13px; margin-bottom: 6px; }
.af-hist-chart { width: 100%; height: auto; display: block; margin-bottom: 8px; }
.af-hist-row { display: flex; gap: 12px; align-items: baseline; font-size: 13px;
  padding: 3px 0; border-top: 1px dashed var(--surf2); font-variant-numeric: tabular-nums; }
.af-hist-row > span:first-child { color: var(--muted); font-size: 12px; min-width: 88px; }

/* ── Debt: live owed line ───────────────────────────────────── */
.debt-owed-now { margin: 6px 0 10px; font-size: 14px; }
.debt-owed-break { font-size: 12px; color: var(--muted); margin-top: 2px; }
/* Private Wealth plan editor */
#wl-config summary { cursor: pointer; }
#wl-config .wl-sub { margin: 10px 0; }
.wl-config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 14px 0; }
.wl-config-field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.wl-config-field input { width: 100%; min-width: 0; padding: 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surf2); color: var(--text); font: inherit; }
.wl-config-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.wl-config-actions button, .wl-config-import { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--surf2); color: var(--text); font: inherit; font-size: 12px; cursor: pointer; }
.wl-config-import input { display: block; margin-top: 6px; max-width: 100%; }
.wl-config-import { display: block; max-width: 100%; min-width: 0; overflow: hidden; }
.wl-config-import input[type="file"] { width: 100%; min-width: 0; }
.wl-unconfigured > .card:not(#wl-config), .wl-unconfigured > .wl-mode { display: none; }

/* ═══ Hybrid design layer (Midnight + Paper) ═══════════════════════
   Everything below refines the components above for the calmer look:
   sentence-case labels at readable sizes, one accent, meaning-only colour,
   net worth first, and secondary cards that fold away. Nothing here removes
   a control: folded cards keep every field and button inside them. */

/* Page headings */
.section-title { font-size: 28px; font-weight: 700; letter-spacing: -.8px; margin-bottom: 4px; line-height: 1.15; }
.section-sub { font-size: 14px; color: var(--muted); margin-bottom: 18px; }

/* Labels: sentence case, readable. (Kept as a list so every JS-rendered
   label picks it up.) */
.group-header, .ts-label, .history-table th, .badge, .debt-stat-label,
.loan-paid-label, .recurring-badge, .acct-label, .ratio-label, .gdrive-label,
.acct-mgmt-group, .things-cat-badge, .things-analysis-sub-title,
.things-filter-label, .things-timing-label, .things-unknown-badge, .af-country,
.filter-label, .kpi-label {
  text-transform: none; letter-spacing: 0;
}
.group-header { font-size: 13px; font-weight: 600; color: var(--muted); border-bottom-color: var(--hair); margin: 18px 0 10px; }
.acct-label { font-size: 13px; font-weight: 500; }
.acct-input { min-height: 44px; border-radius: var(--radius-sm); font-size: 15px; font-weight: 500; }
.acct-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.acct-input.debt-input:focus { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.ts-label { font-size: 12.5px; font-weight: 500; }
.history-table { font-size: 13px; }
.history-table th { font-size: 12px; font-weight: 600; }
.history-table tr:hover td { background: var(--surf2); }
.badge { font-size: 11px; font-weight: 600; }
.recurring-badge { font-size: 10.5px; font-weight: 600; padding: 1px 7px; }
.debt-stat-label, .loan-paid-label, .gdrive-label, .ratio-label { font-size: 12.5px; font-weight: 500; }
.acct-mgmt-group, .things-cat-badge, .things-unknown-badge { font-size: 11px; font-weight: 600; }
.things-analysis-sub-title, .things-filter-label, .things-timing-label, .af-country { font-size: 12.5px; font-weight: 600; }
.filter-label { font-size: 12.5px; font-weight: 500; }
.kpi-sub, .txn-meta, .loan-meta, .bill-meta, .an-big-meta, .ratio-sub { font-size: 12px; }
.nw-lbl, .an-bar-amt { font-size: 11px; }
.day-lbl { font-size: 10px; }
.cat-pct, .an-delta { font-size: 11.5px; }
.cat-label, .cat-amount { font-size: 13px; }

/* ── Accounts: net worth first ─────────────────────────────────── */
#account-kpis {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px;
  margin-bottom: 12px;
}
.kpi-hero {
  border-radius: var(--radius);
  padding: 22px 22px 20px;
  display: flex; flex-direction: column; justify-content: center;
}
.kpi-hero .kpi-label { font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.kpi-hero .kpi-value { font-size: 44px; font-weight: 700; letter-spacing: -1.6px; line-height: 1.02; }
.kpi-hero .kpi-value .kpi-cents { font-size: .55em; font-weight: 600; letter-spacing: -.4px; color: var(--muted); }
.kpi-hero .kpi-value.neg { color: var(--red); }
.kpi-hero .kpi-sub { font-size: 13px; margin-top: 10px; }
.kpi-delta-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.kpi-delta {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 11px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.kpi-delta svg { width: 13px; height: 13px; }
.kpi-delta.up   { background: var(--green-soft); color: var(--green); }
.kpi-delta.down { background: var(--red-soft);   color: var(--red); }
.kpi-delta-note { font-size: 13px; color: var(--muted); }

.kpi-list {
  background: var(--surf); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 4px 16px;
}
.kpi-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 62px; padding: 8px 0;
  border-bottom: 1px solid var(--hair);
}
.kpi-row:last-child { border-bottom: 0; }
.kpi-ico {
  width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.kpi-ico svg { width: 18px; height: 18px; }
.kpi-row .kpi-text { flex: 1; min-width: 0; }
.kpi-row .kpi-label { font-size: 15px; font-weight: 600; color: var(--text); margin: 0; }
.kpi-row .kpi-sub { margin: 1px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-row .kpi-value { font-size: 15.5px; font-weight: 600; letter-spacing: -.2px; flex-shrink: 0; }
.kpi-row .kpi-value.neg { color: var(--red); }
.kpi-row .kpi-value.pos { color: var(--green); }
.tone-blue   { background: var(--accent-soft); color: var(--accent-text); }
.tone-green  { background: var(--green-soft);  color: var(--green); }
.tone-violet { background: color-mix(in srgb, var(--purple) 15%, transparent); color: var(--purple); }
.tone-teal   { background: color-mix(in srgb, var(--teal) 15%, transparent);   color: var(--teal); }
.tone-red    { background: var(--red-soft);    color: var(--red); }
.tone-gold   { background: var(--gold-soft);   color: var(--gold); }
.tone-plain  { background: var(--surf2);       color: var(--muted); }

.savings-change-note { font-size: 13px; margin: 0 0 16px; }

/* Quick actions under the summary */
.quick-actions { display: flex; gap: 10px; margin: 0 0 20px; }
.quick-actions .btn { flex: 1; min-height: 48px; font-size: 14.5px; }

/* ── Cards that fold away (data-collapse) ────────────────────────── */
.card[data-collapse] > .card-title { cursor: pointer; user-select: none; -webkit-user-select: none; }
.card[data-collapse] > .card-title:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.card-chev {
  width: 20px; height: 20px; margin-left: auto; flex-shrink: 0;
  color: var(--muted); transition: transform .2s ease;
}
.card-fold {
  margin-left: auto; flex-shrink: 0;
  width: 40px; height: 40px; border-radius: 10px; border: 0;
  background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.card-fold:hover { background: var(--surf2); color: var(--text); }
.card-fold .card-chev { margin: 0; }
.card[data-collapse] > .card-title { margin-top: -6px; margin-bottom: 10px; }
.card { scroll-margin-top: calc(var(--nav-h) + var(--safe-top) + 12px); }
/* The Add/Edit Transaction heading is a span but it is the title itself. */
.card-title > #txn-form-label { font-size: 16px !important; font-weight: 600 !important; color: var(--text) !important; }
.card.collapsed { padding-top: 12px; padding-bottom: 12px; }
.card.collapsed > .card-title { margin-bottom: 0; }
.card.collapsed > :not(.card-title) { display: none !important; }
.card.collapsed .card-chev { transform: rotate(-90deg); }

/* ── Component refresh ───────────────────────────────────────────── */
.ratio-card { background: var(--surf2); border-radius: var(--radius-sm); padding: 14px 16px; }
.ratio-value { font-size: 22px; font-weight: 600; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }

.nw-trend { height: 96px; gap: 8px; margin-top: 4px; }
.nw-bar { background: var(--surf3); opacity: 1; border-radius: 7px 7px 4px 4px; }
.nw-bar-col:last-child .nw-bar { background: var(--accent); }
.nw-bar-col:last-child .nw-lbl { color: var(--text); font-weight: 600; }

.trend-tabs { gap: 8px; }
.trend-tab { min-height: 36px; padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 500; background: var(--surf); }
.trend-tab.active { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.trend-legend { border-top-color: var(--hair); }
.trend-legend-item { font-size: 12px; }

.an-modes { border-radius: var(--radius-sm); padding: 3px; }
.an-mode { min-height: 36px; padding: 6px 16px; font-size: 13px; font-weight: 600; border-radius: 9px; }
.an-arrow { width: 40px; height: 40px; font-size: 18px; }
.an-period-label { font-size: 14px; font-weight: 600; }
.an-big-amt { font-weight: 600; }
.an-pulse-value { font-weight: 600; }
.an-insight { font-size: 14px; }

.day-bar { background: var(--accent); opacity: .85; border-radius: 4px 4px 2px 2px; }

.tracker-summary { gap: 12px; }
.ts-card { text-align: left; border-radius: var(--radius-sm); padding: 14px 16px; background: var(--surf); box-shadow: var(--shadow); }
.ts-value { font-size: 20px; font-weight: 600; letter-spacing: -.3px; }

.filter-bar select,
.filter-bar input[type="date"] { min-height: 40px; border-radius: 10px; font-size: 14px; padding: 8px 10px; }
.filter-bar select:focus,
.filter-bar input[type="date"]:focus { border-color: var(--accent); }

.txn-list { gap: 0; }
.txn-item {
  background: transparent; border-radius: 0;
  border-bottom: 1px solid var(--hair);
  padding: 12px 4px; min-height: 60px; font-size: 13px;
}
.txn-item:last-child { border-bottom: 0; }
.txn-item:hover { background: var(--surf2); }
.txn-desc { font-size: 14.5px; font-weight: 500; }
.txn-amount { font-size: 15px; font-weight: 600; }
.txn-btn { min-height: 36px; min-width: 40px; padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.txn-btn:hover.edit { color: var(--accent-text); background: var(--accent-soft); }
.txn-btn:hover.del  { color: var(--red); background: var(--red-soft); }

.cat-bar-wrap, .goal-progress-wrap { background: var(--surf3); }
.budget-bar-wrap, .wl-bar, .wl-var-track { background: var(--surf3); }
.goal-progress-bar { background: var(--accent); }
.goal-name, .bill-name { font-size: 14.5px; font-weight: 500; }
.bill-item, .goal-item, .loan-item, .acct-mgmt-item, .an-big-row, .an-pulse-row, .an-insight, .wl-row, .af-item { border-bottom-color: var(--hair); }
.loan-amount, .things-unit-cost { color: var(--text); font-weight: 600; }
.debt-card { background: var(--surf2); border-radius: var(--radius-sm); }
.debt-balance, .debt-stat-value { font-weight: 600; }

.things-item-card { border-radius: var(--radius-sm); }
.things-item-card:hover { transform: none; }
.things-section-nav { background: transparent; border: 0; padding: 0; gap: 8px; }
.things-sec-link { min-height: 36px; display: inline-flex; align-items: center; padding: 6px 14px; font-size: 13px; border: 1px solid var(--border); background: var(--surf); color: var(--muted); border-radius: 999px; }
.things-sec-link:hover { color: var(--text); background: var(--surf2); border-color: var(--brig); }
.things-filter-select { min-height: 40px; border-radius: 10px; font-size: 14px; }
.things-insight { font-style: normal; background: var(--surf2); border-radius: var(--radius-sm); }
/* Things section heads: icon then title, left-aligned (not the title's space-between). */
.card-title.things-section-head { justify-content: flex-start; gap: 10px; }
.card-title.things-section-head > .things-section-icon { font-size: 18px !important; color: inherit !important; }
.things-controls-bar input, .things-controls-bar select { min-height: 40px; border-radius: 10px; font-size: 14px; }

.wl-mode button { min-height: 36px; border-radius: 999px; padding: 6px 16px; font-size: 13px; }
.wl-mode button.on { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.wl-callout { border-radius: var(--radius-sm); background: var(--surf2); }
.wl-config-field input, .wl-config-actions button, .wl-config-import { border-radius: 10px; min-height: 40px; }

.kpi:hover { transform: none; }

/* Login */
#login-overlay { background: var(--bg); }
.login-box { border-radius: 24px; padding: 32px 26px; max-width: 360px; box-shadow: var(--shadow-lg); }
.login-brand { font-size: 20px; font-weight: 700; letter-spacing: -.4px; gap: 12px; margin-bottom: 8px; }
.login-sub { font-size: 14px; }
.login-error { font-size: 13px; }

/* Focus ring in the accent */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Email-code lock screen + Lock button in the hybrid look */
.el-code { min-height: 52px; font-size: 22px; font-weight: 600; letter-spacing: .4em; }
.el-row { font-size: 13px; }
.el-link { color: var(--accent-text); min-height: 40px; display: inline-flex; align-items: center; }
.el-hint { font-size: 13px; }
#lock-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surf); border: 1px solid var(--border);
  color: var(--muted); margin-left: 0;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: color .15s, border-color .15s;
}
#lock-btn svg { width: 19px; height: 19px; }
#lock-btn:hover { color: var(--text); border-color: var(--brig); background: var(--surf); transform: none; }

/* Toasts: centred above the phone tab bar, readable in both themes. */
#toast-msg {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 9999; max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 14px; box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 600; line-height: 1.35; text-align: center;
  transition: opacity .3s; pointer-events: none;
  background: var(--text); color: var(--bg);
}
#toast-msg.toast-success { background: var(--green); color: var(--on-accent); }
#toast-msg.toast-error   { background: var(--red);   color: #FFFFFF; }
#toast-msg.toast-info    { background: var(--accent); color: var(--on-accent); }
body.light #toast-msg.toast-success { color: #FFFFFF; }
body:not(.light) #toast-msg.toast-error { color: #1A0906; }
@media (max-width: 820px) { #toast-msg { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px); } }

/* The account is shown by the coloured dot; text next to it stays readable. */
.txn-meta [style*="color"] { color: var(--muted) !important; }

/* Every control at least 40px tall (audit) */
.trend-tab, .an-mode, .wl-mode button { min-height: 40px; }
.txn-btn { min-height: 40px; min-width: 40px; }
#wl-config summary { min-height: 44px; display: flex; align-items: center; margin-bottom: 0; }
#wl-config details[open] > summary { margin-bottom: 14px; }
.wl-config-import input[type="file"] { min-height: 40px; }

/* Grid columns may shrink below their content (a 31-day chart scrolls inside
   its card instead of widening the page and making phones zoom out). */
.analysis-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.analysis-grid > *, .summary-grid > *, .form-grid > *, .tracker-summary > *,
.budget-grid > *, .ratios-grid > *, .things-item-grid > *, .things-timing-grid > *,
.wl-ctrl-grid > *, .wl-config-grid > *, .account-fields > * { min-width: 0; }

/* ─── Responsive (kept last so phone rules win) ──────────────────── */
@media (min-width: 821px) {
  /* Desktop: net worth beside the account list. */
  #account-kpis { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: stretch; }
  .quick-actions { max-width: 460px; }
  #nav { -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px); }
}

/* Savings figures show their transaction and snapshot evidence on tap. */
.savings-disclosure { min-width: 0; }
.savings-disclosure > summary { cursor: pointer; list-style: none; }
.savings-disclosure > summary::-webkit-details-marker { display: none; }
.savings-disclosure > summary span:last-child { color: var(--muted); font-size: 11px; margin-left: 5px; }
.savings-disclosure[open] > summary { margin-bottom: 10px; }
.savings-evidence-group { border-top: 1px solid var(--hair); padding-top: 8px; margin-top: 8px; color: var(--text); }
.savings-evidence-group ul { margin: 6px 0 0; padding-left: 18px; }
.savings-evidence-group li { margin: 4px 0; overflow-wrap: anywhere; }
.savings-disclosure p { color: var(--muted); margin: 8px 0 0; }
.an-savings-card[open] { grid-column: span 2; }
.an-savings-card .ts-label span { font-weight: 400; text-transform: none; letter-spacing: 0; }
.an-savings-card summary > span { display: block; }

.backup-key-dialog { width: min(92vw, 480px); max-height: 90vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surf); color: var(--text); box-shadow: var(--shadow); padding: 22px; }
.backup-key-dialog::backdrop { background: rgba(0, 0, 0, .72); }
.backup-key-dialog h2 { margin: 0 0 8px; font-size: 20px; }
.backup-key-dialog p { color: var(--muted); line-height: 1.45; }
.backup-key-dialog label { display: block; margin: 12px 0 5px; }
.backup-key-dialog textarea, .backup-key-dialog input[type=password] { width: 100%; box-sizing: border-box; }
.backup-key-dialog textarea { overflow-wrap: anywhere; resize: vertical; }
.backup-key-dialog .backup-key-confirm { display: flex; align-items: flex-start; gap: 8px; }
.backup-key-dialog .backup-key-confirm input { margin-top: 3px; }
.backup-key-dialog #backup-key-error { color: var(--red); min-height: 1.2em; }
.backup-key-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@media (min-width: 821px) {
  #sec-tracker .tracker-summary, #an-scorecard { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .tracker-summary { grid-template-columns: repeat(2, 1fr); }
}

/* Phones: brand bar on top, tabs in a bottom tab bar. (#nav must not get a
   backdrop-filter or transform here: that would trap the fixed tab bar.) */
@media (max-width: 820px) {
  #nav { gap: 10px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .nav-brand { flex: 1; }
  #nav [role="tablist"] {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 101;
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding: 4px 4px var(--safe-bottom);
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0;
    background: var(--surf);
    border-top: 1px solid var(--border);
    overflow: visible;
  }
  [role="tab"] {
    flex-direction: column; justify-content: center;
    height: auto; min-height: 54px; padding: 4px 0 2px; gap: 3px;
    font-size: 10.5px; font-weight: 500; border-radius: 10px;
  }
  [role="tab"] svg { width: 22px; height: 22px; }
  [role="tab"]:hover, [role="tab"][aria-selected="true"] { background: transparent; }
  [role="tab"][aria-selected="true"] { color: var(--accent-text); font-weight: 600; }
  [role="tab"][aria-selected="true"] svg { color: currentColor; }
  main { padding: 18px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px); }
}

@media (max-width: 600px) {
  /* Card titles: title + fold arrow on the first line, a title's own buttons
     next, the grey explainer on its own line underneath. */
  .card-title > .card-fold { order: 1; }
  .card-title > button:not(.card-fold), .card-title > div, .card-title > label { order: 2; }
  .card-title > span:not(#txn-form-label):not(.things-section-icon) { order: 3; flex-basis: 100%; margin-top: -8px; }

  /* Tracker filters: tidy label/value pairs instead of a ragged wrap. */
  .filter-bar { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px 12px; align-items: center; }
  .filter-bar > .btn { grid-column: 1 / -1; justify-self: start; }
  .ts-value { font-size: 17px; }
  .form-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .cat-label { min-width: 90px; }
  .analysis-grid { grid-template-columns: minmax(0, 1fr); }
  .section-title { font-size: 26px; }

  /* Debt meta: stack APR and min payment */
  .debt-meta-grid { grid-template-columns: 1fr; }

  /* Loan items: wrap paid/delete buttons below name */
  .loan-item { flex-wrap: wrap; }
  .loan-item > div:first-child { flex: 1 1 100%; }

  /* Filter bar: full-width selects */
  .filter-bar select,
  .filter-bar input[type="date"] { flex: 1; min-width: 120px; }

  /* Transaction items: tighten on small screens */
  .txn-amount { font-size: 14px; }
  .txn-actions { gap: 2px; }

  /* Manage accounts item: wrap group badge to new line */
  .acct-mgmt-item { flex-wrap: wrap; }
  .acct-mgmt-name { flex: 1 1 auto; min-width: 0; }

  /* 16px inputs: iOS zooms the page on anything smaller */
  .form-group input, .form-group select, .form-group textarea,
  .acct-input, .filter-bar select, .filter-bar input[type="date"],
  .things-filter-select, .wl-config-field input { font-size: 16px; }

  .card { padding: 16px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 18px; }
  .kpi-hero { padding: 20px; }
  .kpi-hero .kpi-value { font-size: 40px; }
  .kpi-row .kpi-value { font-size: 15px; }
}

@media (max-width: 360px) {
  .summary-grid { grid-template-columns: 1fr; }
  .tracker-summary { grid-template-columns: repeat(2, 1fr); }
  .kpi-hero .kpi-value { font-size: 34px; }
  [role="tab"] { font-size: 9.5px; }
}

/* ══ Everyday pack: add sheet, transactions by day, coming-up bills, backup ══ */
.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;
}
:root {
  --warn-bg: rgba(255,178,36,.10); --warn-border: rgba(255,178,36,.24); --warn-tile: rgba(255,178,36,.16);
  --warn-icon: #FFC25C; --warn-text: #FFD28A; --warn-text2: #D9BD8E;
}
body.light {
  --warn-bg: #FFF5E1; --warn-border: #F3DDB0; --warn-tile: #FDE7B8;
  --warn-icon: #8A5300; --warn-text: #6B4000; --warn-text2: #7A5A22;
}

/* Text buttons */
.btn-link {
  background: none; border: 0; padding: 0 4px; min-height: 44px;
  color: var(--accent-text); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.btn-link-muted { color: var(--muted); font-weight: 500; }
.btn-link-danger { color: var(--red); }

/* Chips: one-tap choices */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 0 14px; border-radius: 22px;
  border: 1px solid var(--border); background: var(--surf); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: var(--brig); }
.chip[aria-pressed="true"] {
  border: 1.5px solid var(--accent); background: var(--accent-soft); color: var(--accent-text); font-weight: 600;
}
.chip-more { border-style: dashed; background: transparent; color: var(--muted); }
.chip-more[aria-expanded="true"] { border-style: solid; color: var(--text); }

/* The + button: bottom right, above the phone tab bar */
.fab {
  position: fixed; right: 18px; bottom: calc(24px + var(--safe-bottom)); z-index: 60;
  width: 58px; height: 58px; border-radius: 29px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 8px 22px rgba(29,95,209,.32);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s;
}
.fab:active { transform: scale(.95); }
body:not([data-tab]) .fab,
body[data-tab="things"] .fab, body[data-tab="africa"] .fab,
body.sheet-open .fab { display: none; }
@media (max-width: 820px) { .fab { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); } }

/* Add / edit sheet */
body.sheet-open { overflow: hidden; }
.sheet-scrim { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.55); }
body.light .sheet-scrim { background: rgba(21,23,28,.38); }
.txn-sheet {
  position: fixed; z-index: 201; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(560px, 100%); max-height: calc(100dvh - 48px); overflow-y: auto; overscroll-behavior: contain;
  margin: 0; border-radius: 26px 26px 0 0;
  padding: 8px 20px calc(18px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-lg);
}
@media (min-width: 821px) {
  .txn-sheet { bottom: auto; top: 50%; transform: translate(-50%, -50%); border-radius: 24px; padding-bottom: 18px; max-height: calc(100dvh - 64px); }
  .sheet-handle { display: none; }
}
.sheet-handle { align-self: center; width: 38px; height: 5px; border-radius: 3px; background: var(--brig); flex-shrink: 0; }
.sheet-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.sheet-title #txn-form-label { font-size: 18px; font-weight: 700; letter-spacing: -.3px; color: var(--text); }
.sheet-close {
  width: 44px; height: 44px; border-radius: 22px; flex-shrink: 0; cursor: pointer;
  border: 1px solid var(--border); background: var(--surf); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.sheet-close:hover { color: var(--text); border-color: var(--brig); }
.seg {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px;
  padding: 4px; border-radius: 13px; background: var(--bg);
}
.seg button {
  min-height: 38px; border: 0; border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--muted); font: inherit; font-size: 14px; font-weight: 500;
}
.seg button[aria-checked="true"] { background: var(--surf); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
body.light .seg button[aria-checked="true"] { box-shadow: 0 1px 3px rgba(20,20,15,.12); }
.sheet-amount { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.sheet-amount label { font-size: 13px; font-weight: 500; color: var(--muted); }
.sheet-amount-row { display: flex; align-items: baseline; justify-content: center; gap: 2px; }
.sheet-amount-row span { font-size: 28px; font-weight: 600; color: var(--muted); }
.sheet-amount-row input {
  width: 9ch; border: 0; background: transparent; color: var(--text); outline: none;
  font: inherit; font-size: 42px; font-weight: 700; letter-spacing: -1.3px; line-height: 1.15;
  font-variant-numeric: tabular-nums; padding: 0; -moz-appearance: textfield; appearance: textfield;
}
.sheet-amount-row input::-webkit-outer-spin-button,
.sheet-amount-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.sheet-amount-row input::placeholder { color: var(--faint); }
.sheet-field { display: flex; flex-direction: column; gap: 8px; }
.sheet-field > label, .sheet-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.txn-sheet .sheet-field input:not([type="hidden"]),
.txn-sheet .sheet-field select {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 13px;
  border: 1px solid var(--border); background: var(--surf2); color: var(--text);
  font: inherit; font-size: 16px; outline: none;
}
.txn-sheet .sheet-field input:focus,
.txn-sheet .sheet-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#txn-desc::-webkit-calendar-picker-indicator { display: none !important; }
.sheet-hint { margin: 0; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sheet-hint::before {
  content: ''; width: 14px; height: 14px; flex-shrink: 0; background: var(--green);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / contain no-repeat;
}
.sheet-save { min-height: 52px; border-radius: 15px; font-size: 16px; font-weight: 600; width: 100%; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: -6px; }

/* Transactions, grouped by day */
.txn-type-chips { margin: 0 0 14px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.txn-type-chips::-webkit-scrollbar { display: none; }
.txn-type-chips .chip { min-height: 40px; padding: 0 12px; font-size: 13.5px; flex-shrink: 0; }
.txn-type-chips .chip[aria-checked="true"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.txn-list { gap: 14px; }
.txn-day-head { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 6px; font-size: 13px; }
.txn-day-date { font-weight: 600; color: var(--text); }
.txn-day-total { color: var(--muted); font-variant-numeric: tabular-nums; }
.txn-day-card { background: var(--surf); border: 1px solid var(--border); border-radius: 18px; padding: 0 14px; }
.txn-day-card .txn-item {
  display: block; padding: 0; min-height: 0; background: transparent; border-radius: 0;
  border-bottom: 1px solid var(--hair);
}
.txn-day-card .txn-item:last-child { border-bottom: 0; }
.txn-day-card .txn-item:hover { background: transparent; }
.txn-row {
  width: 100%; min-height: 62px; display: flex; align-items: center; gap: 12px;
  border: 0; background: none; color: inherit; padding: 8px 0; text-align: left;
  font: inherit; cursor: pointer;
}
.txn-row:hover .txn-desc { text-decoration: underline; text-underline-offset: 3px; }
.txn-icon {
  width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0;
  background: var(--surf3); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.txn-icon--income   { background: var(--green-soft); color: var(--green); }
.txn-icon--transfer { background: var(--accent-soft); color: var(--accent-text); }
.txn-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.txn-row .txn-desc { font-size: 15px; font-weight: 600; }
.txn-row .txn-meta { font-size: 12.5px; color: var(--muted); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-row .txn-amount { font-size: 15px; font-weight: 600; color: var(--text); }
.txn-amount--income   { color: var(--green) !important; }
.txn-amount--transfer { color: var(--muted) !important; }

/* Coming up: bills you can mark paid */
.card-title > .bills-due-total { font-size: 13px !important; }
.bills-due-total b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.bill-row { display: flex; align-items: center; gap: 10px; min-height: 64px; border-top: 1px solid var(--hair); padding: 8px 0; }
.bills-list > .bill-row:first-child { border-top: 0; }
.bill-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.bill-row .bill-name { font-size: 15px; font-weight: 600; }
.bill-row .bill-meta { font-size: 12.5px; color: var(--muted); }
.bill-row .bill-amount { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bill-row--soon .bill-meta { color: var(--gold); }
.bill-row--overdue .bill-meta { color: var(--red); font-weight: 600; }
.bill-row--paid .bill-name, .bill-row--paid .bill-amount { color: var(--muted); }
.bill-paid-text { color: var(--green); font-weight: 600; }
.bill-pay {
  min-height: 44px; padding: 0 14px; border-radius: 22px; cursor: pointer; flex-shrink: 0;
  border: 1.5px solid var(--accent); background: var(--surf); color: var(--accent-text);
  font: inherit; font-size: 14px; font-weight: 600;
}
.bill-pay:hover { background: var(--accent-soft); }
.bill-paid-badge {
  width: 28px; height: 28px; border-radius: 14px; flex-shrink: 0;
  background: var(--green-soft); color: var(--green);
  display: inline-flex; align-items: center; justify-content: center;
}
.bill-del {
  width: 44px; height: 44px; border-radius: 22px; flex-shrink: 0; cursor: pointer;
  border: 1px solid var(--border); background: var(--surf); color: var(--red);
  display: inline-flex; align-items: center; justify-content: center;
}
.bills-empty { margin: 0; font-size: 14px; color: var(--muted); }
.bills-foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Backup warning and status */
.backup-banner {
  display: flex; gap: 12px; padding: 14px; margin: 0 0 16px; border-radius: 18px;
  background: var(--warn-bg); border: 1px solid var(--warn-border);
}
.backup-banner-icon {
  width: 36px; height: 36px; border-radius: 11px; flex-shrink: 0;
  background: var(--warn-tile); color: var(--warn-icon);
  display: inline-flex; align-items: center; justify-content: center;
}
.backup-banner-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.backup-banner-title { font-size: 15px; font-weight: 600; color: var(--warn-text); }
.backup-banner-text { font-size: 13px; color: var(--warn-text2); }
.backup-banner-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 10px; }
.backup-status-line { margin: 0 0 12px; font-size: 13px; color: var(--muted); }

/* Toast with an Undo action, above the phone tab bar */
.action-toast {
  position: fixed; z-index: 9998; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + var(--safe-bottom)); width: min(460px, calc(100vw - 32px));
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; border-radius: 16px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg);
  font-size: 13.5px; line-height: 1.35;
}
.action-toast span { flex: 1; }
.action-toast button {
  min-height: 44px; padding: 0 14px; border: 0; border-radius: 12px; cursor: pointer;
  background: transparent; color: var(--accent); font: inherit; font-weight: 700;
}
body:not(.light) .action-toast button { color: #1D5FD1; }
body.light .action-toast button { color: #9DBDFF; }
@media (max-width: 820px) { .action-toast { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px); } }

/* ══ Safe to spend until payday (slot between net worth and the account list) ══ */
.safe-card {
  background: var(--surf); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; gap: 6px;
}
.safe-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.safe-title { font-size: 15px; font-weight: 700; color: var(--text); }
.safe-until { font-size: 13px; color: var(--muted); }
.safe-amount { font-size: 40px; font-weight: 700; letter-spacing: -1.4px; line-height: 1.1; font-variant-numeric: tabular-nums; margin-top: 4px; }
.safe-amount .kpi-cents { font-size: .55em; font-weight: 600; letter-spacing: -.4px; color: var(--muted); }
.safe-amount--short, .safe-amount--short .kpi-cents { color: var(--red); }
.safe-sub { font-size: 13.5px; color: var(--muted); }
.safe-sub--short { color: var(--red); font-weight: 600; }
.safe-bar { display: flex; gap: 3px; height: 10px; margin: 8px 0 2px; }
.safe-seg { background: var(--brig); border-radius: 2px; min-width: 3px; }
.safe-seg:first-child { border-radius: 5px 2px 2px 5px; }
.safe-seg:last-child { border-radius: 2px 5px 5px 2px; }
.safe-seg:only-child { border-radius: 5px; }
.safe-seg--free { background: var(--accent); }
.safe-rows { display: flex; flex-direction: column; margin-top: 8px; border-top: 1px solid var(--hair); }
.safe-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 32px; font-size: 13.5px; }
.safe-row span:first-child { color: var(--muted); min-width: 0; }
.safe-row span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text); }
.safe-row:first-child span:last-child { font-weight: 600; }
.safe-note, .safe-setup { margin: 4px 0 0; font-size: 12px; line-height: 1.4; color: var(--muted); }
.safe-setup { font-size: 14px; }
@media (min-width: 821px) {
  #account-kpis { grid-template-areas: "hero list" "safe list"; }
  #account-kpis > .kpi-hero { grid-area: hero; }
  #account-kpis > .kpi-list { grid-area: list; }
  #account-kpis > .safe-card { grid-area: safe; }
}
