/* Personal Finance — design system
   Calm, ledger-like: warm paper background, deep green accent,
   tabular numbers everywhere money appears. Light + dark themes. */

:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --border: #e3e1d8;
  --text: #1d2420;
  --muted: #69716b;
  --faint: #9aa29b;
  --accent: #1f6b47;
  --accent-strong: #17583a;
  --accent-soft: #e2efe7;
  --on-accent: #ffffff;
  --danger: #b4382e;
  --danger-soft: #f9e6e3;
  --warn: #9a5b12;
  --warn-soft: #fbefdc;
  --good: #1f7a4d;
  --bad: #b4382e;
  --track: #e9e7df;
  --shadow: 0 1px 2px rgb(29 36 32 / 5%), 0 4px 16px rgb(29 36 32 / 5%);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar: 248px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #191e1b;
    --surface-2: #212724;
    --border: #2c3430;
    --text: #e8ece9;
    --muted: #9ba59f;
    --faint: #6d7771;
    --accent: #5cc08d;
    --accent-strong: #79d3a4;
    --accent-soft: #1f3a2c;
    --on-accent: #0d1a13;
    --danger: #ef7a6e;
    --danger-soft: #3a1f1c;
    --warn: #e7b062;
    --warn-soft: #362a17;
    --good: #5cc08d;
    --bad: #ef7a6e;
    --track: #2a312d;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 12px; }

.num, .money, .amount, .stat-value, td.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ------------------------------------------------------------ layout */

.app {
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 18px;
  font-weight: 750;
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent);
  color: var(--on-accent);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 560;
  text-decoration: none;
}

.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar .spacer { flex: 1; }
.sidebar form { margin: 0; }
.sidebar .nav-link.as-button {
  width: 100%; justify-content: flex-start; background: none; border: 0;
  color: var(--muted); font: inherit; font-weight: 560; cursor: pointer;
}
.sidebar .nav-link.as-button:hover { background: var(--surface-2); color: var(--text); }
.sidebar .btn { margin: 6px 4px 14px; }

.main {
  margin-left: var(--sidebar);
  padding: 28px 32px 48px;
}

.container { max-width: 1180px; margin: 0 auto; }

.topbar { display: none; }
.tabbar { display: none; }

@media (max-width: 899px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 12px 14px calc(96px + env(safe-area-inset-bottom)); }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 15;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  .topbar .brand { padding: 0; }
  .icon-button {
    width: 42px; height: 42px; display: grid; place-items: center;
    border-radius: 12px; color: var(--muted); background: var(--surface);
    border: 1px solid var(--border);
  }
  .icon-button svg { width: 20px; height: 20px; }

  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    inset: auto 0 0 0;
    z-index: 20;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .tab {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 0; font-size: 11px; font-weight: 600;
    color: var(--muted); text-decoration: none;
  }
  .tab svg { width: 22px; height: 22px; }
  .tab.active { color: var(--accent); }
  .tab-add {
    align-self: center; justify-self: center;
    width: 52px; height: 52px; margin-top: -22px;
    border-radius: 18px; display: grid; place-items: center;
    background: var(--accent); color: var(--on-accent);
    box-shadow: 0 6px 18px rgb(31 107 71 / 35%);
  }
  .tab-add svg { width: 26px; height: 26px; }
}

/* -------------------------------------------------------- page header */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 22px;
}
.page-head p { margin: 4px 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 12px;
  gap: 2px;
  margin-bottom: 18px;
}
.segmented a {
  padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: 14px;
  color: var(--muted); text-decoration: none;
}
.segmented a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.card-head a { font-size: 14px; font-weight: 600; text-decoration: none; }
.card-foot { margin-top: 14px; font-size: 14px; }
.card-foot a { font-weight: 600; text-decoration: none; }

.grid { display: grid; gap: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.stack { display: grid; gap: 16px; align-content: start; }
.stack > .card + .card { margin-top: 0; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 16px; border-radius: 14px; }
}
@media (max-width: 420px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
}

/* ---------------------------------------------------------- stat tiles */

.stat { padding: 16px 18px; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 560; }
.stat-value { font-size: 26px; font-weight: 720; letter-spacing: -0.02em; margin-top: 4px; }
.stat-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.stat-hero .stat-value { font-size: 34px; }
@media (max-width: 420px) {
  .stat { padding: 13px 14px; }
  .stat-value { font-size: 20px; }
}

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 650;
  background: var(--surface-2); color: var(--muted);
}
.pill.up { background: var(--danger-soft); color: var(--bad); }       /* spending up = bad */
.pill.down { background: var(--accent-soft); color: var(--good); }
.pill.gain { background: var(--accent-soft); color: var(--good); }
.pill.loss { background: var(--danger-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

/* ------------------------------------------------------------ buttons */

.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 9px 16px;
  border-radius: 11px; border: 1px solid transparent;
  background: var(--accent); color: var(--on-accent);
  font: inherit; font-weight: 640; text-decoration: none; cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover, button:hover { background: var(--accent-strong); }
.btn:active, button:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; }
.btn-secondary {
  background: var(--surface); color: var(--text); border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--accent); padding-inline: 10px; }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, black); }
.btn-small { min-height: 34px; padding: 5px 11px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; }
button:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: progress; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* ------------------------------------------------------------- forms */

.form-card { max-width: 620px; margin: 0 auto; }
.field { margin-bottom: 16px; }
.field label, .field-label {
  display: block; margin-bottom: 6px; font-size: 14px; font-weight: 620;
}
.field .help { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 520px) { .field-row { grid-template-columns: minmax(0, 1fr); } }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* stops iOS zooming into fields */
}
input[type="checkbox"] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--accent); }
.checkbox-field { display: flex; align-items: center; gap: 10px; }
.checkbox-field label { margin: 0; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
select:disabled { opacity: .6; }
.amount-input { font-size: 28px !important; font-weight: 700; min-height: 60px; font-variant-numeric: tabular-nums; }
.errorlist { list-style: none; margin: 6px 0 0; padding: 0; color: var(--danger); font-size: 13px; font-weight: 560; }
.errorlist.nonfield { padding: 10px 12px; background: var(--danger-soft); border-radius: 10px; margin-bottom: 14px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 8px; }
details summary { cursor: pointer; font-weight: 600; color: var(--accent); margin: 6px 0 12px; }

.filters {
  display: grid;
  grid-template-columns: minmax(0, 2fr) repeat(5, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}
.filters .field { margin: 0; }
.filters label { font-size: 12px; color: var(--muted); }
@media (max-width: 1100px) { .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); } .filters .search { grid-column: 1 / -1; } }
@media (max-width: 560px) { .filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

/* ---------------------------------------------------------- messages */

.messages { display: grid; gap: 8px; margin-bottom: 18px; }
.message {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent-strong); font-weight: 560;
}
.message.error { background: var(--danger-soft); color: var(--danger); }
.message.warning, .notice { background: var(--warn-soft); color: var(--warn); }
.notice { padding: 11px 14px; border-radius: 12px; font-size: 14px; font-weight: 560; margin-bottom: 14px; }
.notice a { color: inherit; font-weight: 700; }

/* --------------------------------------------------------------- bars */

.bar { height: 8px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.bar.thick { height: 12px; }
.bar .mid { background: #d08a2c; }
.bar .high { background: var(--danger); }

/* --------------------------------------------------------- list rows */

.list { margin: 0; padding: 0; list-style: none; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
  min-width: 0;
}
.list > .row:last-child, .row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-end { text-align: right; flex-shrink: 0; }
.row-amount { font-weight: 680; font-variant-numeric: tabular-nums; }
button.row {
  width: 100%; background: none; color: inherit; border: 0;
  border-bottom: 1px solid var(--border); border-radius: 0;
  font: inherit; font-weight: inherit; text-align: left; min-height: 0;
}
button.row:hover { background: var(--surface-2); }

.dot {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff;
}
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

.day-group + .day-group { margin-top: 6px; }
.day-head {
  display: flex; justify-content: space-between;
  padding: 14px 0 6px; font-size: 13px; font-weight: 650; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.future-tag { color: var(--warn); }

/* ------------------------------------------------------------- charts */

.donut-wrap { display: grid; grid-template-columns: 168px minmax(0, 1fr); gap: 22px; align-items: center; }
.donut {
  width: 168px; aspect-ratio: 1; border-radius: 50%;
  position: relative;
}
.donut::after {
  content: ""; position: absolute; inset: 24px; border-radius: 50%; background: var(--surface);
}
.donut-center {
  position: absolute; inset: 0; z-index: 1;
  display: grid; place-content: center; text-align: center;
}
.donut-center strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.donut-center span { font-size: 12px; color: var(--muted); }
@media (max-width: 560px) {
  .donut-wrap { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .donut-wrap > div:last-child { width: 100%; }
}

.cat-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 9px 0; }
.cat-row .bar { grid-column: 1 / -1; height: 6px; }
.cat-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 580; }
.cat-name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.trend {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  align-items: end; gap: 6px; height: 150px; padding-top: 8px;
}
.trend a {
  height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600;
}
.trend .col {
  width: 100%; max-width: 34px; border-radius: 6px 6px 3px 3px;
  background: color-mix(in srgb, var(--accent) 30%, var(--track)); min-height: 3px;
}
.trend a.selected .col { background: var(--accent); }
.trend a.selected { color: var(--text); }
.trend a:hover .col { background: color-mix(in srgb, var(--accent) 70%, var(--track)); }

/* ---------------------------------------------------- month switcher */

.month-switch { display: flex; align-items: center; gap: 6px; }
.month-switch .label { font-weight: 680; min-width: 128px; text-align: center; }
.month-switch a {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); text-decoration: none;
}
.month-switch a:hover { background: var(--surface-2); }

/* --------------------------------------------------------- data table */

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; }
.ticker { font-weight: 750; letter-spacing: .02em; }

/* ------------------------------------------------- holdings (mobile) */

.holding-card { display: none; }
@media (max-width: 760px) {
  .holdings-table { display: none; }
  .holding-card { display: block; padding: 14px 0; border-bottom: 1px solid var(--border); }
  .holding-card:last-child { border-bottom: 0; }
  .holding-top { display: flex; justify-content: space-between; gap: 12px; }
  .holding-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; font-size: 13px; }
  .holding-meta span { display: block; color: var(--muted); font-size: 12px; }
}

/* ------------------------------------------------- credit card tiles */

.cc-tile { display: grid; gap: 10px; }
.cc-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.cc-name { font-weight: 700; font-size: 16px; }
.cc-figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; font-size: 13px; }
.cc-figures span { display: block; color: var(--muted); font-size: 12px; }
.cc-figures strong { font-variant-numeric: tabular-nums; }
.cc-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* --------------------------------------------------- dialogs (sheets) */

dialog.sheet {
  width: min(720px, calc(100% - 24px));
  max-height: 88vh; max-height: 88dvh;
  padding: 0; border: 0; border-radius: 20px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 25%);
  overflow: hidden;
}
dialog.sheet::backdrop { background: rgb(10 14 12 / 50%); }
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .18s ease-out; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.sheet-body { padding: 18px 20px 22px; overflow-y: auto; overscroll-behavior: contain; }
.sheet-close {
  width: 36px; height: 36px; min-height: 36px; padding: 0; border-radius: 10px;
  background: var(--surface-2); color: var(--text); font-size: 22px; line-height: 1;
}
.sheet-close:hover { background: var(--track); }
@media (max-width: 640px) {
  dialog.sheet {
    width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0;
    max-height: 92dvh;
  }
  dialog.sheet[open] { animation: sheet-up .22s ease-out; }
}
@keyframes sheet-in { from { opacity: 0; transform: scale(.98); } }
@keyframes sheet-up { from { transform: translateY(30px); opacity: .6; } }

.detail-list { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.detail-list dt, .detail-list dd { padding: 10px 0; border-bottom: 1px solid var(--border); margin: 0; }
.detail-list dt { color: var(--muted); font-size: 14px; }
.detail-list dd { overflow-wrap: anywhere; white-space: pre-wrap; }

.hist-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) 92px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.hist-row strong { text-align: right; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------- misc / empty */

.empty {
  text-align: center; padding: 28px 12px; color: var(--muted);
}
.empty strong { display: block; color: var(--text); margin-bottom: 4px; font-size: 16px; }

.pagination { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 16px; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 26px 0 10px; }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px;
  border-radius: 99px; background: var(--surface-2); font-size: 13px; color: var(--text);
  text-decoration: none; border: 1px solid var(--border);
}
.tag:hover { border-color: var(--accent); }
.tag.archived { opacity: .55; text-decoration: line-through; }

.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(420px, 100%); }
.auth-card .brand { justify-content: center; padding-bottom: 8px; }

.progress-ring-label { font-size: 13px; color: var(--muted); }

.activity-filters { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 4px; }
@media (max-width: 560px) { .activity-filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .activity-filters .field:first-child { grid-column: 1 / -1; } }
tfoot td { border-top: 1px solid var(--border); border-bottom: 0; }

/* budget */
.budget-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.budget-bar { position: relative; overflow: visible; }
.budget-bar > span { max-width: 100%; }
.budget-bar .pace { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); opacity: .55; border-radius: 2px; }
.budget-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
@media (max-width: 520px) { .budget-grid { grid-template-columns: minmax(0, 1fr); } }

/* SVG donut with hover labels */
.donut-svg { position: relative; width: 168px; aspect-ratio: 1; }
.donut-svg svg { width: 100%; height: 100%; display: block; overflow: visible; }
.donut-svg path { cursor: pointer; transition: opacity .15s, transform .15s; transform-origin: 50px 50px; outline: none; }
.donut-svg.hovering path:not(.active) { opacity: .35; }
.donut-svg path.active { transform: scale(1.04); }
.donut-svg .donut-center { position: absolute; inset: 22%; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-svg .donut-center strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.donut-svg .donut-center span { font-size: 11px; color: var(--muted); line-height: 1.25; max-width: 92px; margin: 0 auto; }
.donut-tip {
  position: absolute; z-index: 5; transform: translate(-50%, calc(-100% - 12px)); pointer-events: none;
  padding: 5px 9px; border-radius: 8px; background: var(--text); color: var(--bg);
  font-size: 12px; font-weight: 650; white-space: nowrap; box-shadow: var(--shadow);
}
.month-select {
  width: auto; min-height: 36px; padding: 6px 30px 6px 12px; font-weight: 680; font-size: 15px;
  border-radius: 10px; background-color: var(--surface);
}
.budget-month-picker { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.budget-row { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, .8fr) minmax(0, 1.5fr) auto; gap: 8px; margin-bottom: 8px; }
.budget-head { margin-bottom: 4px; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.budget-head > span:last-child { width: 44px; }
/* Phones: line + amount on top, the note full-width underneath. */
@media (max-width: 600px) {
  .budget-row { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; row-gap: 6px; padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
  .budget-row .budget-note { grid-column: 1 / 3; grid-row: 2; }
  .budget-row .remove-row { grid-row: 1; grid-column: 3; }
  .budget-head { border-bottom: 0; padding-bottom: 0; }
  .budget-head .budget-note { display: none; }
}
.budget-month-nav { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: stretch; margin: 10px 0 14px; }
.month-step { min-width: 48px; padding: 0 12px; display: grid; place-items: center; }
.month-current { position: relative; display: grid; place-items: center; min-height: 48px; margin: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
.month-current-name { font-weight: 700; font-size: 16px; pointer-events: none; }
.month-current input[type="month"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.budget-line-note { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 1px; }
.sheet-tx-list .row { width: 100%; text-align: left; }
.purchase-list .row { padding: 8px 0; }
.budget-row .remove-row { min-height: 44px; padding: 0 12px; font-size: 20px; color: var(--muted); }
.tag.active-tag { border-color: var(--accent); color: var(--accent); font-weight: 650; }
.sort-select { width: auto; }
.sort-label { margin: 0 0 0 auto; font-size: 13px; color: var(--muted); font-weight: 600; align-self: center; }
@media (max-width: 560px) { .sort-label { margin-left: 0; } .sort-select { flex: 1; } }
.asset-card .cc-top { align-items: flex-start; }

/* =================================================================
   Additions for the Google Drive edition (server-less app)
   ================================================================= */

button.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
button.link:hover { background: none; text-decoration: underline; }
.month-switch button {
  width: 36px; height: 36px; min-height: 36px; padding: 0; display: grid; place-items: center;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.month-switch button:hover { background: var(--surface-2); }
.icon-button { cursor: pointer; }
.topbar-end { display: flex; align-items: center; gap: 8px; min-width: 0; }

/* sync status chip (top bar on phones, sidebar on desktop) */
.sync-chip {
  display: inline-flex; align-items: center; gap: 7px; min-width: 0; max-width: 100%;
  min-height: 34px; padding: 0 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--muted);
  font: 600 12.5px var(--font); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.sync-chip:hover { background: var(--surface-2); }
.sync-chip::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.sync-chip[data-state="ok"]::before { background: var(--good); }
.sync-chip[data-state="busy"]::before { background: var(--accent); animation: chip-pulse 1s infinite alternate; }
.sync-chip[data-state="attention"] { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.sync-chip[data-state="attention"]::before { background: var(--warn); }
.sync-chip[data-state="error"] { color: var(--danger); }
.sync-chip[data-state="error"]::before { background: var(--danger); }
@keyframes chip-pulse { to { opacity: .3; } }
.sidebar .sync-chip { margin: 0 4px 8px; justify-content: flex-start; }
@media (max-width: 899px) { .topbar .sync-chip { max-width: 52vw; } }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60;
  transform: translateX(-50%); max-width: min(560px, calc(100% - 32px));
  padding: 11px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-weight: 600; box-shadow: var(--shadow); text-align: center;
}
.toast[data-kind="error"] { background: var(--danger); color: #fff; }
@media (max-width: 899px) { .toast { bottom: calc(92px + env(safe-area-inset-bottom)); } }

.diag { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.diag dt { color: var(--muted); }
.diag dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.preview-box { margin: 16px 0; box-shadow: none; background: var(--surface-2); }
.trend button {
  height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px;
  padding: 0; min-height: 0; border: 0; background: none; border-radius: 0;
  color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer;
}
.trend button:hover { background: none; }
.trend button.selected .col { background: var(--accent); }
.trend button.selected { color: var(--text); }
.trend button:hover .col { background: color-mix(in srgb, var(--accent) 70%, var(--track)); }
.show-more { display: flex; justify-content: center; margin-top: 14px; }
.file-button { position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.empty-hero { text-align: center; padding: 36px 16px; }
.empty-hero h2 { margin-bottom: 8px; }
.empty-hero .form-actions { justify-content: center; margin-top: 16px; }
.boot { display: grid; place-items: center; min-height: 40vh; color: var(--muted); }

/* earnings */
@media (max-width: 899px) { .tabbar { grid-template-columns: repeat(5, 1fr); } }
.trend.dual .pair { display: flex; align-items: flex-end; justify-content: center; gap: 2px; width: 100%; height: 100%; }
.trend.dual .col { max-width: 15px; flex: 1; }
.trend.dual .col.earned { background: color-mix(in srgb, var(--accent) 45%, var(--track)); }
.trend.dual .col.spent { background: color-mix(in srgb, #d08a2c 40%, var(--track)); }
.trend.dual a.selected .col.earned { background: var(--accent); }
.trend.dual a.selected .col.spent { background: #d08a2c; }
.trend.dual a:hover .col { filter: brightness(.92); }
.legend { display: inline-flex; gap: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.earnings-filters { grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)); margin-bottom: 4px; }
@media (max-width: 1100px) { .earnings-filters { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .earnings-filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.cashflow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cashflow span { display: block; color: var(--muted); font-size: 12px; }
.cashflow strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.site-links { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; }

/* public pages: about / privacy / terms */
.site-page { min-height: 100vh; display: flex; flex-direction: column; }
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 1080px; width: 100%; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 20px 8px; }
.site-header .brand { padding: 0; }
.site-logo { border-radius: 9px; }
.site-nav { display: flex; align-items: center; gap: 4px 16px; flex-wrap: wrap; font-weight: 600; font-size: 14px; }
.site-nav a:not(.btn) { color: var(--muted); text-decoration: none; }
.site-nav a:not(.btn):hover { color: var(--text); }
.site-main { flex: 1; max-width: 1080px; width: 100%; margin: 0 auto; padding: 12px 20px 40px; }
.site-hero { text-align: center; padding: 36px 0 20px; }
.site-hero-logo { border-radius: 22px; box-shadow: var(--shadow); margin-bottom: 18px; }
.site-hero h1 { font-size: clamp(30px, 5vw, 46px); letter-spacing: -0.03em; margin-bottom: 14px; }
.site-lead { max-width: 680px; margin: 0 auto 22px; font-size: 17px; color: var(--muted); }
.site-section { margin-top: 44px; }
.site-section > h2 { font-size: 24px; margin-bottom: 12px; }
.site-features h3, .site-section .card h3 { margin-bottom: 6px; }
.site-features p { margin: 0; }
.site-steps { margin: 8px 0 0; padding-left: 20px; }
.site-steps li { margin-bottom: 6px; }
.site-doc { max-width: 760px; }
.site-doc h1 { font-size: 32px; margin: 18px 0 4px; }
.site-doc h2 { font-size: 19px; margin: 28px 0 8px; }
.site-doc li { margin-bottom: 6px; }
.site-doc code { font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
.site-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px;
  max-width: 1080px; width: 100%; margin: 0 auto; padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }

/* quick add (+) on the title row — phones only; desktop has the sidebar button */
.head-add { display: none; }
@media (max-width: 899px) {
  .page-head.has-add { position: relative; }
  .page-head.has-add > div:first-child { padding-right: 64px; }
  .head-add {
    display: grid; place-items: center; position: absolute; top: 0; right: 0;
    width: 52px; height: 52px; min-height: 52px; padding: 0; border-radius: 16px;
    background: var(--accent); color: var(--on-accent);
    box-shadow: 0 6px 18px rgb(31 107 71 / 30%);
  }
}
.quick-add .row { color: inherit; text-decoration: none; }
.quick-add .row:hover { background: var(--surface-2); }
.quick-icon { background: var(--accent-soft); color: var(--accent); border-radius: 12px; width: 40px; height: 40px; }

/* ---------- Install guide (about.html#install): tabs + illustrated steps */
:root { --hl: #e8590c; }
@media (prefers-color-scheme: dark) { :root { --hl: #ff8f4d; } }
.install-first { margin: 4px 0 18px; line-height: 1.55; }
.install-first code { font-size: 13px; background: var(--surface); padding: 1px 6px; border-radius: 5px; overflow-wrap: anywhere; }
.install-tabs { display: none; }
.install-js .install-tabs { display: flex; gap: 6px; padding: 4px; margin-bottom: 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; width: fit-content; max-width: 100%; }
.install-tabs button { appearance: none; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 650; font-size: 14px; padding: 9px 16px; border-radius: 10px; cursor: pointer; min-height: 40px; }
.install-tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.install-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.install-panel + .install-panel { margin-top: 16px; }
.install-js .install-panel + .install-panel { margin-top: 0; }
.install-panel > h3 { margin-bottom: 14px; }
.install-steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
#panel-android .install-steps { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 760px; }
@media (max-width: 760px) { .install-steps, #panel-android .install-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; } }
.install-step { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.install-step figcaption { display: flex; gap: 9px; align-items: flex-start; font-size: 14px; line-height: 1.45; }
.install-num { flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--hl); color: #fff; font-weight: 700; font-size: 13px; }
.install-step-wide { max-width: 640px; }
.install-tips { display: grid; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 14px; line-height: 1.55; color: var(--muted); }
.install-tips strong { color: var(--text); }

/* Mockup drawings */
.mk { display: block; width: 100%; max-width: 210px; height: auto; margin: 0 auto; font-family: var(--font); }
.mk-wide { max-width: 640px; }
.mk-frame { fill: var(--text); opacity: .88; }
.mk-screen, .mk-screen-tab { fill: var(--bg); }
.mk-card { fill: var(--surface); stroke: var(--border); }
.mk-card-fill { fill: var(--surface); }
.mk-sheet { fill: var(--surface); stroke: var(--border); }
.mk-pop { filter: drop-shadow(0 6px 14px rgb(0 0 0 / 18%)); }
.mk-glass, .mk-chrome { fill: var(--surface-2); stroke: var(--border); }
.mk-chrome { stroke: none; }
.mk-accent { fill: var(--accent); }
.mk-on-accent { fill: none; stroke: var(--on-accent); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.mk-ink { fill: var(--text); opacity: .75; }
.mk-soft, .mk-soft-c { fill: var(--track); }
.mk-track { fill: var(--track); }
.mk-dim { fill: #000; opacity: .28; }
.mk-sep { stroke: var(--border); }
.mk-stroke, .mk-icon { fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mk-dots circle { fill: var(--text); }
.mk-url { font-size: 8.5px; fill: var(--muted); }
.mk-row { font-size: 9.5px; fill: var(--text); }
.mk-row-b { font-size: 10.5px; font-weight: 700; fill: var(--text); }
.mk-sub { font-size: 8px; fill: var(--muted); }
.mk-link { font-size: 10px; fill: var(--accent); }
.mk-link-b { font-size: 10.5px; font-weight: 700; fill: var(--accent); }
.mk-btn-t { font-size: 9.5px; font-weight: 700; fill: var(--on-accent); }
.mk-knob { fill: #fff; }
.mk-tabs { fill: none; stroke: var(--text); stroke-width: 1.5; }
.mk-tabs-t { font-size: 8px; font-weight: 700; fill: var(--text); }
.mk-hl { fill: none; stroke: var(--hl); stroke-width: 3; }
.mk-tap { fill: var(--hl); opacity: .35; stroke: var(--hl); stroke-width: 1.5; }
.mk-badge { fill: var(--hl); }
.mk-badge-t { font-size: 12px; font-weight: 700; fill: #fff; }
.mk-dot-r { fill: #ec6a5e; } .mk-dot-y { fill: #f4bf4f; } .mk-dot-g { fill: #61c554; }
.budget-card-head { flex-wrap: wrap; gap: 6px 10px; }
.budget-card-head h2 { margin-right: auto; }
.budget-card-nav { display: flex; align-items: center; gap: 4px; font-weight: 650; font-size: 14px; }
.budget-card-nav .icon-button { width: 34px; height: 34px; min-height: 34px; }
.budget-card-nav span { min-width: 118px; text-align: center; }
.budget-card-nav .link { margin-left: 4px; }
@media (max-width: 560px) { .budget-card-nav { order: 3; width: 100%; justify-content: center; } }
.budget-card-nav .icon-button { display: grid; place-items: center; padding: 0; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; box-shadow: none; }
.budget-card-nav .icon-button:hover { background: var(--surface-2); }
.budget-card-nav .icon-button svg { width: 18px; height: 18px; }
.budget-card-nav .link { background: none; border: 0; padding: 0; min-height: 0; color: var(--accent); font-weight: 650; box-shadow: none; }
.loan-stats { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 14px 28px; }
.loan-stats > div:last-child { text-align: right; }
@media (max-width: 560px) { .loan-stats > div:last-child { text-align: left; } .loan-stats .stat-value { font-size: 28px !important; } }

/* Earnings: deposit split rows */
.deposits { display: grid; gap: 8px; margin-bottom: 8px; }
.deposit-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.deposit-row [name=depAmount], .deposit-row .remove-row { display: none; }
.deposits.is-split .deposit-row { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; }
.deposits.is-split .deposit-row [name=depAmount] { display: block; }
.deposits.is-split .deposit-row .remove-row { display: block; min-height: 44px; padding: 0 12px; font-size: 20px; color: var(--muted); }
.deposit-row [name=depNew] { grid-column: 1 / -1; }
/* Assets: linked accounts */
.check-list { display: grid; gap: 4px; }
.check-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-weight: 500; cursor: pointer; margin: 0; }
.check-item input { width: 18px; height: 18px; flex: none; }
.flow-line { margin-top: 2px; color: var(--muted); }

/* Budget: paid marks */
.budget-line-end { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.paid-toggle { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: inherit; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; cursor: pointer; min-height: 26px; box-shadow: none; }
.paid-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--surface); }
.paid-toggle.is-paid { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.budget-row { grid-template-columns: minmax(0, 1.3fr) minmax(0, .8fr) minmax(0, 1.5fr) auto auto; }
.budget-paid { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.budget-paid input { width: 18px; height: 18px; }
.budget-head .budget-paid { font-size: 12px; }
@media (max-width: 600px) {
  .budget-row { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; }
  .budget-row .budget-note { grid-column: 1 / 2; grid-row: 2; }
  .budget-row .budget-paid { grid-column: 2 / 3; grid-row: 2; }
  .budget-head .budget-paid { display: none; }
}
.filter-total { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; background: var(--accent-soft); border-color: transparent; }
.filter-total .stat-value { color: var(--accent-strong); }

/* Investments: value chart (Robinhood-style) */
.history-card { --line: var(--muted); }
.history-card.up { --line: var(--good); }
.history-card.down { --line: var(--bad); }
.history-value { font-size: 30px; font-weight: 750; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.history-change { font-size: 14px; font-weight: 600; margin-top: 2px; min-height: 20px; }
.history-chart { position: relative; height: 190px; margin: 14px 0 8px; touch-action: pan-y; }
.history-chart svg { display: block; width: 100%; height: 100%; overflow: visible; cursor: crosshair; }
.history-line { fill: none; stroke: var(--line); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.history-base { stroke: var(--faint); stroke-width: 1; stroke-dasharray: 2 5; vector-effect: non-scaling-stroke; }
.history-cursor { stroke: var(--faint); stroke-width: 1; }
.history-dot { position: absolute; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; border-radius: 50%; background: var(--line); border: 2px solid var(--surface); pointer-events: none; }
.history-tip { position: absolute; top: -18px; transform: translateX(-50%); font-size: 11px; font-weight: 600; color: var(--muted); white-space: nowrap; pointer-events: none; }
.history-empty { height: 100%; display: grid; place-items: center; text-align: center; padding: 0 12px; color: var(--muted); font-size: 13px; line-height: 1.5; border: 1px dashed var(--border); border-radius: var(--radius-sm); }
.history-ranges { display: flex; gap: 2px; border-top: 1px solid var(--border); padding-top: 10px; overflow-x: auto; }
.history-ranges button { appearance: none; border: 0; background: none; box-shadow: none; color: var(--muted); font: inherit; font-size: 13px; font-weight: 700; padding: 6px 10px; min-height: 32px; border-radius: 8px; cursor: pointer; }
.history-ranges button:hover { background: var(--surface-2); color: var(--text); }
.history-ranges button[aria-pressed="true"] { color: var(--line); background: var(--surface-2); }
/* Crypto search */
.coin-results { margin-top: 6px; display: grid; }
.coin-results:empty { display: none; }
.coin-option { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; }
.coin-option img { border-radius: 50%; flex: none; }
.export-history { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.export-history > div { flex: 1 1 260px; }
