/* =============================================================================================
   Money Management - application styles
   Design tokens first, then layout, then components. Light and dark are both defined so the app
   follows the operating system setting.
   ============================================================================================= */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #fafbfc;
    --surface-3: #f0f2f5;
    --border: #e2e5ea;
    --border-strong: #cbd1da;

    --text: #14181f;
    --text-muted: #5c6672;
    --text-subtle: #8a929c;
    --text-inverse: #ffffff;

    --accent: #2f6df6;
    --accent-hover: #2559d6;
    --accent-soft: #e8f0fe;

    --success: #12855b;
    --success-soft: #e2f5ec;
    --warning: #a2650a;
    --warning-soft: #fdf1dc;
    --danger: #c62f3d;
    --danger-soft: #fdeaec;
    --info: #4a5568;
    --info-soft: #eef0f3;

    --chart-1: #2f6df6;
    --chart-2: #12855b;
    --chart-3: #a2650a;
    --chart-4: #7c3aed;
    --chart-5: #0891a8;
    --chart-6: #c62f3d;
    --chart-7: #5c6672;

    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow: 0 2px 8px rgba(16, 24, 40, 0.07);
    --sidebar-width: 248px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SFMono-Regular", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1218;
        --surface: #171b23;
        --surface-2: #1c212a;
        --surface-3: #232935;
        --border: #2a313d;
        --border-strong: #3a4351;

        --text: #e8ebf0;
        --text-muted: #9aa4b2;
        --text-subtle: #6f7987;
        --text-inverse: #ffffff;

        --accent: #5b8dfa;
        --accent-hover: #7aa3fb;
        --accent-soft: #1a2740;

        --success: #3ec98d;
        --success-soft: #10291f;
        --warning: #e0a23c;
        --warning-soft: #2c2314;
        --danger: #f2707d;
        --danger-soft: #2e1619;
        --info: #9aa4b2;
        --info-soft: #222833;

        --chart-1: #5b8dfa;
        --chart-2: #3ec98d;
        --chart-3: #e0a23c;
        --chart-4: #a78bfa;
        --chart-5: #38bdd8;
        --chart-6: #f2707d;
        --chart-7: #9aa4b2;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    }
}

/* ---------------------------------------------------------------------------- base ---- */

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

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; line-height: 1.3; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

table { border-collapse: collapse; width: 100%; }

.numeric { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.mono { font-family: var(--font-mono); font-size: 0.9em; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.small { font-size: 0.82rem; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

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

.app-shell { display: flex; min-height: 100vh; }

.app-main {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-width);
}

.app-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.75rem 2rem 4rem;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header__meta { color: var(--text-muted); font-size: 0.88rem; margin-top: 0.2rem; }
.page-header__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.section { margin-bottom: 1.75rem; }
.section__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

/* ------------------------------------------------------------------------- sidebar ---- */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.25rem 0.85rem 1rem;
    z-index: 20;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0 0.5rem 1.25rem;
}

.sidebar__logo { font-size: 1.5rem; line-height: 1; }
.sidebar__title { font-weight: 680; font-size: 0.95rem; letter-spacing: -0.01em; }
.sidebar__subtitle { font-size: 0.75rem; color: var(--text-subtle); }

.sidebar__nav { list-style: none; margin: 0 0 0.9rem; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.sidebar__section {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 650;
    color: var(--text-subtle);
    padding: 0 0.7rem 0.35rem;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 550;
    font-size: 0.9rem;
}

.sidebar__link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }

.sidebar__link.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 620;
}

.sidebar__icon { font-size: 1rem; width: 1.2rem; text-align: center; }

.sidebar__cta { margin-top: 1rem; padding: 0 0.15rem; }

.sidebar__footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.sidebar__user { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }

.sidebar__avatar {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--text-inverse);
    display: grid;
    place-items: center;
    font-size: 0.78rem;
    font-weight: 650;
}

.sidebar__username {
    font-size: 0.82rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar__signout {
    background: none;
    border: none;
    color: var(--text-subtle);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 0.25rem;
    font-family: inherit;
}

.sidebar__signout:hover { color: var(--danger); text-decoration: underline; }

/* ---------------------------------------------------------------------------- card ---- */

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

.card__head {
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.card__title { font-size: 0.95rem; font-weight: 650; }
.card__body { padding: 1.1rem; }
.card__body--flush { padding: 0; }

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

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.9rem;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-sm);
}

.stat__label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-subtle);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.stat__value {
    font-size: 1.55rem;
    font-weight: 680;
    letter-spacing: -0.02em;
    margin-top: 0.35rem;
    font-variant-numeric: tabular-nums;
}

.stat__value--sm { font-size: 1.2rem; }
.stat__hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; }

.stat--accent { border-left: 3px solid var(--accent); }
.stat--danger { border-left: 3px solid var(--danger); }
.stat--success { border-left: 3px solid var(--success); }
.stat--warning { border-left: 3px solid var(--warning); }

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

.table { font-size: 0.875rem; }

.table th {
    text-align: left;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-subtle);
    font-weight: 650;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    white-space: nowrap;
}

.table td {
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }

/* A totals row, set apart from the rows it sums. */
.table__totals td {
    background: var(--surface-2);
    border-top: 2px solid var(--border-strong);
    border-bottom: none;
}
.table tbody tr:hover { background: var(--surface-2); }
.table--clickable tbody tr { cursor: pointer; }

.table__scroll { overflow-x: auto; }

.table tr.is-paid { color: var(--text-muted); }
.table tr.is-overdue { background: var(--danger-soft); }
.table tr.is-next { background: var(--accent-soft); }

/* --------------------------------------------------------------------------- badge ---- */

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 620;
    letter-spacing: 0.01em;
    white-space: nowrap;
    background: var(--info-soft);
    color: var(--info);
}

.badge--active { background: var(--accent-soft); color: var(--accent); }
.badge--closed { background: var(--success-soft); color: var(--success); }
.badge--settled { background: var(--warning-soft); color: var(--warning); }
.badge--overdue { background: var(--danger-soft); color: var(--danger); }
.badge--paid { background: var(--success-soft); color: var(--success); }
.badge--pending { background: var(--info-soft); color: var(--info); }

/* How dear a rate is. Deliberately the same four colours used everywhere else, so a red badge
   here reads as trouble without anyone having to learn a second scale. */
.badge--free { background: var(--success-soft); color: var(--success); }
.badge--fair { background: var(--info-soft); color: var(--info); }
.badge--costly { background: var(--warning-soft); color: var(--warning); }
.badge--steep { background: var(--danger-soft); color: var(--danger); }

/* The dearest loan gets a tinted row rather than only a badge, so it is the thing the eye lands
   on when the page opens. */
.row--steep { background: var(--danger-soft); }

.chip--sm { padding: 0.02rem 0.35rem; font-size: 0.68rem; margin-left: 0.35rem; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.12rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 580;
    background: var(--surface-3);
    color: var(--text-muted);
    white-space: nowrap;
}

/* -------------------------------------------------------------------------- button ---- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.48rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 0.86rem;
    font-weight: 580;
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease;
    white-space: nowrap;
}

.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--text-inverse); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn--danger { background: var(--danger); border-color: var(--danger); color: var(--text-inverse); }
.btn--danger:hover { filter: brightness(1.08); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }

.btn--sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
.btn--block { width: 100%; }

.btn-group { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.btn-group--end { justify-content: flex-end; }

/* ---------------------------------------------------------------------------- form ---- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1rem 1.1rem;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.field--full { grid-column: 1 / -1; }

.field__label { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.field__hint { font-size: 0.76rem; color: var(--text-subtle); }
.field__error { font-size: 0.78rem; color: var(--danger); }

.input, .select, .textarea {
    width: 100%;
    padding: 0.48rem 0.65rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
}

.input:focus, .select:focus, .textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}

.input.invalid, .select.invalid, .textarea.invalid { border-color: var(--danger); }
.textarea { resize: vertical; min-height: 72px; }

/* Compact variant for editing in place inside a table row. */
.input--sm { padding: 0.32rem 0.45rem; font-size: 0.82rem; min-width: 7rem; }

/* The row being edited, lifted off the rows around it. */
.row--editing td { background: var(--accent-soft); }

.input-prefix { position: relative; display: block; }
.input-prefix__label {
    position: absolute;
    left: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    color: var(--text-subtle);
    pointer-events: none;
}
.input-prefix .input { padding-left: 3.1rem; }

.checkbox { display: flex; align-items: flex-start; gap: 0.5rem; cursor: pointer; }
.checkbox input { margin-top: 0.2rem; flex: 0 0 auto; }

.form-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    padding-top: 1.1rem;
    margin-top: 1.1rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.radio-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.6rem; }

.radio-card {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.75rem;
    cursor: pointer;
    background: var(--surface);
}

.radio-card:hover { border-color: var(--accent); }
.radio-card.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.radio-card__title { font-weight: 620; font-size: 0.85rem; display: flex; align-items: center; gap: 0.4rem; }
.radio-card__desc { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ------------------------------------------------------------------------ progress ---- */

.progress {
    height: 6px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
    min-width: 60px;
}

.progress__bar { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.3s ease; }
.progress__bar--success { background: var(--success); }
.progress__bar--warning { background: var(--warning); }

.progress-row { display: flex; align-items: center; gap: 0.6rem; }
.progress-row .progress { flex: 1; }
.progress-row__label { font-size: 0.78rem; color: var(--text-muted); min-width: 3.2rem; text-align: right; }

/* --------------------------------------------------------------------------- alert ---- */

.alert {
    padding: 0.7rem 0.95rem;
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    border: 1px solid transparent;
    margin-bottom: 1rem;
}

.alert--error { background: var(--danger-soft); color: var(--danger); border-color: currentColor; }
.alert--success { background: var(--success-soft); color: var(--success); border-color: currentColor; }
.alert--warning { background: var(--warning-soft); color: var(--warning); border-color: currentColor; }
.alert--info { background: var(--accent-soft); color: var(--accent); border-color: currentColor; }

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

.empty { text-align: center; padding: 2.75rem 1.25rem; color: var(--text-muted); }
.empty__icon { font-size: 2.25rem; opacity: 0.6; }
.empty__title { font-weight: 620; color: var(--text); margin: 0.5rem 0 0.25rem; }
.empty__text { font-size: 0.86rem; max-width: 380px; margin: 0 auto 1rem; }

.loading { display: flex; align-items: center; justify-content: center; gap: 0.6rem; padding: 2.5rem; color: var(--text-muted); }

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------- login ---- */

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 2rem 1.75rem;
}

.login-card__logo { font-size: 2rem; text-align: center; }
.login-card__title { text-align: center; font-size: 1.2rem; font-weight: 680; margin-top: 0.4rem; }
.login-card__subtitle { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1.5rem; }
.login-card .field { margin-bottom: 0.9rem; }

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

.legend { display: flex; flex-direction: column; gap: 0.55rem; }

.legend__item { display: flex; align-items: center; gap: 0.55rem; font-size: 0.83rem; }

.legend__swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; }
.legend__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend__value { font-variant-numeric: tabular-nums; font-weight: 600; }

.donut-wrap { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.donut-wrap__chart { flex: 0 0 auto; }
.donut-wrap__legend { flex: 1; min-width: 200px; }

/* The centre caption is overlaid rather than drawn in SVG, so it inherits the page font. */
.donut { position: relative; display: inline-flex; }

.donut__centre {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    text-align: center;
    padding: 0 12%;
}

.donut__value { font-size: 1.05rem; font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.donut__caption { font-size: 0.68rem; color: var(--text-subtle); text-transform: uppercase; letter-spacing: 0.04em; }

.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 0.3rem 0.75rem; margin-bottom: 0.8rem; }
.bar-row__label { font-size: 0.83rem; font-weight: 570; }
.bar-row__value { font-size: 0.83rem; font-variant-numeric: tabular-nums; font-weight: 620; }
.bar-row__track { grid-column: 1 / -1; height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar-row__fill { height: 100%; border-radius: 999px; }

/* ------------------------------------------------------- income vs outflow trend ---- */

.trend { display: grid; gap: 0.55rem; align-items: end; }

.trend__col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    height: 100%;
    justify-content: flex-end;
    min-width: 0;
}

.trend__bars { display: flex; gap: 3px; align-items: flex-end; height: 100%; }

.trend__bar {
    width: 14px;
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: height 0.3s ease;
}

.trend__bar--in { background: var(--success); }
.trend__bar--out { background: var(--border-strong); }
.trend__bar--over { background: var(--danger); }

.trend__label {
    font-size: 0.7rem;
    color: var(--text-subtle);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.trend__label--over { color: var(--danger); font-weight: 620; }

.trend__legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 0.9rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-size: 0.76rem;
    color: var(--text-muted);
}

.trend__key { display: inline-flex; align-items: center; gap: 0.4rem; }
.trend__swatch { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 9px; }

/* ------------------------------------------------------------- cash flow waterfall ---- */

.waterfall { display: grid; gap: 0.5rem; align-items: end; }

.waterfall__col {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    height: 100%;
    min-width: 0;
}

/* The bars float, so the track is the full height and each bar is positioned within it. */
.waterfall__track { position: relative; flex: 1 1 auto; min-height: 0; }

.waterfall__bar {
    position: absolute;
    left: 12%;
    right: 12%;
    border-radius: 2px;
    transition: height 0.3s ease, bottom 0.3s ease;
}

.waterfall__bar--up { background: var(--success); }
.waterfall__bar--down { background: var(--danger); }
.waterfall__bar--total { background: var(--border-strong); }

.waterfall__value {
    font-size: 0.72rem;
    font-weight: 640;
    text-align: center;
    white-space: nowrap;
}

.waterfall__label {
    font-size: 0.68rem;
    color: var(--text-subtle);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --------------------------------------------------- weekly spend, stacked by account ---- */

.stack { display: grid; gap: 0.4rem; align-items: end; }

.stack__col {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
    height: 100%;
    justify-content: flex-end;
    min-width: 0;
}

/* column-reverse puts the first segment at the foot of the bar, so the biggest account - which
   the breakdown orders first - is the one sitting on the baseline in every week. */
.stack__bar {
    display: flex;
    flex-direction: column-reverse;
    justify-content: flex-start;
    height: 100%;
    border-radius: 3px;
    overflow: hidden;
}

.stack__seg { width: 100%; transition: height 0.3s ease; }

.stack__label {
    font-size: 0.68rem;
    color: var(--text-subtle);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* ------------------------------------------------------------------------ timeline ---- */

.due-list { display: flex; flex-direction: column; }

.due-item {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.7rem 1.1rem;
    border-bottom: 1px solid var(--border);
}

.due-item:last-child { border-bottom: none; }
.due-item:hover { background: var(--surface-2); }

.due-item__date {
    flex: 0 0 46px;
    text-align: center;
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    padding: 0.25rem 0;
}

.due-item__day { font-size: 1rem; font-weight: 680; line-height: 1.1; }
.due-item__month { font-size: 0.66rem; text-transform: uppercase; color: var(--text-subtle); font-weight: 620; }
.due-item__body { flex: 1; min-width: 0; }
.due-item__title { font-weight: 600; font-size: 0.87rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.due-item__meta { font-size: 0.76rem; color: var(--text-muted); }
.due-item__amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.due-item.is-overdue .due-item__date { background: var(--danger-soft); }
.due-item.is-overdue .due-item__day { color: var(--danger); }

/* ------------------------------------------------------------------------- summary ---- */

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem 1.25rem; font-size: 0.86rem; }
.kv__key { color: var(--text-muted); white-space: nowrap; }
.kv__value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 570; }

.split { display: grid; gap: 1.1rem; }
.split--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.split--sidebar { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }

@media (max-width: 900px) {
    .split--sidebar { grid-template-columns: 1fr; }
}

/* -------------------------------------------------------------------------- mobile ---- */

@media (max-width: 760px) {
    .sidebar {
        position: static;
        width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
        padding: 0.6rem 0.9rem;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-x: auto;
    }

    .sidebar__brand { padding: 0; }
    .sidebar__subtitle { display: none; }
    .sidebar__nav { flex-direction: row; }
    .sidebar__cta { margin-top: 0; }
    .sidebar__footer { margin-top: 0; padding-top: 0; border-top: none; }
    .sidebar__username { display: none; }

    .app-shell { flex-direction: column; }
    .app-main { margin-left: 0; }
    .app-content { padding: 1rem 0.9rem 3rem; }
}

/* ------------------------------------------------------------- safe to spend ---- */

.hero {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1.6rem;
    box-shadow: var(--shadow-sm);
}

.hero--comfortable { border-left: 4px solid var(--success); }
.hero--ontrack { border-left: 4px solid var(--accent); }
.hero--tight { border-left: 4px solid var(--warning); }
.hero--overspent { border-left: 4px solid var(--danger); }
.hero--unknown { border-left: 4px solid var(--border-strong); }

.hero__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.hero__label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-subtle);
    font-weight: 620;
}

.hero__amount {
    font-size: 2.6rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    margin-top: 0.15rem;
}

.hero__amount--negative { color: var(--danger); }

.hero__daily { font-size: 1rem; color: var(--text-muted); margin-top: 0.3rem; }
.hero__daily strong { color: var(--text); font-weight: 650; }

.hero__aside { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 0.4rem; }
.hero__meta { font-size: 0.8rem; color: var(--text-subtle); }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 620;
}

.status-pill--comfortable { background: var(--success-soft); color: var(--success); }
.status-pill--ontrack { background: var(--accent-soft); color: var(--accent); }
.status-pill--tight { background: var(--warning-soft); color: var(--warning); }
.status-pill--overspent { background: var(--danger-soft); color: var(--danger); }
.status-pill--unknown { background: var(--info-soft); color: var(--info); }

/* Where the cycle's money went: one bar, three parts. */
.split-bar { display: flex; height: 30px; border-radius: var(--radius-sm); overflow: hidden; gap: 2px; }

.split-bar__part {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.74rem;
    font-weight: 650;
    min-width: 2px;
    transition: flex-grow 0.3s ease;
}

.split-bar__part--committed { background: var(--accent-soft); color: var(--accent); }
.split-bar__part--spent { background: var(--warning-soft); color: var(--warning); }
.split-bar__part--saved { background: var(--info-soft); color: var(--info); }
.split-bar__part--left { background: var(--success-soft); color: var(--success); }

.split-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 0.9rem;
}

.split-legend__label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-muted); }
.split-legend__dot { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 9px; }
.split-legend__value { font-size: 1.02rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 0.1rem; }
.split-legend__hint { font-size: 0.74rem; color: var(--text-subtle); }

/* Pace: how far through the budget against how far through the cycle. */
.pace { position: relative; height: 12px; background: var(--surface-3); border-radius: 999px; margin: 0.75rem 0 0; }
.pace__fill { position: absolute; top: 0; left: 0; bottom: 0; border-radius: 999px; transition: width 0.3s ease; }
.pace__fill--under { background: var(--success); }
.pace__fill--over { background: var(--danger); }
.pace__marker { position: absolute; top: -5px; width: 2px; height: 22px; background: var(--text); border-radius: 1px; }
.pace__footer { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.76rem; color: var(--text-subtle); margin-top: 0.6rem; }

/* Category rows compared against the usual figure. */
.cat-row { margin-bottom: 0.9rem; }
.cat-row:last-child { margin-bottom: 0; }

.cat-row__head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; margin-bottom: 0.35rem; }
.cat-row__name { font-size: 0.87rem; font-weight: 570; display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.cat-row__amount { font-size: 0.87rem; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat-row__usual { font-weight: 400; font-size: 0.76rem; color: var(--text-subtle); }
.cat-row__usual--over { color: var(--danger); }
.cat-row__track { height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; position: relative; }
.cat-row__fill { height: 100%; border-radius: 999px; }
.cat-row__benchmark { position: absolute; top: -2px; width: 2px; height: 11px; background: var(--text-subtle); }

/* Cycle navigation. */
.cycle-nav { display: flex; align-items: center; gap: 0.4rem; }
.cycle-nav__label { font-size: 0.86rem; font-weight: 620; min-width: 10.5rem; text-align: center; }

/* Quick add strip. */
.quick-add { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.6rem; align-items: end; }
.quick-add__actions { display: flex; gap: 0.4rem; }

/* Compact list rows used by bills and commitments. */
.line-item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.65rem 1.1rem;
    border-bottom: 1px solid var(--border);
}

.line-item:last-child { border-bottom: none; }
.line-item:hover { background: var(--surface-2); }
.line-item__body { flex: 1; min-width: 0; }
.line-item__title { font-size: 0.87rem; font-weight: 570; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-item__meta { font-size: 0.76rem; color: var(--text-muted); }
.line-item__amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.line-item--paid .line-item__title { color: var(--text-muted); }
.line-item--overdue { background: var(--danger-soft); }

/* --------------------------------------------------------------- blazor error bar ---- */

#blazor-error-ui {
    color-scheme: light only;
    background: #ffeb3b;
    color: #14181f;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}
