/* ══════════════════════════════════════════════════════════════
   Sporthallennutzung — Shared Styles
   ══════════════════════════════════════════════════════════════ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --color-zero: #1e293b;
    --color-zero-bg: #f1f5f9;
    --color-low: #ef4444;
    --color-low-bg: #fef2f2;
    --color-medium: #eab308;
    --color-medium-bg: #fefce8;
    --color-high: #22c55e;
    --color-high-bg: #f0fdf4;
    --color-holiday: #a855f7;
    --color-holiday-bg: rgba(168, 85, 247, 0.12);
    --color-vacation: #3b82f6;
    --color-vacation-bg: rgba(59, 130, 246, 0.10);
    --color-border: #d9d9d9;
    --color-bg: #dfdfdf;
    --color-surface: #fff;
    --color-surface-alt: #f7fcff;
    --color-surface-hover: #D6EEF8;
    --color-text: #444;
    --color-text-secondary: #5f5f5f;
    --color-text-muted: #666;
    --color-text-faint: #808080;
    --color-input-bg: #fff;
    --color-input-border: #ccc;
    --color-tag-bg: #D6EEF8;
    --color-tag-text: #005b79;
    --color-cell-border: rgba(0,0,0,0.04);
    --color-cell-text: rgba(0,0,0,0.55);
    --color-no-data: #f1f5f9;
    --color-accent: #0E8CC7;
    --color-accent-hover: #005b79;
    --color-accent-secondary: #dc4e1f;
    --color-week-border: #bbb;
    --radius: 5px;
    --cell-w: 38px;
    --cell-h: 15px;
    --time-col-w: 56px;
    --day-header-h: 36px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-zero: #e2e8f0;
        --color-zero-bg: #1e293b;
        --color-low: #f87171;
        --color-low-bg: #2d1519;
        --color-medium: #facc15;
        --color-medium-bg: #2d2505;
        --color-high: #4ade80;
        --color-high-bg: #0d2818;
        --color-holiday: #c084fc;
        --color-holiday-bg: rgba(168, 85, 247, 0.2);
        --color-vacation: #60a5fa;
        --color-vacation-bg: rgba(59, 130, 246, 0.2);
        --color-border: #334155;
        --color-bg: #0f172a;
        --color-surface: #1e293b;
        --color-surface-alt: #1e293b;
        --color-surface-hover: #1a3a4a;
        --color-text: #e2e8f0;
        --color-text-secondary: #cbd5e1;
        --color-text-muted: #94a3b8;
        --color-text-faint: #64748b;
        --color-input-bg: #1e293b;
        --color-input-border: #475569;
        --color-tag-bg: #1a3a4a;
        --color-tag-text: #7cc8e8;
        --color-cell-border: rgba(255,255,255,0.06);
        --color-cell-text: rgba(255,255,255,0.6);
        --color-no-data: #334155;
        --color-accent: #0E8CC7;
        --color-accent-hover: #4db8e0;
        --color-accent-secondary: #e8764a;
        --color-week-border: #475569;
    }
    .sport-icon { filter: invert(1); }
    .usage-block.empty { color: #1e293b; }
    .usage-block.empty .u-sport-icon { filter: none; }
}

body {
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.4;
}

/* Vollhöhen-Layout (Dashboard, Detail): Body als Flex-Spalte, die exakt
   den Viewport füllt. Der Hauptbereich (.main-container/.heatmap-wrapper)
   nimmt den Restplatz, statt ihn per Magic-Number-Subtraktion zu schätzen —
   das verhindert den minimalen vertikalen Overflow (u.a. unter Safari). */
body.app-fullheight {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
body.app-fullheight > * { flex: none; }
body.app-fullheight .main-container,
body.app-fullheight .heatmap-wrapper {
    flex: 1;
    min-height: 0;
    height: auto;
}

/* ── Stadt Münster Branding ── */
.brand-bar {
    background: #005b79;
    display: flex;
    align-items: center;
    padding: 0.4rem 1.5rem;
    gap: 1rem;
}

.brand-bar img {
    height: 32px;
}

.brand-bar .brand-divider {
    width: 1px;
    height: 24px;
    background: rgba(255,255,255,0.3);
}

.brand-bar .brand-label {
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.brand-stripe {
    height: 4px;
    background: var(--color-accent);
}

@media (prefers-color-scheme: dark) {
    .brand-bar { background: #003d52; }
}

header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 1.5rem;
}

header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-accent-secondary);
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-faint);
    font-size: 0.9rem;
}

/* ── Loading Spinner Overlay ── */
.loading-spinner-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.15);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.loading-spinner-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.loading-spinner {
    width: 64px;
    height: 64px;
    border: 6px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}


/* ══════════════════════════════════════════════════════════════
   Index Page
   ══════════════════════════════════════════════════════════════ */

.header-top {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.header-top .time-picker {
    flex: 1;
    justify-content: center;
}

.status-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ── Time Picker ── */
.time-picker {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.time-picker label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.time-picker input {
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--color-input-border);
    border-radius: 6px;
    color: var(--color-text);
    background: var(--color-input-bg);
}

.time-picker input:focus {
    outline: none;
    border-color: var(--color-accent);
    background: #fff8d1;
    box-shadow: none;
}

@media (prefers-color-scheme: dark) {
    .time-picker input:focus { background: #2d2a10; }
}

.time-picker .btn {
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    background: var(--color-surface-alt);
    color: var(--color-text-secondary);
}

.time-picker .btn:hover { background: var(--color-surface-hover); }

.time-picker .btn.active {
    background: var(--color-accent-secondary);
    color: #fff;
    border-color: var(--color-accent-secondary);
}

.time-info {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-style: italic;
}

/* ── Global Status Bar ── */
.status-bar {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.status-pill {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1rem;
    border-radius: 999px;
    font-size: 0.875rem;
    font-weight: 600;
}

.status-pill .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-pill.empty  { background: var(--color-zero-bg);  color: var(--color-text-secondary); }
.status-pill.empty .dot  { background: var(--color-zero); }
.status-pill.is-locked { background: #f1f5f9; color: #64748b; }
.status-pill.is-locked .dot { background: #cbd5e1; }
.status-pill.low    { background: var(--color-low-bg);    color: var(--color-low); }
.status-pill.low .dot    { background: var(--color-low); }
.status-pill.medium  { background: var(--color-medium-bg);  color: var(--color-text-secondary); }
.status-pill.medium .dot  { background: var(--color-medium); }
.status-pill.occupied { background: var(--color-high-bg); color: var(--color-high); }
.status-pill.occupied .dot { background: var(--color-high); }

.status-pill .count {
    font-size: 1.1rem;
    font-weight: 800;
    min-width: 1.5rem;
    text-align: center;
}

/* ── Main Layout ── */
.main-container {
    display: flex;
    height: calc(100vh - 130px);
}

/* ── Arena List ── */
.list-panel {
    width: 450px;
    min-width: 320px;
    flex-shrink: 0;
    overflow-y: auto;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
}

.list-header {
    position: sticky;
    top: 0;
    background: var(--color-surface-alt);
    display: grid;
    grid-template-columns: 54px 1fr 50px;
    column-gap: 0.3rem;
    padding: 0.6rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    border-bottom: 2px solid var(--color-border);
    z-index: 10;
}

.list-header span {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.list-header span:last-child {
    justify-content: flex-end;
}

.list-header span:hover { color: var(--color-text); }
.list-header span .sort-arrow { font-size: 0.65rem; }

.arena-row {
    display: grid;
    grid-template-columns: 54px 1fr 50px;
    column-gap: 0.3rem;
    padding: 0.55rem 0.5rem;
    border-bottom: 1px solid var(--color-border);
    align-items: center;
    transition: background 0.2s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.arena-row:hover { filter: brightness(0.95); }

@media (prefers-color-scheme: dark) {
    .arena-row:hover { filter: brightness(1.1); }
}

.arena-row .abbr {
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: -0.02em;
}

.arena-row .name-col {
    overflow: hidden;
}

.arena-row .name {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.arena-row .usage-info {
    font-size: 0.7rem;
    color: var(--color-text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.arena-row .people-badge {
    justify-self: end;
    padding: 0.2rem 0.45rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.8rem;
    color: #fff;
    min-width: 2.2rem;
    text-align: center;
    position: relative;
}

.arena-row .people-badge.empty    { background: var(--color-zero); }
.arena-row .people-badge.is-locked   { background: #cbd5e1; color: #64748b; }
.arena-row .people-badge.low      { background: var(--color-low); }
.arena-row .people-badge.medium   { background: var(--color-medium); color: #422006; }
.arena-row .people-badge.occupied  { background: var(--color-high); }

.arena-row.status-empty    { background: var(--color-zero-bg); }
.arena-row.status-locked   { background: #f1f5f9; }
.arena-row.status-low      { background: var(--color-low-bg); }
.arena-row.status-medium   { background: var(--color-medium-bg); }
.arena-row.status-occupied { background: var(--color-high-bg); }

/* Live update animation */
@keyframes badge-flash {
    0%   { transform: scale(1);   filter: brightness(1); }
    30%  { transform: scale(1.25); filter: brightness(1.4); }
    100% { transform: scale(1);   filter: brightness(1); }
}

.people-badge.flash,
.arena-marker.flash {
    animation: badge-flash 0.5s ease-out;
}

/* Tooltip (index page) */
.tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    background: var(--color-text);
    color: var(--color-bg);
    font-size: 0.75rem;
    font-weight: 400;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    white-space: nowrap;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 1rem;
    border: 6px solid transparent;
    border-top-color: var(--color-text);
}

.people-badge:hover .tooltip { display: block; }

/* ── Map ── */
.map-panel {
    flex: 1;
    min-width: 0;
}

#map { width: 100%; height: 100%; }

/* Leaflet marker overrides */
.arena-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
    color: #fff;
    border-radius: 50%;
    border: 3px solid var(--color-surface);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    text-align: center;
    line-height: 1;
    cursor: pointer;
    width: 36px;
    height: 36px;
}

.arena-marker.empty    { background: var(--color-zero); }
.arena-marker.is-locked   { background: #cbd5e1; color: #64748b; }
.arena-marker.low      { background: var(--color-low); }
.arena-marker.medium   { background: var(--color-medium); color: #422006; }
.arena-marker.occupied { background: var(--color-high); }

/* ── Responsive (index) ── */
@media (max-width: 768px) {
    /* Vollhöhen-Layout auf Mobile zurücknehmen: natürlicher Fluss + Scroll. */
    body.app-fullheight { height: auto; display: block; overflow: visible; }
    body.app-fullheight .main-container { flex: none; height: auto; }
    body.app-fullheight .heatmap-wrapper { flex: none; height: calc(100vh - 160px); }
    .main-container { height: auto; }
    .list-panel { width: 100%; border-right: none; }
    .map-panel { display: none; }
    .header-top { flex-direction: column; align-items: flex-start; }
}


/* ══════════════════════════════════════════════════════════════
   Detail Page
   ══════════════════════════════════════════════════════════════ */

/* Detail header is flex row */
.detail-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    background: var(--color-surface-hover);
    transition: background 0.15s;
}

.back-btn:hover { background: var(--color-tag-bg); }

.abbr-tag {
    background: var(--color-tag-bg);
    color: var(--color-tag-text);
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
}

.tag-link { color: inherit; text-decoration: none; }
.tag-link:hover { text-decoration: underline; color: var(--color-accent); }

.detail-title { min-width: 0; }
.detail-title-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.detail-title-row h1 { margin: 0; }
.detail-address { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.15rem; }

.cam-filter { display: flex; align-items: center; gap: 0.5rem; }

.cam-btn {
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    background: var(--color-surface-hover);
    color: var(--color-text-faint);
    transition: all 0.15s;
}

.cam-btn:hover { background: var(--color-tag-bg); }

.cam-btn.active {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}

/* ── Legend ── */
.legend {
    display: flex;
    gap: 1.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    font-size: 0.8rem;
    flex-wrap: wrap;
}

.legend-label { font-weight: 700; color: var(--color-text-muted); }

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.legend-swatch {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

.legend-swatch.empty    { background: var(--color-zero); }
.legend-swatch.low      { background: var(--color-low); }
.legend-swatch.medium   { background: var(--color-medium); }
.legend-swatch.occupied { background: var(--color-high); }
.legend-swatch.is-locked   { background: #cbd5e1; }
.legend-swatch.no-data  { background: var(--color-no-data); border: 1px solid var(--color-border); }
.legend-swatch.holiday  { background: var(--color-holiday); }
.legend-swatch.vacation { background: var(--color-vacation); }

/* ── Heatmap Container ── */
.heatmap-wrapper {
    display: flex;
    height: calc(100vh - 160px);
    overflow: hidden;
}

/* Time column wrapper */
.time-col-wrapper {
    width: var(--time-col-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
}

.usage-toggle {
    height: var(--day-header-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--color-text-muted);
    cursor: pointer;
    user-select: none;
    background: var(--color-surface-alt);
    border-bottom: 2px solid var(--color-border);
    transition: background 0.15s;
    white-space: nowrap;
}

.usage-toggle:hover { background: var(--color-surface-hover); }

/* Fixed time column */
.time-column {
    flex: 1;
    overflow: hidden;
}

.time-label {
    height: var(--cell-h);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    font-size: 0.65rem;
    color: var(--color-text-faint);
    font-variant-numeric: tabular-nums;
}

.time-label.hour-start {
    font-weight: 700;
    color: var(--color-text-secondary);
}

/* Scrollable grid area */
.grid-scroll {
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
}

.grid-inner {
    display: inline-flex;
    flex-direction: column;
    min-width: 100%;
}

/* Day headers row */
.day-headers {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--color-surface);
    border-bottom: 2px solid var(--color-border);
    height: var(--day-header-h);
}

.day-header {
    width: var(--cell-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    line-height: 1.3;
    border-right: 1px solid var(--color-cell-border);
}

.day-header .dow {
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.day-header .date {
    color: var(--color-text-faint);
}

.day-header.weekend  { background: var(--color-surface-alt); }
.day-header.holiday  { background: rgba(168, 85, 247, 0.66); }
.day-header.vacation { background: rgba(59, 130, 246, 0.66); }
.day-header.holiday .dow,
.day-header.holiday .date { color: #fff; }
.day-header.vacation .dow,
.day-header.vacation .date { color: #fff; }
.day-header.week-start { border-left: 2px solid var(--color-week-border); }

/* Grid rows */
.grid-row {
    display: flex;
}

.grid-cell {
    width: var(--cell-w);
    height: var(--cell-h);
    flex-shrink: 0;
    border-right: 1px solid var(--color-cell-border);
    border-bottom: 1px solid var(--color-cell-border);
    cursor: pointer;
    position: relative;
    transition: opacity 0.1s;
}

.grid-cell:hover { opacity: 0.75; outline: 2px solid var(--color-text); z-index: 5; }

.grid-cell.empty    { background: rgba(30, 41, 59, 0.66); }
.grid-cell.is-locked   { background: rgba(203, 213, 225, 0.66); }
.grid-cell.low      { background: rgba(239, 68, 68, 0.66); }
.grid-cell.medium   { background: rgba(234, 179, 8, 0.66); }
.grid-cell.occupied { background: rgba(34, 197, 94, 0.66); }
.grid-cell.no-data  { background: var(--color-no-data); }

@media (prefers-color-scheme: dark) {
    .grid-cell.empty { background: rgba(226, 232, 240, 0.66); }
    .grid-cell.is-locked { background: rgba(100, 116, 139, 0.66); }
}

.grid-cell.grid-disabled {
    opacity: 0.2;
    filter: grayscale(80%);
}

.grid-cell.hour-start { border-top: 1px solid var(--color-cell-border); }
.grid-cell.week-start { border-left: 2px solid var(--color-week-border); }

/* Cell tooltip */
.cell-tooltip {
    display: none;
    position: fixed;
    background: var(--color-text);
    color: var(--color-bg);
    font-size: 0.75rem;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    z-index: 1000;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    pointer-events: none;
    white-space: nowrap;
    line-height: 1.5;
}

.cell-tooltip .tt-header {
    font-weight: 700;
    margin-bottom: 0.3rem;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    padding-bottom: 0.3rem;
}

.cell-tooltip .tt-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.cell-tooltip .tt-label { color: var(--color-text-faint); }
.cell-tooltip .tt-dimmed { opacity: 0.35; }

.cell-tooltip .tt-fields {
    margin-top: 0.3rem;
    border-top: 1px solid rgba(255,255,255,0.15);
    padding-top: 0.3rem;
}

.cell-tooltip .tt-usages {
    margin-top: 0.3rem;
    border-top: 1px solid rgba(255,255,255,0.15);
    padding-top: 0.3rem;
    font-size: 0.7rem;
}

.cell-tooltip .tt-validity {
    font-size: 0.65rem;
    opacity: 0.7;
    font-style: italic;
}

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-faint);
    font-size: 0.9rem;
}

.load-more-indicator {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    padding: 5px 14px;
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    z-index: 200;
    pointer-events: none;
}

/* ── Usage Panel ── */
.usage-panel {
    flex-shrink: 0;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    transition: width 0.2s;
}

.usage-panel.collapsed { width: 0 !important; border-right: none; overflow: hidden; }

.usage-header {
    display: flex;
    height: var(--day-header-h);
    border-bottom: 2px solid var(--color-border);
    flex-shrink: 0;
}

.usage-header-cell {
    width: 76px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-text-muted);
    border-right: 1px solid var(--color-cell-border);
    cursor: pointer;
    user-select: none;
}

.usage-header-cell:hover {
    background: var(--color-surface-hover);
}


.usage-body {
    flex: 1;
    overflow: hidden;
}

.usage-cols {
    display: flex;
    position: relative;
}

.usage-col {
    width: 76px;
    flex-shrink: 0;
    position: relative;
    border-right: 1px solid var(--color-cell-border);
}


.usage-block {
    position: absolute;
    left: 2px;
    right: 2px;
    border-radius: 3px;
    padding: 2px 3px;
    font-size: 0.55rem;
    line-height: 1.25;
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: #fff;
    font-weight: 600;
    border: 1px solid rgba(255,255,255,0.4);
}

.usage-block.empty    { background: var(--color-zero); }
.usage-block.low      { background: var(--color-low); }
.usage-block.medium   { background: var(--color-medium); color: #422006; }
.usage-block.occupied { background: var(--color-high); }
.usage-block.no-avg   { background: var(--color-text-faint); }

.usage-block.usage-disabled {
    opacity: 0.2;
    filter: grayscale(80%);
}

.usage-block .u-club { font-weight: 700; }
.usage-block .u-team { opacity: 0.85; }
.usage-block .u-avg  { margin-top: 1px; font-size: 0.5rem; opacity: 0.85; }

.sport-icon {
    height: 1em;
    width: 1.2em;
    object-fit: contain;
    vertical-align: -0.15em;
    margin-right: 0.3em;
}

.usage-block .u-sport-icon {
    position: absolute;
    top: 1px;
    left: 50%;
    transform: translateX(-50%);
    height: 1rem;
    opacity: 1;
    pointer-events: none;
    z-index: 0;
    filter: invert(1);
}

.usage-block.medium .u-sport-icon {
    filter: none;
}

.usage-block .u-club,
.usage-block .u-team,
.usage-block .u-avg {
    position: relative;
    z-index: 1;
}


/* ══════════════════════════════════════════════════════════════
   Navigation
   ══════════════════════════════════════════════════════════════ */

.main-nav {
    display: flex;
    gap: 0.25rem;
    margin-left: auto;
}

.nav-link {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--color-text);
    background: #eee;
    transition: all 0.15s;
}

.nav-link:hover {
    background: var(--color-accent-secondary);
    color: #fff;
}

.nav-link.active {
    background: var(--color-accent-secondary);
    color: #fff;
}

@media (prefers-color-scheme: dark) {
    .nav-link { background: #334155; color: var(--color-text); }
    .nav-link:hover { background: var(--color-accent-secondary); color: #fff; }
}


/* ══════════════════════════════════════════════════════════════
   Vereine Page
   ══════════════════════════════════════════════════════════════ */

.vereine-container {
    margin: 0 auto;
    padding: 1rem 1.5rem;
}

.vereine-search {
    margin-bottom: 1rem;
}

.vereine-search input {
    width: 100%;
    font-family: inherit;
    font-size: 0.9rem;
    padding: 0.6rem 1rem;
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius);
    background: var(--color-input-bg);
    color: var(--color-text);
}

.vereine-search input:focus {
    outline: none;
    border-color: var(--color-accent);
    background: #fff8d1;
    box-shadow: none;
}

@media (prefers-color-scheme: dark) {
    .vereine-search input:focus { background: #2d2a10; }
}

.club-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.club-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.club-header:hover { background: var(--color-surface-alt); }

.club-expand {
    font-size: 0.7rem;
    color: var(--color-text-faint);
    width: 1rem;
    text-align: center;
    flex-shrink: 0;
}

.club-abbr {
    font-weight: 700;
    font-size: 0.85rem;
    background: var(--color-tag-bg);
    color: var(--color-tag-text);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    flex-shrink: 0;
}

.club-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.club-meta {
    font-size: 0.75rem;
    color: var(--color-text-faint);
    flex-shrink: 0;
    white-space: nowrap;
}

.club-stats-link {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    text-decoration: none;
    color: var(--color-text-secondary);
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.club-stats-link:hover {
    background: var(--color-accent-secondary);
    color: #fff;
    border-color: var(--color-accent-secondary);
}

.club-body {
    border-top: 1px solid var(--color-border);
    padding: 0.5rem 0;
}

.team-section {
    padding: 0.5rem 1rem 0.5rem 2.75rem;
    border-bottom: 1px solid var(--color-cell-border);
}

.team-section:last-child { border-bottom: none; }

.team-section.highlighted {
    background: var(--color-vacation-bg);
    border-left: 3px solid var(--color-accent);
}

.team-section.search-match {
    background: var(--color-medium-bg);
}

.team-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.team-stats-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    border-radius: 4px;
    padding: 0.2rem 0.4rem;
    margin: -0.2rem -0.4rem;
    transition: background 0.15s;
}

.team-stats-link:hover { background: var(--color-surface-hover); }

.team-stats-icon {
    font-size: 0.7rem;
    color: var(--color-text-faint);
    margin-left: auto;
    transition: color 0.15s;
}

.team-stats-link:hover .team-stats-icon { color: var(--color-accent); }

.team-abbr {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
}

.team-name {
    font-size: 0.85rem;
    color: var(--color-text);
}

.team-usages {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.usage-arena-group {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    font-size: 0.8rem;
}

.usage-arena-link {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    color: var(--color-text-secondary);
    flex-shrink: 0;
    min-width: 160px;
    transition: color 0.15s;
}

.usage-arena-link:hover { color: var(--color-accent); }

.usage-arena-abbr {
    font-weight: 700;
    font-size: 0.75rem;
    background: var(--color-surface-hover);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
}

.usage-arena-name {
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.usage-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.usage-slot {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-surface-alt);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--color-cell-border);
    white-space: nowrap;
}

.usage-slot-link {
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.usage-slot-link:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-border);
    color: var(--color-accent);
}

.validity-hint {
    font-size: 0.65rem;
    opacity: 0.7;
    font-style: italic;
}

/* Clickable usage links on index and detail pages */
.usage-link {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.usage-link:hover {
    text-decoration: underline;
    color: var(--color-accent);
}

@media (max-width: 768px) {
    .vereine-container { padding: 0.75rem; }
    .team-section { padding-left: 1.5rem; }
    .usage-arena-group { flex-direction: column; gap: 0.2rem; }
    .usage-arena-link { min-width: auto; }
}


/* ══════════════════════════════════════════════════════════════
   Stats Page
   ══════════════════════════════════════════════════════════════ */

/* ── Controls ── */
.stats-controls {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.stats-controls label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.stats-controls input[type="date"] {
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--color-input-border);
    border-radius: 6px;
    color: var(--color-text);
    background: var(--color-input-bg);
}

.stats-controls input[type="date"]:focus {
    outline: none;
    border-color: var(--color-accent);
    background: #fff8d1;
    box-shadow: none;
}

@media (prefers-color-scheme: dark) {
    .stats-controls input[type="date"]:focus { background: #2d2a10; }
}

.stats-controls .btn {
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--color-accent-hover);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    background: var(--color-accent-hover);
    color: #fff;
}

.stats-controls .btn:hover { background: var(--color-accent); border-color: var(--color-accent); }

.stats-info {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-left: auto;
}

.locked-hint {
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.section-heading {
    font-size: 1rem;
    font-weight: 700;
    padding: 0.75rem 1.5rem 0;
    color: var(--color-accent-secondary);
}

/* ── Stats Heatmap ── */
.stats-heatmap-wrapper {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin: 0.75rem 1.5rem;
}

.stats-heatmap-header {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--color-surface);
    border-bottom: 2px solid var(--color-border);
    height: var(--day-header-h);
}

.stats-day-header {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-text-muted);
    border-right: 1px solid var(--color-cell-border);
}

.stats-day-header.weekend { background: var(--color-surface-alt); }

.stats-grid-row {
    display: flex;
}

.stats-time-cell {
    width: var(--time-col-w);
    flex-shrink: 0;
    height: var(--cell-h);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    font-size: 0.65rem;
    color: var(--color-text-faint);
    font-variant-numeric: tabular-nums;
    border-right: 1px solid var(--color-border);
    background: var(--color-surface);
}

.stats-time-cell.hour-start {
    font-weight: 700;
    color: var(--color-text-secondary);
}

.stats-cell {
    flex: 1;
    height: var(--cell-h);
    border-right: 1px solid var(--color-cell-border);
    border-bottom: 1px solid var(--color-cell-border);
    cursor: pointer;
    position: relative;
    transition: opacity 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    font-weight: 600;
    color: var(--color-cell-text);
    font-variant-numeric: tabular-nums;
}

.stats-cell:hover { opacity: 0.75; outline: 2px solid var(--color-text); z-index: 5; }
.stats-cell.no-data  { background: var(--color-no-data); }
.stats-cell.hour-start { border-top: 1px solid var(--color-cell-border); }

/* ── Stats Table ── */
.stats-table-section {
    padding: 1rem 1.5rem 2rem;
}

.stats-table-section h2 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--color-accent-secondary);
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.stats-table th {
    background: #d9d9d9;
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #333;
    border-bottom: 2px solid var(--color-border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

@media (prefers-color-scheme: dark) {
    .stats-table th { background: #334155; color: var(--color-text-muted); }
}

.stats-table th:hover { color: var(--color-text); }
.stats-table th.active { color: var(--color-accent); }

.stats-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    background: #eee;
}

@media (prefers-color-scheme: dark) {
    .stats-table td { background: var(--color-surface); }
}

.stats-table th.num,
.stats-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.stats-table .sort-arrow {
    font-size: 0.65rem;
}

tr.usage-highlight td {
    background: var(--color-accent);
    color: #fff;
    transition: background 0.3s;
}

.stats-table tbody tr:hover {
    background: var(--color-surface-alt);
}

.stats-empty {
    text-align: center;
    color: var(--color-text-faint);
    padding: 2rem !important;
}

/* ── Team Charts ── */
.team-chart-wrapper {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin: 0.75rem 1.5rem;
    padding: 0.75rem 1rem;
}

.team-chart-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.chart-validity {
    font-size: 0.85em;
    font-weight: 400;
    color: #94a3b8;
    font-style: italic;
}

.team-chart-area {
    display: flex;
    height: 160px;
}

.team-chart-yaxis {
    width: 32px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-right: 4px;
}

.team-chart-ylabel {
    font-size: 0.6rem;
    color: var(--color-text-muted);
    text-align: right;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.team-chart-body {
    flex: 1;
    position: relative;
    min-width: 0;
}

.team-chart-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 4px;
}

.team-chart-heatstrip {
    display: flex;
    margin-top: 2px;
}

.team-chart-yaxis-spacer {
    width: 32px;
    flex-shrink: 0;
}

.team-chart-heatcells {
    flex: 1;
    display: flex;
    min-width: 0;
}

.team-chart-heatcell {
    flex: 1;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    border-right: 1px solid var(--color-cell-border);
    font-variant-numeric: tabular-nums;
}

.team-chart-heatcell:first-child { border-radius: 3px 0 0 3px; }
.team-chart-heatcell:last-child  { border-radius: 0 3px 3px 0; border-right: none; }

.team-chart-xaxis {
    display: flex;
    margin-top: 2px;
}

.team-chart-xlabels {
    flex: 1;
    display: flex;
    min-width: 0;
}

.team-chart-xlabel {
    flex: 1;
    font-size: 0.6rem;
    color: var(--color-text-muted);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ── Inline Charts in Table ── */
.inline-chart-row td {
    padding: 0 0.75rem 0.75rem !important;
    border-bottom: 2px solid var(--color-border) !important;
}

.inline-chart {
    display: flex;
    flex-direction: column;
}

.inline-chart-canvas-wrap {
    position: relative;
    height: 80px;
}

.inline-chart-canvas-wrap canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 4px 4px 0 0;
}

.inline-chart-heatcells {
    display: flex;
}

.inline-chart-xlabels {
    display: flex;
}

@media (max-width: 768px) {
    .stats-controls { flex-direction: column; align-items: flex-start; }
    .stats-info { margin-left: 0; }
    .stats-table-section { padding: 0.75rem; overflow-x: auto; }
    .team-chart-wrapper { margin: 0.5rem; }
}
