/* BudgetBook application styles. Self-contained (CSP: default-src 'self'). */

:root {
    --bg: #0f1720;
    --surface: #17212e;
    --surface-2: #1e2a3a;
    --line: #26374a;
    --text: #e6edf3;
    --muted: #93a4b8;
    --accent: #3d8bfd;
    --accent-ink: #ffffff;
    --ok: #35c98a;
    --fail: #ff6b6b;
    --warn: #f0b429;
    /* Semantic finance colours (reusable across the app) */
    --income: #35c98a;
    --expense: #ff6b6b;
    /* Contracts debited every month: the "Summe mtl. abgebucht" box and the rows it
       counts. One variable so the two can never drift apart. */
    --billed: var(--accent);
    /* Progress bars: deliberately their own, punchier greens rather than --income.
       As a large filled area a bar can carry far more saturation than text, which
       has to stay readable — reusing --income here would leave the bar washed out
       against the surface. The gradient runs light -> deep from left to right. */
    --bar-from: #34d399;
    --bar-to: #059669;
    --bar-track: #22303f;
    /* Per-list-mode bar colours (Chart::bar variants). "saving" reuses the green
       above. "general" is a calm blue, "paydown" an amber that reads as a balance
       being worked down rather than money growing. */
    --bar-gen-from: #38bdf8;
    --bar-gen-to: #2563eb;
    --bar-pay-from: #fbbf24;
    --bar-pay-to: #d97706;
    --input-bg: #0e1620;
    --radius: 12px;
    --content-width: 1240px;
}

/* Light theme fallback for users/environments that prefer light. */
@media (prefers-color-scheme: light) {
    :root {
        --bg: #f3f5f8;
        --surface: #ffffff;
        --surface-2: #eef1f6;
        --line: #d7dee8;
        --text: #1a2330;
        --muted: #5c6b7e;
        --accent: #1f6feb;
        --accent-ink: #ffffff;
        --input-bg: #ffffff;
        /* Darker greens on light backgrounds: the same fill that pops on the dark
           surface would glare against white. */
        --bar-from: #10b981;
        --bar-to: #047857;
        --bar-track: #dfe5ee;
        --bar-gen-from: #0ea5e9;
        --bar-gen-to: #1d4ed8;
        --bar-pay-from: #f59e0b;
        --bar-pay-to: #b45309;
    }
}

/* Explicit theme choice (Verwaltung → Darstellung) overrides the system setting. */
:root[data-theme="dark"] {
    --bg: #0f1720; --surface: #17212e; --surface-2: #1e2a3a; --line: #26374a;
    --text: #e6edf3; --muted: #93a4b8; --accent: #3d8bfd; --accent-ink: #ffffff; --input-bg: #0e1620;
    --bar-from: #34d399; --bar-to: #059669; --bar-track: #22303f;
    --bar-gen-from: #38bdf8; --bar-gen-to: #2563eb; --bar-pay-from: #fbbf24; --bar-pay-to: #d97706;
}
:root[data-theme="light"] {
    --bg: #f3f5f8; --surface: #ffffff; --surface-2: #eef1f6; --line: #d7dee8;
    --text: #1a2330; --muted: #5c6b7e; --accent: #1f6feb; --accent-ink: #ffffff; --input-bg: #ffffff;
    --bar-from: #10b981; --bar-to: #047857; --bar-track: #dfe5ee;
    --bar-gen-from: #0ea5e9; --bar-gen-to: #1d4ed8; --bar-pay-from: #f59e0b; --bar-pay-to: #b45309;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* Accessibility: skip link + visible keyboard focus. */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--accent);
    color: var(--accent-ink);
    padding: 0.6rem 1rem;
    border-radius: 0 0 8px 0;
    z-index: 100;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
}

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

/* ---- Forms ---- */
.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; margin-bottom: 0.3rem; font-size: 0.9rem; color: var(--muted); }
/* Consistent styling for all text controls (not just those inside .field). */
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="url"], input[type="date"], input[type="search"], input[type="tel"],
select, textarea {
    padding: 0.6rem 0.7rem;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--input-bg);
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent);
    border-color: var(--accent);
}
.field input, .field select, .field textarea { width: 100%; }
.check { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1.1rem; color: var(--muted); font-size: 0.95rem; }
.check input { width: 1rem; height: 1rem; flex: 0 0 auto; }
/* Checkbox labels with a secondary hint: drop the hint onto its own line and
   top-align the box so it lines up with the first line of text. */
.check:has(small) { align-items: flex-start; }
.check:has(small) input { margin-top: 0.2rem; }
.check small { display: block; margin-top: 0.1rem; }
.code-input { letter-spacing: 0.5em; text-align: center; font-size: 1.4rem; }

/* ---- Buttons ---- */
.btn {
    display: inline-block;
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
}
.btn:hover { border-color: var(--muted); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--block { width: 100%; }
.btn--link { border: none; background: none; color: var(--accent); padding: 0.4rem; }
.btn--danger { color: var(--fail); border-color: var(--fail); }

/* ---- Alerts ---- */
/* Same bottom gap as a .card so info boxes line up with the rest of the rhythm. */
.alert { padding: 0.75rem 1rem; border-radius: 8px; margin: 0 0 1.25rem; }
.alert ul { margin: 0; padding-left: 1.2rem; }
.alert--error { background: rgba(255,107,107,0.12); border: 1px solid var(--fail); }
.alert--warn { background: rgba(240,180,41,0.12); border: 1px solid var(--warn); }
.alert--ok { background: rgba(53,201,138,0.12); border: 1px solid var(--ok); }
.alert--info { background: rgba(61,139,253,0.10); border: 1px solid var(--accent); }
/* Dashboard heads-up for upcoming non-monthly insurance debits. */
.notice-upcoming__list { margin: 0.4rem 0 0; padding-left: 1.1rem; font-size: 0.9rem; }
.notice-upcoming__list li { margin-bottom: 0.15rem; }
.notice-upcoming__list a { text-decoration: none; }
.notice-upcoming__list a:hover, .notice-upcoming__list a:focus-visible { text-decoration: underline; }
.notice-upcoming__sum {
    display: flex; justify-content: space-between; gap: 1rem;
    margin: 0.5rem 0 0; padding-top: 0.4rem;
    border-top: 1px solid var(--line);
    font-size: 0.9rem;
}

/* Dashboard reminder to update a savings position's saved amount. */
.notice-saved__row { display: flex; align-items: center; gap: 0.5rem 0.75rem; flex-wrap: wrap; padding: 0.4rem 0; border-top: 1px solid var(--line); }
.notice-saved__name { font-weight: 600; flex: 1 1 8rem; min-width: 8rem; }
.notice-saved__form { display: flex; align-items: center; gap: 0.4rem; margin: 0; }
.notice-saved .inline { margin: 0; }

/* ---- Auth screens ---- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-shell { width: 100%; max-width: 420px; }
.auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 2rem 1.75rem;
}
.auth-brand { display: flex; align-items: center; gap: 0.6rem; justify-content: center; margin-bottom: 1.5rem; }
.auth-brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.auth-logo { display: inline-block; width: 2.2rem; height: 2.2rem; line-height: 0; }
.auth-logo img { width: 100%; height: 100%; display: block; }
.auth-title { margin: 0 0 0.4rem; font-size: 1.25rem; }
.auth-sub { margin: 0 0 1.25rem; color: var(--muted); font-size: 0.95rem; }
.auth-resend { text-align: center; margin-top: 0.5rem; }

/* ---- App shell ---- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar__inner {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.topbar__brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; color: var(--text); text-decoration: none; }
.topbar__brand .auth-logo { width: 1.8rem; height: 1.8rem; font-size: 1rem; border-radius: 8px; }
.topbar__toggle { margin-left: auto; background: none; border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 0.35rem 0.6rem; font-size: 1.1rem; cursor: pointer; display: none; }

.mainnav { margin-left: auto; display: flex; align-items: center; gap: 0.15rem; }
.mainnav__link {
    color: var(--muted);
    text-decoration: none;
    padding: 0.5rem 0.7rem;
    border-radius: 8px;
    font-size: 0.95rem;
    white-space: nowrap;
}
.mainnav__link:hover { color: var(--text); background: var(--surface-2); }
.mainnav__link.is-active { color: var(--text); background: var(--surface-2); font-weight: 600; }

/* Compact icon actions on the right of the header (search, Verwaltung, logout). */
.topbar__actions { display: flex; align-items: center; gap: 0.25rem; margin-left: 0.5rem; }
.topbar__logout { margin: 0; }
.iconbtn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2.3rem; height: 2.3rem; padding: 0;
    background: none; border: 1px solid transparent; border-radius: 10px;
    color: var(--muted); cursor: pointer; text-decoration: none;
}
.iconbtn:hover, .iconbtn:focus-visible { color: var(--text); background: var(--surface-2); }
.iconbtn.is-active { color: var(--accent); }

/* Funktionsmenü: <details> as a dropdown. No JS involved — the panel is
   positioned absolutely so it overlays the page instead of pushing the header
   apart when it opens. */
.funcmenu { position: relative; }
.funcmenu > summary { list-style: none; cursor: pointer; }
.funcmenu > summary::-webkit-details-marker { display: none; }
.funcmenu > summary::marker { content: ''; }
.funcmenu.is-active > summary { color: var(--accent); }
.funcmenu__panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.35rem);
    z-index: 40;
    min-width: 13rem;
    padding: 0.35rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.funcmenu__item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.funcmenu__item:hover, .funcmenu__item:focus-visible { background: var(--surface-2); }
.funcmenu__item.is-active { color: var(--accent); }
.funcmenu__item svg { flex: 0 0 auto; }
.funcmenu__logout { margin: 0.35rem 0 0; padding-top: 0.35rem; border-top: 1px solid var(--line); }
.icon-glyph { width: 1.15rem; height: 1.15rem; display: block; }

/* Full-width search drawer that slides down below the header, over the content. */
.search-drawer {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 25;
    background: var(--surface); border-bottom: 1px solid var(--line);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.18);
}
.search-drawer[hidden] { display: none; }
.search-drawer__form {
    max-width: var(--content-width); margin: 0 auto;
    display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem 1rem;
}
.search-drawer__form input[type="search"] { flex: 1 1 auto; }
.search-drawer__icon { width: 1.1rem; height: 1.1rem; color: var(--muted); flex: 0 0 auto; }

.content { max-width: var(--content-width); margin: 0 auto; padding: 1.5rem 1rem 4rem; }

/* ---- Page head + stats ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 1rem; display: flex; flex-direction: column; gap: 0.15rem; }
.stat__label { color: var(--muted); font-size: 0.8rem; }
.stat__value { font-size: 1.35rem; font-weight: 700; }
.stat__value--sm { font-size: 1.05rem; font-weight: 600; }
.stat--accent { border-color: var(--accent); }
.stat--accent .stat__value { color: var(--accent); }
.stat--warn { border-color: var(--warn); }
.stat--warn .stat__value { color: var(--warn); }
/* "Summe mtl. abgebucht" — shares --billed with the highlighted contract rows, so
   the box and the rows it summarises are the same colour by construction. Change
   the variable and both follow. */
.stat--billed { border-color: var(--billed); }
.stat--billed .stat__value { color: var(--billed); }
/* Gesamt-Sparrate box — green, like every other savings element. */
.stat--savings { border-color: var(--income); }
.stat--savings .stat__value { color: var(--income); }
/* Summary tiles: 2 per row on small screens, 4 per row on desktop (so the
   dashboard's six tiles read as 4 on top + 2 below). */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.1rem; margin-bottom: 1.5rem; }
@media (min-width: 720px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

/* ---- Cards ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.card__title { margin: 0 0 1rem; font-size: 1.1rem; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card__head .card__title { margin: 0; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { color: var(--muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table tfoot th { border-top: 2px solid var(--line); border-bottom: none; font-size: 0.95rem; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table--compact th, .table--compact td { padding: 0.4rem 0.5rem; font-size: 0.85rem; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.85rem; }
.actions-col { white-space: nowrap; text-align: right; }
/* Keep the cell a real table-cell (not flex) so its bottom border stays aligned
   with the other cells when a row grows to two lines; lay the actions out inline
   and centre them vertically instead. */
td.actions-col { vertical-align: middle; }
td.actions-col > * { vertical-align: middle; }
td.actions-col > * + * { margin-left: 0.4rem; }
.actions-col form.inline { margin: 0; }
.is-inactive td { opacity: 0.55; }
/* Contracts debited every month (Versicherungen). Same --billed as the box above
   the table. The tint uses color-mix so it follows the variable; where that is
   unsupported the accent bar alone still carries the marking. */
.is-billed-monthly td { background: color-mix(in srgb, var(--billed) 7%, transparent); }
.is-billed-monthly td:first-child { box-shadow: inset 3px 0 0 0 var(--billed); }
/* The session the current browser is using. Same --billed treatment as above:
   "this is the one you are looking at" is a highlight, not a warning. */
.is-current-session td { background: color-mix(in srgb, var(--billed) 7%, transparent); }
.is-current-session td:first-child { box-shadow: inset 3px 0 0 0 var(--billed); }
/* A row that needs attention: a stuck cron task or a failed mail. Same tinting
   idea as the markers above, but with --fail so it reads as a problem, not a
   highlight. Where color-mix is unsupported the accent bar alone still marks it. */
.is-stuck td { background: color-mix(in srgb, var(--fail) 8%, transparent); }
.is-stuck td:first-child { box-shadow: inset 3px 0 0 0 var(--fail); }
.empty { color: var(--muted); margin: 0.5rem 0; }
.hint { color: var(--muted); font-size: 0.85rem; margin: -0.5rem 0 1.25rem; }
/* Preformatted block: the shell command (Cronjobs) and the text body of a logged
   mail (E-Mails). Wraps instead of forcing the page wide; scrolls only if it must. */
.codeblock { margin: 0.5rem 0 0; padding: 0.6rem 0.75rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; font-size: 0.82rem; line-height: 1.5; }
details > summary { cursor: pointer; color: var(--accent); }
.badge { display: inline-block; font-size: 0.72rem; padding: 0.1rem 0.45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge--inactive { color: var(--muted); }
.badge--excluded { color: var(--warn); border-color: var(--warn); }
/* "Wird jeden Monat abgebucht" — Versicherungen und Haus-Kosten. Uses --billed,
   the same variable as the row tint and the "Summe mtl. abgebucht" box, so badge,
   row and box can never drift apart. */
.badge--monthly {
    color: var(--billed);
    border-color: var(--billed);
    background: color-mix(in srgb, var(--billed) 12%, transparent);
    font-weight: 600;
}
/* Non-monthly contract that will be debited next month — a heads-up, hence the
   alarm colour and the filled look that sets it apart from the quieter badges. */
.badge--due {
    color: var(--fail);
    border-color: var(--fail);
    background: color-mix(in srgb, var(--fail) 12%, transparent);
    font-weight: 600;
}

/* ---- Buttons (small) ---- */
.btn--sm { padding: 0.3rem 0.6rem; font-size: 0.82rem; }
.inline { display: inline; }

/* ---- Forms: rows & stacks ---- */
.form-row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.form-row .field { flex: 1 1 12rem; margin-bottom: 0; }
.form-row .field--amount { flex: 0 0 9rem; }
.form-row__submit { flex: 0 0 auto; }
.form-row--tight { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--line); }

.form-stack .field { margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-section { font-size: 0.95rem; color: var(--muted); margin: 1.25rem 0 0.75rem; padding-top: 1rem; border-top: 1px solid var(--line); }

/* ---- Category management ---- */
.cat-manage { display: grid; gap: 0.5rem; margin-bottom: 0.5rem; }
.cat-manage__row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.cat-manage__edit { display: flex; gap: 0.5rem; align-items: center; }
.cat-manage__edit input { max-width: 16rem; }

/* Page-head side actions (button + stat) */
.page-head__side { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* Category management list (own page) */
.cat-list { display: grid; gap: 0.6rem; }
.cat-list__row {
    display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap;
    justify-content: space-between;
    padding: 0.6rem 0; border-bottom: 1px solid var(--line);
}
.cat-list__row:last-child { border-bottom: none; }
.cat-list__edit { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; flex: 1 1 auto; }
.cat-list__edit input[type="text"] { flex: 1 1 12rem; max-width: 20rem; }
/* Savings target/saved fields stay narrow next to the (flexible) name field.
   Needs the same specificity as the rule above, otherwise that one wins. */
.cat-list__edit input[type="text"].cat-list__amount { flex: 0 0 8rem; max-width: 8rem; }
.check--inline { margin: 0; }

/* Collapsible "add" disclosure (Item 4) */
.add-details { margin-top: 1rem; }
.add-details > summary {
    cursor: pointer;
    list-style: none;
    width: fit-content;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border-radius: 8px;
    border: 1px dashed var(--line);
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 500;
}
.add-details > summary::-webkit-details-marker { display: none; }
.add-details > summary::before { content: "+"; font-weight: 700; font-size: 1.05em; line-height: 1; }
.add-details > summary:hover { color: var(--text); border-color: var(--accent); }
.add-details[open] > summary { border-style: solid; margin-bottom: 1rem; }
.add-details > .form-row { margin-top: 0; }
/* Breathing room between a stand-alone "add" disclosure and the table card
   that follows it (Einnahmen, Budgets …). */
.add-details + .card { margin-top: 1.25rem; }

/* ---- Sorting: drag handle (desktop) + arrows (tablet/mobile) ---- */
.sort-cell { width: 2.6rem; white-space: nowrap; }
.drag-handle {
    cursor: grab;
    color: var(--muted);
    user-select: none;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 0.2rem;
}
.drag-handle:active { cursor: grabbing; }
[data-id].is-dragging { opacity: 0.4; }
.sort-arrows { display: none; flex-direction: column; gap: 2px; }
.sort-arrow {
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 5px;
    width: 1.8rem;
    height: 1.35rem;
    line-height: 1;
    font-size: 0.7rem;
    cursor: pointer;
    padding: 0;
}
.sort-arrow:hover { border-color: var(--accent); }
.cat-list__row .drag-handle, .cat-list__row .sort-arrows { flex: 0 0 auto; }

@media (max-width: 900px) {
    .drag-handle { display: none; }
    .sort-arrows { display: inline-flex; }
}

/* ---- Columns ---- */
.cols { display: grid; gap: 1.25rem; margin-bottom: 1.25rem; }
.cols--2 { grid-template-columns: 1fr 1fr; }
.cols .card { margin-bottom: 0; }

/* ---- Chart (donut + legend) ---- */
.chart { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.chart__donut { flex: 0 0 auto; width: 150px; }
.donut { width: 150px; height: 150px; }
.donut-seg { transition: none; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1 1 12rem; display: grid; gap: 0.4rem; }
.legend__item { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.legend__val { color: var(--muted); font-size: 0.82rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.swatch { width: 12px; height: 12px; display: block; }

/* Clickable expense labels in the overview (donut legend + rest-cascade):
   subtle dotted underline, accent on hover — Einmalausgaben stay plain text. */
.legend__label a, .table--compact td a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--muted); }
.legend__label a:hover, .legend__label a:focus-visible,
.table--compact td a:hover, .table--compact td a:focus-visible { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- Sparen (dashboard boxes + category badge) ---- */
.savings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.9rem; }
.savings-box {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.savings-box__name { color: var(--muted); font-size: 0.8rem; text-decoration: none; }
.savings-box__name:hover, .savings-box__name:focus-visible { color: var(--accent); }
.savings-box__amount { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.savings-box__meta { color: var(--muted); font-size: 0.78rem; }
.savings-box__rate { color: var(--income); font-weight: 600; font-size: 0.9rem; margin-top: 0.35rem; font-variant-numeric: tabular-nums; }
.savings-rate { color: var(--income); font-weight: 600; white-space: nowrap; }
.savings-box__goal { font-size: 0.78rem; color: var(--text); margin-top: 0.45rem; border-top: 1px solid var(--line); padding-top: 0.45rem; }
/* Quick action at the bottom of an overview tile ("Gespartes aktualisieren" /
   "Eintrag hinzufügen"). A fixed margin rather than margin-top:auto: auto would
   collapse to the flex gap (0.15rem) on whichever tile is tallest and has no
   spare room, leaving that one button glued to the text. */
.savings-box__action { margin-top: 0.75rem; align-self: flex-start; }

/* Share bar (Chart::bar): the fill width is an SVG attribute, the colours come
   from here — inline styles are not allowed by the CSP.
   The fill itself is painted by the SVG gradient (fill="url(#…)"), so no `fill`
   rule may be set on .bar__fill — a CSS declaration would beat the presentation
   attribute and flatten the gradient back to one colour. The gradient's colours
   are steered through its <stop>s instead, which keeps the bar theme-aware. */
.bar { display: block; width: 100%; height: 8px; margin-top: 0.4rem; overflow: visible; }
.bar__track { fill: var(--bar-track); }
/* Default + "saving": green. The gradient is steered through the <stop>s (never a
   `fill` on .bar__fill — that would beat the presentation attribute). Per-mode
   variants (Chart::bar) only swap the stop-colors, so the shape stays identical. */
.bar__from { stop-color: var(--bar-from); }
.bar__to { stop-color: var(--bar-to); }
.bar--general .bar__from { stop-color: var(--bar-gen-from); }
.bar--general .bar__to { stop-color: var(--bar-gen-to); }
.bar--paydown .bar__from { stop-color: var(--bar-pay-from); }
.bar--paydown .bar__to { stop-color: var(--bar-pay-to); }

/* Savings target block on the expenses page. */
.goal { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 0.9rem; margin-bottom: 1rem; }
.goal__head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.goal__label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.goal__figures { font-weight: 600; font-variant-numeric: tabular-nums; }
.goal__eta { margin: 0.5rem 0 0; font-size: 0.85rem; }
.goal__done { color: var(--income); font-weight: 700; }

/* ---- Notes: light contenteditable editor ---- */
.editor { border: 1px solid var(--line); border-radius: var(--radius); background: var(--input-bg); overflow: hidden; }
.editor__toolbar { display: flex; align-items: center; gap: 0.25rem; padding: 0.4rem; border-bottom: 1px solid var(--line); background: var(--surface-2); flex-wrap: wrap; }
.editor__btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
    padding: 0.25rem 0.55rem;
    line-height: 1.4;
}
.editor__btn:hover { background: var(--surface); border-color: var(--line); }
.editor__btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.editor__sep { width: 1px; height: 1.2rem; background: var(--line); margin: 0 0.25rem; }
.editor__area { min-height: 9rem; padding: 0.85rem 1rem; outline: none; line-height: 1.6; overflow-wrap: break-word; }
.editor__area:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.editor__area > :first-child { margin-top: 0; }
.editor__area > :last-child { margin-bottom: 0; }
.editor__area p { margin: 0 0 0.6rem; }
.editor__area ul, .editor__area ol { margin: 0 0 0.6rem; padding-left: 1.5rem; }
.editor__area li { margin-bottom: 0.2rem; }
/* Placeholder: :empty is unreliable in contenteditable (browsers insert a stray
   <br>), so JS toggles .is-empty instead. */
.editor__area.is-empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }

/* Form-bound editor (Benachrichtigungen). The <textarea> is the real form field
   and therefore the DEFAULT view: without JavaScript the editor chrome is hidden
   and the textarea is what the user types into. `.js` flips it — editor visible,
   textarea hidden but still submitted, kept in sync by app.js. Reversing this
   would leave a non-JS visitor with a box that silently discards input. */
.editor--field { display: none; }
.editor__source { display: block; width: 100%; min-height: 9rem; font-family: inherit; }
.js .editor--field { display: block; }
.js .editor__source { display: none; }

/* Notification form: the repeat block is a plain grid of fields. */
.notify-repeat { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 0.75rem; }
/* display:grid beats the [hidden] UA rule; restore hiding so the JS toggle can
   actually remove an inactive group (same fix as .month-picker). */
.notify-repeat[hidden], .notify-dayrule[hidden] { display: none; }
.fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 0 0 1rem; }
.fieldset legend { padding: 0 0.4rem; color: var(--muted); font-size: 0.85rem; }

/* ---- Listen ---- */
/* The list cards sit in a .cat-list grid, which already provides the gap. */
.cat-list .list-card { margin-bottom: 0; }
.list-card .card__title { display: flex; align-items: center; gap: 0.5rem; }
.list-card .card__title a { color: inherit; text-decoration: none; }
.list-card .card__title a:hover, .list-card .card__title a:focus-visible { color: var(--accent); }
.list-figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
/* The progress bar in a list card sits between the figures and the action buttons;
   give it room so it does not touch the buttons below. */
.list-card .bar { margin-bottom: 1rem; }
.list-figure { display: flex; flex-direction: column; gap: 0.15rem; }
.list-figure__label { color: var(--muted); font-size: 0.78rem; }
.list-figure__value { font-weight: 700; font-variant-numeric: tabular-nums; }
/* Amount inputs in the entries table stay compact and right-aligned. */
.input--amount { max-width: 8rem; text-align: right; font-variant-numeric: tabular-nums; }

/* List entries: date span (one day / from-to dates / from-to months).
   Only the active mode's group is shown; app.js sets [hidden] on the others and
   disables their inputs, so nothing stale is submitted. Using :not([hidden])
   rather than a display override keeps `hidden` authoritative. */
.date-span { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.date-span__fields:not([hidden]) { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.date-span__sep { color: var(--muted); }
.form-row .date-span__fields:not([hidden]) { gap: 0.75rem; align-items: flex-end; }

/* Read-only entry rows.
   The stylesheet's default is the no-JS state: every input visible and its own
   save button next to it — exactly how the table behaved before 2.2.0. The `.js`
   rules below then hide the inputs, reveal the plain text plus a quiet
   "Bearbeiten" button, and bring the inputs back for one row at a time. That way
   an entry stays editable even when the script never runs. */
.row-view { display: none; }
.row-edit-btn { display: none; }

.js .row-view { display: inline; }
.js .row-edit { display: none; }
.js .row-edit-btn { display: inline-block; }
.js .row-save-btn { display: none; }

.js [data-item-row].is-editing .row-view { display: none; }
.js [data-item-row].is-editing .row-edit { display: inline-block; }
.js [data-item-row].is-editing .row-edit.date-span { display: inline-flex; }
.js [data-item-row].is-editing .row-edit-btn { display: none; }
.js [data-item-row].is-editing .row-save-btn { display: inline-block; }

/* Checkbox list for the piecewise export (Verwaltung → Export). */
.pick-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 0.15rem 1rem; margin-bottom: 1rem; }
.pick-list .check { margin-bottom: 0.35rem; }

/* Verwaltung → Änderungen (Changelog). */
.changelog__entry { padding: 0.9rem 0; border-top: 1px solid var(--line); }
.changelog__entry:first-of-type { border-top: none; }
.changelog__head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.changelog__version { font-weight: 700; font-size: 1.05rem; }
.changelog__date { color: var(--muted); font-size: 0.85rem; }
.changelog__section { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin: 0.75rem 0 0.25rem; }
.changelog__list { margin: 0; padding-left: 1.1rem; font-size: 0.9rem; }
.changelog__list li { margin-bottom: 0.2rem; }

/* Icon boxes (Core\Icon): a rounded square with a tinted background and the
   coloured glyph — everything drawn inside the SVG, so no inline styles. */
.icon-box { display: inline-block; width: 2rem; height: 2rem; vertical-align: middle; flex: 0 0 auto; }
.icon-box--sm { width: 1.4rem; height: 1.4rem; }
.icon-box--lg { width: 2.6rem; height: 2.6rem; }

/* Icon picker in forms. */
.icon-field__row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.icon-field__preview { display: inline-flex; align-items: center; justify-content: center; width: 2.6rem; height: 2.6rem; }
.icon-field__preview .icon-box { width: 2.6rem; height: 2.6rem; }
.icon-field__empty { color: var(--muted); font-size: 1.2rem; border: 1px dashed var(--line); border-radius: 12px; width: 2.6rem; height: 2.6rem; display: inline-flex; align-items: center; justify-content: center; }
.icon-field__color { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--muted); font-size: 0.85rem; }
.icon-field__color input[type="color"] { width: 2.2rem; height: 2rem; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; }
.icon-picker { margin-top: 0.75rem; border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem; background: var(--surface-2); }
.icon-picker__head { display: flex; gap: 0.6rem; margin-bottom: 0.6rem; flex-wrap: wrap; }
.icon-picker__head input[type="search"] { flex: 1 1 12rem; }
.icon-picker__results { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr)); gap: 0.4rem; max-height: 16rem; overflow-y: auto; }
.icon-pick { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 0.3rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.icon-pick:hover, .icon-pick:focus-visible { border-color: var(--accent); }
.icon-pick .icon-box { width: 1.8rem; height: 1.8rem; }
/* Icon shown inline before a name in a table/heading. */
.cell-icon { margin-right: 0.2rem; }
.cell-icon .icon-box { width: 1.5rem; height: 1.5rem; }

/* Rest-Kaskade: vorgemerkte Budgets unter der Restsumme. Abgesetzt und leiser als
   die gerechneten Zeilen — sie verändern keine Summe, das muss man sehen. */
.cascade-memo__head > th { padding-top: 0.9rem; font-weight: 600; border-top: 1px dashed var(--line); }
.cascade-memo > td { color: var(--muted); }
.cascade-memo--sum > td { border-top: 1px solid var(--line); }

/* Rechner: Kontostand-Verlauf. Gleiche Bauart wie der Fälligkeitsplan der
   Versicherungen — Balkenhöhe steckt in SVG-Attributen, Farben kommen aus diesen
   Klassen (Inline-Styles wären nach der CSP wirkungslos). Balken unter der
   Nulllinie hängen, der erste positive steht darüber. */
.balance-chart {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(2.6rem, 1fr);
    gap: 0.3rem;
    margin: 0.75rem 0 0.25rem;
    overflow-x: auto;
}
.balance-col { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; min-width: 0; }
.balance-col__amount { font-size: 0.68rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.balance-col__track { width: 100%; max-width: 2.4rem; height: 96px; display: block; }
.balance-col__bar { width: 100%; height: 100%; display: block; }
.balance-col__bar rect { fill: var(--warn, #f0b429); }
.balance-col.is-positive .balance-col__bar rect { fill: var(--income, #35c98a); }
.balance-col.is-negative .balance-col__bar rect { fill: var(--expense, #ff6b6b); }
.balance-col__zero { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.balance-col__month { font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.card__subtitle { margin: 1.25rem 0 0; font-size: 1rem; }

@media (max-width: 640px) {
    .balance-col__amount { font-size: 0.6rem; }
    .balance-col__month { font-size: 0.62rem; }
}

/* Collapsed per-entry note inside a table cell (e.g. an insurance contract). */
.row-note { margin-top: 0.35rem; }
.row-note > summary { cursor: pointer; font-size: 0.82rem; color: var(--muted); }
.row-note > summary:hover { color: var(--text); }
.row-note__text { margin: 0.35rem 0 0; font-size: 0.85rem; color: var(--muted); max-width: 32rem; }

/* Loan (Kredit) list: KPI figures + a scrollable amortisation schedule whose
   current instalment is highlighted. */
.loan-figures { margin-top: 1rem; }

/* "Kredit-Angaben": read-only once saved, with a quiet edit button. As everywhere
   else the CSS default is the no-JS state (form visible, no toggle button); the
   `.js` rules then hide the form until "Bearbeiten" is pressed. */
.loan-edit-btn { display: none; }
.js .loan-edit-btn { display: inline-block; }
.js [data-loan-edit] .loan-form { display: none; }
.js [data-loan-edit] .loan-view { display: block; }
.js [data-loan-edit].is-editing .loan-form { display: flex; }
.js [data-loan-edit].is-editing .loan-view { display: none; }
.js [data-loan-edit].is-editing .loan-edit-btn { display: none; }
.table-wrap--tall { max-height: 24rem; overflow-y: auto; }
.is-current-row td { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.is-current-row td:first-child { box-shadow: inset 3px 0 0 0 var(--accent); }

/* Global search results page. */
.search-results { list-style: none; margin: 0; padding: 0; }
.search-results li { padding: 0.35rem 0; border-top: 1px solid var(--line); }
.search-results li:first-child { border-top: none; }
.search-results a { text-decoration: none; font-weight: 600; }
.search-results a:hover, .search-results a:focus-visible { text-decoration: underline; }

.note-status { font-size: 0.8rem; color: var(--muted); min-height: 1.2em; }
.note-status--ok { color: var(--income); }
.note-status--fail { color: var(--fail); }
.hint--below { margin: 0.6rem 0 0; }
.badge--savings { color: var(--income); border-color: var(--income); }
/* List-mode badges — same hues as the mode's progress bar, so badge and bar read
   as one. General needs no badge (it is the default). */
.badge--mode-saving { color: var(--bar-from); border-color: var(--bar-from); }
.badge--mode-paydown { color: var(--bar-pay-from); border-color: var(--bar-pay-from); }
.badge--mode-loan { color: var(--bar-pay-from); border-color: var(--bar-pay-from); }

/* ---- Verwaltung → Update: check results + step list ---- */
.check-ok { color: var(--ok); font-weight: 600; white-space: nowrap; }
.check-fail { color: var(--fail); font-weight: 600; white-space: nowrap; }
.steps { margin: 0 0 1.1rem; padding-left: 1.3rem; display: grid; gap: 0.4rem; }
.steps li { line-height: 1.5; }
.steps code, .alert code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.85em;
    background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0.05em 0.35em; }

/* Verwaltung → Info definition list */
.info-list { margin: 0; display: grid; gap: 0.75rem; }
.info-list__row { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 0.75rem; }
.info-list__row:last-child { border-bottom: none; padding-bottom: 0; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; font-weight: 600; }

.strong { font-weight: 700; }
.neg { color: var(--fail); }
.txt-income { color: var(--income); }
.txt-expense { color: var(--expense); }
/* Neutral "worth noticing" — used where exceeding a figure is information, not a
   fault (a list's target may be a savings goal, where over-shooting is good). */
.txt-warn { color: var(--warn); }

/* ---- Confirmation modal (Item 9) ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 26rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.modal__msg { margin: 0 0 1.25rem; font-size: 1.02rem; line-height: 1.5; }
.modal__actions { display: flex; justify-content: flex-end; gap: 0.6rem; }
.modal--info { max-width: 30rem; }
.modal__body { margin: 0 0 1.25rem; }

/* ---- Insurance due plan (Fälligkeitsplan) ---- */
.stat--sm { padding: 0.5rem 0.75rem; }
.due-chart {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 0.3rem;
    align-items: end;
    margin-top: 0.25rem;
}
.due-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    background: none;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.3rem 0.15rem 0.35rem;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
}
.due-col:not(.is-empty):hover { border-color: var(--line); background: var(--surface-2); }
.due-col.is-empty { cursor: default; }
.due-col__amount { font-size: 0.68rem; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1em; white-space: nowrap; }
.due-col__track { width: 100%; max-width: 2.2rem; height: 84px; display: flex; align-items: flex-end; }
.due-col__bar { width: 100%; height: 100%; display: block; }
.due-col__bar rect { fill: var(--accent); }
.due-col.is-empty .due-col__bar rect { fill: var(--line); }
.due-col:not(.is-empty):hover .due-col__bar rect { fill: var(--income); }
.due-col__month { font-size: 0.75rem; color: var(--muted); }

.due-detail__head { margin: 0 0 0.85rem; font-size: 1.1rem; }
.due-detail__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.due-detail__list li {
    display: flex; justify-content: space-between; gap: 0.75rem; align-items: baseline;
    border-bottom: 1px solid var(--line); padding-bottom: 0.5rem;
}
.due-detail__list li:last-child { border-bottom: none; padding-bottom: 0; }
.due-detail__meta { white-space: nowrap; display: inline-flex; gap: 0.5rem; align-items: baseline; }
.due-detail__amt { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- Insurance form: billing-month picker ---- */
.month-picker { border: 1px solid var(--line); border-radius: 8px; padding: 0.9rem; }
/* .field sets display:block, which would beat the [hidden] UA rule — restore it
   so the JS toggle (frequency = 12 → monthly) can actually hide the picker. */
.month-picker[hidden] { display: none; }
.month-picker__legend { display: block; margin-bottom: 0.3rem; font-size: 0.9rem; color: var(--muted); }
.month-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr)); gap: 0.35rem 0.75rem; margin-top: 0.6rem; }
.month-grid .check { margin-bottom: 0; }
.hint--inline { margin: 0.25rem 0 0; }

@media (max-width: 620px) {
    .due-col__amount { display: none; }
    .due-col__month { font-size: 0.62rem; }
    .due-col { padding-left: 0; padding-right: 0; }
    .due-chart { gap: 0.15rem; }
}

/* ---- Settings (Verwaltung) tabs & controls ---- */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; flex-wrap: wrap; }
.tabs__link {
    padding: 0.6rem 0.9rem;
    color: var(--muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-size: 0.95rem;
}
.tabs__link:hover { color: var(--text); }
.tabs__link.is-active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.radio-list { display: grid; gap: 0.75rem; margin-bottom: 1.25rem; }
.radio-option {
    display: flex; gap: 0.6rem; align-items: flex-start;
    padding: 0.75rem 0.9rem; border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.radio-option input { margin-top: 0.2rem; width: 1rem; height: 1rem; }
.radio-option span { display: flex; flex-direction: column; gap: 0.15rem; }

.divider { border: none; border-top: 1px solid var(--line); margin: 1.5rem 0; }
.inline-form { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* ---- Responsive ---- */
@media (max-width: 860px) {
    .cols--2 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
    .topbar__toggle { display: block; }
    .topbar__actions { margin-left: auto; }
    .mainnav {
        display: none;
        position: absolute;
        top: 100%; left: 0; right: 0;
        margin: 0;
        flex-direction: column;
        align-items: stretch;
        background: var(--surface);
        border-bottom: 1px solid var(--line);
        padding: 0.5rem;
        gap: 0.15rem;
        z-index: 30;
    }
    .mainnav.is-open { display: flex; }
    .grid-2 { grid-template-columns: 1fr; }
}
