:root {
    --accent: #2a78d6;
    --person-color-0: #2a78d6;   /* was the single hardcoded accent */
    --person-color-1: #eb6834;   /* was the second person's hardcoded accent */
    --person-color-2: #1baf7a;
    --person-color-3: #9085e9;
    --category-aqua: #1baf7a;
    --category-yellow: #eda100;
    --category-magenta: #e87ba4;
    --category-green: #008300;
    --category-violet: #4a3aa7;
    --category-red: #e34948;
    --status-good: #0ca30c;
    --status-critical: #d03b3b;
    --page-bg: #f9f9f7;
    --surface: #fcfcfb;
    --surface-inset: #f3f2ee;
    --ink-primary: #0b0b0b;
    --ink-secondary: #52514e;
    --ink-muted: #898781;
    --border: #e2e0d9;
    color-scheme: light dark;
}

:root[data-theme="dark"] {
    color-scheme: dark;
}

:root[data-theme="light"] {
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --accent: #3987e5;
        --person-color-0: #3987e5;
        --person-color-1: #d95926;
        --person-color-2: #199e70;
        --person-color-3: #9085e9;
        --category-aqua: #199e70;
        --category-yellow: #c98500;
        --category-magenta: #d55181;
        --category-green: #008300;
        --category-violet: #9085e9;
        --category-red: #e66767;
        --page-bg: #0d0d0d;
        --surface: #1a1a19;
        --surface-inset: #232320;
        --ink-primary: #ffffff;
        --ink-secondary: #c3c2b7;
        --border: #322f29;
    }
}

:root[data-theme="dark"] {
    --accent: #3987e5;
    --person-color-0: #3987e5;
    --person-color-1: #d95926;
    --person-color-2: #199e70;
    --person-color-3: #9085e9;
    --category-aqua: #199e70;
    --category-yellow: #c98500;
    --category-magenta: #d55181;
    --category-green: #008300;
    --category-violet: #9085e9;
    --category-red: #e66767;
    --page-bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-inset: #232320;
    --ink-primary: #ffffff;
    --ink-secondary: #c3c2b7;
    --border: #322f29;
}

:root[data-theme="light"] {
    --accent: #2a78d6;
    --person-color-0: #2a78d6;
    --person-color-1: #eb6834;
    --person-color-2: #1baf7a;
    --person-color-3: #9085e9;
    --category-aqua: #1baf7a;
    --category-yellow: #eda100;
    --category-magenta: #e87ba4;
    --category-green: #008300;
    --category-violet: #4a3aa7;
    --category-red: #e34948;
    --page-bg: #f9f9f7;
    --surface: #fcfcfb;
    --surface-inset: #f3f2ee;
    --ink-primary: #0b0b0b;
    --ink-secondary: #52514e;
    --border: #e2e0d9;
}

* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem;
    background: var(--page-bg);
    color: var(--ink-primary);
}

h1 {
    font-size: 1.6rem;
    margin: 0 0 1.25rem;
}

h2 {
    font-size: 1.1rem;
    margin: 0 0 1rem;
}

/* Nav */
nav {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 2rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

nav a {
    color: var(--ink-secondary);
    text-decoration: none;
    font-weight: 500;
    padding-bottom: 0.25rem;
    border-bottom: 2px solid transparent;
}

nav a:hover {
    color: var(--accent);
}

nav a.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.nav-spacer {
    flex: 1;
}

#theme-toggle {
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface-inset);
    color: var(--ink-primary);
    border-radius: 0.4rem;
    padding: 0.35rem 0.6rem;
    font-size: 0.9rem;
    line-height: 1;
}

/* allauth requires POST to log out, so the nav link has to be a form button. */
.nav-logout {
    display: inline-flex;
    margin: 0;
}

.nav-logout button {
    border: none;
    background: none;
    padding: 0 0 0.25rem;
    font: inherit;
    font-weight: 500;
    color: var(--ink-secondary);
    cursor: pointer;
}

.nav-logout button:hover {
    color: var(--accent);
    filter: none;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}

/* Tables */
table {
    border-collapse: collapse;
    width: 100%;
}

td, th {
    padding: 0.5rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

tr:first-child th {
    color: var(--ink-secondary);
    background: var(--surface-inset);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

tr:hover {
    background: var(--surface-inset);
}

.money {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.stat-figure {
    font-size: 1.35rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Badges: neutral pill + colored dot, so text stays legible regardless of
   the status color's contrast against the pill background (green/red text
   directly on a near-white/near-black surface can dip below comfortable
   body-text contrast at small sizes; a colored dot next to neutral text
   keeps the signal without that risk). */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--surface-inset);
    color: var(--ink-secondary);
    white-space: nowrap;
}

.badge::before {
    content: "";
    display: inline-block;
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: var(--badge-dot, var(--ink-muted));
}

/* Was two separate per-person badge classes. The index comes from
   Person.color_index, so a Household's second person is orange whatever
   they are called. */
.badge { --badge-dot: var(--person-accent, var(--person-color-0)); }

.badge--good {
    --badge-dot: var(--status-good);
}

.badge--critical {
    --badge-dot: var(--status-critical);
    color: var(--ink-primary);
}

.badge--muted {
    --badge-dot: var(--ink-muted);
}

.badge--aqua {
    --badge-dot: var(--category-aqua);
}

.badge--yellow {
    --badge-dot: var(--category-yellow);
}

.badge--magenta {
    --badge-dot: var(--category-magenta);
}

.badge--green {
    --badge-dot: var(--category-green);
}

.badge--violet {
    --badge-dot: var(--category-violet);
}

.badge--red {
    --badge-dot: var(--category-red);
}

/* Person color dots. The index comes from Person.color_index, so a
   Household's second person is orange whatever they are called. */
.person-dot {
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--person-accent, var(--person-color-0));
    margin-right: 0.4rem;
}

/* Collapsible sections */
.salary-form-toggle summary {
    cursor: pointer;
    color: var(--ink-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.salary-form-toggle summary:hover {
    color: var(--accent);
}

/* Forms */
form {
    margin-bottom: 1rem;
}

form label {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    color: var(--ink-secondary);
}

input, select {
    display: block;
    margin-top: 0.3rem;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    background: var(--surface);
    color: var(--ink-primary);
    font: inherit;
    width: 100%;
    max-width: 22rem;
}

button {
    cursor: pointer;
    border: none;
    border-radius: 0.4rem;
    padding: 0.5rem 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    background: var(--accent);
    color: #fff;
}

button:hover {
    filter: brightness(1.1);
}

.btn-delete {
    background: transparent;
    border: 1px solid var(--status-critical);
    color: var(--status-critical);
}

.btn-delete:hover {
    background: var(--status-critical);
    color: #fff;
    filter: none;
}

.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
}

.inline-form + .inline-form {
    margin-top: 0.5rem;
}

.amount-input {
    width: 8rem;
    max-width: 8rem;
    display: inline-block;
    margin-top: 0;
}

.toggle-btn {
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface-inset);
    border-radius: 0.3rem;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    font-size: 0.9rem;
    color: var(--ink-secondary);
}

/* Compact table variant: for tables with many rows (e.g. Money Sources)
   where the default row height reads as oversized and clumsy. */
.table-compact td,
.table-compact th {
    padding: 0.35rem 1rem;
    font-size: 0.85rem;
}

.table-compact .actions-col {
    padding-left: 2rem;
}

.table-compact .badge {
    padding: 0.15rem 0.55rem;
    font-size: 0.72rem;
}

.table-compact .badge::before {
    width: 0.4rem;
    height: 0.4rem;
}

.table-compact button {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
}

.table-compact .toggle-btn {
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.8rem;
}

.table-compact .inline-form + .inline-form {
    margin-top: 0.35rem;
}

.indented {
    padding-left: 2rem;
}

.deactivated {
    opacity: 0.55;
}

/* Money waterfall (Dashboard) */
.waterfall {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.waterfall-row {
    display: grid;
    grid-template-columns: 11rem 1fr 9rem;
    align-items: center;
    gap: 0.75rem;
}

.waterfall-label {
    color: var(--ink-secondary);
    font-size: 0.9rem;
}

.waterfall-bar-track {
    background: var(--surface-inset);
    border-radius: 0.3rem;
    height: 0.85rem;
    overflow: hidden;
}

.waterfall-bar {
    height: 100%;
    border-radius: 0.3rem;
    background: var(--accent);
}

.waterfall-bar--outflow {
    background: var(--ink-muted);
}

.waterfall-bar--good {
    background: var(--status-good);
}

.waterfall-bar--critical {
    background: var(--status-critical);
}

.waterfall-amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--ink-primary);
}

.waterfall-row--final .waterfall-label,
.waterfall-row--final .waterfall-amount {
    font-size: 1.25rem;
    font-weight: 700;
}

.waterfall-amount--good {
    color: var(--status-good);
}

.waterfall-amount--critical {
    color: var(--status-critical);
}

/* ---- Mobile: single column, bottom nav, cards instead of tables ---- */
@media (max-width: 640px) {
    main {
        padding: 0.75rem 0.75rem 4.5rem;   /* clear the bottom nav */
    }

    nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        display: flex;
        justify-content: space-around;
        padding: 0.4rem 0;
        border-top: 1px solid var(--border);
        background: var(--surface);
        z-index: 10;
    }

    nav a {
        font-size: 0.7rem;
        padding: 0.5rem 0.25rem;
        min-height: 44px;              /* touch target */
        display: flex;
        align-items: center;
    }

    .nav-spacer { display: none; }

    .nav-logout button {
        font-size: 0.7rem;
        padding: 0.5rem 0.25rem;
        min-height: 44px;              /* touch target */
    }

    /* Tables collapse into stacked cards. Each cell carries its own label. */
    table, thead, tbody, tr, th, td { display: block; }
    thead { display: none; }

    tr {
        margin-bottom: 0.75rem;
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 0.5rem;
        background: var(--surface);
    }

    td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.35rem 0;
        border: none;
    }

    td::before {
        content: attr(data-label);
        color: var(--ink-muted);
        font-size: 0.8rem;
    }

    input, select, button {
        min-height: 44px;
        font-size: 16px;               /* stops iOS zooming on focus */
        width: 100%;
    }

    .card { padding: 0.75rem; }
}
