/* Vaplong Mini: hand-written styles, no build step. */

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("../fonts/inter-latin-wght.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("../fonts/inter-latin-ext-wght.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Tokens ---------- */
:root {
    color-scheme: light;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --surface-3: #f1f3f6;
    --border: #e6e8ee;
    --border-strong: #d6dae2;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --faint: #94a3b8;

    --brand: #4f46e5;
    --brand-hover: #4338ca;
    --brand-soft: #eef2ff;
    --brand-ring: rgba(79, 70, 229, .22);

    --owes: #dc2626;
    --owes-soft: #fef2f2;
    --owes-line: #fecaca;
    --credit: #059669;
    --credit-soft: #ecfdf5;
    --credit-line: #a7f3d0;
    --settled: #64748b;
    --settled-soft: #f1f5f9;
    --warn: #b45309;
    --warn-soft: #fffbeb;

    --side-bg: #0b1120;
    --side-text: #94a3b8;
    --side-text-strong: #f8fafc;
    --side-hover: rgba(148, 163, 184, .08);
    --side-active: rgba(99, 102, 241, .16);
    --side-border: rgba(148, 163, 184, .12);

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
    --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, .08), 0 2px 4px -2px rgba(15, 23, 42, .05);
    --shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, .18);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;

    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0a0e17;
        --surface: #111726;
        --surface-2: #0e1420;
        --surface-3: #182033;
        --border: #1e2738;
        --border-strong: #2a3549;
        --text: #e8ecf3;
        --text-2: #c3cad6;
        --muted: #8b95a7;
        --faint: #5f6b80;
        --brand: #818cf8;
        --brand-hover: #a5b4fc;
        --brand-soft: rgba(129, 140, 248, .12);
        --brand-ring: rgba(129, 140, 248, .3);
        --owes: #f87171;
        --owes-soft: rgba(248, 113, 113, .1);
        --owes-line: rgba(248, 113, 113, .3);
        --credit: #34d399;
        --credit-soft: rgba(52, 211, 153, .1);
        --credit-line: rgba(52, 211, 153, .3);
        --settled: #94a3b8;
        --settled-soft: rgba(148, 163, 184, .1);
        --warn: #fbbf24;
        --warn-soft: rgba(251, 191, 36, .1);
        --side-bg: #070a12;
        --shadow-xs: none;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
        --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, .5);
        --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .6);
    }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv11", "ss01";
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }
h1, h2, h3 { margin: 0; color: var(--text); letter-spacing: -.015em; }
h1 { font-size: 24px; font-weight: 650; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
p { margin: 0; }
img, svg { display: block; }
.icon { flex: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num, .amount { font-variant-numeric: tabular-nums; }
.num { text-align: right; }
.tone-owes { color: var(--owes); }
.tone-credit { color: var(--credit); }
.tone-settled { color: var(--settled); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column;
    background: var(--side-bg);
    color: var(--side-text);
    border-right: 1px solid var(--side-border);
    padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; color: var(--side-text-strong); }
.brand:hover { color: var(--side-text-strong); }
.brand-name { font-size: 15px; font-weight: 650; letter-spacing: -.01em; line-height: 1.15; }
.brand-name small { display: block; font-size: 11.5px; font-weight: 500; color: var(--side-text); letter-spacing: 0; }

.side-label { padding: 14px 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: #4b5870; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 10px; border-radius: 9px;
    color: var(--side-text); font-weight: 500;
    transition: background .15s, color .15s;
}
.side-nav a:hover { background: var(--side-hover); color: var(--side-text-strong); }
.side-nav a.active { background: var(--side-active); color: var(--side-text-strong); }
.side-nav a.active .icon { color: #a5b4fc; }

.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--side-border); display: flex; align-items: center; gap: 10px; }
.side-user { min-width: 0; flex: 1; }
.side-user strong { display: block; color: var(--side-text-strong); font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user span { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, #6366f1, #0ea5e9); color: #fff; font-weight: 650; font-size: 12.5px; flex: none; }
.icon-btn {
    display: inline-grid; place-items: center; width: 34px; height: 34px;
    border-radius: 9px; border: 0; background: transparent; color: var(--side-text); cursor: pointer;
}
.icon-btn:hover { background: var(--side-hover); color: var(--side-text-strong); }

.main { min-width: 0; }
.content { max-width: 1280px; margin: 0 auto; padding: 32px 36px 56px; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head .subtitle { color: var(--muted); margin-top: 4px; }
.eyebrow { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 10px; }
.eyebrow:hover { color: var(--text); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 36px; padding: 0 14px;
    font: inherit; font-weight: 550; font-size: 13.5px; line-height: 1;
    color: var(--text-2); background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: 9px;
    box-shadow: var(--shadow-xs);
    cursor: pointer; white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--faint); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(79, 70, 229, .3), inset 0 1px 0 rgba(255, 255, 255, .12); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .btn-primary { color: #0b1120; }
    :root:not([data-theme="light"]) .btn-primary:hover { color: #0b1120; }
}
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-danger { color: var(--owes); }
.btn-danger:hover { color: var(--owes); background: var(--owes-soft); border-color: var(--owes-line); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; gap: 6px; }
.btn-block { width: 100%; }
.btn-lg { height: 42px; font-size: 14.5px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; flex-wrap: wrap; }
.card-head p { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card-body { padding: 20px; }
.card-flush { overflow: hidden; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-main-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.mt { margin-top: 20px; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { padding: 18px 20px; position: relative; overflow: hidden; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 13px; font-weight: 500; color: var(--muted); }
.kpi-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.kpi-icon.owes { background: var(--owes-soft); color: var(--owes); }
.kpi-icon.credit { background: var(--credit-soft); color: var(--credit); }
.kpi-icon.neutral { background: var(--surface-3); color: var(--text-2); }
.kpi-value { margin-top: 10px; font-size: 26px; font-weight: 680; letter-spacing: -.025em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-foot { margin-top: 8px; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-foot a { font-weight: 550; display: inline-flex; align-items: center; gap: 3px; }

/* ---------- Chart ---------- */
.chart { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 10px; align-items: end; height: 210px; padding: 24px 20px 0; }
.chart-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 8px; position: relative; }
.chart-bar {
    width: 100%; max-width: 40px; min-height: 3px;
    border-radius: 7px 7px 3px 3px;
    background: linear-gradient(180deg, #818cf8, #6366f1);
    opacity: .9; transition: opacity .15s, transform .15s;
}
.chart-bar.empty { background: var(--surface-3); opacity: 1; }
.chart-bar.current { background: linear-gradient(180deg, #38bdf8, #0ea5e9); }
.chart-col:hover .chart-bar { opacity: 1; }
.chart-label { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.chart-tip {
    position: absolute; bottom: calc(100% - 4px); left: 50%; transform: translate(-50%, 4px);
    background: var(--text); color: var(--surface); font-size: 11.5px; font-weight: 600;
    padding: 5px 8px; border-radius: 7px; white-space: nowrap; pointer-events: none;
    opacity: 0; transition: opacity .12s, transform .12s; font-variant-numeric: tabular-nums; z-index: 2;
}
.chart-col:hover .chart-tip { opacity: 1; transform: translate(-50%, 0); }
.chart-axis { border-top: 1px solid var(--border); margin: 0 20px; }
.chart-legend { display: flex; gap: 16px; padding: 12px 20px 18px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

/* ---------- Split / meter ---------- */
.split-figure { font-size: 28px; font-weight: 680; letter-spacing: -.025em; font-variant-numeric: tabular-nums; margin-top: 6px; }
.meter { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface-3); margin: 18px 0 16px; gap: 2px; }
.meter span { display: block; height: 100%; }
.meter .owes { background: var(--owes); }
.meter .credit { background: var(--credit); }
.legend-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.legend-list li { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.legend-list li .grow { flex: 1; color: var(--text-2); }
.legend-list li strong { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Lists ---------- */
.rank-list { list-style: none; margin: 0; padding: 8px 8px 10px; }
.rank-list li a { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; color: inherit; }
.rank-list li a:hover { background: var(--surface-2); }
.rank-name { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-bar { height: 5px; border-radius: 99px; background: var(--surface-3); margin-top: 6px; overflow: hidden; }
.rank-bar span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #f87171, #dc2626); }
.rank-amount { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--owes); white-space: nowrap; }

.activity { list-style: none; margin: 0; padding: 8px 8px 10px; }
.activity li a { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 9px 12px; border-radius: 10px; color: inherit; }
.activity li a:hover { background: var(--surface-2); }
.activity-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.activity-icon.in { background: var(--credit-soft); color: var(--credit); }
.activity-icon.out { background: var(--owes-soft); color: var(--owes); }
.activity-title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity-meta { font-size: 12px; color: var(--muted); }
.activity-amount { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.activity-amount.in { color: var(--credit); }
.reversed-text { text-decoration: line-through; color: var(--faint) !important; }

.empty-state { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty-state .icon { margin: 0 auto 10px; color: var(--faint); }

/* ---------- Avatars ---------- */
.avatar { display: inline-grid; place-items: center; border-radius: 10px; font-weight: 650; flex: none; letter-spacing: .01em; }
.avatar-sm { width: 30px; height: 30px; font-size: 11.5px; border-radius: 8px; }
.avatar-md { width: 36px; height: 36px; font-size: 12.5px; }
.avatar-lg { width: 56px; height: 56px; font-size: 19px; border-radius: 14px; }
.av-0 { background: #eef2ff; color: #4338ca; }
.av-1 { background: #ecfeff; color: #0e7490; }
.av-2 { background: #fdf4ff; color: #a21caf; }
.av-3 { background: #fff7ed; color: #c2410c; }
.av-4 { background: #f0fdf4; color: #15803d; }
.av-5 { background: #fef2f2; color: #b91c1c; }
.av-6 { background: #f0f9ff; color: #0369a1; }
.av-7 { background: #fefce8; color: #a16207; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .avatar { background: var(--surface-3); }
    :root:not([data-theme="light"]) .av-0 { color: #a5b4fc; }
    :root:not([data-theme="light"]) .av-1 { color: #67e8f9; }
    :root:not([data-theme="light"]) .av-2 { color: #f0abfc; }
    :root:not([data-theme="light"]) .av-3 { color: #fdba74; }
    :root:not([data-theme="light"]) .av-4 { color: #86efac; }
    :root:not([data-theme="light"]) .av-5 { color: #fca5a5; }
    :root:not([data-theme="light"]) .av-6 { color: #7dd3fc; }
    :root:not([data-theme="light"]) .av-7 { color: #fde047; }
}

/* ---------- Balance badge ---------- */
.balance { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.balance .tag {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
    background: var(--settled-soft); color: var(--settled);
}
.balance .tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.balance .amt { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
.balance.tone-owes .tag { background: var(--owes-soft); color: var(--owes); }
.balance.tone-owes .amt { color: var(--owes); }
.balance.tone-credit .tag { background: var(--credit-soft); color: var(--credit); }
.balance.tone-credit .amt { color: var(--credit); }
.balance.tone-settled .amt { color: var(--muted); }
.balance-plain { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Pills (entry kinds) ---------- */
.pill {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; font-weight: 550; line-height: 1;
    padding: 5px 9px; border-radius: 99px;
    background: var(--surface-3); color: var(--text-2); white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill.sale { background: #eef2ff; color: #4338ca; }
.pill.shipping { background: #f1f5f9; color: #475569; }
.pill.sale_payment { background: #ecfeff; color: #0e7490; }
.pill.return { background: #fffbeb; color: #b45309; }
.pill.payment { background: #ecfdf5; color: #047857; }
.pill.charge { background: #fff1f2; color: #be123c; }
.pill.reversal { background: #faf5ff; color: #7e22ce; }
.pill.inactive { background: var(--surface-3); color: var(--muted); }
.pill.inactive::before { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .pill { background: var(--surface-3); }
    :root:not([data-theme="light"]) .pill.sale { color: #a5b4fc; }
    :root:not([data-theme="light"]) .pill.shipping { color: #cbd5e1; }
    :root:not([data-theme="light"]) .pill.sale_payment { color: #67e8f9; }
    :root:not([data-theme="light"]) .pill.return { color: #fcd34d; }
    :root:not([data-theme="light"]) .pill.payment { color: #6ee7b7; }
    :root:not([data-theme="light"]) .pill.charge { color: #fda4af; }
    :root:not([data-theme="light"]) .pill.reversal { color: #d8b4fe; }
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { padding: 12px 16px; text-align: left; vertical-align: middle; }
thead th {
    font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); background: var(--surface-2);
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
thead th.num { text-align: right; }
tbody td { border-bottom: 1px solid var(--border); color: var(--text-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr[data-href] { cursor: pointer; }
td.num { color: var(--text); }
tfoot th, tfoot td { padding: 14px 16px; border-top: 1px solid var(--border-strong); background: var(--surface-2); font-weight: 600; font-variant-numeric: tabular-nums; }
tfoot th:first-child { font-size: 12.5px; color: var(--muted); font-weight: 600; }
tr.reversed td { color: var(--faint); }
tr.reversed td.amount { text-decoration: line-through; }
tr.opening td { background: var(--surface-2); font-weight: 550; color: var(--text-2); }
.cell-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell-title { font-weight: 600; color: var(--text); }
.cell-title:hover { color: var(--brand); }
.cell-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.cell-stack > * + * { margin-top: 3px; }
.cell-stack .meta-line { display: flex; }
.meta-line { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); }
.amount-in { color: var(--credit) !important; font-weight: 550; }
.amount-out { color: var(--text); font-weight: 550; }
th.col-actions, td.col-actions { width: 1%; text-align: right; }

/* ---------- Toolbar & filters ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 10px; }
.tabs a { padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 550; color: var(--muted); white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.search { position: relative; flex: 1; min-width: 220px; }
.search { margin: 0; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; z-index: 1; }
.search input[type=search] { padding-left: 36px; }
.toolbar select { width: auto; min-width: 190px; }
.result-count { font-size: 12.5px; color: var(--muted); }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
label, .label { display: block; font-size: 13px; font-weight: 550; color: var(--text-2); margin-bottom: 6px; }
.label-hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=number], select, textarea {
    width: 100%; height: 38px; padding: 0 12px;
    font: inherit; font-size: 14px; color: var(--text);
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 9px;
    box-shadow: var(--shadow-xs);
    transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
select {
    appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
input[type=file] { width: 100%; font: inherit; font-size: 13px; color: var(--muted); padding: 8px; border: 1px dashed var(--border-strong); border-radius: 9px; background: var(--surface-2); cursor: pointer; }
input[type=file]::file-selector-button { font: inherit; font-weight: 550; font-size: 12.5px; margin-right: 10px; padding: 6px 10px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); cursor: pointer; }
.input-affix { position: relative; }
.input-affix .affix { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 550; pointer-events: none; }
.input-affix input[type=text] { padding-left: 30px; font-variant-numeric: tabular-nums; font-weight: 550; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--owes); }
.error { color: var(--owes); font-size: 12.5px; margin-top: 6px; font-weight: 500; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.checkbox { display: inline-flex; align-items: center; gap: 9px; font-weight: 500; cursor: pointer; margin: 0; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--brand); margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-section { padding: 22px 24px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; }
.form-section:last-of-type { border-bottom: 0; }
.form-section h2 { font-size: 14px; }
.form-section p { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.form-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; gap: 4px; background: var(--surface-3); border-radius: 11px; }
.segmented label { margin: 0; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
    display: flex; align-items: center; justify-content: center; gap: 7px;
    height: 36px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted);
    transition: background .15s, color .15s, box-shadow .15s;
}
.segmented span:hover { color: var(--text); }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented input[value=payment]:checked + span { color: var(--credit); }
.segmented input[value=charge]:checked + span { color: var(--owes); }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 1px; }

.period-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.period-form input[type=date], .period-form select { height: 32px; font-size: 13px; width: auto; padding-right: 10px; }
.period-form select { padding-right: 32px; }
.period-form .sep { color: var(--faint); }

/* ---------- Alerts ---------- */
.alert { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; margin-bottom: 20px; font-weight: 500; border: 1px solid; }
.alert-success { background: var(--credit-soft); border-color: var(--credit-line); color: var(--credit); }
.alert-error { background: var(--owes-soft); border-color: var(--owes-line); color: var(--owes); }
.alert .grow { flex: 1; color: var(--text); }
.alert-close { border: 0; background: transparent; color: inherit; cursor: pointer; padding: 2px; border-radius: 6px; opacity: .7; }
.alert-close:hover { opacity: 1; }

/* ---------- Customer header ---------- */
.profile { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 24px; flex-wrap: wrap; }
.profile-main { display: flex; align-items: center; gap: 16px; min-width: 0; }
.profile-main h1 { font-size: 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; }
.chips span { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.balance-panel { text-align: right; padding: 14px 18px; border-radius: 14px; background: var(--settled-soft); min-width: 220px; }
.balance-panel.tone-owes { background: var(--owes-soft); }
.balance-panel.tone-credit { background: var(--credit-soft); }
.balance-panel .balance { flex-direction: column; align-items: flex-end; gap: 4px; }
.balance-panel .balance .tag { background: transparent; padding: 0; font-size: 12.5px; }
.balance-panel .balance .amt { font-size: 28px; font-weight: 700; letter-spacing: -.025em; }
.profile-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 24px 20px; margin-top: -4px; }

.mini-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--border); }
.mini-stats > div { padding: 14px 24px; }
.mini-stats > div + div { border-left: 1px solid var(--border); }
.mini-stats .label { font-size: 12px; color: var(--muted); font-weight: 500; margin: 0; }
.mini-stats .value { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }

.details-list { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px 16px; margin: 0; font-size: 13px; }
.details-list dt { color: var(--muted); }
.details-list dd { margin: 0; color: var(--text); text-align: right; overflow-wrap: anywhere; }

/* Reverse popover */
.reverse { position: relative; display: inline-block; }
.reverse summary { list-style: none; cursor: pointer; }
.reverse summary::-webkit-details-marker { display: none; }
.reverse[open] summary { background: var(--surface-3); color: var(--text); }
.reverse-pop {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; width: 280px;
    padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
    text-align: left;
}
.reverse-pop p { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; white-space: normal; }
.reverse-pop .row { display: flex; gap: 8px; }
.reverse-pop input { height: 32px; font-size: 13px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.pagination .pages { display: flex; gap: 6px; }
.pagination .btn[aria-disabled=true] { opacity: .45; pointer-events: none; }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--surface); }
.auth-aside {
    position: relative; overflow: hidden; color: #e2e8f0; padding: 48px;
    display: flex; flex-direction: column; justify-content: space-between;
    background:
        radial-gradient(900px 500px at 10% -10%, rgba(99, 102, 241, .45), transparent 60%),
        radial-gradient(700px 500px at 110% 110%, rgba(14, 165, 233, .35), transparent 60%),
        #0b1120;
}
.auth-aside::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background-image: linear-gradient(rgba(148, 163, 184, .07) 1px, transparent 1px), linear-gradient(90deg, rgba(148, 163, 184, .07) 1px, transparent 1px);
    background-size: 44px 44px; mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
}
.auth-aside > * { position: relative; z-index: 1; }
.auth-aside .brand { padding: 0; }
.auth-pitch h2 { color: #fff; font-size: 34px; font-weight: 700; line-height: 1.15; letter-spacing: -.03em; max-width: 440px; }
.auth-pitch p { margin-top: 14px; color: #94a3b8; font-size: 15px; max-width: 420px; }
.auth-points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.auth-points li { display: flex; align-items: center; gap: 10px; color: #cbd5e1; }
.auth-points .icon { color: #818cf8; }
.auth-preview { margin-top: 36px; max-width: 400px; background: rgba(15, 23, 42, .6); border: 1px solid rgba(148, 163, 184, .16); border-radius: 16px; padding: 18px; backdrop-filter: blur(6px); }
.auth-preview .row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; font-size: 13px; }
.auth-preview .row + .row { border-top: 1px solid rgba(148, 163, 184, .12); }
.auth-preview .pos { color: #34d399; font-weight: 600; font-variant-numeric: tabular-nums; }
.auth-preview .neg { color: #f87171; font-weight: 600; font-variant-numeric: tabular-nums; }
.auth-copy { font-size: 12.5px; color: #64748b; }
.auth-main { display: grid; place-items: center; padding: 48px 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 26px; }
.auth-card .subtitle { color: var(--muted); margin: 6px 0 28px; }
.auth-card .panel { padding: 28px; }
.auth-foot { margin-top: 20px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.auth-mobile-brand { display: none; }

/* ---------- Statement (print) ---------- */
.statement-page { background: var(--bg); min-height: 100vh; padding: 32px 16px; }
.statement-bar { max-width: 880px; margin: 0 auto 16px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.statement { max-width: 880px; margin: 0 auto; background: #fff; color: #0f172a; border-radius: 16px; box-shadow: var(--shadow-md); padding: 48px; border: 1px solid var(--border); }
.statement .st-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 28px; border-bottom: 2px solid #0f172a; }
.statement .st-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.statement .st-title { text-align: right; }
.statement .st-title h1 { font-size: 22px; color: #0f172a; }
.statement .st-title div { color: #64748b; font-size: 13px; margin-top: 2px; }
.statement .st-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; padding: 24px 0; }
.statement .st-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: #64748b; margin-bottom: 6px; }
.statement .st-summary { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid #e2e8f0; border-radius: 12px; margin-bottom: 24px; overflow: hidden; }
.statement .st-summary > div { padding: 14px 16px; }
.statement .st-summary > div + div { border-left: 1px solid #e2e8f0; }
.statement .st-summary .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.statement .st-summary .due { background: #f8fafc; }
.statement table { font-size: 12.5px; }
.statement th, .statement td { padding: 9px 10px; color: #0f172a; }
.statement thead th { background: #f8fafc; color: #64748b; border-bottom: 1px solid #e2e8f0; }
.statement tbody td { border-bottom: 1px solid #f1f5f9; }
.statement tbody tr:hover td { background: transparent; }
.statement tfoot th { background: #f8fafc; border-top: 1px solid #cbd5e1; color: #0f172a; }
.statement tr.reversed td { color: #94a3b8; }
.statement .st-note { margin-top: 20px; font-size: 11.5px; color: #64748b; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-main-side { grid-template-columns: minmax(0, 1fr); }
    .grid-main-side .side-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
}
@media (max-width: 960px) {
    .app { grid-template-columns: minmax(0, 1fr); }
    .sidebar { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 6px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--side-border); }
    .brand { padding: 0 8px 0 0; }
    .brand-name small, .side-label, .side-user { display: none; }
    .side-nav { flex-direction: row; gap: 2px; margin-left: auto; }
    .side-nav a { padding: 8px 10px; }
    .side-foot { margin: 0; padding: 0 0 0 4px; border: 0; }
    .side-foot .user-chip { display: none; }
    .content { padding: 24px 16px 48px; }
    .grid-2, .grid-3-1 { grid-template-columns: minmax(0, 1fr); }
    .auth { grid-template-columns: minmax(0, 1fr); }
    .auth-aside { display: none; }
    .auth-mobile-brand { display: flex; justify-content: center; margin-bottom: 24px; }
    .form-section { grid-template-columns: minmax(0, 1fr); gap: 14px; }
}
@media (max-width: 640px) {
    h1 { font-size: 21px; }
    .side-nav a span { display: none; }
    .kpis { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .kpi-value { font-size: 23px; }
    .grid-main-side .side-col { grid-template-columns: minmax(0, 1fr); }
    .hide-sm { display: none; }
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .form-grid .span-2 { grid-column: auto; }
    .chart { gap: 5px; padding: 20px 12px 0; height: 170px; }
    .chart-label { font-size: 10px; }
    .chart-axis { margin: 0 12px; }
    .profile { padding: 18px; }
    .balance-panel { text-align: left; width: 100%; }
    .balance-panel .balance { align-items: flex-start; }
    .profile-actions { padding: 0 18px 18px; }
    .mini-stats > div { padding: 12px 14px; }
    .mini-stats .value { font-size: 14.5px; }
    .toolbar select { min-width: 0; width: 100%; }
    .statement { padding: 24px; }
    .statement .st-parties, .statement .st-summary { grid-template-columns: 1fr; }
    .statement .st-summary > div + div { border-left: 0; border-top: 1px solid #e2e8f0; }
}

@media print {
    @page { margin: 14mm; }
    body, .statement-page { background: #fff !important; padding: 0; }
    .no-print { display: none !important; }
    .statement { box-shadow: none; border: 0; padding: 0; max-width: none; border-radius: 0; }
    .statement tr { break-inside: avoid; }
    .statement thead { display: table-header-group; }
}

/* ---------- Live search ---------- */
[hidden] { display: none !important; }
.js .no-js-only { display: none; }
.search-spinner {
    position: absolute; right: 12px; top: 50%; width: 16px; height: 16px; margin-top: -8px;
    border: 2px solid var(--border-strong); border-top-color: var(--brand); border-radius: 50%;
    opacity: 0; transition: opacity .15s; pointer-events: none;
}
.is-loading .search-spinner { opacity: 1; animation: spin .7s linear infinite; }
.is-loading + .table-wrap, .toolbar.is-loading ~ #customer-results { opacity: .55; transition: opacity .15s; }
#customer-results { transition: opacity .15s; }
@keyframes spin { to { transform: rotate(360deg); } }
input[type=search]::-webkit-search-cancel-button { cursor: pointer; }
@media (prefers-reduced-motion: reduce) { .is-loading .search-spinner { animation-duration: 1.6s; } }

/* ---------- Accounts, 2FA & users ---------- */
.side-account { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 6px; margin: -6px; border-radius: 10px; color: inherit; }
.side-account:hover, .side-account.active { background: var(--side-hover); color: inherit; }
.btn[aria-disabled=true] { opacity: .5; cursor: not-allowed; }

.auth-card-wide { max-width: 560px; }
.auth-badge { display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 13px; background: var(--brand-soft); color: var(--brand); margin-bottom: 16px; }
.auth-badge.ok { background: var(--credit-soft); color: var(--credit); }
.auth-badge.warn { background: var(--warn-soft); color: var(--warn); }
.auth-back { margin-top: 18px; text-align: center; font-size: 13px; }
.auth-back a { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.auth-back a:hover { color: var(--text); }
.panel-title { display: flex; align-items: center; gap: 10px; font-size: 15px; margin-bottom: 16px; }

.step-no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-size: 12px; font-weight: 700; flex: none; }
.setup-steps { display: grid; gap: 18px; margin-bottom: 22px; }
.setup-step { display: flex; gap: 12px; align-items: flex-start; }
.setup-step strong { display: block; font-size: 13.5px; color: var(--text); margin-top: 2px; }
.setup-step p { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.qr-box { display: flex; gap: 16px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.qr { background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--border); line-height: 0; flex: none; }
.qr svg { width: 160px; height: 160px; }
.qr-alt { flex: 1; min-width: 180px; display: grid; gap: 8px; justify-items: start; }
.qr-alt p { margin: 0; }
.secret-key { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; letter-spacing: .04em; padding: 8px 10px; border-radius: 8px; background: var(--surface-3); color: var(--text); word-break: break-all; user-select: all; }
input.code-input { height: 52px; font-size: 24px; font-weight: 650; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
input.code-input::placeholder { letter-spacing: .35em; color: var(--border-strong); }

.recovery-toggle { margin-top: 16px; }
.recovery-toggle summary { cursor: pointer; text-align: center; font-size: 13px; color: var(--muted); list-style: none; }
.recovery-toggle summary::-webkit-details-marker { display: none; }
.recovery-toggle summary:hover { color: var(--text); }
.recovery-codes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; counter-reset: rc; }
.recovery-codes li { counter-increment: rc; display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.recovery-codes li::before { content: counter(rc); font-size: 11px; color: var(--faint); width: 14px; }
.recovery-codes code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; font-weight: 600; letter-spacing: .03em; color: var(--text); }

.pill.role-admin { background: var(--brand-soft); color: var(--brand); }
.pill.role-staff { background: var(--surface-3); color: var(--text-2); }
.invite-result { border-color: var(--credit-line); }
.invite-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.invite-link { display: flex; gap: 8px; }
.invite-link input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--surface-2); }
.role-options { display: grid; gap: 8px; }
.role-option { margin: 0; cursor: pointer; }
.role-option input { position: absolute; opacity: 0; pointer-events: none; }
.role-option span { display: block; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 10px; transition: border-color .15s, background .15s, box-shadow .15s; }
.role-option strong { display: block; font-size: 13px; color: var(--text); }
.role-option small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 1px; }
.role-option input:checked + span { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px var(--brand-ring); }
.role-option input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (max-width: 960px) {
    .side-account { flex: none; margin: 0; padding: 0; }
}
@media (max-width: 640px) {
    .recovery-codes { grid-template-columns: minmax(0, 1fr); }
    .invite-link { flex-direction: column; }
}
@media print {
    .auth-aside, .auth-foot, .auth-mobile-brand, .recovery-codes ~ *, .actions, #continue, .checkbox { display: none !important; }
    .auth { display: block; }
    .auth-main { background: #fff; padding: 0; }
}

/* ---------- Backups ---------- */
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.tips { margin: 0; padding-left: 18px; color: var(--text-2); font-size: 13px; display: grid; gap: 8px; }
.profile-actions form { margin: 0; }
@media (max-width: 1180px) { .kpis[style] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; } }
@media (max-width: 640px) { .kpis[style] { grid-template-columns: minmax(0, 1fr) !important; } }

/* ---------- Confirmation code ---------- */
input.pin-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .3em; font-weight: 650; text-align: center; }
.confirm-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px; align-items: end; margin-bottom: 16px; }
.confirm-row .field { margin: 0; }
.confirm-row .btn { width: 100%; height: 38px; }
.reverse-pop .row .pin-input { width: 96px; flex: none; }
@media (max-width: 640px) { .confirm-row { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Multi-select ---------- */
th.col-check, td.col-check { width: 1%; padding-right: 0; }
.check-cell { display: grid; place-items: center; width: 28px; height: 28px; margin: -4px; cursor: pointer; border-radius: 7px; }
.check-cell:hover { background: var(--surface-3); }
.check-cell input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); cursor: pointer; }
tbody tr.is-selected td { background: var(--brand-soft); }
tbody tr.is-selected:hover td { background: var(--brand-soft); }
.bulk-bar {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.bulk-count { font-size: 13px; color: var(--text-2); margin-right: auto; }
.bulk-count strong { color: var(--brand); font-variant-numeric: tabular-nums; }
@media (max-width: 960px) { .bulk-bar { top: 57px; } }
.bulk-bar .bulk-pin { width: 96px; height: 30px; font-size: 13px; }
.delete-customer .reverse-pop { right: 0; }

/* ---------- Entry form: payment vs. add to balance ---------- */
.entry-card { border-top: 4px solid var(--credit); transition: border-color .2s; }
.entry-card.mode-charge { border-top-color: var(--owes); }
.entry-card .when-charge { display: none; }
.entry-card.mode-charge .when-charge { display: inline; }
.entry-card.mode-charge .when-payment { display: none; }

.type-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.type-option { margin: 0; cursor: pointer; }
.type-option input { position: absolute; opacity: 0; pointer-events: none; }
.type-option > span {
    display: flex; align-items: center; gap: 12px; height: 100%;
    padding: 12px 14px; border-radius: 12px; border: 2px solid var(--border-strong); background: var(--surface);
    transition: border-color .15s, background .15s, box-shadow .15s, opacity .15s;
}
.type-option:hover > span { border-color: var(--faint); }
.type-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none; background: var(--surface-3); color: var(--muted); transition: background .15s, color .15s; }
.type-text { flex: 1; min-width: 0; }
.type-text strong { display: block; font-size: 14.5px; color: var(--text); }
.type-text small { display: block; font-size: 12.5px; color: var(--muted); margin-top: 1px; line-height: 1.35; }
.type-sign { font-size: 24px; font-weight: 700; color: var(--faint); line-height: 1; }
.type-payment input:checked + span { border-color: var(--credit); background: var(--credit-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--credit) 18%, transparent); }
.type-payment input:checked + span .type-icon { background: var(--credit); color: #fff; }
.type-payment input:checked + span .type-sign { color: var(--credit); }
.type-charge input:checked + span { border-color: var(--owes); background: var(--owes-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--owes) 18%, transparent); }
.type-charge input:checked + span .type-icon { background: var(--owes); color: #fff; }
.type-charge input:checked + span .type-sign { color: var(--owes); }
.type-option input:not(:checked) + span { opacity: .75; }
.type-option input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

.mode-payment .input-affix input { border-color: color-mix(in srgb, var(--credit) 45%, var(--border-strong)); }
.mode-charge .input-affix input { border-color: color-mix(in srgb, var(--owes) 45%, var(--border-strong)); }
.mode-payment .input-affix .affix { color: var(--credit); }
.mode-charge .input-affix .affix { color: var(--owes); }

.balance-preview { display: flex; align-items: center; gap: 14px; padding: 12px 14px; margin: -4px 0 18px; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--border-strong); }
.balance-preview > div { display: grid; gap: 1px; }
.balance-preview .muted { font-size: 11.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.balance-preview strong { font-size: 15px; font-variant-numeric: tabular-nums; }

.entry-submit { color: #fff; border: 0; width: 100%; }
.mode-payment .entry-submit { background: var(--credit); box-shadow: 0 1px 2px rgba(5, 150, 105, .35); }
.mode-payment .entry-submit:hover { background: #047857; color: #fff; }
.mode-charge .entry-submit { background: var(--owes); box-shadow: 0 1px 2px rgba(220, 38, 38, .35); }
.mode-charge .entry-submit:hover { background: #b91c1c; color: #fff; }
.confirm-row.no-pin { grid-template-columns: minmax(0, 1fr); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .entry-submit { color: #0b1120; }
    :root:not([data-theme="light"]) .mode-payment .entry-submit:hover, :root:not([data-theme="light"]) .mode-charge .entry-submit:hover { color: #0b1120; filter: brightness(1.1); }
}
@media (max-width: 640px) {
    .type-options { grid-template-columns: minmax(0, 1fr); }
    .balance-preview { flex-wrap: wrap; }
}
