/* ═══════════════════════════════════════════════════════════════════════════
   投資旅程 · App Design System
   共用：色彩 token、深淺色、漲跌色慣例、App 外殼（側欄／頂欄／底部分頁）、
   卡片、數據、表格、表單、對話框與 PWA 提示元件。頁面專屬樣式放在各頁 CSS。
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
    color-scheme: light;
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --surface-3: #eef1f5;
    --line: #e3e7ed;
    --line-strong: #cfd6e0;
    --ink: #0f1728;
    --ink-2: #3a4657;
    --muted: #677285;
    --faint: #98a2b2;

    --brand: #2350d8;
    --brand-strong: #1a3fb0;
    --brand-soft: #e9efff;
    --brand-ink: #ffffff;
    --hero-from: #142a6e;
    --hero-to: #2350d8;

    --red: #d93a43;
    --red-soft: #fdecee;
    --green: #0f9d6b;
    --green-soft: #e2f5ee;
    --warn: #b7791f;
    --warn-soft: #fcf2df;
    --violet: #6b4fd8;
    --violet-soft: #efebfd;

    /* 漲跌色：預設台股慣例「紅漲綠跌」，data-updown="us" 時互換 */
    --gain: var(--red);
    --gain-soft: var(--red-soft);
    --loss: var(--green);
    --loss-soft: var(--green-soft);

    --chart-1: #2350d8;
    --chart-2: #f2a33a;
    --chart-3: #12a5a0;
    --chart-4: #8b5cf6;
    --chart-5: #e05d8c;
    --chart-6: #5b7fa6;
    --chart-7: #9bb33c;
    --chart-8: #c27a4a;
    --chart-grid: rgba(15, 23, 40, .07);
    --chart-text: #677285;
    --tooltip-bg: rgba(15, 23, 40, .94);

    --shadow-sm: 0 1px 2px rgba(15, 23, 40, .05);
    --shadow-md: 0 4px 16px rgba(15, 23, 40, .06);
    --shadow-lg: 0 18px 48px rgba(15, 23, 40, .14);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 999px;

    --font-ui: "Inter", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
    --font-num: "Inter", "Noto Sans TC", system-ui, sans-serif;

    --side-w: 236px;
    --bar-h: 60px;
    --tab-h: 64px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* 舊頁面程式碼仍引用的別名 */
    --profit: var(--gain);
    --profit-soft: var(--gain-soft);
    --loss-color: var(--loss);
    --positive: var(--gain);
    --negative: var(--loss);
    --accent: var(--brand);
    --text-primary: var(--ink);
    --text-secondary: var(--ink-2);
    --text-tertiary: var(--muted);
    --bg-card: var(--surface);
    --bg-subtle: var(--surface-3);
    --bg-hover: var(--surface-2);
    --border: var(--line);
    --border-strong: var(--line-strong);
    --gold: var(--warn);
    --gold-soft: var(--warn-soft);
    --purple: var(--violet);
    --purple-soft: var(--violet-soft);
}

:root[data-updown="us"] {
    --gain: var(--green);
    --gain-soft: var(--green-soft);
    --loss: var(--red);
    --loss-soft: var(--red-soft);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0a0e15;
    --surface: #121823;
    --surface-2: #171f2c;
    --surface-3: #1e2735;
    --line: #243042;
    --line-strong: #33415a;
    --ink: #e9eef6;
    --ink-2: #c3ccd9;
    --muted: #8d98aa;
    --faint: #5f6b7e;
    --brand: #5b8bff;
    --brand-strong: #7aa2ff;
    --brand-soft: rgba(91, 139, 255, .16);
    --brand-ink: #071024;
    --hero-from: #16244d;
    --hero-to: #2a4fc4;
    --red: #ff5f67;
    --red-soft: rgba(255, 95, 103, .14);
    --green: #2fc98e;
    --green-soft: rgba(47, 201, 142, .14);
    --warn: #f0b24f;
    --warn-soft: rgba(240, 178, 79, .14);
    --violet: #a48bff;
    --violet-soft: rgba(164, 139, 255, .16);
    --chart-1: #5b8bff;
    --chart-2: #f5b04f;
    --chart-3: #2ec4bd;
    --chart-4: #a48bff;
    --chart-5: #f07aa5;
    --chart-6: #7f9fc4;
    --chart-7: #b5cc58;
    --chart-8: #dc9466;
    --chart-grid: rgba(233, 238, 246, .08);
    --chart-text: #8d98aa;
    --tooltip-bg: rgba(30, 39, 53, .97);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .3);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .5);
}

/* ── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + var(--safe-top) + 12px); }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: .875rem;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
::selection { background: var(--brand-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.num, .kpi-value, .s-value, td, .tabular { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.skip-link { position: absolute; left: 12px; top: -60px; z-index: 1000; padding: 10px 14px; background: var(--brand); color: var(--brand-ink); border-radius: var(--radius-sm); font-weight: 700; }
.skip-link:focus { top: calc(12px + var(--safe-top)); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── App shell ──────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }

.side-nav {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; gap: 22px;
    padding: 20px 14px 16px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; color: var(--ink); }
.brand-mark {
    width: 34px; height: 34px; flex-shrink: 0;
    display: grid; place-items: center;
    border-radius: 10px;
    background: linear-gradient(140deg, var(--hero-from), var(--hero-to));
    color: #fff;
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-text { display: grid; line-height: 1.2; }
.brand-text strong { font-size: .98rem; font-weight: 750; letter-spacing: -.01em; }
.brand-text small { color: var(--muted); font-size: .7rem; }

.nav-list { display: grid; gap: 2px; }
.nav-list a, .side-link {
    display: flex; align-items: center; gap: 12px;
    min-height: 40px; padding: 8px 12px;
    color: var(--ink-2); border-radius: 10px;
    font-size: .875rem; font-weight: 550;
    transition: background .15s, color .15s;
}
.nav-list a svg, .side-link svg { width: 19px; height: 19px; flex-shrink: 0; color: var(--muted); }
.nav-list a:hover, .side-link:hover { background: var(--surface-3); color: var(--ink); }
.nav-list a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.nav-list a.active svg { color: var(--brand); }
.side-link.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.side-link.active svg { color: var(--brand); }
.nav-cta { margin: 0 4px; }
.nav-cta .btn { width: 100%; }

.side-section { display: grid; gap: 6px; padding: 0 4px; }
.side-label { padding: 0 8px; color: var(--faint); font-size: .68rem; font-weight: 700; letter-spacing: .08em; }
.side-foot { margin-top: auto; display: grid; gap: 8px; }
.side-foot .side-link { width: 100%; border: 0; background: none; cursor: pointer; text-align: left; }
.sync-card { padding: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-md); font-size: .74rem; line-height: 1.6; }
.sync-card b { color: var(--ink); font-weight: 650; }

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

.app-bar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; gap: 16px;
    min-height: calc(var(--bar-h) + var(--safe-top));
    padding: var(--safe-top) clamp(16px, 3vw, 36px) 0;
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    -webkit-backdrop-filter: saturate(160%) blur(16px);
    backdrop-filter: saturate(160%) blur(16px);
    border-bottom: 1px solid transparent;
    transition: border-color .2s;
}
.app-bar.scrolled { border-bottom-color: var(--line); }
.app-bar .brand { display: none; padding: 0; }
.app-bar-title { min-width: 0; flex: 1; }
.app-bar-title h1 { font-size: 1.25rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.25; }
.app-bar-sub { color: var(--muted); font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-bar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.content { width: 100%; max-width: 1440px; margin: 0 auto; padding: 8px clamp(16px, 3vw, 36px) 64px; }

/* Bottom tab bar (mobile) */
.bottom-tab {
    display: none;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: saturate(160%) blur(18px);
    backdrop-filter: saturate(160%) blur(18px);
    border-top: 1px solid var(--line);
}
.tab-items { display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; height: calc(var(--tab-h) + var(--safe-bottom)); padding: 0 4px var(--safe-bottom); }
.tab-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    height: var(--tab-h);
    color: var(--muted); font-size: .68rem; font-weight: 600;
}
.tab-item svg { width: 23px; height: 23px; }
.tab-item.active { color: var(--brand); }
.tab-fab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: var(--tab-h); color: var(--ink-2); font-size: .68rem; font-weight: 650; }
.tab-fab span:first-child {
    width: 44px; height: 44px; margin-top: -14px;
    display: grid; place-items: center;
    border-radius: 14px;
    background: linear-gradient(140deg, var(--hero-from), var(--hero-to));
    color: #fff;
    box-shadow: 0 8px 20px rgba(35, 80, 216, .35);
}
.tab-fab svg { width: 22px; height: 22px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn, .btn-primary {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 38px; padding: 8px 16px;
    border: 1px solid transparent; border-radius: 10px;
    font-size: .84rem; font-weight: 650; line-height: 1.2;
    white-space: nowrap; cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn svg { width: 17px; height: 17px; }
.btn-dark, .btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-dark:hover, .btn-primary:hover:not(:disabled) { background: var(--brand-strong); }
.btn-ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-3); color: var(--ink); }
.btn-danger, .btn-delete-tx { background: transparent; color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.btn-danger:hover, .btn-delete-tx:hover { background: var(--red-soft); }
.btn:disabled, .btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { min-height: 32px; padding: 6px 12px; font-size: .78rem; border-radius: 9px; }
.icon-btn {
    width: 38px; height: 38px; flex-shrink: 0;
    display: inline-grid; place-items: center;
    border: 1px solid var(--line-strong); border-radius: 10px;
    background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn svg { width: 19px; height: 19px; }
.btn-primary .arrow { display: inline-block; }
.btn-primary.loading .arrow, .is-spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Status pill ────────────────────────────────────────────────────────── */
.status-pill, .status-link {
    display: inline-flex; align-items: center; gap: 7px;
    min-height: 32px; padding: 5px 12px;
    color: var(--ink-2); background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius-full);
    font-size: .76rem; font-weight: 600; white-space: nowrap;
}
.status-pill::before, .status-link::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.status-link.is-ok::before, .status-pill.is-ok::before { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.status-link.is-error::before, .status-pill.is-error::before { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.status-link:hover { border-color: var(--line-strong); }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card, .panel {
    min-width: 0;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-head, .panel-head {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px 16px; flex-wrap: wrap;
    margin-bottom: 16px;
}
.card-head h2, .card-title, .panel-title { font-size: 1rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.35; }
.card-head p, .card-sub { margin-top: 2px; color: var(--muted); font-size: .76rem; }
.card-head > a, .card-link { color: var(--brand); font-size: .78rem; font-weight: 650; white-space: nowrap; }
.card-head > a:hover, .card-link:hover { text-decoration: underline; }
.eyebrow, .panel-kicker { display: block; color: var(--muted); font-size: .7rem; font-weight: 700; letter-spacing: .06em; }
.record-count { color: var(--muted); font-size: .76rem; }

.section { margin-top: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head h2 { font-size: 1.12rem; font-weight: 750; letter-spacing: -.015em; }
.section-head p { color: var(--muted); font-size: .78rem; }

/* ── KPI ────────────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi {
    min-width: 0;
    display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    text-align: left;
}
.kpi-label { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .76rem; font-weight: 600; }
.kpi-value { font-size: 1.45rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; }
.kpi-sub { color: var(--muted); font-size: .74rem; line-height: 1.5; }
.kpi.primary, .kpi-hero {
    color: #fff;
    background: radial-gradient(120% 140% at 100% 0%, rgba(255, 255, 255, .16), transparent 55%), linear-gradient(140deg, var(--hero-from), var(--hero-to));
    border-color: transparent;
}
.kpi.primary .kpi-label, .kpi.primary .kpi-sub, .kpi-hero .kpi-label, .kpi-hero small { color: rgba(255, 255, 255, .78); }
.kpi.primary .kpi-value { color: #fff; font-size: 1.75rem; }
.kpi-value.profit, .profit { color: var(--gain); }
.kpi-value.loss, .loss { color: var(--loss); }
.kpi-value.warning { color: var(--warn); }
.kpi-value.healthy { color: var(--green); }
.up { color: var(--gain) !important; }
.down { color: var(--loss) !important; }

.tag {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 8px; margin-right: 6px;
    border-radius: var(--radius-full);
    background: var(--surface-3); color: var(--ink-2);
    font-size: .7rem; font-weight: 700; white-space: nowrap;
}
.tag.up { background: var(--gain-soft); color: var(--gain) !important; }
.tag.down { background: var(--loss-soft); color: var(--loss) !important; }

/* Stat strip */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { min-width: 0; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.s-label { color: var(--muted); font-size: .74rem; font-weight: 600; }
.s-value { margin: 6px 0 2px; font-size: 1.3rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.2; overflow-wrap: anywhere; }
.s-sub { color: var(--muted); font-size: .72rem; overflow-wrap: anywhere; }
.s-value.v-profit { color: var(--gain); }
.s-value.v-loss { color: var(--loss); }

/* ── Badges & amounts ───────────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: .7rem; font-weight: 700; white-space: nowrap;
}
.b-buy { background: var(--gain-soft); color: var(--gain); }
.b-sell { background: var(--loss-soft); color: var(--loss); }
.b-dividend { background: var(--warn-soft); color: var(--warn); }
.b-capital { background: var(--violet-soft); color: var(--violet); }
.a-buy { color: var(--ink); font-weight: 650; }
.a-sell { color: var(--ink); font-weight: 650; }
.a-dividend { color: var(--warn); font-weight: 650; }
.a-capital { color: var(--violet); font-weight: 650; }
.amount-positive { color: var(--gain); font-weight: 600; }
.amount-negative { color: var(--loss); font-weight: 600; }
.bal-pos { color: var(--gain); }
.bal-neg { color: var(--loss); }
.td-muted { color: var(--muted); font-size: .8rem; }
.stock-code, .stock-ticker { font-weight: 700; }
.transaction-tag {
    display: inline-flex; max-width: 160px; padding: 2px 8px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--brand); background: var(--brand-soft);
    border-radius: 6px; font-size: .7rem; font-weight: 650;
}

/* ── Segmented controls ─────────────────────────────────────────────────── */
.seg, .mode-switch, .transaction-tabs, .stock-market-switch {
    display: inline-flex; flex-wrap: wrap; gap: 2px;
    padding: 3px;
    background: var(--surface-3);
    border-radius: 11px;
}
.seg button, .mode-switch button, .tab-btn, .stock-market-switch button {
    min-height: 32px; padding: 5px 13px;
    border: 0; border-radius: 8px;
    background: transparent; color: var(--muted);
    font-size: .8rem; font-weight: 650; cursor: pointer;
    transition: background .15s, color .15s;
}
.seg button:hover, .mode-switch button:hover, .tab-btn:hover, .stock-market-switch button:hover { color: var(--ink); }
.seg button.active, .mode-switch button.active, .tab-btn.active, .stock-market-switch button.active {
    background: var(--surface); color: var(--ink);
    box-shadow: 0 1px 3px rgba(15, 23, 40, .12);
}
.tab-btn small { margin-left: 4px; color: var(--faint); font-size: .66rem; font-weight: 700; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap { min-width: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table, table.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.table-wrap th {
    position: sticky; top: 0;
    padding: 9px 12px;
    background: var(--surface-2);
    color: var(--muted);
    border-bottom: 1px solid var(--line);
    font-size: .72rem; font-weight: 650; white-space: nowrap;
}
.table-wrap th:first-child { border-top-left-radius: 8px; }
.table-wrap th:last-child { border-top-right-radius: 8px; }
.table-wrap td {
    padding: 11px 12px;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
    font-size: .84rem; white-space: nowrap; vertical-align: middle;
}
.table-wrap tbody tr:last-child td { border-bottom: 0; }
.table-wrap tbody tr { transition: background .12s; }
.table-wrap tbody tr:hover { background: var(--surface-2); }
.mobile-cell-value { display: contents; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.filter-bar { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)) auto; gap: 10px; align-items: end; margin-bottom: 16px; }
.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.filter-label { color: var(--muted); font-size: .7rem; font-weight: 650; }
.filter-select, .form-group input, .form-group select, .review-dialog input, .review-dialog select, .template-controls select, .template-controls input, .settings-dialog select {
    width: 100%; min-height: 38px;
    padding: 8px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font-size: .84rem;
    transition: border-color .15s, box-shadow .15s;
}
.filter-select, .settings-dialog select {
    padding-right: 32px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23778294' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
    cursor: pointer;
}
.filter-select:focus, .form-group input:focus, .form-group select:focus, .review-dialog input:focus, .review-dialog select:focus {
    outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.filter-actions { display: flex; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.form-group label { color: var(--ink-2); font-size: .76rem; font-weight: 650; }

/* Switch (checkbox) */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .toggle-ui { position: relative; width: 38px; height: 22px; flex-shrink: 0; border-radius: 99px; background: var(--line-strong); transition: background .15s; }
.switch .toggle-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s; }
.switch input:checked + .toggle-ui { background: var(--brand); }
.switch input:checked + .toggle-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .toggle-ui { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ── Pagination ─────────────────────────────────────────────────────────── */
.pagination { display: flex; justify-content: center; align-items: center; gap: 12px; padding-top: 14px; margin-top: 4px; border-top: 1px solid var(--line); }
.pagination span { color: var(--muted); font-size: .78rem; }
.btn-page { min-height: 34px; padding: 5px 14px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); color: var(--ink-2); font-size: .78rem; font-weight: 600; cursor: pointer; }
.btn-page:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.btn-page:disabled { opacity: .35; cursor: not-allowed; }

/* ── Modal & dialogs ────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    background: rgba(8, 12, 20, .45);
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.modal-box {
    width: 100%; max-width: 620px; max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
}
.modal-box h2 { margin-bottom: 18px; font-size: 1.15rem; font-weight: 750; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.modal-note { margin-top: 12px; color: var(--muted); font-size: .72rem; text-align: center; }

dialog { color: var(--ink); }
dialog::backdrop { background: rgba(8, 12, 20, .5); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.review-dialog, .settings-dialog, .asset-breakdown-dialog {
    width: min(820px, calc(100vw - 32px)); max-height: 86vh;
    padding: 22px;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
}
.review-dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 8px; }
.review-dialog-head h2 { font-size: 1.12rem; font-weight: 750; }
.review-dialog p { font-size: .84rem; line-height: 1.7; color: var(--ink-2); }
.review-dialog a, .review-note a { color: var(--brand); font-weight: 600; }
.review-dialog table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.review-dialog td, .review-dialog th { padding: 9px; text-align: left; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.review-dialog th { color: var(--muted); font-weight: 650; }
.review-dialog .table-wrap { max-height: 42vh; overflow: auto; }
.review-dialog label { display: grid; gap: 6px; margin: 12px 0; color: var(--ink-2); font-size: .8rem; font-weight: 600; }
.review-dialog button { cursor: pointer; }
.review-dialog-head button:not(.btn) { min-height: 34px; padding: 6px 14px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); color: var(--ink-2); font-weight: 650; }
.review-accounts { display: flex; gap: 10px; flex-wrap: wrap; }
.review-history { display: grid; }
.review-history a { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: .82rem; }
.review-history a:hover { color: var(--brand); }

/* ── Feedback states ────────────────────────────────────────────────────── */
.empty, .empty-state, .empty-soft, .loading-state {
    padding: 32px 16px;
    color: var(--muted);
    font-size: .82rem; line-height: 1.7; text-align: center;
}
.empty-state, .empty-soft { border: 1px dashed var(--line-strong); border-radius: var(--radius-md); background: var(--surface-2); }
.error-message, .error-state {
    padding: 14px 16px;
    color: var(--red);
    background: var(--red-soft);
    border-radius: var(--radius-md);
    font-size: .82rem; line-height: 1.6;
}
.loading-pulse { animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* ── Shared ledger / review tools ───────────────────────────────────────── */
.holding-link { min-height: 32px; padding: 0; border: 0; background: none; color: var(--ink); font-weight: 700; text-align: left; cursor: pointer; }
.holding-link:hover { color: var(--brand); text-decoration: underline; text-underline-offset: 3px; }
.review-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 14px 0; }
.review-metrics > div { padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-md); color: var(--muted); font-size: .76rem; }
.review-metrics strong { display: block; margin: 6px 0 2px; color: var(--ink); font-size: 1.2rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.review-metrics small, .review-note { color: var(--muted); font-size: .76rem; line-height: 1.7; }
.ledger-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.ledger-tools-note { flex-basis: 100%; color: var(--muted); font-size: .74rem; line-height: 1.6; }
.ledger-focus { margin: 0 0 16px; padding: 14px 16px; background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent); border-radius: var(--radius-md); }
.ledger-focus a { color: var(--brand); font-weight: 600; }
.ledger-focus ul { padding-left: 20px; line-height: 1.9; }
.ledger-row-highlight { outline: 2px solid var(--warn); outline-offset: -2px; background: var(--warn-soft) !important; }
.template-controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.template-controls select, .template-controls input { width: auto; flex: 1 1 150px; }
.tool-error { color: var(--red); }
.tool-ok { color: var(--green); }

/* ── Toast, install & update prompts ────────────────────────────────────── */
.app-toast, .toast {
    position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); z-index: 2000;
    display: flex; align-items: center; gap: 12px;
    max-width: min(460px, calc(100vw - 24px));
    padding: 12px 14px 12px 16px;
    color: #fff; background: #111827;
    border-radius: 14px; box-shadow: var(--shadow-lg);
    font-size: .84rem; font-weight: 600;
    transform: translate(-50%, 150%); opacity: 0;
    transition: transform .25s ease, opacity .25s ease;
}
.app-toast.show, .toast.show { transform: translate(-50%, 0); opacity: 1; }
.app-toast button { flex-shrink: 0; min-height: 32px; padding: 6px 12px; border: 0; border-radius: 8px; background: #fff; color: #111827; font-weight: 700; cursor: pointer; }
.app-toast button.ghost { background: transparent; color: rgba(255, 255, 255, .75); }

.offline-banner {
    position: fixed; top: calc(var(--safe-top) + 8px); left: 50%; z-index: 1500;
    padding: 6px 14px;
    color: #fff; background: #b45309;
    border-radius: 99px; box-shadow: var(--shadow-md);
    font-size: .74rem; font-weight: 700;
    transform: translateX(-50%);
}

.settings-dialog { width: min(440px, calc(100vw - 32px)); }
.settings-dialog h2 { font-size: 1.1rem; font-weight: 750; }
.settings-list { display: grid; gap: 4px; margin: 14px 0 4px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row > div:first-child { display: grid; gap: 2px; }
.setting-row strong { font-size: .86rem; }
.setting-row small { color: var(--muted); font-size: .74rem; }
.setting-row { flex-wrap: wrap; }
.setting-row .seg { flex-wrap: nowrap; flex-shrink: 0; }
.setting-row .seg button { padding: 5px 10px; white-space: nowrap; }
.settings-version { margin-top: 10px; color: var(--faint); font-size: .72rem; text-align: center; }

/* ── Responsive shell ───────────────────────────────────────────────────── */
@media (max-width: 1023px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
    .side-nav { display: none; }
    .app-bar { gap: 10px; }
    .app-bar .brand { display: flex; }
    .app-bar .brand-text { display: none; }
    .app-bar-title h1 { font-size: 1.08rem; }
    .bottom-tab { display: block; }
    .content { padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 28px); }
    .app-toast, .toast { bottom: calc(var(--tab-h) + var(--safe-bottom) + 12px); }
    .hide-mobile { display: none !important; }
    .filter-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .filter-actions { grid-column: 1 / -1; }
}
@media (min-width: 1024px) {
    .hide-desktop { display: none !important; }
}

@media (max-width: 768px) {
    .content { padding-left: 14px; padding-right: 14px; }
    .app-bar { padding-left: 14px; padding-right: 14px; }
    .app-bar-actions .btn-label { display: none; }
    .card, .panel { padding: 16px; border-radius: 14px; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .stat-card { padding: 12px; border-radius: 12px; }
    .s-value { font-size: clamp(1.02rem, 4.2vw, 1.25rem); }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .kpi { padding: 14px; border-radius: 14px; }
    .kpi-value { font-size: 1.18rem; }
    .kpi.primary { grid-column: 1 / -1; }
    .kpi.primary .kpi-value { font-size: 1.6rem; }
    .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

    /* Tables → cards */
    .table-wrap { overflow-x: visible; }
    .table-wrap table { display: block; }
    .table-wrap thead { display: none; }
    .table-wrap tbody { display: block; }
    .table-wrap tbody tr {
        display: grid;
        padding: 6px 14px;
        margin-bottom: 8px;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 12px;
    }
    .table-wrap tbody tr:last-child { margin-bottom: 0; }
    .table-wrap tbody tr:hover { background: var(--surface); }
    .table-wrap td {
        display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 12px; align-items: start;
        min-width: 0; padding: 9px 0;
        border: 0; border-bottom: 1px solid var(--line);
        white-space: normal; text-align: right;
        font-size: .84rem; line-height: 1.5;
    }
    .table-wrap tbody tr td:last-child { border-bottom: 0; }
    .table-wrap td::before { content: attr(data-label); color: var(--muted); font-size: .76rem; font-weight: 500; text-align: left; }
    .table-wrap td[data-empty="1"] { display: none; }
    .table-wrap .mobile-cell-value { display: block; min-width: 0; overflow-wrap: anywhere; }

    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal-box {
        max-width: 100%; max-height: 92vh;
        padding: 10px 16px calc(16px + var(--safe-bottom));
        border-radius: 22px 22px 0 0;
        border-bottom: 0;
    }
    .modal-box::before { content: ""; display: block; width: 40px; height: 4px; margin: 0 auto 14px; border-radius: 99px; background: var(--line-strong); }
    .form-grid { grid-template-columns: 1fr; gap: 12px; }
    .form-full { grid-column: 1; }
    .form-group input, .form-group select, .filter-select { font-size: 16px; }
    .modal-actions { position: sticky; bottom: calc(-16px - var(--safe-bottom)); margin: 18px -16px 0; padding: 12px 16px calc(12px + var(--safe-bottom)); background: var(--surface); border-top: 1px solid var(--line); flex-wrap: wrap; }
    .modal-actions .btn { flex: 1; min-height: 44px; }
    .review-dialog, .settings-dialog, .asset-breakdown-dialog { padding: 16px; }
    .review-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .review-metrics > div:last-child:nth-child(odd), .kpi-grid > .kpi:last-child:nth-child(even) { grid-column: 1 / -1; }
    .review-history a { flex-direction: column; gap: 2px; }
    .ledger-toolbar { flex-wrap: nowrap; overflow-x: auto; margin-right: -14px; padding-right: 14px; scrollbar-width: none; }
    .ledger-toolbar::-webkit-scrollbar { display: none; }
    .ledger-toolbar .btn { flex: 0 0 auto; }
    .ledger-tools-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

@media print {
    .side-nav, .app-bar-actions, .bottom-tab, .app-toast { display: none !important; }
    .shell { display: block; }
    body { background: #fff; }
}
