:root {
  color-scheme: light;
  --surface-1: #ffffff;
  --surface-2: #f6f7f5;
  --page: #f2f3f1;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e6e5e0;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.08);
  --shadow-sm: 0 1px 2px rgba(20, 20, 15, 0.05);
  --shadow-md: 0 6px 20px rgba(20, 20, 15, 0.07);
  /* Stewardly's brand accent, #1B3A44 -- accent-2/accent-track are derived
     from it with the exact same color-mix() formula the custom-accent
     picker uses (see :root[data-custom-accent] below), so the shipped
     default behaves like any other chosen accent, not a special case. */
  --accent: #1b3a44;
  --accent-2: color-mix(in srgb, #1b3a44 78%, white);
  --accent-track: color-mix(in srgb, #1b3a44 18%, white);
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-text: #b3261e;

  /* Cream companion to the brand accent, used in the logo mark -- fixed
     regardless of theme/accent, like dylan-color/lilly-color below. */
  --brand-cream: #faf9f6;

  /* categorical identity slots (dataviz palette, light) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  /* Dylan/Lilly's personal accent colors, for identifying "whose" data
     something is (e.g. an income source dot) regardless of which theme the
     current viewer has selected -- distinct from --accent, which follows
     the signed-in user's own theme choice. */
  --dylan-color: #841617;
  --lilly-color: #d6336c;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1c1c1a;
    --surface-2: #232320;
    --page: #121212;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8d86;
    --gridline: #313130;
    --baseline: #3a3a37;
    --border: rgba(255, 255, 255, 0.09);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.4);
    --accent: color-mix(in srgb, #1b3a44 82%, white);
    --accent-2: color-mix(in srgb, #1b3a44 62%, white);
    --accent-track: color-mix(in srgb, #1b3a44 32%, transparent);
    --good: #0ca30c;
    --good-text: #0ca30c;
    --warning: #fab219;
    --critical: #e66767;
    --critical-text: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --dylan-color: #c4272a;
    --lilly-color: #f0508a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1c1c1a;
  --surface-2: #232320;
  --page: #121212;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8d86;
  --gridline: #313130;
  --baseline: #3a3a37;
  --border: rgba(255, 255, 255, 0.09);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.4);
  --accent: color-mix(in srgb, #1b3a44 82%, white);
  --accent-2: color-mix(in srgb, #1b3a44 62%, white);
  --accent-track: color-mix(in srgb, #1b3a44 32%, transparent);
  --good: #0ca30c;
  --good-text: #0ca30c;
  --warning: #fab219;
  --critical: #e66767;
  --critical-text: #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --dylan-color: #c4272a;
  --lilly-color: #f0508a;
}

/* ---- Per-user accent themes -- light/dark toggle still works within each.
   Category colors (--series-*) and status colors (good/warning/critical)
   stay universal across users so shared data reads consistently. ---- */
:root[data-user-theme="dylan"] {
  --accent: #841617;
  --accent-2: #b23a3b;
  --accent-track: #f2d9d3;
}
:root[data-user-theme="dylan"][data-theme="dark"] {
  --accent: #c4272a;
  --accent-2: #e2645f;
  --accent-track: rgba(196, 39, 42, 0.28);
}
@media (prefers-color-scheme: dark) {
  :root[data-user-theme="dylan"]:where(:not([data-theme="light"])) {
    --accent: #c4272a;
    --accent-2: #e2645f;
    --accent-track: rgba(196, 39, 42, 0.28);
  }
}

:root[data-user-theme="lilly"] {
  --accent: #d6336c;
  --accent-2: #e8698f;
  --accent-track: #f6d3e6;
}
:root[data-user-theme="lilly"][data-theme="dark"] {
  --accent: #f0508a;
  --accent-2: #f58bab;
  --accent-track: rgba(240, 80, 138, 0.28);
}
@media (prefers-color-scheme: dark) {
  :root[data-user-theme="lilly"]:where(:not([data-theme="light"])) {
    --accent: #f0508a;
    --accent-2: #f58bab;
    --accent-track: rgba(240, 80, 138, 0.28);
  }
}

/* ---- User-chosen custom accent color (Admin > Appearance > Theme) --
   overrides both the plain default and the dylan/lilly presets above when
   set, since it's a deliberate per-browser choice. Only --custom-accent-base
   itself is set from JS (a plain hex); --accent-2/--accent-track derive from
   it via color-mix() so the light/dark toggle keeps working without any JS
   recomputation on theme change, the same way the hardcoded presets do. */
:root[data-custom-accent] {
  --accent: var(--custom-accent-base);
  --accent-2: color-mix(in srgb, var(--custom-accent-base) 78%, white);
  --accent-track: color-mix(in srgb, var(--custom-accent-base) 18%, white);
}
:root[data-custom-accent][data-theme="dark"] {
  --accent: color-mix(in srgb, var(--custom-accent-base) 82%, white);
  --accent-2: color-mix(in srgb, var(--custom-accent-base) 62%, white);
  --accent-track: color-mix(in srgb, var(--custom-accent-base) 32%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root[data-custom-accent]:where(:not([data-theme="light"])) {
    --accent: color-mix(in srgb, var(--custom-accent-base) 82%, white);
    --accent-2: color-mix(in srgb, var(--custom-accent-base) 62%, white);
    --accent-track: color-mix(in srgb, var(--custom-accent-base) 32%, transparent);
  }
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/inter/inter-variable-latin.woff2") format("woff2");
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ---- Shell layout ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: none;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px; }
.brand-mark svg { width: 28px; height: 28px; display: block; }
.brand-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.household-name { font-size: 12px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.household-name:empty { display: none; }
.last-sync { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { width: 18px; height: 18px; flex: none; }
.icon-sun, .icon-moon { display: none; }
html:not([data-theme="dark"]) .icon-moon { display: block; }
html[data-theme="dark"] .icon-sun { display: block; }

/* Admin/theme/sign-out live in the topbar's icon group on desktop (see
   .topbar-icon-group below) -- this sidebar copy is desktop-hidden here and
   only re-shown for mobile, where it becomes the top icon row instead. */
.sidebar-footer { display: none; border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; flex-direction: column; gap: 8px; }
.sidebar-footer .btn.active { background: var(--accent); color: #fff; border-color: transparent; }
.btn-block { width: 100%; justify-content: flex-start; }
.mobile-tabbar { display: none; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  background: color-mix(in srgb, var(--surface-1) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title-group { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-title { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-icon-group { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; padding: 0; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-secondary); cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, box-shadow 0.15s ease;
}
.icon-btn:hover { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.active { background: var(--accent); color: #fff; border-color: transparent; }
.month-picker { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.month-picker input { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text-primary);
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.12s ease;
}
.btn-icon { width: 15px; height: 15px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; box-shadow: var(--shadow-sm); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }

/* ---- Main content ---- */
main { padding: 28px 32px 48px; max-width: 1080px; }
.section-heading { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 40px 0 10px; }
.section-heading:first-child { margin-top: 0; }

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 16px; padding: 16px 18px; box-shadow: var(--shadow-sm); }
.stat-tile .stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.stat-tile .stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-tile .stat-value.positive { color: var(--good-text); }
.stat-tile .stat-value.negative { color: var(--critical-text); }
.stat-tile .stat-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat-tile .stat-sub.text-positive { color: var(--good-text); }
.stat-tile .stat-sub.text-negative { color: var(--critical-text); }
.text-positive { color: var(--good-text); }
.text-negative { color: var(--critical-text); }
.stat-tile.income { border-left: 3px solid var(--series-1); }
.stat-tile.savings { border-left: 3px solid var(--series-2); }
.stat-tile.fixed { border-left: 3px solid var(--series-4); }
.view { display: none; animation: fade-in 0.18s ease; }
.view.active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.view-leaving { animation: fade-out 0.14s ease forwards; }
@keyframes fade-out { to { opacity: 0; transform: translateY(4px); } }

.status-banner[hidden] { display: none; }
.status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 18px;
  font-size: 14px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.status-banner.error { background: color-mix(in srgb, var(--critical) 12%, var(--surface-1)); color: var(--critical-text); border-color: color-mix(in srgb, var(--critical) 30%, var(--border)); }
.status-banner.ok { background: color-mix(in srgb, var(--good) 12%, var(--surface-1)); color: var(--good-text); border-color: color-mix(in srgb, var(--good) 30%, var(--border)); }
.status-banner-text { flex: 1; }
.status-banner-close {
  flex-shrink: 0;
  width: 22px; height: 22px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 50%;
  color: inherit; opacity: 0.6; font-size: 18px; line-height: 1; cursor: pointer;
}
.status-banner-close:hover { opacity: 1; background: color-mix(in srgb, currentColor 12%, transparent); }

/* ---- Cards (shared) ---- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

/* ---- Trends ---- */
.trends-toolbar { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.trends-range { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.trends-range select {
  font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary);
}
.chart-card { padding: 18px 20px; margin-bottom: 18px; }
.chart-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-bar-group rect { transition: opacity 0.1s ease; }
.chart-bar-group:hover rect { opacity: 0.8; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 12px; color: var(--text-secondary); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chart-tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--text-primary); box-shadow: var(--shadow-md);
  white-space: nowrap;
}
.chart-tooltip.hidden { display: none; }

/* ---- Account visibility (Admin page) ---- */
.account-visibility-list { display: flex; flex-direction: column; }
.visibility-group:not(:first-child) { margin-top: 10px; }
.visibility-inst-heading {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); margin: 0 0 2px; padding: 8px 2px 4px; border-top: 1px solid var(--gridline);
}
.visibility-group:first-child .visibility-inst-heading { border-top: none; padding-top: 0; }
.visibility-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--gridline); }
.visibility-row:last-child { border-bottom: none; }
.visibility-name { font-size: 14px; color: var(--text-primary); }
.visibility-controls { display: flex; align-items: center; gap: 10px; }
.account-delete {
  width: 22px; height: 22px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 50%;
  color: var(--text-muted); font-size: 16px; line-height: 1; cursor: pointer;
}
.account-delete:hover { background: var(--critical); color: var(--critical-text); }
.toggle-switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; cursor: pointer; }
.toggle-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.toggle-track { position: absolute; inset: 0; background: var(--gridline); border-radius: 999px; transition: background 0.15s ease; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform 0.15s ease; }
.toggle-switch input:checked + .toggle-track { background: var(--good); }
.toggle-switch input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle-switch input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Users (Admin page) ---- */
.users-list { display: flex; flex-direction: column; margin-top: 4px; }
.user-row { padding: 10px 2px; border-bottom: 1px solid var(--gridline); }
.user-row:last-child { border-bottom: none; }
.user-info { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.user-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.user-meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.user-actions { display: flex; gap: 8px; margin-top: 8px; }
.user-devices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.device-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); background: var(--gridline); border-radius: 999px; padding: 3px 8px 3px 10px; }
.device-chip-empty { font-size: 11px; color: var(--text-muted); font-style: italic; }
.device-remove { border: none; background: none; color: var(--text-muted); font-size: 14px; line-height: 1; cursor: pointer; padding: 0 2px; }
.device-remove:hover { color: var(--critical); }
.user-reset-form, .user-delete-form { margin: 10px 0 0; }
.btn-danger { background: var(--critical); color: #fff; border-color: transparent; }

/* ---- All households (Admin page, operator-only) -- own card per household
   rather than reusing .user-row/.user-meta directly, since this is a
   two-level list (household -> its users), not a flat one. */
.household-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.household-card:last-child { margin-bottom: 0; }
.household-card-header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.household-card-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.household-card-meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.household-card-users {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.household-user-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }

/* ---- Category spend breakdown (Categories page) ---- */
.cat-spend-row { margin-bottom: 14px; }
.cat-spend-row:last-child { margin-bottom: 0; }
.cat-spend-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-bottom: 6px; }
.cat-spend-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.cat-spend-amount { color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat-spend-pct { color: var(--text-muted); font-weight: 400; margin-left: 2px; }

/* ---- Accounts (stat tiles) ---- */
.accounts-groups { display: flex; flex-direction: column; gap: 8px; }
.accounts-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.account-card {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.account-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.account-card.tx-expanded {
  overflow: visible;
  /* Span the full grid row so the transactions table has room to show all
     its columns -- otherwise it's squeezed into a single ~230px card. */
  grid-column: 1 / -1;
}
.account-tx-toggle {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--gridline);
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
}
.account-tx-toggle .chevron { width: 14px; height: 14px; color: var(--text-muted); transition: transform 0.15s ease; flex: none; }
.account-card.tx-expanded .account-tx-toggle .chevron { transform: rotate(180deg); }
.account-tx-details-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.22s ease;
}
.account-card.tx-expanded .account-tx-details-wrap { grid-template-rows: 1fr; }
.account-tx-details-wrap > .account-tx-details { overflow: hidden; min-height: 0; margin-top: 12px; }
.account-tx-details .table-card { margin: 0; }
@media (prefers-reduced-motion: reduce) { .account-tx-details-wrap { transition: none; } }
.account-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--tile-accent, var(--accent));
}
.account-card .inst { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding-left: 22px; padding-right: 22px; }
.account-card .name { font-size: 14px; color: var(--text-secondary); margin: 3px 0 14px; }
.account-synced-name { display: block; font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.account-card .balance { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.account-card .balance.negative { color: var(--critical-text); }
.account-card .synced { font-size: 11.5px; color: var(--text-muted); margin-top: 8px; }
.account-rename-btn {
  position: absolute; top: 14px; right: 14px;
  width: 22px; height: 22px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 6px;
  color: var(--text-muted); cursor: pointer;
}
.account-rename-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.account-rename-btn svg { width: 14px; height: 14px; }
.account-drag-handle {
  position: absolute; top: 14px; left: 14px;
  width: 22px; height: 22px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 6px;
  color: var(--text-muted); cursor: grab;
  touch-action: none;
}
.account-drag-handle:hover { background: var(--surface-2); color: var(--text-primary); }
.account-drag-handle svg { width: 14px; height: 14px; }
.account-card.dragging { opacity: 0.55; cursor: grabbing; box-shadow: var(--shadow-md); }
.account-name-form { margin: 3px 0 14px; gap: 6px; }
.account-name-form .account-name-input { flex: 1; min-width: 0; }
.account-type-field {
  display: flex; align-items: center; gap: 6px; margin-top: 10px;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.account-type-select {
  font: inherit; font-size: 11.5px; font-weight: 600; text-transform: none; letter-spacing: normal;
  color: var(--text-secondary); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 8px; cursor: pointer;
}

/* ---- Small utility ---- */
.hidden { display: none !important; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---- Summary / meters ---- */
.summary-list { display: flex; flex-direction: column; gap: 10px; }
.summary-row {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cat-color, var(--accent));
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.summary-row.needs-review { background: color-mix(in srgb, var(--warning) 6%, var(--surface-1)); }
.tag-review {
  font-size: 10px; font-weight: 700; color: var(--warning); border: 1px solid var(--warning);
  border-radius: 999px; padding: 2px 8px; text-transform: uppercase; letter-spacing: 0.03em;
}
.detail-tx .detail-category { flex: none; }
.summary-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; font: inherit; font-size: 14px; margin-bottom: 10px;
  background: none; border: none; padding: 0; cursor: pointer; color: inherit; text-align: left;
}
.summary-row .cat { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.cat-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--cat-color, var(--accent)); flex: none; }
.summary-row .amounts { color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; display: flex; align-items: center; gap: 10px; }
.chevron { width: 14px; height: 14px; color: var(--text-muted); transition: transform 0.15s ease; flex: none; }
.summary-row.expanded .chevron { transform: rotate(180deg); }
.meter-track { height: 8px; border-radius: 6px; background: var(--gridline); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 6px; transition: width 0.3s ease; }
.meter-fill.good { background: var(--good); }
.meter-fill.warning { background: var(--warning); }
.meter-fill.critical { background: var(--critical); }
.summary-row .pct { font-size: 12px; color: var(--text-muted); margin-top: 7px; }

.summary-details-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.22s ease;
}
.summary-row.expanded .summary-details-wrap { grid-template-rows: 1fr; }
.summary-details-wrap > .summary-details { overflow: hidden; min-height: 0; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--gridline); display: flex; flex-direction: column; gap: 2px; }
@media (prefers-reduced-motion: reduce) { .summary-details-wrap { transition: none; } }
.detail-tx { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 2px; font-size: 13px; border-bottom: 1px solid var(--gridline); }
.detail-tx:last-child { border-bottom: none; }
.detail-tx .d-desc { color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-tx .d-date { color: var(--text-muted); font-size: 12px; flex: none; }
.detail-tx .d-account { color: var(--text-muted); font-size: 12px; flex: none; border-left: 1px solid var(--border); padding-left: 10px; }
.detail-tx .d-amt { font-variant-numeric: tabular-nums; flex: none; margin-left: auto; }
.detail-meta { display: flex; gap: 10px; flex: 1; min-width: 0; }

/* ---- Tables ---- */
.table-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--gridline); font-size: 13.5px; }
th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.amount-negative { color: var(--critical-text); }
td.amount-positive { color: var(--good-text); }
.text-muted { color: var(--text-muted); font-size: 12px; }

.cat-pill { display: inline-flex; align-items: center; gap: 6px; }
.cat-pill .cat-dot { width: 7px; height: 7px; }

select, input[type="text"], input[type="number"], input[type="url"], input[type="password"], input[type="month"] {
  font: inherit;
  font-size: 13.5px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
}
select:focus, input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }

.filters { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 16px; font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.filter-group { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.filter-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.filter-search-group { flex: 1; min-width: 180px; }
.filter-search-group input { width: 100%; box-sizing: border-box; }

.ms-filter { position: relative; }
.ms-filter-btn {
  font: inherit; font-size: 13.5px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
  cursor: pointer; white-space: nowrap; min-width: 140px; text-align: left;
}
.ms-filter-btn:hover { background: var(--surface-1); }
.ms-filter-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 20;
  min-width: 210px; max-height: 260px; overflow-y: auto;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-md); padding: 6px;
}
.ms-filter-menu.hidden { display: none; }
.ms-filter-option {
  display: flex; flex-direction: row; align-items: center; justify-content: flex-start; text-align: left;
  gap: 8px; padding: 6px 8px; border-radius: 6px; font-size: 13.5px; font-weight: 500; color: var(--text-primary); cursor: pointer;
}
.ms-filter-option input[type="checkbox"] { flex: none; width: 16px; height: 16px; margin: 0; }
.ms-filter-option:hover { background: var(--surface-2); }

.tx-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.tx-actions-buttons { display: flex; gap: 8px; margin-left: auto; }
.tag-manual { font-size: 10px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 2px 8px; text-transform: uppercase; letter-spacing: 0.03em; margin-left: 6px; }
.tag-split { font-size: 10px; font-weight: 700; color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; text-transform: uppercase; letter-spacing: 0.03em; margin-left: 6px; }

.access-result { font-size: 10px; font-weight: 700; border-radius: 999px; padding: 2px 8px; text-transform: uppercase; letter-spacing: 0.03em; border: 1px solid; white-space: nowrap; }
.access-result.success { color: var(--good-text); border-color: var(--good); }
.access-result.fail { color: var(--critical-text); border-color: var(--critical); }
.access-result.locked { color: var(--warning); border-color: var(--warning); }

.status-connected { color: var(--good-text); font-weight: 600; }
#claimSimplefinForm input:disabled,
#claimSimplefinForm button:disabled { opacity: 0.45; cursor: default; }
.manual-edit, .manual-delete {
  width: 18px; height: 18px; padding: 0; margin-left: 2px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 50%;
  color: var(--text-muted); font-size: 15px; line-height: 1; cursor: pointer; flex: none;
}
.manual-edit svg { width: 11px; height: 11px; }
.manual-edit:hover { background: var(--accent-track); color: var(--accent); }
.manual-delete:hover { background: var(--critical); color: var(--critical-text); }

.tx-split-btn {
  width: 18px; height: 18px; padding: 0; margin-left: 2px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 50%;
  color: var(--text-muted); cursor: pointer; flex: none;
}
.tx-split-btn svg { width: 12px; height: 12px; }
.tx-split-btn:hover:not(:disabled) { background: var(--accent-track); color: var(--accent); }
.tx-split-btn:disabled { opacity: 0.35; cursor: default; }

.split-summary { display: flex; flex-direction: column; gap: 3px; margin-bottom: 6px; }
.split-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; }
.split-chip .cat-dot { width: 7px; height: 7px; flex: none; }
.split-actions { display: flex; gap: 6px; }

/* Each split is its own card (category + remove on top, amount below) --
   a single horizontal row of select+input+button was too cramped on
   mobile, especially with longer category names. */
#splitDialog .dialog-form { width: min(420px, calc(100vw - 48px)); }
/* Non-modal (dialog.show(), not showModal()) -- unlike every other dialog in
   the app, this one deliberately doesn't block the page: Next itself
   navigates to and spotlights (.tour-highlight below) the thing being
   described, so staying open and interactive is the whole point, instead of
   it disappearing and forcing a trip back to Admin to continue.
   Fixed-position corner card instead of the centered/backdrop treatment the
   base `dialog` rule gives every other dialog. z-index keeps it above a
   .tour-highlight's own dimming layer (see below), regardless of DOM order. */
#tourDialog { position: fixed; inset: auto 24px 24px auto; margin: 0; z-index: 1001; }
#tourDialog::backdrop { display: none; }
#tourDialog .dialog-form { width: min(360px, calc(100vw - 48px)); }
.tour-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tour-step-count { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin: 0; }
.tour-close-btn {
  background: none; border: none; padding: 0 2px; font-size: 22px; line-height: 1;
  color: var(--text-muted); cursor: pointer;
}
.tour-close-btn:hover { color: var(--text-primary); }
@media (max-width: 760px) {
  /* Clear the fixed .mobile-tabbar instead of sitting on top of it -- same
     88px + safe-area figure `main`'s own bottom padding already uses. */
  #tourDialog { inset: auto 12px calc(88px + env(safe-area-inset-bottom)) 12px; }
}

/* Spotlight effect for whatever element the current tour step is about --
   no overlay div or position math to maintain on scroll/resize, since the
   dimming IS the target's own box-shadow, painted outward from its real
   edges to the viewport. Only works because no ancestor of any tour target
   (main, .admin-group, .collapsible-body) clips overflow -- an
   overflow:hidden/auto ancestor would cut this off before it reaches the
   viewport edge. */
.tour-highlight {
  position: relative;
  z-index: 1000;
  outline: 3px solid var(--accent);
  outline-offset: 4px;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
}
.split-rows { display: flex; flex-direction: column; gap: 10px; margin: 4px 0; }
.split-row {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 10px 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.split-row-top { display: flex; align-items: center; gap: 8px; }
.split-row-category { flex: 1; min-width: 0; }
.split-row-amount-wrap { display: flex; align-items: center; gap: 6px; }
.split-row-amount-wrap .text-muted { font-size: 14px; font-weight: 600; }
.split-row-amount { flex: 1; min-width: 0; }
.split-row-remove {
  width: 24px; height: 24px; padding: 0; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 50%;
  color: var(--text-muted); font-size: 17px; line-height: 1; cursor: pointer;
}
.split-row-remove:hover { background: var(--critical); color: var(--critical-text); }

.inline-form { display: flex; gap: 8px; margin-bottom: 18px; }
.inline-form input[type="text"] { flex: 2 1 200px; }
.inline-form .currency-input { flex: 1 1 140px; max-width: 160px; }
.inline-form select { flex: 1 1 180px; }
.rules-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.rule-search-input { flex: 1; min-width: 180px; max-width: 280px; }
.rule-override-cell { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.rule-payee-input { width: 100%; max-width: 200px; }
.rule-override-cell .rule-threshold-input { width: 80px; }

.categories-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.categories-list li {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 8px 7px 14px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-sm);
}
.category-rename, .category-delete {
  width: 18px; height: 18px; padding: 0; margin-left: 2px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 50%;
  color: var(--text-muted); font-size: 15px; line-height: 1; cursor: pointer;
}
.category-rename svg { width: 12px; height: 12px; }
.category-rename:hover { background: var(--accent-track); color: var(--accent); }
.category-delete:hover { background: var(--critical); color: var(--critical-text); }

.hint { color: var(--text-muted); font-size: 13px; margin: -4px 0 16px; }
.hint-steps { padding-left: 20px; }
.hint-steps li { margin-bottom: 4px; }
.hint-steps li:last-child { margin-bottom: 0; }

.alert-settings-form { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.plan-picker { display: flex; flex-direction: column; gap: 8px; margin: 4px 0; }
.plan-option {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; font-size: 14px;
}
.plan-option:has(input:checked) { border-color: var(--accent); background: var(--accent-track); }
.plan-option input[type="radio"] { width: 16px; height: 16px; flex: none; accent-color: var(--accent); }
.plan-option-label { flex: 1; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.plan-option-save { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--good); }
.plan-option-price { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.alert-settings-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.alert-settings-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; cursor: pointer; }
.alert-settings-toggle input[type="checkbox"] { width: 16px; height: 16px; }
.alert-settings-num { width: 60px; }

.admin-sync-row { display: flex; }

/* Groups related Admin sections into a visibly bounded card -- a plain text
   label alone (matching .section-heading, reused by .collapsible summary
   too) didn't read as a distinct grouping, just another row. */
.admin-group {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  padding: 18px 20px 4px;
  margin: 0 0 22px;
}
.admin-group-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.admin-group .collapsible:first-of-type { margin-top: 0; }

.admin-subtabs { display: flex; gap: 16px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.admin-subtab {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  padding: 8px 2px; margin-bottom: -1px;
  font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer;
}
.admin-subtab:hover { color: var(--text-primary); }
.admin-subtab.active { color: var(--accent); border-bottom-color: var(--accent); }
.admin-subtab-panel.hidden { display: none; }

/* ---- Collapsible sections (Budgets / Admin) ---- */
.collapsible { margin: 22px 0; }
.collapsible:first-child { margin-top: 0; }
.collapsible summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  cursor: pointer; list-style: none;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 10px 2px;
}
.collapsible summary::-webkit-details-marker { display: none; }
.collapsible summary:hover { color: var(--text-primary); }
.collapsible summary .chevron { margin: 0; }
.collapsible-title { display: flex; align-items: center; gap: 10px; }
.collapsible-meta {
  font-size: 11px; font-weight: 600; text-transform: none; letter-spacing: 0;
  color: var(--text-secondary); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 10px; font-variant-numeric: tabular-nums;
}
.collapsible-meta:empty { display: none; }
.collapsible[open] summary .chevron { transform: rotate(180deg); }
.collapsible .collapsible-body { padding-top: 6px; }
.collapsible .collapsible-body .hint:first-child { margin-top: 0; }
.collapsible[data-kind="income"] .collapsible-body .table-card { border-left: 3px solid var(--series-1); }
.collapsible[data-kind="fixed"] .collapsible-body .table-card { border-left: 3px solid var(--series-4); }
.collapsible[data-kind="savings"] .collapsible-body .table-card { border-left: 3px solid var(--series-2); }
.collapsible[data-kind="expenses"] .collapsible-body .table-card { border-left: 3px solid var(--series-3); }
.budget-input.inherited { color: var(--text-muted); }
.tag-override { font-size: 10.5px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 3px 9px; white-space: nowrap; text-transform: uppercase; letter-spacing: 0.03em; }
.tag-fixed { font-size: 10.5px; font-weight: 700; color: var(--series-4); border: 1px solid var(--series-4); border-radius: 999px; padding: 3px 9px; white-space: nowrap; text-transform: uppercase; letter-spacing: 0.03em; }
.tag-savings { font-size: 10.5px; font-weight: 700; color: var(--series-2); border: 1px solid var(--series-2); border-radius: 999px; padding: 3px 9px; white-space: nowrap; text-transform: uppercase; letter-spacing: 0.03em; }
.tag-income { font-size: 10.5px; font-weight: 700; color: var(--series-1); border: 1px solid var(--series-1); border-radius: 999px; padding: 3px 9px; white-space: nowrap; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-pending { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; font-weight: 700; color: var(--text-secondary); border: 1px solid var(--border); border-radius: 999px; padding: 3px 9px 3px 7px; white-space: nowrap; text-transform: uppercase; letter-spacing: 0.03em; flex: none; }
.pending-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warning); flex: none; }
.fixed-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.savings-row-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.recurring-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 18px 18px 4px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.recurring-group + .recurring-group { border-top: 1px solid var(--gridline); margin-top: 14px; padding-top: 16px; }
.recurring-heading { display: flex; align-items: center; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 0 0 10px; }
.bundle-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bundle-color, var(--accent)); margin-right: 8px; flex: none; }
.recurring-group .summary-list { gap: 8px; margin-bottom: 14px; }
.recurring-group .summary-row { background: var(--surface-2); box-shadow: none; padding: 12px 14px; }
.recurring-group .empty-state { padding: 8px 0 14px; text-align: left; font-size: 13px; }

dialog {
  border: none; border-radius: 18px; padding: 0; background: var(--surface-1); color: var(--text-primary);
  box-shadow: var(--shadow-md); max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); box-sizing: border-box;
  opacity: 1; transform: scale(1);
  transition: opacity 0.16s ease, transform 0.16s ease, overlay 0.16s allow-discrete, display 0.16s allow-discrete;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(2px); transition: background-color 0.16s ease; }
@starting-style { dialog[open] { opacity: 0; transform: scale(0.94); } }
@media (prefers-reduced-motion: reduce) { dialog { transition: none; } }

.dialog-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(360px, calc(100vw - 64px));
  box-sizing: border-box;
}
.dialog-form h2 { margin: 0 0 4px; font-size: 17px; }
.dialog-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.dialog-form input { width: 100%; box-sizing: border-box; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.form-error { color: var(--critical-text); font-size: 12.5px; margin: -4px 0 0; }
.form-error:empty { display: none; }

/* ---- Sign-in: a dedicated full-screen moment, not just a dialog on top of the app ---- */
#loginDialog::backdrop {
  background: radial-gradient(circle at 30% 20%, color-mix(in srgb, var(--accent) 16%, var(--page)), var(--page) 62%);
}
.login-brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; margin-bottom: 4px; }
.login-logo {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 18px;
  background: var(--accent-track);
}
.login-logo svg { width: 32px; height: 32px; }
.login-brand h1 { margin: 2px 0 0; font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.login-credit { margin: 0; display: flex; align-items: center; justify-content: center; gap: 5px; font-size: 10.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.login-credit-mark svg { width: 12px; height: 12px; display: block; }
.login-subtitle { margin: 0; font-size: 13px; color: var(--text-muted); }

/* ---- Two-factor setup (Admin > People & security) ---- */
.totp-secret-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 12px;
}
.totp-secret-box code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; letter-spacing: 0.04em; }
.recovery-codes-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px;
  margin-bottom: 12px;
}
.recovery-codes-grid code {
  display: block; text-align: center; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 6px;
}

/* Quiet attribution at the foot of Admin -- reachable from both the desktop
   sidebar and the mobile "More" menu without needing its own responsive
   placement, unlike the sidebar/topbar chrome which differs by viewport. */
.app-credit { margin: 28px 0 8px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 11px; color: var(--text-muted); text-align: center; }
.app-credit-mark svg { width: 14px; height: 14px; display: block; }
/* .btn-block defaults to left-aligned (flex-start) for icon+label buttons
   like the sidebar nav -- the login dialog's secondary actions want their
   text centered instead, same as the primary Sign in button beside them. */
.login-dialog-btn { margin-top: 10px; justify-content: center; }

/* ---- Demo mode ---- */
.demo-banner {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; font-size: 13px; font-weight: 600; text-align: center;
  background: var(--warning); color: #1a1400;
}
.demo-banner .btn { flex: none; }

.paywall-banner {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; font-size: 13px; font-weight: 600; text-align: center;
  background: var(--critical); color: #fff;
}
.paywall-banner .btn { flex: none; }

/* Full-screen splash shown between a successful sign-in and loadAll()
   actually finishing -- opaque (not a translucent backdrop) so there's no
   flash of a stale/empty app shell underneath while data is still loading.
   Roughly the same footprint as the login dialog's own .dialog-form. */
.loading-overlay {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: var(--page);
}
.loading-box {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  width: min(360px, calc(100vw - 64px));
  padding: 24px; text-align: center;
}
.loading-box p { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-primary); }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

.empty-state { color: var(--text-muted); font-size: 14px; padding: 28px; text-align: center; }

/* ---- Responsive ---- */
@media (max-width: 760px) {
  .app-shell { flex-direction: column; }

  /* Sidebar becomes a top bar: brand + icon actions on one row, a
     horizontally scrollable tab strip on the row below. Pinned above the
     page's .topbar (also sticky, see below) so both stay put on scroll --
     .topbar's `top` offset is kept in sync with this bar's real (variable,
     since household name / last sync populate in async) height via a
     ResizeObserver in app.js rather than a guessed pixel value. */
  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 6;
    border-right: none;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface-1) 92%, transparent);
    backdrop-filter: blur(8px);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 10px 14px 0;
    gap: 4px 10px;
  }
  .brand { order: 1; flex: 1; padding: 4px 0; }

  .sidebar-footer {
    display: flex;
    order: 2;
    border-top: none;
    margin: 0;
    padding: 0;
    flex-direction: row;
    gap: 6px;
  }
  .topbar-icon-group { display: none; }
  .sidebar-footer .btn-block {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
    flex: none;
  }
  .sidebar-footer .btn-block span:last-child { display: none; }

  /* The pill strip is replaced by a fixed bottom tab bar on mobile -- a
     thumb-reachable, always-visible native-app pattern instead of a
     top-of-screen <select>. */
  .side-nav { display: none; }

  .btn-block { width: auto; }
  main { padding: 20px 16px calc(88px + env(safe-area-inset-bottom)); }

  .mobile-tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    background: color-mix(in srgb, var(--surface-1) 92%, transparent);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .mobile-tab,
  .mobile-more > summary {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font: inherit;
    font-size: 10.5px;
    font-weight: 600;
    padding: 6px 2px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 10px;
    white-space: nowrap;
    list-style: none;
  }
  .mobile-tab svg,
  .mobile-more > summary svg {
    width: 20px;
    height: 20px;
  }
  .mobile-tab.active,
  .mobile-more.active > summary {
    color: var(--accent);
  }
  .mobile-more { position: relative; flex: 1; }
  .mobile-more > summary::-webkit-details-marker { display: none; }
  .mobile-more[open] > summary { color: var(--accent); }
  .mobile-more-panel {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 160px;
  }
  .mobile-more-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    padding: 9px 10px;
    border: none;
    background: none;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
  }
  .mobile-more-item:hover { background: var(--surface-2); color: var(--text-primary); }
  .mobile-more-item.active { background: var(--accent); color: #fff; }
  .mobile-more-item svg { width: 16px; height: 16px; flex: none; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 10px; top: var(--mobile-header-h, 64px); }
  .topbar-title { font-size: 17px; }

  /* Tables reflow into stacked cards instead of scrolling horizontally.
     Each <td> becomes a label/value line; the label text is injected via
     nth-child position, since column order is fixed and known per table --
     no markup changes needed. */
  .table-card:has(.tx-table), .table-card:has(.budget-table) {
    background: transparent; border: none; box-shadow: none; overflow: visible;
  }
  .tx-table, .budget-table { display: block; }
  .tx-table thead, .budget-table thead { display: none; }
  .tx-table tbody, .budget-table tbody { display: block; }
  .tx-table tr, .budget-table tr {
    display: block;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px 12px;
    margin: 10px;
    box-shadow: var(--shadow-sm);
  }
  .tx-table tr:hover, .budget-table tr:hover { background: var(--surface-1); }
  .tx-table td, .budget-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--gridline);
    text-align: right;
    white-space: normal;
  }
  .tx-table td:last-child, .budget-table td:last-child { border-bottom: none; }
  .tx-table td:empty, .budget-table td:empty { display: none; }
  .tx-table td::before, .budget-table td::before {
    content: "";
    font-weight: 600; font-size: 10.5px; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.03em; text-align: left; flex: none;
  }

  .tx-table td:nth-child(1)::before { content: "Date"; }
  .tx-table td:nth-child(2)::before { content: "Payee"; }
  .tx-table td:nth-child(3)::before { content: "Description"; }
  .tx-table td:nth-child(4)::before { content: "Account"; }
  .tx-table td:nth-child(5)::before { content: "Amount"; }
  .tx-table td:nth-child(6)::before { content: "Category"; }

  #incomeTableBody td:nth-child(1)::before,
  #fixedExpenseTableBody td:nth-child(1)::before,
  #budgetTableBody td:nth-child(1)::before,
  #incomeDefaultsTableBody td:nth-child(1)::before,
  #fixedExpenseDefaultsTableBody td:nth-child(1)::before,
  #defaultsTableBody td:nth-child(1)::before { content: "Source"; }
  #incomeTableBody td:nth-child(2)::before,
  #fixedExpenseTableBody td:nth-child(2)::before,
  #budgetTableBody td:nth-child(2)::before,
  #incomeDefaultsTableBody td:nth-child(2)::before,
  #fixedExpenseDefaultsTableBody td:nth-child(2)::before,
  #defaultsTableBody td:nth-child(2)::before { content: "Amount"; }
  /* Savings defaults has an extra "Linked account" column the other
     recurring-defaults tables don't -- Goal(1)/Linked account(2)/Default
     monthly amount(3)/action(4), not the shared Source(1)/Amount(2) layout
     above, which was mislabeling column 2 "Amount" and leaving the real
     amount column (3) unlabeled. Kept short ("Amount", not "Default monthly
     amount") -- the longer label text alone was wide enough to push the row
     past the card's border on narrow screens. */
  #savingsDefaultsTableBody td:nth-child(1)::before { content: "Goal"; }
  #savingsDefaultsTableBody td:nth-child(2)::before { content: "Linked account"; }
  #savingsDefaultsTableBody td:nth-child(3)::before { content: "Amount"; }
  #savingsDefaultsTableBody td:nth-child(3) { justify-content: space-between; }
  /* Budgets page's savings table has both a "Linked account" select and an
     "Actual" column (this month's real balance growth) the other
     Budgets-page tables don't -- Source(1)/Linked account(2)/Actual(3)/
     Amount(4)/tag(5)/action(6), not the shared Source(1)/Amount(2) layout.
     Without these overrides the generic .budget-table nth-child(3)/(4)
     flex-start rule below (meant for the plain tag/action columns other
     tables have there) lands on the real Actual/Amount values instead,
     left-aligning them against their label instead of right-aligning like
     every other value column. */
  #savingsTableBody td:nth-child(1)::before { content: "Source"; }
  #savingsTableBody td:nth-child(2)::before { content: "Linked account"; }
  #savingsTableBody td:nth-child(3)::before { content: "Actual"; }
  #savingsTableBody td:nth-child(4)::before { content: "Amount"; }
  #savingsTableBody td:nth-child(3),
  #savingsTableBody td:nth-child(4) { justify-content: space-between; }
  #savingsTableBody td:nth-child(5),
  #savingsTableBody td:nth-child(6) { justify-content: flex-start; }
  /* Same select-overflow fix as #savingsDefaultsTableBody below -- a long
     account name otherwise pushes the select past the stacked card's edge. */
  #savingsTableBody td:nth-child(2) { flex-wrap: wrap; }
  #savingsTableBody .savings-account-select { max-width: 100%; min-width: 0; flex: 1 1 100%; }
  #rulesTableBody td:nth-child(1)::before { content: "Payee"; }
  #rulesTableBody td:nth-child(2)::before { content: "Category"; }
  #rulesTableBody td:nth-child(3)::before { content: "Small purchase"; }
  #accessLogTableBody td:nth-child(1)::before { content: "Time"; }
  #accessLogTableBody td:nth-child(2)::before { content: "Username"; }
  #accessLogTableBody td:nth-child(3)::before { content: "Result"; }
  #accessLogTableBody td:nth-child(4)::before { content: "Device"; }
  #accessLogTableBody td:nth-child(5)::before { content: "IP address"; }

  /* Tag/action-only columns: no label, left-align instead of space-between */
  .budget-table td:nth-child(3),
  .budget-table td:nth-child(4),
  #rulesTableBody td:nth-child(4) { justify-content: flex-start; }
  /* Access log has real labeled values (not tags/actions) in every column,
     including 3 and 4 -- override the generic .budget-table rule above so
     they keep the same label-left/value-right layout as columns 1, 2, 5. */
  #accessLogTableBody td:nth-child(3),
  #accessLogTableBody td:nth-child(4) { justify-content: space-between; }

  /* "No data yet" rows: plain centered text, no label/flex layout */
  .tx-table td.empty-state, .budget-table td.empty-state { display: block; text-align: center; border-bottom: none; }
  .tx-table td.empty-state::before, .budget-table td.empty-state::before { content: none; }

  /* Linked-account select had no width limit, so a longer account name
     pushed it past the stacked card's border, same overflow bug as the
     rules table's small-purchase override select. Wrap the label onto its
     own line (like .rule-override-cell) so the select gets the card's full
     width instead of being squeezed into whatever's left after the label --
     flex items don't shrink below their content width otherwise. */
  #savingsDefaultsTableBody td:nth-child(2) { flex-wrap: wrap; }
  #savingsDefaultsTableBody .savings-account-select { max-width: 100%; min-width: 0; flex: 1 1 100%; }

  /* Trends table -- same stacked-card reflow as the other tables */
  .table-card:has(.trends-table) { background: transparent; border: none; box-shadow: none; overflow: visible; }
  .trends-table { display: block; }
  .trends-table thead { display: none; }
  .trends-table tbody { display: block; }
  .trends-table tr {
    display: block;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px 12px;
    margin: 10px;
    box-shadow: var(--shadow-sm);
  }
  .trends-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--gridline);
    text-align: right;
  }
  .trends-table td:last-child { border-bottom: none; }
  .trends-table td::before {
    content: "";
    font-weight: 600; font-size: 10.5px; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.03em; text-align: left; flex: none;
  }
  .trends-table td:nth-child(1)::before { content: "Month"; }
  .trends-table td:nth-child(2)::before { content: "Income"; }
  .trends-table td:nth-child(3)::before { content: "Budgeted"; }
  .trends-table td:nth-child(4)::before { content: "Spent"; }
  .trends-table td:nth-child(5)::before { content: "Savings"; }
  .trends-table td:nth-child(6)::before { content: "Net"; }

  .tx-table td input[type="number"],
  .budget-table td input[type="number"],
  .tx-table td .currency-input,
  .budget-table td .currency-input { max-width: 130px; }

  /* The small-purchase override cell's own flex row (label + threshold +
     category select) was overflowing past the stacked card's border on
     narrow screens -- let it wrap instead of forcing everything onto one
     line, and stop the select from claiming its full desktop width. */
  #rulesTableBody .rule-override-cell {
    flex-wrap: wrap;
    justify-content: flex-start !important;
    max-width: 100%;
  }
  #rulesTableBody .rule-small-category-select { max-width: 100%; flex: 1 1 auto; }

  .filters { flex-wrap: wrap; gap: 10px 18px; }
  .inline-form { flex-wrap: wrap; }

  /* Bigger touch targets */
  .category-rename, .category-delete { width: 26px; height: 26px; }
  .account-rename-btn { width: 28px; height: 28px; }

  /* Expanded category transaction rows: payee gets its own full-width line
     instead of being squeezed onto one line with date/account/amount. */
  .detail-tx { align-items: flex-start; padding: 9px 2px; }
  .detail-meta { flex-wrap: wrap; row-gap: 3px; }
  .detail-tx .d-desc { order: 1; flex: 1 1 100%; font-weight: 600; font-size: 13.5px; }
  .detail-tx .d-date { order: 2; font-size: 11.5px; }
  .detail-tx .d-account { order: 3; font-size: 11.5px; }
  .detail-tx .badge-pending { order: 4; }
  .detail-tx .d-amt { padding-top: 1px; }

  /* Tighter card padding, and let the meta line ("Created ... · N users")
     wrap instead of forcing nowrap -- on the narrowest phones that string
     alone can be wider than the card, and flex-wrap on the header only
     helps once name and meta are already each on their own line. */
  .household-card { padding: 10px 12px; }
  .household-card-meta { white-space: normal; }

  .accent-picker-row { flex-wrap: wrap; }
}
