/**
 * Unified Timeline Styles
 */

.unified-timeline {
    position: fixed;
    bottom: 80px; /* Au-dessus de la barre d'icônes (30px + 44px + 6px gap) */
    left: 50%;
    transform: translateX(-50%);
    right: auto;
    background: transparent;
    padding: 8px;
    z-index: 999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* État inactif (aucune couche temporelle activée) */
.unified-timeline.inactive .timeline-datetime,
.unified-timeline.inactive .timeline-slider-row,
.unified-timeline.inactive .nav-btn.nav-now {
    pointer-events: none;
    cursor: default;
}

.unified-timeline.inactive .step-value,
.unified-timeline.inactive .separator,
.unified-timeline.inactive .nav-btn-inline,
.unified-timeline.inactive .nav-btn.nav-now,
.unified-timeline.inactive .timeline-slider-row {
    opacity: 0.5;
}

.unified-timeline.inactive .step-value.selectable:hover,
.unified-timeline.inactive .nav-btn-inline:hover,
.unified-timeline.inactive .nav-btn.nav-now:hover {
    background: transparent;
    transform: none;
}

/* Le bouton UTC/Local reste toujours visible et cliquable */
.unified-timeline.inactive .tz-toggle {
    opacity: 1 !important;
    pointer-events: auto !important;
    cursor: pointer;
}

.unified-timeline .tz-toggle {
    pointer-events: auto;
}

/* Les éléments interactifs doivent capturer les événements */
.unified-timeline > * {
    pointer-events: auto;
}

/* Conteneur central (datetime + slider) */
.timeline-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* Ancien bouton Now externe - masqué (remplacé par bouton inline) */
.unified-timeline .nav-btn.nav-now:not(.nav-now-inline) {
    display: none;
}

.timeline-datetime {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: rgba(255,255,255,0.95);
    border-radius: 12px;
    padding: 8px 14px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    /* Largeur fixe pour alignement avec les icônes */
    width: 320px;
    box-sizing: border-box;
}

/* Boutons navigation inline ◀ ▶ (à l'intérieur de timeline-datetime) */
.nav-btn-inline {
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 4px 8px;
    font-size: var(--text-base);
    border-radius: 4px;
    transition: all 0.15s;
    line-height: 1;
}

.nav-btn-inline:hover {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
}

.nav-btn-inline:active {
    transform: scale(0.95);
    background: rgba(52, 152, 219, 0.2);
}

/* Bouton "Présent" / "Now" - à gauche, même hauteur que datetime */
.nav-btn.nav-now {
    background: #fff;
    border: none;
    color: #3498db;
    cursor: pointer;
    padding: 8px 12px;
    font-size: var(--text-3xl);
    font-weight: 900;
    border-radius: 12px;
    transition: all 0.15s;
    line-height: 1;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-text-stroke: 1px #3498db;
}

.nav-btn.nav-now:hover {
    background: #f8f8f8;
    color: #2980b9;
    transform: scale(1.05);
}

.nav-btn.nav-now:active {
    transform: scale(0.95);
    background: #f0f0f0;
}

/* Valeurs cliquables */
.step-value {
    font-size: var(--text-lg);
    font-weight: 600;
    color: #333;
    text-align: center;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Largeurs adaptées au contenu */
.step-value[data-unit="day"],
.step-value[data-unit="hour"],
.step-value[data-unit="minute"] {
    min-width: 28px;
}

.step-value[data-unit="month"] {
    min-width: 42px;
}

.step-value[data-unit="year"] {
    min-width: 48px;
}

.step-value.selectable {
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: all 0.15s;
    box-sizing: border-box;
}

.step-value.selectable:hover {
    background: rgba(52, 152, 219, 0.2);
}

.step-value.selectable.active {
    background: transparent;
    color: #3498db;
    border: 2px solid #3498db;
    padding: 2px 4px;
}

/* Éléments verrouillés (non modifiables) */
.step-value.selectable.locked {
    color: #999;
    cursor: default;
    opacity: 0.6;
}

.step-value.selectable.locked:hover {
    background: transparent;
}

/* Slider désactivé */
.timeline-slider:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Séparateurs */
.separator {
    color: #999;
    font-weight: 300;
    margin: 0 2px;
    font-size: var(--text-lg);
}

.time-sep {
    font-weight: 600;
    color: #666;
}

/* Bouton toggle UTC/Local - masqué, remplacé par Now */
.tz-toggle {
    display: none;
}

/* Bouton Now inline (rond) dans la timeline */
.nav-btn-inline.nav-now-inline {
    background: #3498db !important;
    border: none !important;
    color: #fff !important;
    font-size: var(--text-md) !important;
    font-weight: 900;
    padding: 0 !important;
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    max-width: 28px !important;
    max-height: 28px !important;
    aspect-ratio: 1 / 1 !important;
    border-radius: 50% !important;
    cursor: pointer;
    transition: all 0.15s;
    margin: 0 4px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    line-height: 1 !important;
    box-sizing: border-box !important;
    flex-shrink: 0 !important;
}

.nav-btn-inline.nav-now-inline:hover {
    background: #2980b9 !important;
    transform: scale(1.1);
}

.nav-btn-inline.nav-now-inline:active {
    transform: scale(0.95);
}

/* Ligne 2: Slider */
.timeline-slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.95);
    padding: 8px 14px;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    /* Même largeur que datetime et icônes */
    width: 320px;
    box-sizing: border-box;
}

.slider-label {
    font-size: var(--text-base);
    font-weight: 600;
    color: #3498db;
    min-width: 36px;
    text-align: center;
    background: transparent;
    padding: 4px 8px;
}

.slider-min {
    text-align: right;
}

.slider-max {
    text-align: left;
}

.timeline-slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    border-radius: 3px;
    outline: none;
}

.timeline-slider::-webkit-slider-runnable-track {
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
}

.timeline-slider::-moz-range-track {
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
}

.timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: #3498db;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.1s;
    margin-top: -6px; /* Centrer verticalement: (track height - thumb height) / 2 = (6 - 18) / 2 */
}

.timeline-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.timeline-slider::-webkit-slider-thumb:active {
    transform: scale(1.1);
    background: #2980b9;
}

.timeline-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #3498db;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* ============================================
   RESPONSIVE - Mobile
   ============================================ */

@media (max-width: 768px) {
    .unified-timeline {
        /* Positionner au-dessus de la barre d'icônes mobile (100px + 44px + 6px) */
        bottom: 150px;
        bottom: calc(150px + env(safe-area-inset-bottom, 0px));
        left: 50%;
        transform: translateX(-50%);
        padding: 0;
        gap: 8px;
    }

    .timeline-center {
        gap: 6px;
    }

    .timeline-datetime {
        padding: 6px 8px;
        gap: 1px;
        background: #fff !important;
        box-shadow: 0 1px 4px rgba(0,0,0,0.15);
        color: #333 !important;
        width: 260px;
        align-items: center;
        justify-content: center;
    }

    /* Masquer l'ancien bouton Now externe */
    .unified-timeline .nav-btn.nav-now:not(.nav-now-inline) {
        display: none !important;
    }

    .nav-btn-inline {
        padding: 2px 6px;
        font-size: var(--text-xs);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Bouton Now inline rond en mobile */
    .nav-btn-inline.nav-now-inline {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        min-height: 24px !important;
        max-width: 24px !important;
        max-height: 24px !important;
        font-size: var(--text-base) !important;
        padding: 0 !important;
        aspect-ratio: 1 / 1 !important;
    }

    .step-value {
        font-size: var(--text-base);
        padding: 2px 4px;
        color: #333 !important;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .step-value[data-unit="day"],
    .step-value[data-unit="hour"],
    .step-value[data-unit="minute"] {
        min-width: 22px;
    }

    .step-value[data-unit="month"] {
        min-width: 36px;
    }

    .step-value[data-unit="year"] {
        min-width: 40px;
    }

    .separator {
        margin: 0;
        font-size: var(--text-base);
        color: #999 !important;
    }

    .tz-toggle {
        font-size: var(--text-xs);
        padding: 3px 5px;
        margin: 0 2px;
        min-width: 30px;
        height: 22px;
    }

    .timeline-slider-row {
        gap: 6px;
        padding: 4px 8px;
        width: 260px;
        background: #fff !important;
    }

    .slider-label {
        font-size: var(--text-xs);
        min-width: 28px;
        color: #3498db !important;
        background: transparent !important;
        padding: 3px 6px;
    }

    .timeline-slider::-webkit-slider-runnable-track {
        height: 6px;
        background: #e0e0e0 !important;
        border-radius: 3px;
    }

    .timeline-slider::-moz-range-track {
        height: 6px;
        background: #e0e0e0 !important;
        border-radius: 3px;
    }

    .timeline-slider {
        height: 6px;
        background: transparent !important;
    }

    .timeline-slider::-webkit-slider-thumb {
        width: 16px;
        height: 16px;
        margin-top: -5px; /* Centrer verticalement: (6 - 16) / 2 */
    }
}

/* Tablette - version compacte */
@media (min-width: 769px) and (max-width: 1024px) {
    .unified-timeline {
        padding: 6px 8px;
    }

    .timeline-display {
        gap: 10px;
    }

    .step-value {
        font-size: var(--text-sm);
        min-width: 24px;
    }

}

/* ============================================
   Mobile paysage - Timeline sur la moitié droite
   ============================================ */
@media (max-height: 500px) and (min-width: 500px) {
    .unified-timeline {
        bottom: 75px; /* Juste au-dessus des icônes */
        left: 75%; /* Centre de la moitié droite */
        transform: translateX(-50%);
        flex-direction: column !important;
        align-items: center !important;
    }

    /* Masquer l'ancien bouton Now externe s'il existe */
    .unified-timeline .nav-btn.nav-now:not(.nav-now-inline) {
        display: none !important;
    }
}

/* ============================================
   Mode sombre (si supporté)
   ============================================ */

@media (prefers-color-scheme: dark) {
    .timeline-datetime,
    .timeline-slider-row {
        background: rgba(40,40,45,0.95);
    }

    .step-value {
        color: #eee;
    }

    .nav-btn {
        background: rgba(40,40,45,0.95);
        color: #ddd;
    }

    .nav-btn:hover {
        background: rgba(60,60,65,0.95);
    }

    .nav-btn.nav-now {
        background: rgba(40, 40, 45, 0.95);
        color: #5dade2;
    }

    .nav-btn.nav-now:hover {
        background: rgba(60, 60, 65, 0.95);
    }

    .separator {
        color: #888;
    }

    .timeline-slider {
        background: transparent;
    }

    .timeline-slider::-webkit-slider-runnable-track {
        background: #555;
    }

    .timeline-slider::-moz-range-track {
        background: #555;
    }

    .slider-label {
        color: #5dade2;
        background: transparent;
    }

    .timeline-slider-row {
        background: rgba(40,40,45,0.95);
    }

}

/* ============================================
   Ajustement de la carte pour la timeline
   ============================================ */

/* Quand la timeline est visible, ajouter du padding en bas de la carte */
body.timeline-active #map {
    padding-bottom: 80px;
}

/* Animation d'apparition */
.unified-timeline {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* =============================================================================
   DARK/ASTRO THEME SUPPORT
   ============================================================================= */

/* Dark mode */
[data-theme="dark"] .timeline-datetime,
[data-theme="dark"] .timeline-slider-row {
    background: rgba(30, 30, 30, 0.95) !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4) !important;
}

[data-theme="dark"] .step-value {
    color: #eee !important;
}

[data-theme="dark"] .step-value.selectable:hover {
    background: rgba(255,255,255,0.1) !important;
}

[data-theme="dark"] .nav-btn-inline {
    color: #aaa !important;
}

[data-theme="dark"] .nav-btn-inline:hover {
    background: rgba(255,255,255,0.1) !important;
    color: #fff !important;
}

[data-theme="dark"] .separator,
[data-theme="dark"] .time-sep {
    color: #888 !important;
}

[data-theme="dark"] .slider-label {
    color: #3498db;
}

[data-theme="dark"] .timeline-slider::-webkit-slider-runnable-track {
    background: #444;
}

[data-theme="dark"] .timeline-slider::-moz-range-track {
    background: #444;
}

/* Astro mode */
[data-theme="astro"] .timeline-datetime,
[data-theme="astro"] .timeline-slider-row {
    background: rgba(20, 0, 0, 0.95) !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5) !important;
    border: 1px solid #400 !important;
}

[data-theme="astro"] .step-value {
    color: #c00 !important;
}

[data-theme="astro"] .step-value.selectable:hover {
    background: rgba(200,0,0,0.2) !important;
}

[data-theme="astro"] .nav-btn-inline {
    color: #800 !important;
}

[data-theme="astro"] .nav-btn-inline:hover {
    background: rgba(200,0,0,0.2) !important;
    color: #c00 !important;
}

[data-theme="astro"] .nav-btn-inline.nav-now-inline {
    background: #800 !important;
}

[data-theme="astro"] .nav-btn-inline.nav-now-inline:hover {
    background: #a00 !important;
}

[data-theme="astro"] .separator,
[data-theme="astro"] .time-sep {
    color: #600 !important;
}

[data-theme="astro"] .step-value.selectable.active {
    color: #c00 !important;
    border-color: #c00 !important;
}

[data-theme="astro"] .slider-label {
    color: #c00;
}

[data-theme="astro"] .timeline-slider::-webkit-slider-runnable-track {
    background: #400;
}

[data-theme="astro"] .timeline-slider::-moz-range-track {
    background: #400;
}

[data-theme="astro"] .timeline-slider::-webkit-slider-thumb {
    background: #c00;
}

[data-theme="astro"] .timeline-slider::-moz-range-thumb {
    background: #c00;
}
