/* --- Dark Theme (default) --- */
:root {
    --bg: #0f1117;
    --surface: #1a1c23;
    --surface2: #252830;
    --accent: #D4301A;
    --text: #e8e6e1;
    --text-dim: #8a8a8a;
    --border: #2a2d35;
}

/* --- Light Theme --- */
[data-theme="light"] {
    --bg: #f5f3ef;
    --surface: #ffffff;
    --surface2: #eae7e2;
    --accent: #D4301A;
    --text: #1a1a1f;
    --text-dim: #6b6b6b;
    --border: #d5d0ca;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }

.hidden { display: none !important; }
.screen { width: 100vw; height: 100vh; overflow: hidden; }

.login-box { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
.login-box h1 { font-size: 2rem; font-family: 'Space Grotesk', sans-serif; color: var(--accent); margin-bottom: 0.5rem; }

header { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); height: 48px; }
header h1 { font-size: 1rem; font-family: 'Space Grotesk', sans-serif; color: var(--accent); white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 0.5rem; }
.badge { background: var(--accent); color: white; border-radius: 10px; padding: 2px 8px; font-size: 0.75rem; }
.btn-small { background: none; border: 1px solid var(--border); color: var(--text-dim); padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }

/* --- Layout: Desktop + iPad Landscape --- */
.main-layout { display: flex; height: calc(100vh - 48px); }
#map { flex: 1; min-height: 0; }
/* Basemap entsättigen damit Kurven-Farben hervorstechen */
.maplibregl-canvas { filter: saturate(0.3) brightness(0.85); }
[data-theme="light"] .maplibregl-canvas { filter: saturate(0.4) brightness(0.95); }

/* --- MapLibre Custom Controls --- */
.maplibre-layer-control {
    position: absolute; top: 10px; right: 10px; z-index: 10;
    display: flex; flex-direction: column; gap: 2px;
    background: rgba(15,17,23,0.92); border-radius: 8px; padding: 6px;
    backdrop-filter: blur(8px); max-height: 300px; overflow-y: auto;
}
[data-theme="light"] .maplibre-layer-control {
    background: rgba(255,255,255,0.92);
}
.maplibre-layer-control button {
    display: block; width: 100%; text-align: left;
    padding: 6px 10px; border: none; border-radius: 4px;
    background: transparent; color: var(--text-dim); cursor: pointer;
    font-size: 12px; font-family: inherit; white-space: nowrap;
}
.maplibre-layer-control button:hover { background: rgba(255,255,255,0.08); }
[data-theme="light"] .maplibre-layer-control button:hover { background: rgba(0,0,0,0.06); }
.maplibre-layer-control button.active {
    background: rgba(212,48,26,0.15); color: #D4301A; font-weight: 600;
}

.maplibre-search-control {
    position: absolute; top: 10px; right: 230px; z-index: 10;
    display: flex; gap: 4px;
    background: rgba(15,17,23,0.92); padding: 6px 8px; border-radius: 8px;
    backdrop-filter: blur(8px);
}
[data-theme="light"] .maplibre-search-control {
    background: rgba(255,255,255,0.92);
}
.maplibre-search-control input {
    width: 180px; padding: 6px 10px; border-radius: 6px;
    border: 1px solid var(--border); background: var(--bg);
    color: var(--text); font-size: 13px; font-family: inherit; outline: none;
}
.maplibre-search-control button {
    padding: 6px 12px; border-radius: 6px; border: none;
    background: #D4301A; color: #fff; font-size: 12px;
    cursor: pointer; font-weight: 600;
}
#sidebar { width: 360px; background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }

.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab { flex: 1; padding: 10px 4px; background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 0.82rem; white-space: nowrap; min-width: 0; }
.tab.active { color: var(--accent); border-bottom: 2px solid var(--accent); }
#tab-content { flex: 1; overflow-y: auto; padding: 1rem; -webkit-overflow-scrolling: touch; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.btn { background: var(--accent); color: white; border: none; padding: 10px 16px; border-radius: 6px; cursor: pointer; width: 100%; margin-bottom: 1rem; font-size: 0.9rem; -webkit-appearance: none; }
.btn:hover { opacity: 0.9; }

.curve-info { margin-bottom: 1rem; }
.curve-info h3 { color: var(--accent); margin-bottom: 0.5rem; }
.field { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.field .label { color: var(--text-dim); }

.correction-form select, .correction-form input, .correction-form textarea {
    width: 100%; padding: 10px; margin-bottom: 8px; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; font-size: 16px; /* 16px prevents iOS auto-zoom */
}

.list-item { padding: 12px 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.list-item:hover { background: var(--surface2); }
.status { font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; }
.status-pending { background: #f0ad4e; color: black; }
.status-approved { background: #5cb85c; color: white; }
.status-rejected { background: #d9534f; color: white; }

.stat-card { background: var(--surface2); padding: 14px; border-radius: 8px; margin-bottom: 8px; }
.stat-card .number { font-size: 1.5rem; font-weight: bold; font-family: 'Roboto Mono', monospace; color: var(--accent); }
.stat-card .label { color: var(--text-dim); font-size: 0.8rem; }

.hint { color: var(--text-dim); font-style: italic; font-size: 0.85rem; }

/* --- Filter Sidebar --- */
.filter-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.filter-title { font-weight: 600; font-size: 0.95rem; }
.filter-count { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 12px; }
.filter-count strong { color: var(--accent); font-weight: 700; }

.filter-section { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.filter-section:last-child { border-bottom: none; }
.filter-section-title { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin-bottom: 8px; }

.filter-check { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; font-size: 0.85rem; }
.filter-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }

.grade-buttons { display: flex; gap: 6px; }
.grade-btn { width: 36px; height: 36px; border-radius: 8px; border: 2px solid var(--border); background: transparent; color: var(--text-dim); font-weight: 700; font-size: 0.9rem; cursor: pointer; transition: all 0.15s; }
.grade-btn.active { background: var(--gc); color: #000; border-color: var(--gc); }
.grade-btn:hover { opacity: 0.8; }

.danger-extreme { color: #D4301A; font-weight: 600; }
.danger-high { color: #ef4444; font-weight: 600; }
.danger-medium { color: #eab308; font-weight: 600; }
.danger-low { color: #22c55e; font-weight: 600; }

.range-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); height: 4px; }
.range-row span { font-size: 0.8rem; color: var(--text-dim); white-space: nowrap; min-width: 100px; text-align: right; }

/* --- Burger Button (hidden on desktop) --- */
.burger-btn { display: none; background: none; border: none; color: var(--text); font-size: 1.4rem; cursor: pointer; padding: 4px 8px; line-height: 1; }

/* --- Sidebar Backdrop (hidden on desktop) --- */
.sidebar-backdrop { display: none; }

/* --- iPad Portrait (< 820px) --- */
@media (max-width: 820px) {
    .main-layout { flex-direction: column; }
    #map { height: 55vh; flex: none; }
    #sidebar { width: 100%; height: 45vh; border-left: none; border-top: 1px solid var(--border); }
    header h1 { font-size: 0.9rem; }
    #user-info { display: none; }
    .grade-buttons { flex-wrap: wrap; }
}

/* --- Tablet + Smartphone (< 1024px): Burger + Fullscreen Map + Overlay Sidebar --- */
@media (max-width: 1024px) {
    .burger-btn { display: block; }

    .main-layout { flex-direction: column; position: relative; }

    /* Karte bekommt den vollen Bildschirm */
    #map { height: calc(100vh - 42px) !important; flex: none; }

    /* Sidebar wird zum Slide-Over-Panel */
    #sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 85vw;
        max-width: 360px;
        height: 100vh;
        z-index: 2000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-left: none;
        border-right: 1px solid var(--border);
        
    }
    #sidebar.open {
        transform: translateX(0);
    }

    /* Backdrop / Overlay hinter der Sidebar */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1999;
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
    }
    .sidebar-backdrop.visible {
        display: block;
    }

    /* Tabs vertikal als Menü-Items */
    .tabs {
        flex-direction: column;
        border-bottom: none;
        padding: 0.5rem 0;
    }
    .tab {
        text-align: left;
        padding: 12px 16px;
        font-size: 0.95rem;
        border-bottom: 1px solid var(--border);
    }
    .tab.active {
        border-bottom: 1px solid var(--border);
        border-left: 3px solid var(--accent);
        background: var(--surface2);
    }

    /* Header kompakter */
    header { padding: 0.4rem 0.6rem; height: 42px; gap: 0.3rem; }
    header h1 { font-size: 0.85rem; }
    .header-right { gap: 0.2rem; }
    .btn-small { padding: 3px 6px; font-size: 0.75rem; }
    #logout-btn { display: none; }

    /* Tab-Content füllt restlichen Platz */
    #tab-content { padding: 0.75rem; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

    /* Touch-freundliche Größen */
    .filter-section-title { font-size: 0.7rem; }
    .filter-check { padding: 6px 0; font-size: 0.9rem; }
    .filter-check input[type="checkbox"] { width: 20px; height: 20px; }
    .grade-btn { width: 42px; height: 42px; font-size: 1rem; }
    .range-row input[type="range"] { height: 8px; }
    .range-row span { font-size: 0.85rem; }
    .field { font-size: 0.9rem; padding: 8px 0; }
    .curve-info h3 { font-size: 1rem; }
    .stat-card { padding: 12px; }
    .stat-card .number { font-size: 1.3rem; }

    /* MapLibre Controls auf Mobile repositionieren */
    .maplibre-search-control { right: 10px; top: 56px; }
    .maplibre-search-control input { width: 140px; }
    .maplibre-layer-control { top: 56px; }
    .changelog-content { width: 95vw; max-height: 85vh; }
}

/* Changelog Modal */
.changelog-modal { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; }
.changelog-modal.hidden { display: none; }
.changelog-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.changelog-content {
    position: relative; z-index: 1;
    background: var(--bg, #0f1117); color: var(--text, #e8e6e1);
    border: 1px solid var(--border); border-radius: 12px;
    width: 720px; max-width: 90vw; max-height: 80vh;
    display: flex; flex-direction: column;
    
}
.changelog-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid #333;
}
.changelog-header h2 { margin: 0; font-size: 1.2rem; }
.changelog-body {
    padding: 20px; overflow-y: auto; font-size: 0.9rem; line-height: 1.6;
}
.changelog-body h2 { color: #f5c842; font-size: 1.05rem; margin: 20px 0 8px; border-bottom: 1px solid #333; padding-bottom: 4px; }
.changelog-body h2:first-child { margin-top: 0; }
.changelog-body h3 { color: #00d4ff; font-size: 0.95rem; margin: 14px 0 6px; }
.changelog-body ul { padding-left: 18px; margin: 4px 0; }
.changelog-body li { margin: 2px 0; }
.changelog-body strong { color: #f0f0f0; }
.changelog-body table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 0.85rem; }
.changelog-body th, .changelog-body td { padding: 5px 8px; border: 1px solid #333; text-align: left; }
.changelog-body th { background: rgba(255,255,255,0.05); color: #f5c842; }
.changelog-body code { background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 3px; font-size: 0.85em; }
.changelog-body hr { border: none; border-top: 1px solid #333; margin: 16px 0; }
