:root {
    --bg: #f8f9fa;
    --card: #fff;
    --border: #dee2e6;
    --accent: #2563eb;
    --text: #17191e;
    --muted: #5a6a7e;
    --focus: #2563eb;
    /* Chart-Palette (wie im Artifact / Buckets) */
    --c-pkw: #e34948;
    --c-lkw: #4a3aa7;
    --c-rad: #12a06f;
    --c-rad-elektro: #067a53;
    --c-escooter: #46c19a;
    --c-bus: #eb6834;
    --c-motorrad: #d9772e;
    --c-moped: #f0996b;
    --c-traktor: #b3541e;
    --c-schiene: #8a6d3b;
    --c-fussgaenger: #64748b;
    --c-sonstige: #9aa0a8;
    /* Mischfarben für die Sammelgruppen (Mittelwert der jeweils
       zusammengefassten Untergruppen-Farben), nur für die
       Kennzahl-Karten "motorisierter Verkehr" / "Mikromobilität" */
    --c-motor: #bb644c;
    --c-mikro: #2cb084;
    /* Dunklere Fassungen für Text (Kennzahl-Zahlen): die Balkenfarben
       erreichen auf Weiß keine 3:1. Balkenfarbe bleibt unverändert. */
    --t-mikro: #0f7a5a;
    --t-escooter: #1f8060;
    --t-moped: #b4561e;
    --t-sonstige: #6b7280;
    --pill: #0b7a55;
    color-scheme: light dark;
    --header-bg: #17191e;
    --field: #fff;
    --hover: #f1f5f9;
    --accent-bg: #2563eb;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1116;
        --card: #171c24;
        --border: #2f3744;
        --text: #e6e9ee;
        --muted: #9aa7b8;
        --accent: #8ab4ff;
        --focus: #8ab4ff;
        --header-bg: #0a0d12;
        --field: #1f2631;
        --hover: #202734;
        --c-lkw: #7265ba;
        --c-rad-elektro: #15825d;
        --t-mikro: #2cb084;
        --t-escooter: #46c19a;
        --t-moped: #f0996b;
        --t-sonstige: #9aa0a8;
    }
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}
header {
    background: var(--header-bg);
    color: white;
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
header h1 {
    font-size: 1.4rem;
    font-weight: 600;
}
header h1 a {
    color: inherit;
    text-decoration: none;
}
header .sub {
    color: #94a3b8;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}
header nav {
    display: flex;
    gap: 1.25rem;
    align-items: center;
}
header nav a {
    color: #94a3b8;
    font-size: 0.9rem;
    text-decoration: none;
}
header nav a:hover {
    color: white;
}
.pill {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--pill);
    color: #fff;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    vertical-align: middle;
    margin-left: 0.5rem;
}
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
}

.filter-heading {
    flex-basis: 100%;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}
.filter-top {
    flex-basis: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}
.filter-top .filter-heading {
    flex-basis: auto;
}
.filter-bottom {
    flex-basis: 100%;
}
.filter-heading select {
    margin: 0 0.15rem;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: end;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.filter-group label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
select,
button {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--field);
    cursor: pointer;
    color: var(--text);
}
select:focus {
    outline: 2px solid var(--accent);
    border-color: transparent;
}

.mode-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.mode-toggle button {
    border: none;
    border-radius: 0;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    background: var(--field);
    color: var(--muted);
    transition: all 0.15s;
}
.mode-toggle button.active {
    background: var(--accent-bg);
    color: white;
    font-weight: 600;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}
.stat-card .number {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.stat-card .label {
    font-size: 0.875rem;
    color: var(--muted);
}

.chart-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.chart-container h2 {
    font-size: 1.05rem;
    margin-bottom: 0.15rem;
}
.chart-sub {
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 1.25rem;
}

/* Horizontale Balken */
.bars {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.bar-row {
    display: grid;
    grid-template-columns: 12rem 1fr;
    gap: 0.9rem;
    align-items: center;
}
.bar-lab {
    font-size: 0.875rem;
    color: var(--text);
    text-align: right;
    overflow-wrap: anywhere;
}
.bar-track {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.bar {
    height: 22px;
    border-radius: 0 4px 4px 0;
    min-width: 2px;
}
@media (prefers-reduced-motion: no-preference) {
    .bar {
        transition: width 0.4s ease;
    }
}
.bar-val {
    font-size: 0.875rem;
    color: var(--text);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.bar-val .n {
    color: var(--muted);
}
.bar-expand {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--muted);
    padding: 0 0.3rem;
    line-height: 1;
    vertical-align: middle;
}
.bar-expand:hover {
    color: var(--text);
}
.bar-expand:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}
.bar-sub-group {
    display: contents;
}
.bar-row.sub {
    padding-left: 1.5rem;
}
.bar-row.sub .bar-lab {
    font-size: 0.875rem;
    color: var(--muted);
}
.bar-row.sub .bar {
    height: 16px;
}
.bar-row.sub .bar-lab a {
    color: inherit;
    text-decoration: underline;
}
.bar-row.sub .bar-lab a:hover {
    color: var(--text);
}

/* Tabelle */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
    font-size: 0.875rem;
}
caption {
    text-align: left;
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
}
th,
td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
th {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}
td.num,
th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
tbody tr:hover {
    background: var(--hover);
}
tr.sub-row th[scope="row"] {
    padding-left: 2rem;
}
tr.sub-row {
    font-size: 0.875rem;
    color: var(--muted);
}
tfoot td,
tfoot th {
    font-weight: 700;
    border-top: 2px solid var(--border);
    border-bottom: none;
}
/* Zeilenköpfe sehen aus wie Zellen, nicht wie Spaltenköpfe */
tbody th[scope="row"],
tfoot th[scope="row"] {
    font-size: inherit;
    text-transform: none;
    letter-spacing: normal;
    color: inherit;
}
tbody th[scope="row"] {
    font-weight: inherit;
}
.swatch {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 3px;
    margin-right: 0.5rem;
    vertical-align: middle;
}

.note {
    font-size: 0.875rem;
    color: var(--muted);
    line-height: 1.6;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
}
.note b {
    color: var(--text);
}
.loading {
    text-align: center;
    padding: 4rem;
    color: var(--muted);
    font-size: 1.1rem;
}
.empty {
    padding: 2rem;
    text-align: center;
    color: var(--muted);
}

/* Umschalter Einfach | Erweitert; Filter der erweiterten Ansicht (.adv) */
.view-switch {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
    background: var(--card);
}
.view-switch button {
    border: 0;
    border-radius: 0;
    background: none;
    padding: 0.4rem 1rem;
    font-size: 0.9rem;
    color: var(--muted);
    cursor: pointer;
}
.view-switch button.on {
    background: var(--accent-bg);
    color: #fff;
}
/* Aktiver Zustand nicht nur durch Farbe: Häkchen vor der Beschriftung
   (leerer Alternativtext, damit Screenreader es nicht vorlesen; aria-pressed
   trägt den Zustand). */
.view-switch button.on::before,
.mode-toggle button.active::before {
    content: "✓\00a0";
    content: "✓\00a0" / "";
}
.view-switch button:not(.on):hover {
    color: var(--text);
}
.adv {
    display: none !important;
}
body.erweitert .adv {
    display: flex !important;
}

/* Schmale Bildschirme (Telefon): Beschriftung über dem Balken statt daneben */
@media (max-width: 600px) {
    .bar-row {
        grid-template-columns: 1fr;
        gap: 0.15rem;
        margin-bottom: 0.55rem;
    }
    .bar-lab {
        text-align: left;
    }
    .bar-track {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.15rem;
    }
    .bar-row.sub {
        padding-left: 1rem;
    }
}

/* Fokusring: einheitlich, 2 px, Kontrast mindestens 3:1 zum Umfeld */
:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}
header :focus-visible {
    outline-color: #fff;
}
/* Umschalter mit overflow: hidden: Ring innen, mit hellem Abstand */
.view-switch button:focus-visible,
.mode-toggle button:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: -4px;
    box-shadow: inset 0 0 0 2px var(--card);
}
.ap-chip button:focus-visible,
.ap-toggle:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}
.ap-chip button:focus-visible {
    outline-color: #fff;
}
/* Sprunglink: nur bei Fokus sichtbar */
.skip {
    position: absolute;
    left: 0.5rem;
    top: 0.5rem;
    z-index: 300;
    padding: 0.5rem 1rem;
    background: #fff;
    color: #000;
    border-radius: 6px;
    font-weight: 600;
    text-decoration: none;
}
.skip:not(:focus) {
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    padding: 0;
}
main:focus {
    outline: none;
}

/* Nur für Screenreader */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
