@font-face { font-family: 'Bitter'; src: url('/fonts/Bitter.woff') format('woff'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'DM Sans'; src: url('/fonts/DMSans.woff') format('woff'); font-weight: 100 1000; font-display: swap; }
:root {
    --radius: 12px;
    --radius-s: 6px;
    --serif: 'Bitter', Georgia, 'Times New Roman', serif;
    --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --on-accent: #ffffff;
    --gold: #E9A81F;
  }
  /* Default theme: the statement-paper palette from the landing page. */
  [data-mode="light"] {
    --bg: #F2F4F7; --surface: #FFFFFF; --surface2: #E8ECF2; --text: #172033; --muted: #556074;
    --accent: #27406B; --accent-hover: #1D3155; --success: #1E8A57; --danger: #C2412D; --warning: #A65F00; --border: #D5DBE3;
    --on-accent: #ffffff;
  }
  /* Same palette after dark: navy statement, envelope blue lightened for contrast. */
  [data-mode="dark"] {
    --bg: #101828; --surface: #172236; --surface2: #213049; --text: #E8ECF3; --muted: #9AA7BD;
    --accent: #9DB8E8; --accent-hover: #B7CBEE; --success: #4CC38E; --danger: #F08672; --warning: #F2B84B; --border: #2E3D59;
    --on-accent: #101828;
  }
  [data-theme="colorful"], [data-theme="ocean"], [data-theme="forest"], [data-theme="sunset"] { --on-accent: #ffffff; }
  [data-theme="ocean"][data-mode="dark"], [data-theme="forest"][data-mode="dark"], [data-theme="sunset"][data-mode="dark"] { --on-accent: #0f172a; }
  [data-theme="colorful"][data-mode="dark"] {
    --bg: #1a0b2e; --surface: #2d1b4e; --surface2: #4a2c7a; --text: #f0e6ff; --muted: #c4b5fd;
    --accent: #a855f7; --accent-hover: #9333ea; --border: #6d28d9;
  }
  [data-theme="colorful"][data-mode="light"] {
    --bg: #faf5ff; --surface: #ffffff; --surface2: #f3e8ff; --text: #3b0764; --muted: #7e22ce;
    --accent: #9333ea; --accent-hover: #7e22ce; --border: #e9d5ff;
  }
  [data-theme="ocean"][data-mode="dark"] {
    --bg: #0c4a6e; --surface: #075985; --surface2: #0369a1; --text: #e0f2fe; --muted: #7dd3fc;
    --accent: #22d3ee; --accent-hover: #06b6d4; --border: #0ea5e9;
  }
  [data-theme="ocean"][data-mode="light"] {
    --bg: #f0f9ff; --surface: #ffffff; --surface2: #e0f2fe; --text: #0c4a6e; --muted: #0369a1;
    --accent: #0284c7; --accent-hover: #0369a1; --border: #bae6fd;
  }
  [data-theme="forest"][data-mode="dark"] {
    --bg: #14532d; --surface: #166534; --surface2: #15803d; --text: #dcfce7; --muted: #86efac;
    --accent: #4ade80; --accent-hover: #22c55e; --border: #16a34a;
  }
  [data-theme="forest"][data-mode="light"] {
    --bg: #f0fdf4; --surface: #ffffff; --surface2: #dcfce7; --text: #14532d; --muted: #166534;
    --accent: #16a34a; --accent-hover: #15803d; --border: #bbf7d0;
  }
  [data-theme="sunset"][data-mode="dark"] {
    --bg: #431407; --surface: #7c2d12; --surface2: #9a3412; --text: #ffedd5; --muted: #fdba74;
    --accent: #fb923c; --accent-hover: #f97316; --border: #ea580c;
  }
  [data-theme="sunset"][data-mode="light"] {
    --bg: #fff7ed; --surface: #ffffff; --surface2: #ffedd5; --text: #7c2d12; --muted: #9a3412;
    --accent: #ea580c; --accent-hover: #c2410c; --border: #fed7aa;
  }
  [data-theme="colorful"] {
    --bg: #1a0b2e;
    --surface: #2d1b4e;
    --surface2: #4a2c7a;
    --text: #f0e6ff;
    --muted: #c4b5fd;
    --accent: #a855f7;
    --accent-hover: #9333ea;
    --success: #34d399;
    --danger: #f87171;
    --warning: #fbbf24;
    --border: #6d28d9;
  }
  [data-theme="ocean"] {
    --bg: #0c4a6e;
    --surface: #075985;
    --surface2: #0369a1;
    --text: #e0f2fe;
    --muted: #7dd3fc;
    --accent: #22d3ee;
    --accent-hover: #06b6d4;
    --success: #4ade80;
    --danger: #f87171;
    --warning: #facc15;
    --border: #0ea5e9;
  }
  [data-theme="forest"] {
    --bg: #14532d;
    --surface: #166534;
    --surface2: #15803d;
    --text: #dcfce7;
    --muted: #86efac;
    --accent: #4ade80;
    --accent-hover: #22c55e;
    --success: #86efac;
    --danger: #f87171;
    --warning: #fde047;
    --border: #16a34a;
  }
  [data-theme="sunset"] {
    --bg: #431407;
    --surface: #7c2d12;
    --surface2: #9a3412;
    --text: #ffedd5;
    --muted: #fdba74;
    --accent: #fb923c;
    --accent-hover: #f97316;
    --success: #4ade80;
    --danger: #f87171;
    --warning: #fde047;
    --border: #ea580c;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    transition: background 0.2s, color 0.2s;
  }
  .app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
  }
  nav {
    background: var(--surface);
    padding: 1.5rem 1rem;
    border-right: 1px solid var(--border);
  }

  .logo-area {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
  }
  .logo-area h1 { margin: 0; font-size: 1.35rem; }
  .logo-icon { flex-shrink: 0; }
  .nav-divider {
    height: 1px;
    background: var(--border);
    margin: 0.75rem 0.5rem;
  }
  nav h1 {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    color: var(--accent);
  }
  nav button {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
  }
  nav button:hover, nav button.active {
    background: var(--surface2);
  }
  main {
    padding: 2rem;
    overflow-y: auto;
  }
  .card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
  }
  .stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
  }
  .stat {
    background: var(--surface2);
    padding: 1.25rem;
    border-radius: var(--radius);
    text-align: center;
  }
  .stat .value {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0.25rem 0;
  }
  .stat .label { color: var(--muted); font-size: 0.85rem; }
  .positive { color: var(--success); }
  .negative { color: var(--danger); }
  table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
  }
  th, td {
    text-align: left;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
  }
  th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
  .actions button, .btn {
    background: var(--accent);
    color: var(--on-accent);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    margin-right: 0.25rem;
    margin-bottom: 0.25rem;
    width: auto;
    display: inline-block;
  }
  form .btn, .form-actions .btn {
    width: auto;
    min-width: 140px;
    justify-self: start;
  }
  form > .btn {
    justify-self: start;
    width: fit-content;
  }
  .actions button:hover, .btn:hover { background: var(--accent-hover); }
  .btn-danger { background: var(--danger); color: var(--on-accent); }
  .btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
  .btn-secondary { background: var(--surface2); color: var(--text); }
  .btn-small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
  form, .form-row {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }
  .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
  }
  input, select, textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    font-size: 0.95rem;
    width: 100%;
  }
  input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
  .section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
  }
  .badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: var(--surface2);
  }
  a.portal-link {
    color: var(--accent);
    text-decoration: none;
    word-break: break-all;
  }
  a.portal-link:hover { text-decoration: underline; }
  .cred-box {
    font-family: monospace;
    font-size: 0.85rem;
    background: var(--bg);
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    white-space: pre-wrap;
    word-break: break-all;
  }
  .theme-toggle {
    display: flex;
    gap: 0.5rem;
    align-items: center;
  }

  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
  }
  .modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  }
  .modal h3 { margin-bottom: 1rem; }
  .cred-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
  }
  .cred-row label {
    min-width: 80px;
    font-size: 0.85rem;
    color: var(--muted);
  }
  .cred-row input {
    flex: 1;
    font-family: monospace;
  }
  .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.25rem;
  }

  @media print {
    nav, .nav-divider, .mobile-bar, #toasts, #export-report-btn, #print-report-btn, .btn { display: none !important; }
    .app { display: block; }
    main { padding: 0; }
    .card { border: none; box-shadow: none; }
    body { background: white; color: black; }
    table { font-size: 11pt; }
    th, td { border-bottom: 1px solid #ccc; }
  }

/* ===== Added in v2 (accounts, server sync, mobile) ===== */
.logo-icon { border-radius: 8px; object-fit: cover; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.skip-link { position: absolute; left: -9999px; top: 0.5rem; background: var(--accent); color: var(--on-accent); padding: 0.5rem 1rem; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 0.5rem; }
.loading { color: var(--muted); padding: 2rem 0; }
.card { overflow-x: auto; }
.field-hint { font-size: 0.8rem; color: var(--muted); margin-top: 0.35rem; }
.field-label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.stacked-field { display: flex; flex-direction: column; gap: 0.2rem; }
.check-label { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.check-label input[type="checkbox"] { width: auto; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.copy-row { display: flex; gap: 0.5rem; align-items: center; max-width: 720px; }
.copy-row input { flex: 1; min-width: 0; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.plain-list { list-style: none; margin: 0.5rem 0 1rem; color: var(--muted); }
.howto { margin-top: 0.75rem; background: var(--surface2); border-radius: 8px; padding: 0.6rem 0.9rem; }
.howto summary { cursor: pointer; font-weight: 600; }
.howto ol { margin: 0.6rem 0 0.3rem 1.2rem; }
.howto li { margin-bottom: 0.3rem; }
.howto a, .doc-page a, .auth-page a, .field-hint a { color: var(--accent); }
.danger-zone { border-color: var(--danger); }
.welcome-card { border-color: var(--accent); }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 0.85rem; text-decoration: underline; }
.link-btn:hover { color: var(--text); }
.receipt-thumb { background: none; border: none; padding: 0; cursor: pointer; }
.receipt-thumb img { max-width: 40px; max-height: 40px; border-radius: 4px; display: block; }
.receipt-modal { max-width: min(92vw, 900px); }
.receipt-modal img { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; border-radius: 8px; }

/* Sidebar footer */
nav { display: flex; flex-direction: column; }
.nav-footer { margin-top: auto; padding: 1rem 0.5rem 0; font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.35rem; }
.nav-user { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sync-status { font-size: 0.8rem; color: var(--muted); }
#sync-status[data-kind="ok"] { color: var(--success); }
#sync-status[data-kind="error"] { color: var(--warning); font-weight: 600; }
@media (min-width: 801px) { nav { position: sticky; top: 0; height: 100vh; overflow-y: auto; } }

/* Toasts */
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 1000; max-width: min(420px, calc(100vw - 2rem)); }
.toast { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 10px; padding: 0.75rem 1rem; box-shadow: 0 8px 24px rgba(0,0,0,0.25); font-size: 0.9rem; transition: opacity 0.35s, transform 0.35s; }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-hide { opacity: 0; transform: translateY(8px); }

/* Mobile */
.mobile-bar { display: none; }
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .mobile-bar { display: flex; align-items: center; gap: 0.75rem; position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.6rem 1rem; }
  .mobile-title { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.1rem; }
  .mobile-title img { border-radius: 6px; }
  .icon-btn { background: var(--surface2); color: var(--text); border: none; border-radius: 8px; font-size: 1.25rem; width: 42px; height: 42px; cursor: pointer; }
  nav { position: fixed; top: 0; left: 0; bottom: 0; width: 270px; max-width: 85vw; z-index: 60; transform: translateX(-100%); transition: transform 0.2s ease; border-right: 1px solid var(--border); overflow-y: auto; }
  body.nav-open nav { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,0.45); }
  main { padding: 1rem; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .section-title { flex-wrap: wrap; gap: 0.5rem; }
  .copy-row { flex-wrap: wrap; }
  #toasts { left: 1rem; right: 1rem; max-width: none; }
}

/* Auth + document pages */
.auth-page { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; }
.auth-wrap { width: 100%; max-width: 420px; }
.auth-brand { text-align: center; margin-bottom: 1.25rem; }
.auth-brand img { border-radius: 16px; }
.auth-brand h1 { margin: 0.5rem 0 0.25rem; }
.auth-brand p { color: var(--muted); }
.auth-card { padding: 1.5rem; }
.auth-form { display: flex; flex-direction: column; gap: 0.85rem; margin-top: 1rem; }
.auth-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; font-weight: 600; }
.auth-form .optional { font-weight: normal; color: var(--muted); }
.auth-form .btn { width: 100%; padding: 0.75rem; font-size: 1rem; margin: 0.25rem 0 0; }
.auth-tabs { display: flex; gap: 0.25rem; background: var(--surface2); border-radius: 10px; padding: 0.25rem; }
.auth-tab { flex: 1; background: none; border: none; color: var(--muted); padding: 0.55rem; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.95rem; }
.auth-tab.active { background: var(--surface); color: var(--text); }
.btn-google { width: 100%; padding: 0.75rem; font-size: 1rem; background: #fff; color: #1f1f1f; border: 1px solid #dadce0; gap: 0.6rem; margin: 0; }
.btn-google:hover { background: #f2f2f2; }
.g-mark { font-weight: 800; font-size: 1.1rem; color: #4285f4; }
.auth-divider { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.85rem; margin: 1.1rem 0; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-message { border-radius: 8px; padding: 0.7rem 0.9rem; margin-bottom: 1rem; font-size: 0.9rem; background: color-mix(in srgb, var(--danger) 18%, transparent); border: 1px solid var(--danger); }
.auth-message[data-kind="info"] { background: color-mix(in srgb, var(--success) 15%, transparent); border-color: var(--success); }
.auth-footer { text-align: center; margin-top: 1rem; font-size: 0.85rem; color: var(--muted); }
.doc-page { max-width: 760px; width: 100%; line-height: 1.65; }
.doc-page h1 { margin: 0.75rem 0 0.25rem; }
.doc-page h2 { font-size: 1.1rem; margin: 1.25rem 0 0.4rem; }
.doc-page ul { margin-left: 1.25rem; }
.doc-page li { margin-bottom: 0.4rem; }
nav button.link-btn, nav button.link-btn:hover { width: auto; background: none; padding: 0; margin: 0; text-align: left; color: var(--muted); font-size: 0.85rem; }
nav button.link-btn:hover { color: var(--text); }
[hidden] { display: none !important; }
.form-grid { align-items: end; }
.auth-form label > span:first-child { display: block; }
.check-label { white-space: nowrap; }

/* Income (v3) */
.stat-sub { font-size: 0.78rem; color: var(--muted); margin-top: 0.25rem; }
.badge-good { background: color-mix(in srgb, var(--success) 25%, transparent); color: var(--success); }
.optional { font-weight: normal; color: var(--muted); }
.income-preview { margin: 0.75rem 0 0.25rem; padding: 0.6rem 0.8rem; border-radius: 8px; background: var(--surface2); font-size: 0.9rem; }
.income-preview:empty { display: none; }
.income-stats { border-top: 1px solid var(--border); padding: 1rem 0 0.5rem; }
.income-stats:first-of-type { border-top: none; }
.income-stats h4 { margin-bottom: 0.6rem; }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.5rem; margin-bottom: 0.75rem; }
.mini-stats > div { background: var(--surface2); border-radius: 8px; padding: 0.5rem 0.7rem; display: flex; flex-direction: column; }
.mini-stats span { font-size: 0.75rem; color: var(--muted); }
.mini-stats strong { font-size: 1.05rem; }
.bars { display: flex; flex-direction: column; gap: 0.3rem; max-width: 560px; }
.bar-row { display: grid; grid-template-columns: 56px 1fr 90px; gap: 0.5rem; align-items: center; font-size: 0.82rem; }
.bar-row span:last-child { text-align: right; }
.bar { background: var(--surface2); border-radius: 4px; height: 12px; overflow: hidden; }
.bar > div { background: var(--accent); height: 100%; border-radius: 4px; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 4.2rem; }
.pw-toggle { position: absolute; right: 0.4rem; top: 50%; transform: translateY(-50%); background: var(--surface2); color: var(--text); border: none; border-radius: 6px; padding: 0.3rem 0.6rem; font-size: 0.8rem; cursor: pointer; }
.terms-check { flex-direction: row !important; align-items: flex-start; gap: 0.55rem !important; font-weight: normal !important; font-size: 0.9rem; }
.terms-check input { width: auto; margin-top: 0.2rem; }
.terms-check a { color: var(--accent); }
.nav-legal { font-size: 0.75rem; color: var(--muted); margin-top: 0.4rem; }
.nav-legal a { color: var(--muted); }
#welcome-body p { margin-bottom: 0.5rem; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.modal a { color: var(--accent); }

/* Payment tracker (v4) */
.tracker-card { padding-bottom: 1rem; }
.pt-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.pt-progress { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.4rem; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; }
.pt-progress strong { color: var(--text); }
.pt-bar { width: 140px; height: 8px; background: var(--surface2); border-radius: 999px; overflow: hidden; }
.pt-bar > div { height: 100%; background: var(--success); border-radius: 999px; transition: width 0.3s; }
.pt-filters { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.pt-filters select, .pt-filters input { width: auto; padding: 0.4rem 0.6rem; font-size: 0.85rem; }
.pt-filters input[type="search"] { width: 150px; }
.seg { display: inline-flex; background: var(--surface2); border-radius: 8px; padding: 2px; }
.seg-btn { background: none; border: none; color: var(--muted); padding: 0.35rem 0.7rem; border-radius: 6px; font-size: 0.82rem; cursor: pointer; white-space: nowrap; }
.seg-btn.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.pt-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; display: inline-block; max-width: 100%; vertical-align: top; }
.pt-table { width: auto; border-collapse: separate; border-spacing: 0; font-size: 0.85rem; }
.pt-table th, .pt-table td { padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border); }
.pt-table tbody tr:last-child td { border-bottom: none; }
.pt-table tbody tr:hover td { background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.pt-table th { text-align: center; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.pt-table th.pt-name, .pt-table td.pt-name { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 220px; max-width: 300px; }
.pt-table tbody tr:hover td.pt-name { background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.pt-name-line { display: flex; align-items: center; gap: 0.45rem; }
.pt-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pt-meta { font-size: 0.75rem; color: var(--muted); margin-left: 2.6rem; }
.pt-type { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; border-radius: 4px; padding: 0.05rem 0.3rem; min-width: 2.1rem; text-align: center; background: var(--surface2); color: var(--muted); }
.pt-type-sub { color: var(--accent); }
.pt-type-debt { color: var(--warning); }
.pt-cell { text-align: center; width: 52px; }
.pt-cell input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--success); margin: 0; }
th.pt-focus, td.pt-focus { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.pt-table tbody tr:hover td.pt-focus { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }
.pt-notdue input:not(:checked) { opacity: 0.25; }
.pt-future input:not(:checked) { opacity: 0.45; }
.pt-empty { text-align: center; padding: 1.25rem !important; color: var(--muted); }
.icon-mini { background: none; border: none; cursor: pointer; font-size: 0.85rem; padding: 0 0.15rem; opacity: 0.7; }
.icon-mini:hover { opacity: 1; }
.howto-card summary { cursor: pointer; }
@media (max-width: 800px) {
  .pt-filters { width: 100%; }
  .pt-filters input[type="search"] { flex: 1; width: auto; }
  .pt-table th.pt-name, .pt-table td.pt-name { min-width: 150px; max-width: 180px; }
  .pt-meta { margin-left: 0; }
}
.pt-warn { color: var(--warning); }
.tracker-card .field-hint { margin-top: 0.5rem; }
.pt-layout { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.pt-upcoming { flex: 1 1 260px; max-width: 420px; background: var(--surface2); border-radius: 10px; padding: 0.9rem 1rem; }
.pt-upcoming h4 { margin-bottom: 0.5rem; }
.pt-upcoming ul { list-style: none; display: flex; flex-direction: column; gap: 0.15rem; }
.pt-upcoming li { display: flex; flex-direction: column; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.pt-upcoming li:last-child { border-bottom: none; }
.pt-upcoming label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.pt-upcoming input { width: 18px; height: 18px; accent-color: var(--success); margin: 0; }
.up-name { font-weight: 600; }
.up-meta { font-size: 0.78rem; color: var(--muted); margin-left: 1.65rem; }
.due-late { color: var(--danger); font-weight: 600; }
.due-soon { color: var(--warning); font-weight: 600; }

/* ===== Added in v3: categories, history, reports, notifications, security, household ===== */
/* Chart series colors: validated categorical palette, stepped per mode. */
[data-mode="light"] { --s1: #257de0; --s2: #f47230; --s3: #00b894; --s4: #f2a600; --s5: #ee7fac; --s6: #008a17; --s7: #6a4ce2; --s8: #ec4647; }
[data-mode="dark"] { --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05; --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263; }

.badge-mini { font-size: 0.68rem; padding: 0.05rem 0.35rem; vertical-align: middle; }
.badge-shared { background: color-mix(in srgb, var(--s7) 22%, transparent); color: var(--text); }
.badge-warn { background: color-mix(in srgb, var(--warning) 25%, transparent); color: var(--text); }
.pt-cat { font-size: 0.85rem; }
.pt-auto input:checked { accent-color: var(--accent); }
.row-ended td { opacity: 0.55; }
.row-hi td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.chg { font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.chg-up { color: var(--danger); }
.chg-down { color: var(--success); }
.chg-flat { color: var(--muted); font-weight: 400; }
.positive { color: var(--success); }
.negative { color: var(--danger); }

/* Alerts & nudges */
.alerts-card { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.alerts { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; }
.alerts li { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; padding: 0.45rem 0.7rem; border-radius: 8px; border-left: 4px solid var(--accent); background: var(--surface2); font-size: 0.9rem; }
.alerts li > span:nth-child(2) { flex: 1; min-width: 200px; }
.alerts .alert-bad { border-left-color: var(--danger); }
.alerts .alert-warn { border-left-color: var(--warning); }
.alert-icon { font-size: 1rem; }
.alert-line { margin: 0.5rem 0; padding: 0.5rem 0.75rem; border-radius: 8px; border-left: 4px solid var(--danger); background: var(--surface2); }
.nudge-card { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; border-color: var(--accent); }
.changes-table td, .changes-table th { white-space: nowrap; }

/* Forms */
.type-picker { position: relative; margin-bottom: 0.85rem; max-width: 560px; }
.type-picker input { margin-top: 0.3rem; }
.type-results { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin-top: 2px; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); max-height: 320px; overflow-y: auto; }
.type-results li { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.9rem; }
.type-results li.active, .type-results li:hover { background: color-mix(in srgb, var(--accent) 15%, var(--surface)); }
.type-meta { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.type-empty { color: var(--muted); cursor: default !important; }
.check-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1.4rem; margin-top: 0.75rem; }
.more-options { margin-top: 0.75rem; background: var(--surface2); border-radius: 8px; padding: 0.6rem 0.9rem; }
.more-options summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.more-options .form-grid { margin-top: 0.6rem; }
.list-filters { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.list-filters input, .list-filters select { width: auto; min-width: 180px; padding: 0.4rem 0.6rem; font-size: 0.85rem; }
.popular-picker { margin-top: 1rem; }
.popular-picker summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.chip { background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: 0.35rem 0.75rem; font-size: 0.85rem; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip-on { background: color-mix(in srgb, var(--accent) 25%, var(--surface)); border-color: var(--accent); font-weight: 600; }
.privacy-note { margin: 0.6rem 0; padding: 0.55rem 0.8rem; border-radius: 8px; background: color-mix(in srgb, var(--success) 12%, transparent); border: 1px solid color-mix(in srgb, var(--success) 40%, transparent); font-size: 0.85rem; }

/* Generic modal */
.modal-wide { max-width: min(94vw, 760px) !important; width: 100%; }
#gen-modal .modal { max-height: 90vh; overflow-y: auto; }
#gen-modal-body { margin: 0.5rem 0 1rem; }
.history-table td, .history-table th { font-size: 0.85rem; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 70px; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.spark-bar { flex: 1; max-width: 28px; background: var(--s1); border-radius: 4px 4px 0 0; min-height: 4px; }
.steps { margin-left: 1.2rem; display: flex; flex-direction: column; gap: 0.75rem; }
.qr-box { background: #fff; padding: 8px; border-radius: 8px; width: 200px; margin: 0.6rem 0; }
.qr-box svg { display: block; width: 100%; height: auto; }
.secret-key { font-size: 0.95rem; letter-spacing: 0.04em; background: var(--surface2); padding: 0.1rem 0.4rem; border-radius: 4px; user-select: all; word-break: break-all; }
.recovery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.4rem; }
.recovery-grid code { background: var(--surface2); padding: 0.4rem; border-radius: 6px; text-align: center; font-size: 1rem; letter-spacing: 0.05em; user-select: all; }

/* Options */
.options-toc-unused { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; margin: -0.25rem 0 1rem; font-size: 0.85rem; }
.options-toc a { color: var(--accent); text-decoration: none; }
.opt-sub { margin: 1rem 0 0.4rem; font-size: 0.95rem; }
.device-chip { display: inline-flex; gap: 0.3rem; align-items: center; background: var(--surface2); border-radius: 999px; padding: 0.1rem 0.6rem; margin: 0.15rem 0.2rem 0 0; }
.activity-table td { font-size: 0.85rem; padding: 0.35rem 0.4rem; }
.act-bad td:first-child { color: var(--danger); }

/* Auth pages */
.auth-alt { text-align: center; font-size: 0.88rem; margin: 0.25rem 0 0; }
.auth-step-title { font-size: 1.15rem; margin-bottom: 0.25rem; }

/* Onboarding */
.onboarding p { margin-bottom: 0.75rem; }
.ob-steps { list-style: none; display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; font-size: 0.82rem; color: var(--muted); }
.ob-steps li { padding: 0.2rem 0.6rem; border-radius: 999px; background: var(--surface2); }
.ob-steps li.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.ob-steps li.done { color: var(--success); }
.ob-tags .chip { font-size: 0.95rem; padding: 0.5rem 0.9rem; }
.ob-search { margin-bottom: 1rem; max-width: 640px; }
.ob-group { border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.9rem 0.7rem; margin-bottom: 0.75rem; }
.ob-group legend { font-weight: 600; padding: 0 0.3rem; }
.ob-row { display: grid; grid-template-columns: minmax(180px, 1.6fr) 110px 100px 1fr; gap: 0.5rem; align-items: center; padding: 0.25rem 0; }
.ob-row input[type="number"], .ob-row input[type="text"] { padding: 0.35rem 0.5rem; font-size: 0.85rem; }
.ob-row:not(.on) input:not([type=checkbox]) { opacity: 0.4; }
@media (max-width: 640px) { .ob-row { grid-template-columns: 1fr 1fr; } .ob-row .check-label { grid-column: 1 / -1; white-space: normal; } .ob-row .field-hint { display: none; } }

/* Reports */
.report-tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; background: var(--surface2); border-radius: 10px; padding: 0.25rem; margin-bottom: 1rem; }
.report-tabs .seg-btn { font-size: 0.85rem; padding: 0.45rem 0.8rem; }
.report-filter { margin-bottom: 0.75rem; }
.report-filter select { width: auto; }
.donut-layout { display: flex; gap: 1.5rem; align-items: flex-start; flex-wrap: wrap; margin-top: 0.75rem; }
.viz-donut { width: 220px; height: 220px; flex: 0 0 220px; }
.viz-table { flex: 1; min-width: 300px; }
.viz-table td, .viz-table th { font-size: 0.88rem; }
.viz-table .sub-row td { font-size: 0.8rem; color: var(--muted); padding-left: 1.6rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 0.45rem; vertical-align: baseline; }
.viz { width: 100%; height: auto; display: block; margin-top: 0.5rem; overflow: visible; }
.viz-fill { stroke: var(--surface); stroke-width: 2; cursor: default; }
.viz-fill:hover, .viz-fill:focus { opacity: 0.85; outline: none; }
.viz-grid { stroke: var(--border); stroke-width: 1; opacity: 0.6; }
.viz-zero { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.viz-axis { fill: var(--muted); font-size: 11px; }
.viz-bar { fill: var(--s1); }
.viz-bar-hi { fill: var(--s1); opacity: 1; }
.viz g:hover .viz-bar, .viz g:focus .viz-bar { opacity: 0.8; }
.viz g:focus { outline: none; }
.viz-mark { stroke: var(--surface); stroke-width: 2; }
.viz-annot { fill: var(--text); font-size: 11px; font-weight: 600; }
.viz-center-label { fill: var(--muted); font-size: 12px; }
.viz-center-value { fill: var(--text); font-size: 20px; font-weight: 700; }
.viz-cross { stroke: var(--muted); stroke-width: 1; }
.viz-col:focus { outline: none; }
.viz-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.82rem; color: var(--text); margin-top: 0.4rem; }
.viz-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 0.4rem; vertical-align: middle; }
.viz-tip { position: absolute; z-index: 2000; display: none; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.6rem; font-size: 0.8rem; box-shadow: 0 6px 20px rgba(0,0,0,0.3); max-width: 340px; }
.forecast-controls { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.forecast-controls input { width: 220px; }
.forecast-controls select { width: auto; min-width: 140px; }
.paycheck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.paycheck-card { margin-bottom: 0; }
.pc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; margin-bottom: 0.5rem; }
.pc-amt { font-size: 1.2rem; font-weight: 700; color: var(--success); }
.pc-bills { list-style: none; display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.88rem; }
.pc-bills li { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.2rem 0; border-bottom: 1px dashed var(--border); }
.pc-paid { opacity: 0.6; }
.pc-foot { display: flex; justify-content: space-between; margin-top: 0.6rem; font-size: 0.9rem; }
.pc-bar { width: 100%; margin-top: 0.4rem; }
.print-only { display: none; }

@media print {
  .print-only { display: inline; }
  p.print-only { display: block; }
  .no-print, .report-tabs, .forecast-controls, .report-filter, #gen-modal, .viz-tip { display: none !important; }
  body { background: #fff !important; color: #000 !important; }
  .card, .stat { background: #fff !important; color: #000 !important; border: 1px solid #ccc !important; break-inside: avoid; }
  .viz-axis, .viz-center-label { fill: #444 !important; }
  .viz-center-value, .viz-annot { fill: #000 !important; }
  .viz-fill, .viz-mark { stroke: #fff !important; }
  .field-hint, .stat .label, .stat-sub { color: #444 !important; }
  .paycheck-grid { grid-template-columns: 1fr 1fr; }
}

/* Options dropdown in the sidebar */
.nav-dropdown { display: flex !important; align-items: center; }
.nav-caret { margin-left: auto; font-size: 0.8rem; color: var(--muted); transition: transform 0.15s; }
.nav-dropdown[aria-expanded="true"] .nav-caret { transform: rotate(180deg); }
.nav-sub { display: flex; flex-direction: column; gap: 1px; margin: 0.15rem 0 0.5rem 0.9rem; padding-left: 0.6rem; border-left: 2px solid var(--border); }
nav .nav-sub-btn { font-size: 0.88rem; padding: 0.45rem 0.7rem; border-radius: 6px; color: var(--muted); margin: 0; }
nav .nav-sub-btn:hover { color: var(--text); background: var(--surface2); }
nav .nav-sub-btn.active { color: var(--text); background: var(--surface2); font-weight: 600; }
.opt-crumb { color: var(--muted); font-weight: 400; font-size: 0.85em; }

/* Brave push setup prompt */
.brave-fix { margin-top: 0.5rem; padding: 0.75rem 0.9rem; border-radius: 10px; background: var(--surface2); border-left: 4px solid var(--warning); }
.brave-fix p { margin: 0 0 0.5rem; font-size: 0.92rem; }
.brave-steps { margin: 0.25rem 0 0.75rem 1.3rem; display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.92rem; }
.brave-steps code { background: var(--surface); padding: 0.1rem 0.4rem; border-radius: 4px; user-select: all; }
.brave-steps .btn { margin: 0 0 0 0.35rem; padding: 0.15rem 0.6rem; vertical-align: middle; }

/* ---------- Brand refresh (v4): statement-paper type, calmer controls ---------- */
body { -webkit-font-smoothing: antialiased; font-size: 0.97rem; }
button, input, select, textarea { font-family: inherit; }
main > .section-title h2, .section-title h2, .card h2, .card h3, .logo-area h1, .mobile-title, .auth-brand h1, .doc-page h1 {
  font-family: var(--serif); letter-spacing: -0.01em;
}
.section-title h2 { font-size: 1.75rem; font-weight: 750; }
.card > h3 { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.75rem; }
.logo-area h1 { color: var(--text); font-weight: 750; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

/* Money reads like a printed statement: Bitter with even-width digits. */
.stat .value, .pt-summary strong, .money, td.num { font-variant-numeric: tabular-nums lining-nums; }
.stat .value { font-family: var(--serif); font-weight: 700; letter-spacing: -0.01em; font-size: 1.7rem; line-height: 1.15; margin: 0.35rem 0 0.15rem; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; }
.stat { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.1rem; }
.stat .label { font-size: 0.82rem; font-weight: 600; }
.stat .value.positive { color: var(--success); }

/* Navigation: quiet list, goldfinch marker on the current page. */
nav button { position: relative; font-size: 0.93rem; padding: 0.6rem 0.9rem; margin-bottom: 0.1rem; border-radius: 6px; color: var(--muted); }
nav button:hover { color: var(--text); background: var(--surface2); }
nav button.active { color: var(--text); font-weight: 650; background: var(--surface2); }
nav .nav-btn.active::before { content: ''; position: absolute; left: -0.55rem; top: 0.45rem; bottom: 0.45rem; width: 3px; border-radius: 2px; background: var(--gold); }

/* Buttons: one primary per area; everything else secondary. */
.actions button, .btn { border-radius: var(--radius-s); font-weight: 600; }
.btn-secondary { border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface2); border-color: var(--muted); }

/* Row actions: one compact line instead of three stacked buttons. */
td.actions { white-space: nowrap; text-align: right; width: 1%; }
td.actions button {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  padding: 0.28rem 0.6rem; font-size: 0.8rem; font-weight: 600; margin: 0 0 0.25rem 0.25rem;
}
td.actions button:hover { background: var(--surface2); border-color: var(--muted); }
td.actions button.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
td.actions button.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.item-table td { padding: 0.65rem 0.6rem; }
.item-table td:first-child { font-weight: 600; }
.item-table td:first-child .field-hint, .item-table td:first-child .badge { font-weight: 400; }

/* Add form folds away once there is a list to look at. */
.add-card > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.add-card > summary::-webkit-details-marker { display: none; }
.add-card > summary h3 { font-family: var(--serif); font-size: 1.15rem; font-weight: 700; margin: 0; }
.add-card > summary .add-toggle { pointer-events: none; }
.add-card[open] > summary { margin-bottom: 0.75rem; }
.add-card[open] > summary .add-toggle { background: transparent; color: var(--text); border: 1px solid var(--border); }
.add-card:not([open]) { padding-top: 1rem; padding-bottom: 1rem; }

/* Phones: item tables become stacked cards so nothing scrolls sideways. */
@media (max-width: 700px) {
  .card:has(> .item-table) { overflow-x: visible; background: none; border: none; padding: 0; }
  .item-table, .item-table tbody, .item-table tr, .item-table td { display: block; width: 100%; }
  .item-table thead { display: none; }
  .item-table tr { border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.8rem; margin-bottom: 0.6rem; background: var(--surface); }
  .item-table td { border: none; padding: 0.2rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  .item-table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 0.82rem; font-weight: 600; text-align: left; flex-shrink: 0; }
  .item-table td:first-child { display: block; text-align: left; font-size: 1.02rem; padding-bottom: 0.35rem; }
  .item-table td.empty-cell { display: none; }
  .item-table td .cell { text-align: right; }
  .item-table td.actions { width: 100%; justify-content: flex-start; padding-top: 0.5rem; text-align: left; }
  .item-table td.actions button { margin: 0 0.35rem 0 0; }
  .item-table tr.no-items { border: none; background: none; padding: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
