/* =========================================================
   Hamburg Verkehr – Dashboard
   ========================================================= */

/* ---------- Tokens ---------- */
:root {
    color-scheme: light;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --surface-3: #eef1f5;
    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.14);
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #8a94a6;

    --accent: #2a78d6;
    --accent-soft: rgba(42, 120, 214, 0.10);
    --accent-ink: #ffffff;

    /* Status – fest, in beiden Modi gleich */
    --good: #0ca30c;
    --warning: #fab219;
    --serious: #ec835a;
    --critical: #d03b3b;
    --low: #8a94a6;

    --radius-xl: 20px;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.18);
    --gap: 16px;
    --topbar-h: 64px;
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        color-scheme: dark;
        --bg: #0b1120;
        --surface: #121a2b;
        --surface-2: #172036;
        --surface-3: #1e2942;
        --border: rgba(255, 255, 255, 0.07);
        --border-strong: rgba(255, 255, 255, 0.14);
        --text: #eef2f8;
        --text-2: #aab4c5;
        --text-3: #74809a;
        --accent: #4b93ea;
        --accent-soft: rgba(75, 147, 234, 0.16);
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
        --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1120;
    --surface: #121a2b;
    --surface-2: #172036;
    --surface-3: #1e2942;
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text: #eef2f8;
    --text-2: #aab4c5;
    --text-3: #74809a;
    --accent: #4b93ea;
    --accent-soft: rgba(75, 147, 234, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* ---------- Basis ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- App-Layout ---------- */
.app {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--gap);
    min-height: 100dvh;
    padding: 0 var(--gap) var(--gap);
    max-width: 1800px;
    margin: 0 auto;
}

/* ---------- Topbar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 900;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    height: var(--topbar-h);
    margin: 0 calc(var(--gap) * -1);
    padding: 0 var(--gap);
    padding-top: env(safe-area-inset-top);
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
    width: 38px; height: 38px; border-radius: 11px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #1f2a44, #0f172a);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}
.brand-logo svg { width: 20px; height: 20px; stroke-width: 1.6; }
.brand-logo circle:nth-of-type(1) { fill: var(--critical); stroke: none; }
.brand-logo circle:nth-of-type(2) { fill: var(--warning); stroke: none; }
.brand-logo circle:nth-of-type(3) { fill: var(--good); stroke: none; }
.brand-text h1 { white-space: nowrap; font-size: 16px; font-weight: 750; letter-spacing: -0.01em; line-height: 1.2; }
.brand-text p { font-size: 12px; color: var(--text-3); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.live-status {
    display: flex; align-items: center; gap: 8px;
    height: 36px; padding: 0 12px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 12.5px; color: var(--text-2); white-space: nowrap;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); position: relative; }
.live-status[data-state="ok"] .live-dot { background: var(--good); }
.live-status[data-state="ok"] .live-dot::after {
    content: ''; position: absolute; inset: -4px; border-radius: 50%;
    border: 2px solid var(--good); opacity: 0; animation: ping 2.4s ease-out infinite;
}
.live-status[data-state="error"] .live-dot { background: var(--critical); }
.live-status[data-state="loading"] .live-dot { background: var(--warning); }
@keyframes ping { 0% { transform: scale(0.6); opacity: 0.8; } 100% { transform: scale(1.8); opacity: 0; } }

.icon-btn {
    width: 36px; height: 36px; border-radius: 10px;
    display: grid; place-items: center;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text-2);
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
#refresh-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) .i-sun { display: block; }
    :root:where(:not([data-theme="light"])) .i-moon { display: none; }
}

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 36px; padding: 0 14px; border-radius: 10px;
    font-weight: 600; font-size: 13.5px;
    background: var(--surface); border: 1px solid var(--border);
}
.btn:hover { background: var(--surface-3); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-filter-toggle { display: none; }

.badge {
    display: inline-grid; place-items: center;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
    font-size: 11.5px; font-weight: 700;
    background: var(--accent); color: #fff;
}

/* ---------- KPIs ---------- */
.kpis {
    display: grid;
    grid-template-columns: minmax(280px, 1.7fr) repeat(4, minmax(0, 1fr));
    gap: var(--gap);
}
.kpi {
    display: flex; flex-direction: column; gap: 6px;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    text-align: left;
    min-width: 0;
}
.kpi-click { transition: transform .15s, border-color .15s, background .15s; }
.kpi-click:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.kpi-click.is-active { border-color: var(--accent); background: linear-gradient(var(--accent-soft), var(--accent-soft)), var(--surface); }
.kpi-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.kpi-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.kpi-value { font-size: 30px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; color: var(--text); }
.kpi-value small { font-size: 13px; font-weight: 600; color: var(--text-3); margin-left: 6px; letter-spacing: 0; }
.kpi-sub { font-size: 12px; color: var(--text-3); }
.kpi-ico {
    width: 24px; height: 24px; border-radius: 7px;
    display: grid; place-items: center;
    background: var(--surface-3); color: var(--text-2);
}
.kpi-ico svg { width: 14px; height: 14px; }

.flowbar {
    display: flex; gap: 2px; height: 10px; margin-top: 4px;
    border-radius: 4px; overflow: hidden; background: var(--surface-3);
}
.flowbar .seg { display: block; height: 100%; width: 0; transition: width .5s ease; }
.seg-good { background: var(--good); }
.seg-warning { background: var(--warning); }
.seg-serious { background: var(--serious); }
.seg-critical { background: var(--critical); }
.flowbar-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--text-2); }
.flowbar-legend li { display: flex; align-items: center; gap: 5px; }
.flowbar-legend b { font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Workspace ---------- */
.workspace {
    display: grid;
    grid-template-columns: 290px minmax(0, 1fr) 400px;
    grid-template-areas: "filters map list";
    gap: var(--gap);
    height: 680px;
}
/* Genug Höhe: Dashboard füllt exakt den Bildschirm, nur Liste/Filter scrollen */
@media (min-width: 768px) and (min-height: 720px) {
    .app { height: 100dvh; }
    .workspace { height: auto; min-height: 0; }
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-height: 0;
}

/* ---------- Filter ---------- */
.filters {
    grid-area: filters;
    display: flex; flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    min-height: 0;
    overflow: hidden;
}
.filters-head {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--border);
}
.filters-head h2 { font-size: 15px; font-weight: 700; margin-right: auto; }
.filters-close { display: none; }
.link-btn { font-size: 12.5px; font-weight: 600; color: var(--accent); padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { background: var(--accent-soft); }
.filters-body { flex: 1; overflow-y: auto; padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 20px; overscroll-behavior: contain; }
.filters-foot { display: none; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.filters-foot .btn { width: 100%; height: 46px; font-size: 15px; }

.field { display: flex; flex-direction: column; gap: 9px; }
.field-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }

.search {
    display: flex; align-items: center; gap: 8px;
    height: 40px; padding: 0 12px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-3);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--text); font-size: 14px; }
.search input::placeholder { color: var(--text-3); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    height: 32px; padding: 0 10px 0 8px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 13px; font-weight: 550; color: var(--text-2);
    transition: background .12s, border-color .12s, color .12s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip svg { width: 14px; height: 14px; }
.chip .count { font-size: 11.5px; font-weight: 700; color: var(--text-3); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.chip[aria-pressed="true"] .count { color: var(--accent); }
.chip.is-empty { opacity: 0.5; }
.chip .sev-dot { width: 10px; height: 10px; border-radius: 50%; margin-left: 2px; }

.segmented {
    display: grid; grid-template-columns: repeat(3, 1fr);
    padding: 3px; gap: 3px;
    background: var(--surface-3); border-radius: 10px;
}
.segmented button { height: 32px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

.switch { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
    position: relative; width: 36px; height: 20px; border-radius: 999px;
    background: var(--surface-3); border: 1px solid var(--border-strong);
    transition: background .15s; flex-shrink: 0;
}
.switch-track::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 14px; height: 14px; border-radius: 50%; background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3); transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.range { margin-top: 4px; }
.range-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.range-head output { font-weight: 700; font-variant-numeric: tabular-nums; }
.range input { width: 100%; accent-color: var(--accent); }
.range-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); }

.scrim { display: none; }

/* ---------- Karte ---------- */
.map-card { grid-area: map; position: relative; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
.map-legend {
    position: absolute; left: 12px; bottom: 12px; z-index: 500;
    padding: 10px 12px;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    font-size: 12px;
}
.legend-title { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: 6px; }
.map-legend ul { list-style: none; display: grid; gap: 4px; }
.map-legend li { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.sw { width: 18px; height: 4px; border-radius: 2px; }
.sw-good { background: var(--good); } .sw-warning { background: var(--warning); }
.sw-serious { background: var(--serious); } .sw-critical { background: var(--critical); }
.map-error {
    position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 600;
    padding: 8px 14px; border-radius: 999px;
    background: var(--critical); color: #fff; font-size: 13px; font-weight: 600;
    box-shadow: var(--shadow);
}

/* Leaflet an Theme anpassen */
.leaflet-container { font-family: var(--font); background: var(--surface-2); }
.leaflet-control-zoom { border: 1px solid var(--border) !important; border-radius: 10px !important; overflow: hidden; box-shadow: var(--shadow) !important; }
.leaflet-control-zoom a { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; width: 34px !important; height: 34px !important; line-height: 34px !important; }
.leaflet-control-zoom a:hover { background: var(--surface-3) !important; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--text-3) !important; font-size: 10.5px; }
.leaflet-control-attribution a { color: var(--text-2) !important; }
.leaflet-popup-content-wrapper { background: var(--surface); color: var(--text); border-radius: 14px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 14px 16px; font-size: 13px; line-height: 1.5; min-width: 220px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-3); }

.pop-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.pop-title { font-weight: 700; font-size: 14px; }
.pop-street { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.pop-desc { color: var(--text-2); }
.pop-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); }
.pop-meta b { color: var(--text); font-weight: 600; }

/* Marker */
.mk-wrap { background: none; border: 0; }
.mk {
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center;
    color: #fff;
    border: 2px solid var(--surface);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: transform .15s;
}
.mk svg { width: 15px; height: 15px; stroke-width: 2.4; }
.mk.sev-critical { background: var(--critical); }
.mk.sev-major { background: var(--serious); }
.mk.sev-minor { background: var(--warning); color: #0b0b0b; }
.mk.sev-low { background: var(--low); }
.mk.is-selected { transform: scale(1.25); box-shadow: 0 0 0 4px var(--accent-soft), 0 0 0 2px var(--accent), 0 4px 10px rgba(0,0,0,0.35); }
.mk-cluster-hint { display: none; }

/* ---------- Liste ---------- */
.list-card { grid-area: list; display: flex; flex-direction: column; }
.list-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 18px 12px;
}
.list-head h2 { font-size: 15px; font-weight: 700; }
.list-count { font-size: 12.5px; color: var(--text-3); }
.select select {
    height: 34px; padding: 0 30px 0 10px;
    border-radius: 9px; border: 1px solid var(--border);
    background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a94a6' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
    appearance: none; -webkit-appearance: none;
    font-size: 13px; font-weight: 550;
}
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 18px; }
.active-filters:not(:empty) { padding-bottom: 10px; }
.af-chip {
    display: inline-flex; align-items: center; gap: 4px;
    height: 26px; padding: 0 6px 0 10px; border-radius: 999px;
    background: var(--accent-soft); color: var(--text);
    font-size: 12px; font-weight: 600;
}
.af-chip svg { width: 13px; height: 13px; color: var(--text-2); }
.af-chip:hover svg { color: var(--text); }

.incident-list { list-style: none; flex: 1; overflow-y: auto; padding: 0 10px 10px; overscroll-behavior: contain; border-top: 1px solid var(--border); }
.incident {
    display: grid; grid-template-columns: 36px 1fr; gap: 12px;
    padding: 12px 10px; margin-top: 4px;
    border-radius: 12px;
    cursor: pointer;
    transition: background .12s;
    position: relative;
}
.incident:hover { background: var(--surface-2); }
.incident.is-selected { background: var(--accent-soft); }
.incident-ico {
    width: 36px; height: 36px; border-radius: 10px;
    display: grid; place-items: center; color: #fff;
}
.incident-ico svg { width: 17px; height: 17px; stroke-width: 2.2; }
.incident-ico.sev-critical { background: var(--critical); }
.incident-ico.sev-major { background: var(--serious); }
.incident-ico.sev-minor { background: var(--warning); color: #0b0b0b; }
.incident-ico.sev-low { background: var(--low); }
.incident-body { min-width: 0; }
.incident-top { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.incident-type { font-size: 12px; font-weight: 650; color: var(--text-2); }
.incident-time { margin-left: auto; font-size: 11.5px; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.incident-title { font-size: 14px; font-weight: 650; color: var(--text); line-height: 1.3; }
.incident-desc {
    font-size: 12.5px; color: var(--text-2); margin-top: 3px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.incident.is-selected .incident-desc { -webkit-line-clamp: unset; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tag {
    display: inline-flex; align-items: center; gap: 4px;
    height: 20px; padding: 0 7px; border-radius: 6px;
    font-size: 11px; font-weight: 650;
    background: var(--surface-3); color: var(--text-2);
}
.tag-sev::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag-sev.sev-critical::before { background: var(--critical); }
.tag-sev.sev-major::before { background: var(--serious); }
.tag-sev.sev-minor::before { background: var(--warning); }
.tag-sev.sev-low::before { background: var(--low); }
.tag-closed { background: color-mix(in srgb, var(--critical) 14%, transparent); color: var(--critical); }
.tag-planned { background: var(--accent-soft); color: var(--accent); }

.empty { padding: 40px 20px; text-align: center; color: var(--text-3); }
.empty svg { width: 32px; height: 32px; margin: 0 auto 10px; display: block; color: var(--text-3); }
.empty strong { display: block; color: var(--text); font-size: 14px; margin-bottom: 4px; }
.empty .link-btn { margin-top: 10px; }

.skeleton { height: 72px; margin: 8px 0; border-radius: 12px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.view-switch { display: none; }

.footer { text-align: center; font-size: 11.5px; color: var(--text-3); padding: 2px 0 4px; }

/* =========================================================
   Responsive
   ========================================================= */

/* Große Laptops: Liste etwas schmaler */
@media (max-width: 1440px) {
    .workspace { grid-template-columns: 270px minmax(0, 1fr) 360px; }
}

/* Tablet & kleine Laptops: Filter als Seitenleiste zum Ausklappen */
@media (max-width: 1180px) {
    .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .kpi-flow { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 24px; align-items: center; }
    .kpi-flow .kpi-head { grid-column: 1; }
    .kpi-flow .kpi-value { grid-column: 1; }
    .kpi-flow .flowbar { grid-column: 2; grid-row: 1; margin: 0; }
    .kpi-flow .flowbar-legend { grid-column: 2; grid-row: 2; }

    .workspace {
        grid-template-columns: minmax(0, 1fr) 360px;
        grid-template-areas: "map list";
    }
    .btn-filter-toggle { display: inline-flex; }
    .filters {
        position: fixed; z-index: 1200;
        top: 0; bottom: 0; left: 0;
        width: min(360px, 88vw);
        border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
        transform: translateX(-105%);
        transition: transform .25s ease;
        box-shadow: var(--shadow-lg);
    }
    .filters.is-open { transform: none; }
    .filters-close { display: grid; }
    .filters-foot { display: block; }
    .scrim {
        display: block; position: fixed; inset: 0; z-index: 1100;
        background: rgba(2, 6, 23, 0.45);
        backdrop-filter: blur(2px);
    }
}

/* Mobil */
@media (max-width: 767px) {
    :root { --gap: 12px; --topbar-h: 58px; }
    body { font-size: 15px; }
    .app { gap: 12px; }
    .brand-text p { display: none; }
    .brand-logo { width: 34px; height: 34px; }
    .live-status { padding: 0 10px; }
    .live-status #last-update { font-size: 12px; }
    .btn-filter-toggle { padding: 0 10px; }

    /* KPIs horizontal scrollbar */
    .kpis {
        display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
        margin: 0 calc(var(--gap) * -1); padding: 2px var(--gap) 6px;
        scrollbar-width: none;
        scroll-padding-inline: var(--gap);
    }
    .kpis::-webkit-scrollbar { display: none; }
    .kpi { flex: 0 0 auto; width: 150px; scroll-snap-align: start; padding: 14px; }
    .kpi-flow { display: flex; width: 260px; align-items: stretch; }
    .kpi-flow .flowbar { margin-top: 4px; }
    .kpi-value { font-size: 26px; }

    .view-switch {
        display: grid; grid-template-columns: 1fr 1fr;
        padding: 4px; gap: 4px; border-radius: 12px;
        background: var(--surface-3);
        position: sticky; top: calc(var(--topbar-h) + 6px); z-index: 800;
    }
    .view-switch button {
        display: flex; align-items: center; justify-content: center; gap: 8px;
        height: 40px; border-radius: 9px; font-weight: 650; color: var(--text-2);
    }
    .view-switch button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
    .view-switch .badge { background: var(--surface-3); color: var(--text-2); }
    .view-switch button.active .badge { background: var(--accent); color: #fff; }

    .workspace { display: flex; flex-direction: column; height: auto; min-height: 0; gap: 12px; }
    .map-card { height: calc(100dvh - var(--topbar-h) - 220px); min-height: 380px; border-radius: var(--radius-lg); }
    .list-card { border-radius: var(--radius-lg); }
    .incident-list { overflow: visible; }
    .workspace[data-view="map"] .list-card { display: none; }
    .workspace[data-view="list"] .map-card { display: none; }

    .map-legend { left: 8px; bottom: 8px; padding: 8px 10px; }
    .map-legend .legend-title { display: none; }
    .map-legend ul { grid-template-columns: 1fr 1fr; column-gap: 12px; }

    /* Filter als Bottom-Sheet */
    .filters {
        top: auto; left: 0; right: 0; bottom: 0;
        width: 100%; max-height: 88dvh;
        border-radius: 22px 22px 0 0;
        transform: translateY(105%);
    }
    .filters::before {
        content: ''; display: block; width: 40px; height: 5px; border-radius: 3px;
        background: var(--border-strong); margin: 8px auto 0;
    }
    .filters.is-open { transform: none; }
    .chip { height: 36px; font-size: 14px; }
    .segmented button { height: 38px; }
    .search { height: 44px; }
    .search input { font-size: 16px; } /* verhindert Zoom auf iOS */

    .leaflet-popup-content { min-width: 200px; }
    .footer { padding-bottom: env(safe-area-inset-bottom); }
}

@media (max-width: 480px) {
    .brand-text h1 { font-size: 15px; }
    .topbar-actions { gap: 6px; }
    .live-status #last-update { display: none; }
    .live-status { width: 36px; padding: 0; justify-content: center; }
    .btn-filter-toggle { width: 36px; padding: 0; position: relative; }
    .btn-filter-toggle .label-text { display: none; }
    .btn-filter-toggle .badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; font-size: 10.5px; padding: 0 4px; }
}
@media (max-width: 340px) {
    .brand-logo { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

:root[data-theme="dark"] .leaflet-tile-pane {
    filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9);
}
@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) .leaflet-tile-pane {
        filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9);
    }
}