/**
 * Zeitleiste - Stylesheet
 * 
 * Struktur:
 * 1. CSS-Variablen
 * 2. Reset & Grundlayout
 * 3. Kontrollbereich
 * 4. Timeline-Container
 * 5. Band & Segmente
 * 6. Jahreszahlen
 * 7. Event-Balken
 * 8. Fahnen & Masten
 * 9. Interaktionen
 * 10. Boundary-Marker
 * 11. Responsive
 */

/* ===========================================
   1. CSS-VARIABLEN
   =========================================== */
:root {
    /* Kategorie-Farben */
    --color-geo: #2b7a3d;
    --color-culture: #e86a34;
    --color-person: #f6c400;
    --color-politics: #4a90d9;
    --color-war: #c43c3c;
    --color-science: #9b59b6;
    
    /* Helle Versionen für Fahnen */
    --color-geo-light: #e7f8eb;
    --color-culture-light: #ffe9dd;
    --color-person-light: #fffadc;
    --color-politics-light: #e3f0ff;
    --color-war-light: #ffe5e5;
    --color-science-light: #f3e8ff;
    
    /* Band-Farben (Farbwechsel für bessere Lesbarkeit) */
    --band-color-1: #001a3d;
    --band-color-2: #0055a0;
    
    /* UI-Farben */
    --bg-controls: rgba(0, 0, 0, 0.85);
    --text-light: #ccc;
    --text-white: #fff;
    
    /* Layout */
    --controls-height: 90px;
    --band-height-percent: 25;
}

/* ===========================================
   2. RESET & GRUNDLAYOUT
   =========================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

/* Mobile: Seite leicht scrollbar für Browser-Chrome-Ausblendung */
@supports (-webkit-touch-callout: none) {
    /* iOS-spezifisch */
    html {
        height: calc(100% + 1px);
    }
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(ellipse at 20% 0%, #2a2a3a 0%, #1a1a1a 50%, #000 100%);
    color: var(--text-light);
    /* Touch-Aktionen für Pinch-to-Zoom erlauben */
    touch-action: pan-x pan-y;
}

/* Wrapper für Mobile-Scroll-Trick */
.page-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
}

/* Auf Mobile: scrollbarer Container */
@media (max-width: 768px) {
    .page-wrapper {
        position: relative;
        min-height: calc(100vh + 60px);  /* Extra Höhe für Scroll */
        overflow: visible;
    }
    
    html, body {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Scroll-Spacer am Ende */
    .scroll-spacer {
        height: 60px;
        pointer-events: none;
    }
}

/* ===========================================
   3. KONTROLLBEREICH
   =========================================== */
.controls {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 16px;
    
    background: var(--bg-controls);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(255,255,255,0.2);
}

.controls__row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.controls__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-white);
}

.controls__hint {
    font-size: 0.75rem;
    color: var(--text-light);
}

.controls__label {
    font-size: 0.75rem;
    color: var(--text-light);
}

/* Mode-Buttons */
.mode-btn {
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 14px;
    border: 1px solid #555;
    background: #333;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.15s;
}

.mode-btn:hover {
    background: #444;
}

.mode-btn--active {
    background: #0077bb;
    border-color: #0077bb;
    color: var(--text-white);
}

/* Filter-Checkboxen */
.filter-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    cursor: pointer;
    padding: 3px 10px;
    border-radius: 10px;
    background: rgba(255,255,255,0.08);
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    border: 2px solid transparent;
}

.filter-checkbox:hover {
    background: rgba(255,255,255,0.15);
}

.filter-checkbox input {
    display: none;
}

/* Farbige Rahmen für Filter-Buttons */
.filter-checkbox--geo { border-color: var(--color-geo); }
.filter-checkbox--culture { border-color: var(--color-culture); }
.filter-checkbox--person { border-color: var(--color-person); }
.filter-checkbox--politics { border-color: var(--color-politics); }
.filter-checkbox--war { border-color: var(--color-war); }
.filter-checkbox--science { border-color: var(--color-science); }
.filter-checkbox--art { border-color: var(--color-art, #e91e63); }

/* Inaktive Filter abgedunkelt (via JavaScript-Klasse) */
.filter-checkbox--inactive {
    opacity: 0.4;
    border-color: #555 !important;
}

/* Controls-Gruppen für flexibles Layout */
.controls__group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.controls__group--modes {
    margin-right: 20px;
}

.controls__group--filters {
    flex-wrap: wrap;
}

/* Admin-Link */
.admin-link {
    margin-left: auto;
    padding: 4px 10px;
    font-size: 1rem;
    text-decoration: none;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.admin-link:hover {
    opacity: 1;
}

/* ===========================================
   4. TIMELINE-CONTAINER
   =========================================== */
.timeline {
    position: fixed;
    top: var(--controls-height);
    left: 0;
    right: 0;
    bottom: 0;
    transition: top 0.3s ease, height 0.3s ease;
}

.timeline__scroll {
    width: 100%;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    /* Besseres Scrolling auf Touch-Geräten */
    -webkit-overflow-scrolling: touch;
}

.timeline__content {
    position: relative;
    height: 100%;
    min-width: 100%;
}

/* ===========================================
   5. BAND & SEGMENTE
   =========================================== */
.timeline__band {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: calc(var(--band-height-percent) * 1%);
    
    background: var(--band-color-1);
    border-top: 2px solid rgba(255,255,255,0.4);
    border-bottom: 2px solid rgba(255,255,255,0.4);
    overflow: visible;
}

.band-segment {
    position: absolute;
    top: 0;
    bottom: 0;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.band-segment--fade-out {
    opacity: 0;
}

.band-segment--odd {
    background: var(--band-color-1);
}

.band-segment--even {
    background: var(--band-color-2);
}

/* ===========================================
   6. JAHRESZAHLEN
   =========================================== */
.timeline__labels {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    pointer-events: none;
    z-index: 30;
}

.year-label {
    position: absolute;
    
    font-size: 0.7rem;
    font-weight: 600;
    font-family: "Courier New", monospace;
    color: var(--text-white);
    white-space: nowrap;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
    
    text-align: left;
}

.year-label--right {
    transform: translateX(-100%);
    text-align: right;
}

.year-tick {
    position: absolute;
    width: 1px;
    background: rgba(255,255,255,0.5);
    pointer-events: none;
}

/* ===========================================
   7. EVENT-BALKEN
   =========================================== */
.event-bar {
    position: absolute;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.5);
    cursor: pointer;
    
    display: flex;
    align-items: center;
    padding: 0 5px;
    overflow: hidden;
    
    transition: transform 0.1s, box-shadow 0.1s;
    z-index: 22;  /* Über Mast (15), unter Fahne (25) */
}

.event-bar__label {
    font-size: 0.6rem;
    font-weight: 500;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Punkt-Events (kleiner Kreis statt Balken) */
.event-bar[data-type="point"] {
    width: 12px !important;
    height: 12px !important;
    border-radius: 50%;
    padding: 0;
    border: 2px solid rgba(255,255,255,0.8);
}

.event-bar[data-type="point"] .event-bar__label {
    display: none;
}

/* Kategorie-Farben */
.event-bar--geo { background: var(--color-geo); }
.event-bar--culture { background: var(--color-culture); }
.event-bar--person { background: var(--color-person); }
.event-bar--politics { background: var(--color-politics); }
.event-bar--war { background: var(--color-war); }
.event-bar--science { background: var(--color-science); }

/* Pfeil links wenn Event vor Modus-Start beginnt */
.event-bar--extends-left {
    border-left: none;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.event-bar--extends-left .event-bar__label::before {
    content: "← ";
    font-weight: bold;
}

/* ===========================================
   8. FAHNEN & MASTEN
   =========================================== */
.timeline__flags {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.event-flag {
    position: absolute;
    pointer-events: auto;
    cursor: pointer;
    
    display: flex;
    flex-direction: row;
    
    max-width: 280px;
    background: #fff;
    border: 2px solid currentColor;
    border-radius: 3px;
    overflow: hidden;
    
    font-size: 0.7rem;
    color: #333;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: transform 0.1s, box-shadow 0.1s;
    
    z-index: 25;
}

/* Bild links in der Fahne */
.event-flag__image {
    flex: 0 0 auto;
    width: 50px;
    height: 50px;
    overflow: hidden;
    display: none;
}

.event-flag__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.event-flag__content {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Fähnchen weht nach rechts (Standard) */
.event-flag--right {
    border-left-width: 3px;
    border-radius: 0 3px 3px 0;
}

/* Fähnchen weht nach links */
.event-flag--left {
    border-right-width: 3px;
    border-left-width: 2px;
    border-radius: 3px 0 0 3px;
}

/* Sticky Fähnchen (am Bildschirmrand) */
.event-flag--sticky {
    opacity: 0.9;
}

.event-flag__header {
    padding: 2px 6px;
    font-weight: 600;
    font-size: 0.65rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-flag__body {
    display: none;
    padding: 4px 6px;
}

.event-flag__date {
    font-size: 0.6rem;
    color: #666;
    margin-bottom: 2px;
}

.event-flag__text {
    font-size: 0.65rem;
    line-height: 1.3;
}

.event-flag__link {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.6rem;
    color: #0066cc;
    text-decoration: none;
}

.event-flag__link:hover {
    text-decoration: underline;
}

/* Kategorie-Farben für Fahnen */
.event-flag--geo { border-color: var(--color-geo); background: var(--color-geo-light); }
.event-flag--geo .event-flag__header { background: var(--color-geo); }

.event-flag--culture { border-color: var(--color-culture); background: var(--color-culture-light); }
.event-flag--culture .event-flag__header { background: var(--color-culture); }

.event-flag--person { border-color: var(--color-person); background: var(--color-person-light); }
.event-flag--person .event-flag__header { background: var(--color-person); }

.event-flag--politics { border-color: var(--color-politics); background: var(--color-politics-light); }
.event-flag--politics .event-flag__header { background: var(--color-politics); }

.event-flag--war { border-color: var(--color-war); background: var(--color-war-light); }
.event-flag--war .event-flag__header { background: var(--color-war); }

.event-flag--science { border-color: var(--color-science); background: var(--color-science-light); }
.event-flag--science .event-flag__header { background: var(--color-science); }

/* Masten - unter allem anderen (Event-Balken, Punkte, Fahnen) */
.event-mast {
    position: absolute;
    width: 2px;
    pointer-events: none;
    z-index: 15;  /* Unter Event-Balken (22) und Fahne (25) */
}

.event-mast--geo { background: var(--color-geo); }
.event-mast--culture { background: var(--color-culture); }
.event-mast--person { background: var(--color-person); }
.event-mast--politics { background: var(--color-politics); }
.event-mast--war { background: var(--color-war); }
.event-mast--science { background: var(--color-science); }

/* ===========================================
   9. INTERAKTIONEN
   =========================================== */

/* Hover */
.event-bar:hover {
    transform: scale(1.05);
    box-shadow: 0 0 8px rgba(255,255,255,0.4);
    z-index: 50;
}

.event-bar[data-type="point"]:hover {
    transform: scale(1.4);
}

.event-flag:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    z-index: 110 !important;
}

/* Aktiv (angeklickt) */
.event-bar--active {
    outline: 3px solid #fff;
    outline-offset: 2px;
    z-index: 80 !important;
}

.event-flag--active {
    z-index: 100 !important;
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0,0,0,0.5);
    outline: 2px dashed #fff;
    outline-offset: 3px;
}

.event-flag--active .event-flag__body {
    display: block;
}

.event-flag--active .event-flag__image {
    display: block;
}

/* Aktiver Mast */
.event-mast--active {
    z-index: 95 !important;
}

/* Ausgeblendet (Filter) */
.event-bar--hidden,
.event-flag--hidden,
.event-mast--hidden {
    display: none !important;
}

/* ===========================================
   10. BOUNDARY-MARKER (Modus-Umschalter)
   =========================================== */
.boundary-marker {
    position: fixed;
    bottom: 20px;
    z-index: 50;
    pointer-events: auto;
}

.boundary-marker--left {
    left: 20px;
}

.boundary-marker--right {
    right: 20px;
}

.boundary-marker__box {
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 8px;
    padding: 8px 12px;
    min-width: 100px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.boundary-marker__title {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-bottom: 6px;
}

.boundary-marker__btn {
    width: 100%;
    font-size: 0.7rem;
    padding: 5px 10px;
}

.boundary-marker--left .boundary-marker__box {
    border-left: 3px solid #ff9800;
}

.boundary-marker--right .boundary-marker__box {
    border-right: 3px solid #4caf50;
}

/* ===========================================
   11. ÜBERLAPPUNGSWARNUNG
   =========================================== */
.overlap-warning {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    
    display: flex;
    align-items: center;
    gap: 10px;
    
    background: rgba(255, 152, 0, 0.95);
    color: #000;
    padding: 10px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    
    pointer-events: none;
}

.overlap-warning__icon {
    font-size: 1.2rem;
}

.overlap-warning__text {
    font-size: 0.8rem;
    font-weight: 500;
}

/* Markierter Bereich für nächsten Modus */
.boundary-range {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(76, 175, 80, 0.12);
    border-left: 2px dashed rgba(76, 175, 80, 0.5);
    pointer-events: none;
    z-index: 4;
}

/* Obsidian Link im Flag-Header */
.obsidian-link {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    opacity: 0.7;
    transition: opacity 0.15s ease;
    vertical-align: middle;
}

.obsidian-link:hover {
    opacity: 1;
}

.obsidian-icon {
    height: 14px;
    width: auto;
}

/* ===========================================
   12. RESPONSIVE
   =========================================== */
@media (max-width: 768px) {
    :root {
        --controls-height: 100px;
    }
    
    .controls {
        padding: 6px 10px;
        gap: 4px;
        transition: transform 0.3s ease;
    }
    
    /* Ausgeblendeter Zustand */
    .controls--hidden {
        transform: translateY(-100%);
    }
    
    /* Einblenden-Indikator (immer sichtbar) */
    .controls::after {
        content: '';
        position: absolute;
        bottom: -20px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: rgba(255,255,255,0.3);
        border-radius: 2px;
        opacity: 0;
        transition: opacity 0.3s;
    }
    
    .controls--hidden::after {
        opacity: 1;
    }
    
    .controls__title {
        font-size: 0.85rem;
    }
    
    .controls__hint {
        display: none; /* Auf Mobile nicht relevant */
    }
    
    /* Mode-Buttons deutlich kleiner auf Mobile */
    .mode-btn {
        font-size: 0.55rem;
        padding: 3px 6px;
        border-radius: 10px;
    }
    
    /* Filter-Checkboxen kompakter mit farbigem Rahmen */
    .filter-checkbox {
        font-size: 0.55rem;
        padding: 2px 6px;
        gap: 2px;
        border-width: 2px;
    }
    
    .filter-mark {
        width: 8px;
        height: 8px;
    }
    
    /* Boundary-Marker kompakter auf Mobile */
    .boundary-marker__box {
        padding: 6px 10px;
        min-width: 80px;
    }
    
    .boundary-marker__title {
        font-size: 0.6rem;
        margin-bottom: 4px;
    }
    
    .boundary-marker__btn {
        font-size: 0.6rem;
        padding: 4px 8px;
    }
    
    /* Fahnen etwas kleiner */
    .event-flag {
        max-width: 200px;
    }
    
    .event-flag__header {
        font-size: 0.6rem;
        padding: 2px 4px;
    }
}

/* Sehr kleine Displays */
@media (max-width: 480px) {
    :root {
        --controls-height: 90px;
    }
    
    .controls__title {
        font-size: 0.75rem;
    }
    
    .controls__label {
        display: none;
    }
    
    .mode-btn {
        font-size: 0.5rem;
        padding: 2px 5px;
    }
    
    .filter-checkbox span:last-child {
        /* Nur Icons, kein Text */
        display: none;
    }
    
    .filter-mark {
        width: 12px;
        height: 12px;
    }
}
