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

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

:root {
    --color-empty: #ef4444;
    --color-empty-bg: #fef2f2;
    --color-low: #eab308;
    --color-low-bg: #fefce8;
    --color-occupied: #22c55e;
    --color-occupied-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: #e5e7eb;
    --radius: 8px;
    --cell-w: 38px;
    --cell-h: 15px;
    --time-col-w: 56px;
    --day-header-h: 36px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8fafc;
    color: #1e293b;
    min-height: 100vh;
}

header {
    background: #fff;
    border-bottom: 1px solid var(--color-border);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1000;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #94a3b8;
    font-size: 0.9rem;
}


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

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

.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: #64748b;
}

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

.time-picker input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.2);
}

.time-picker .btn {
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    background: #f8fafc;
    color: #475569;
}

.time-picker .btn:hover { background: #e2e8f0; }

.time-picker .btn.active {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}

.time-info {
    font-size: 0.8rem;
    color: #64748b;
    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-empty-bg);  color: #991b1b; }
.status-pill.empty .dot  { background: var(--color-empty); }
.status-pill.low    { background: var(--color-low-bg);    color: #854d0e; }
.status-pill.low .dot    { background: var(--color-low); }
.status-pill.occupied { background: var(--color-occupied-bg); color: #166534; }
.status-pill.occupied .dot { background: var(--color-occupied); }

.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: 420px;
    min-width: 320px;
    flex-shrink: 0;
    overflow-y: auto;
    background: #fff;
    border-right: 1px solid var(--color-border);
}

.list-header {
    position: sticky;
    top: 0;
    background: #f8fafc;
    display: grid;
    grid-template-columns: 80px 1fr 90px;
    padding: 0.6rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    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:hover { color: #1e293b; }
.list-header span .sort-arrow { font-size: 0.65rem; }

.arena-row {
    display: grid;
    grid-template-columns: 80px 1fr 90px;
    padding: 0.7rem 1rem;
    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); }

.arena-row .abbr {
    font-weight: 700;
    font-size: 0.9rem;
}

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

.arena-row .name {
    font-size: 0.85rem;
    color: #475569;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.arena-row .usage-info {
    font-size: 0.7rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

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

.arena-row .people-badge.empty    { background: var(--color-empty); }
.arena-row .people-badge.low      { background: var(--color-low); color: #422006; }
.arena-row .people-badge.occupied  { background: var(--color-occupied); }

.arena-row.status-empty    { background: var(--color-empty-bg); }
.arena-row.status-low      { background: var(--color-low-bg); }
.arena-row.status-occupied { background: var(--color-occupied-bg); }

/* Tooltip (index page) */
.tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    background: #1e293b;
    color: #fff;
    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: #1e293b;
}

.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 #fff;
    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-empty); }
.arena-marker.low      { background: var(--color-low); color: #422006; }
.arena-marker.occupied { background: var(--color-occupied); }

/* ── Responsive (index) ── */
@media (max-width: 768px) {
    .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: #475569;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    background: #f1f5f9;
    transition: background 0.15s;
}

.back-btn:hover { background: #e2e8f0; }

.abbr-tag {
    background: #e2e8f0;
    color: #475569;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
}

/* ── Info Bar ── */
.info-bar {
    background: #fff;
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 1.5rem;
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    font-size: 0.85rem;
    color: #64748b;
}

.info-bar .info-item { display: flex; align-items: center; gap: 0.4rem; }
.info-bar .info-value { font-weight: 700; color: #1e293b; }

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

.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-empty); }
.legend-swatch.low      { background: var(--color-low); }
.legend-swatch.occupied { background: var(--color-occupied); }
.legend-swatch.no-data  { background: #f1f5f9; border: 1px solid #e2e8f0; }
.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;
}

/* Fixed time column */
.time-column {
    width: var(--time-col-w);
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid var(--color-border);
    padding-top: var(--day-header-h);
    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: #94a3b8;
    font-variant-numeric: tabular-nums;
}

.time-label.hour-start {
    font-weight: 700;
    color: #475569;
}

/* 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: #fff;
    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 #f1f5f9;
}

.day-header .dow {
    font-weight: 700;
    text-transform: uppercase;
    color: #64748b;
}

.day-header .date {
    color: #94a3b8;
}

.day-header.weekend  { background: #f8fafc; }
.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 #cbd5e1; }

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

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

.grid-cell:hover { opacity: 0.75; outline: 2px solid #1e293b; z-index: 5; }

.grid-cell.empty    { background: rgba(239, 68, 68, 0.66); }
.grid-cell.low      { background: rgba(234, 179, 8, 0.66); }
.grid-cell.occupied { background: rgba(34, 197, 94, 0.66); }
.grid-cell.no-data  { background: #f1f5f9; }

.grid-cell.hour-start { border-top: 1px solid rgba(0,0,0,0.1); }
.grid-cell.week-start { border-left: 2px solid #cbd5e1; }

/* Cell tooltip */
.cell-tooltip {
    display: none;
    position: fixed;
    background: #1e293b;
    color: #fff;
    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: #94a3b8; }

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

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #94a3b8;
    font-size: 0.9rem;
}

/* ── Usage Panel ── */
.usage-panel {
    flex-shrink: 0;
    background: #fff;
    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; }
.usage-panel.collapsed .usage-header,
.usage-panel.collapsed .usage-body { display: none; }

.usage-toggle {
    position: absolute;
    right: -22px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    width: 22px;
    height: 44px;
    background: #e2e8f0;
    border: 1px solid var(--color-border);
    border-left: none;
    border-radius: 0 6px 6px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.65rem;
    color: #64748b;
    transition: background 0.15s;
}

.usage-toggle:hover { background: #cbd5e1; }

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

.usage-header-cell {
    width: 58px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #64748b;
    border-right: 1px solid #f1f5f9;
}

.usage-header-cell.weekend { background: #f8fafc; }

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

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

.usage-col {
    width: 58px;
    flex-shrink: 0;
    position: relative;
    border-right: 1px solid #f1f5f9;
}

.usage-col.weekend { background: #fafbfc; }

.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: default;
    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-empty); }
.usage-block.low      { background: var(--color-low); color: #422006; }
.usage-block.occupied { background: var(--color-occupied); }
.usage-block.no-avg   { background: #94a3b8; }

.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; }

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

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