:root {
    --bg: #f4f5f7;
    --card-bg: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --border: #e2e5eb;
    --accent: #3f6fb0;
    --pos: #2f8f5b;
    --neg: #b0473f;
    --radius: 8px;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --series-5: #e87ba4;
    --series-6: #008300;
    --series-7: #4a3aa7;
    --series-8: #e34948;
    --series-other: #a9a8a2;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
}

.brand { font-weight: 700; font-size: 1.1rem; }

.topbar nav a {
    margin-left: 1.25rem;
    text-decoration: none;
    color: var(--muted);
    font-weight: 500;
}
.topbar nav a.active, .topbar nav a:hover { color: var(--accent); }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
}

h1 { margin-top: 0; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.table-scroll { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; }
table.simple td, table.simple th,
table.cat-table td, table.cat-table th,
table.grid-table td, table.grid-table th {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}
.num { text-align: right; font-variant-numeric: tabular-nums; }

.auth-box {
    max-width: 340px;
    margin: 4rem auto;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
}
.auth-box form { display: flex; flex-direction: column; gap: 0.75rem; }
.auth-box label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 500; }
input, select, button {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
}
button {
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
}
button:hover { opacity: 0.9; }

.error { color: var(--neg); font-weight: 600; }
.success { color: var(--pos); font-weight: 600; }

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.tile {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}
.tile span { display: block; color: var(--muted); font-size: 0.8rem; margin-bottom: 0.35rem; }
.tile strong { font-size: 1.3rem; }
.tile.income strong { color: var(--pos); }
.tile.expense strong { color: var(--neg); }
.tile.other strong { color: var(--accent); }
.tile.warn { border-color: var(--neg); }
.tile.warn strong { color: var(--neg); }

.tile-link { text-decoration: none; color: inherit; display: block; transition: box-shadow 0.15s; }
.tile-link:hover { box-shadow: 0 1px 6px rgba(0,0,0,0.12); }

.year-select { margin-bottom: 1rem; }
.year-select select { font-size: 1rem; }

.barchart {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    height: 160px;
    padding-top: 1rem;
}
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bar { width: 60%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.bar-label { margin-top: 0.35rem; font-size: 0.75rem; color: var(--muted); }

.bar-cell { width: 40%; }
.hbar { height: 10px; background: var(--accent); border-radius: 4px; }

.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; }

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

.tx-list { display: flex; flex-direction: column; gap: 0.75rem; }
.tx-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem;
}
.tx-head { display: flex; align-items: baseline; gap: 0.75rem; }
.tx-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.tx-payee { font-weight: 600; flex: 1; }
.tx-amount { font-weight: 700; }
.tx-amount.neg, .split-amount.neg { color: var(--neg); }
.tx-amount.pos, .split-amount.pos { color: var(--pos); }
.tx-purpose { color: var(--muted); font-size: 0.85rem; margin: 0.35rem 0 0.6rem; }

.split-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    padding: 0.35rem 0;
    border-top: 1px dashed var(--border);
}
.split-row:first-child { border-top: none; }
.split-label { font-size: 0.8rem; color: var(--muted); min-width: 120px; }
.split-amount { min-width: 80px; text-align: right; }
.split-row input[type=text] { width: 140px; }

.tx-card.warn { border-color: var(--neg); }

.stackbar {
    display: flex;
    gap: 2px;
    height: 36px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--card-bg);
}
.stackbar-seg {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2px;
    transition: filter 0.1s;
}
.stackbar-seg:hover { filter: brightness(1.08); }
.stackbar-seg-label {
    color: #fff;
    font-size: 0.78rem;
    font-weight: 600;
    text-shadow: 0 1px 1px rgba(0,0,0,0.25);
    white-space: nowrap;
}
.stackbar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.25rem;
    margin-top: 0.85rem;
}
.stackbar-legend .legend-item { display: flex; align-items: center; gap: 0.45rem; font-size: 0.85rem; }
.stackbar-legend .legend-value { color: var(--muted); }
.breakdown-select { margin-bottom: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.card-head h2 { margin: 0; }
.ins-name { font-weight: 600; width: 220px !important; }
button.danger { background: var(--neg); }
