:root {
    --bg: #0f1117;
    --bg-card: #181b24;
    --bg-card-hover: #1e222d;
    --border: #2a3040;
    --text: #e8eaef;
    --text-muted: #8b93a7;
    --accent: #e85d4c;
    --accent-soft: rgba(232, 93, 76, 0.15);
    --thl: #4dabf7;
    --brand: #ff6b6b;
    --bma: #ffa94d;
    --rd: #69db7c;
    --radius: 14px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --font: 'DM Sans', system-ui, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    overflow-x: clip;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: clip;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(232, 93, 76, 0.12), transparent),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(77, 171, 247, 0.06), transparent);
    pointer-events: none;
    z-index: 0;
}

.app {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 0.875rem 2.5rem;
    padding-left: max(0.875rem, env(safe-area-inset-left));
    padding-right: max(0.875rem, env(safe-area-inset-right));
    padding-bottom: max(2.5rem, env(safe-area-inset-bottom));
}

.header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.header__brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header__logo {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    background: var(--accent-soft);
    border-radius: 12px;
    border: 1px solid rgba(232, 93, 76, 0.25);
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header__sub {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0.15rem;
}

.header__filters {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.filter-group {
    width: 100%;
    min-width: 0;
}

.filter-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.year-pills-scroll {
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 0.15rem;
}

.year-pills {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 0.4rem;
    min-width: min-content;
}

.year-pill {
    flex-shrink: 0;
    padding: 0.45rem 0.85rem;
    touch-action: manipulation;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.year-pill:hover {
    border-color: var(--accent);
    color: var(--text);
}

.year-pill.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.year-pill.is-partial {
    border-style: dashed;
    border-color: #ffa94d;
}

.year-pill.is-partial:not(.is-active) {
    color: #ffc078;
}

.year-pill.is-partial.is-active {
    background: #e67700;
    border-color: #e67700;
}

.year-pill__badge {
    margin-left: 0.25rem;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    opacity: 0.9;
}

.data-warning {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    margin-bottom: 1.25rem;
    padding: 0.9rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 169, 77, 0.45);
    background: rgba(255, 169, 77, 0.1);
    color: #ffd8a8;
}

.data-warning.is-hidden {
    display: none;
}

.data-warning__icon {
    font-size: 1.2rem;
    line-height: 1.4;
}

.data-warning strong {
    display: block;
    color: #ffc078;
    margin-bottom: 0.2rem;
}

.data-warning p {
    color: #ffe8cc;
    font-size: 0.9rem;
}

#feuerwehrSelect {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 0.55rem 0.85rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}

#feuerwehrSelect:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.kpis {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
    margin-bottom: 1.25rem;
}

.kpis .kpi:last-child {
    grid-column: 1 / -1;
}

.kpi {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
}

.kpi__label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.kpi__value {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    word-break: break-word;
}

.kpi__value--thl { color: var(--thl); }
.kpi__value--brand { color: var(--brand); }
.kpi__value--rd { color: var(--rd); }

.grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.85rem;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    min-width: 0;
}

.card--wide,
.card--full {
    grid-column: auto;
}

.card__head {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    margin-bottom: 0.85rem;
}

.card__head h2 {
    font-size: 1rem;
    font-weight: 600;
}

.card__hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.35;
    max-width: 100%;
}

.chart-wrap {
    position: relative;
    width: 100%;
    min-width: 0;
    height: 240px;
}

.chart-wrap--tall {
    height: 320px;
}

.chart-wrap canvas {
    display: block;
    width: 100% !important;
    max-width: 100%;
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.15rem;
    padding: 0 0.15rem;
}

.table-wrap::after {
    content: '';
    display: block;
    height: 1px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.data-table--ff {
    min-width: 36rem;
}

.data-table--compact {
    min-width: 28rem;
}

.recent-time {
    white-space: nowrap;
    font-size: 0.75rem;
}

.col-hide-xs,
.col-hide-sm {
    display: none;
}

.data-table th,
.data-table td {
    padding: 0.65rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.data-table tbody tr:hover {
    background: var(--bg-card-hover);
}

.data-table td.num {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.data-table--compact td,
.data-table--compact th {
    padding: 0.5rem 0.65rem;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge--thl { background: rgba(77, 171, 247, 0.15); color: var(--thl); }
.badge--brand { background: rgba(255, 107, 107, 0.15); color: var(--brand); }
.badge--bma { background: rgba(255, 169, 77, 0.15); color: var(--bma); }
.badge--rd { background: rgba(105, 219, 124, 0.15); color: var(--rd); }

.footer {
    margin-top: 2rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.loading {
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 23, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 100;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading__spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Tablet: 600px+ */
@media (min-width: 600px) {
    .app {
        padding: 1.25rem 1.25rem 2.75rem;
    }

    .header h1 {
        font-size: 1.4rem;
    }

    .kpis {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.75rem;
    }

    .kpis .kpi:last-child {
        grid-column: auto;
    }

    .kpi__value {
        font-size: 1.55rem;
    }

    .chart-wrap {
        height: 260px;
    }

    .col-hide-xs {
        display: table-cell;
    }

    .data-table {
        font-size: 0.875rem;
    }

    .recent-time {
        font-size: inherit;
    }
}

/* Tablet landscape / kleiner Desktop: 768px+ */
@media (min-width: 768px) {
    .card {
        padding: 1.15rem 1.25rem;
    }

    .header {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-end;
        justify-content: space-between;
        gap: 1.5rem;
    }

    .header__filters {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-end;
        width: auto;
        flex: 1 1 20rem;
        justify-content: flex-end;
    }

    .filter-group--year {
        flex: 1 1 14rem;
        max-width: 100%;
    }

    .filter-group--feuerwehr {
        flex: 0 1 16rem;
        min-width: 12rem;
    }

    .year-pills-scroll {
        overflow-x: visible;
    }

    .year-pills {
        flex-wrap: wrap;
        min-width: 0;
    }

    .card__head {
        flex-direction: row;
        align-items: baseline;
        justify-content: space-between;
        gap: 1rem;
    }

    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }

    .card--wide,
    .card--full {
        grid-column: 1 / -1;
    }
}

/* Desktop: 1024px+ */
@media (min-width: 1024px) {
    .app {
        padding: 1.5rem 1.5rem 3rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .header__filters {
        gap: 1.25rem;
    }

    .filter-group--feuerwehr {
        flex: 0 0 16rem;
    }

    #feuerwehrSelect {
        min-width: 14rem;
    }

    .kpis {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 0.85rem;
        margin-bottom: 1.5rem;
    }

    .kpi__value {
        font-size: 1.65rem;
    }

    .chart-wrap--tall {
        height: 420px;
    }

    .col-hide-sm {
        display: table-cell;
    }
}
