:root {
    --tcl-red: #E2001A;
    --bg-white: rgba(255, 255, 255, 0.98);
    --shadow: 0 8px 32px rgba(0,0,0,0.12);
}

body, html { 
    margin: 0; padding: 0; height: 100%; width: 100%;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden; background: #f0f0f0;
}

#map { width: 100%; height: 100%; z-index: 1; }

/* --- MOBILE FIRST (Par défaut) --- */

#status-bar {
    position: absolute; top: 10px; left: 10px; right: 10px;
    background: var(--bg-white);
    padding: 12px; border-radius: 16px;
    box-shadow: var(--shadow);
    z-index: 1000; display: flex; flex-direction: column; gap: 10px;
    border-top: 4px solid var(--tcl-red);
}

.header-main { display: flex; justify-content: space-between; align-items: center; }
#brand { font-weight: 800; color: var(--tcl-red); font-size: 1.2em; letter-spacing: -0.5px; }
#update-text { font-size: 0.75em; color: #888; font-variant-numeric: tabular-nums; }

#controls { display: flex; gap: 8px; }

.ui-button {
    flex: 1; background: #f5f5f5; border: 1px solid #eee; padding: 12px 5px;
    border-radius: 10px; cursor: pointer; font-size: 0.9em; font-weight: 600;
    transition: all 0.2s;
}
.ui-button:active { transform: scale(0.95); background: #eee; }

/* Modales Mobile (Bottom Sheet) */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 2000;
    display: flex; align-items: flex-end; justify-content: center;
}
.modal.hidden { display: none !important; }

.modal-content {
    background: white; width: 100%; padding: 25px;
    border-radius: 24px 24px 0 0; max-height: 80vh; overflow-y: auto;
    position: relative; animation: slideUp 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

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

#filter-list { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }

.filter-section-header {
    font-size: 0.95em; font-weight: 700; color: #333;
    padding: 6px 0 2px; border-bottom: 2px solid #eee;
    grid-column: 1 / -1; /* full width in parent grid */
}
.filter-section-header small { font-weight: 400; color: #999; }

.filter-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}

.line-btn {
    padding: 14px 5px; border: 1px solid #eee; border-radius: 12px;
    background: #fff; cursor: pointer; font-weight: 700; text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    line-height: 1.2;
}
.line-btn.active { background: var(--tcl-red); color: white; border-color: var(--tcl-red); }

.line-dist {
    font-size: 0.65em; font-weight: 500; opacity: 0.7;
    display: block;
}

/* --- DESKTOP ADAPTIVE (Ecrans > 768px) --- */

@media (min-width: 768px) {
    #status-bar {
        width: 380px; top: 20px; left: 20px; right: auto;
        padding: 20px; border-radius: 20px; flex-direction: column;
        border-top: none; border-left: 6px solid var(--tcl-red);
    }

    #controls { flex-direction: row; flex-wrap: wrap; }
    .ui-button { flex: none; padding: 10px 20px; }
    #locate-btn { order: 1; }
    #filter-btn { order: 2; flex-grow: 1; }
    #alert-btn { order: 3; flex-grow: 1; }

    /* Modales Desktop (Centered Card) */
    .modal { align-items: center; padding: 20px; }
    .modal-content {
        width: 500px; border-radius: 24px;
        box-shadow: 0 20px 60px rgba(0,0,0,0.3);
        animation: fadeIn 0.3s ease-out;
    }

    @keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

    .filter-grid { grid-template-columns: repeat(5, 1fr); }
    
    .line-btn:hover { background: #f0f0f0; border-color: #ccc; }
    .line-btn.active:hover { background: #b00014; }
}

/* === Icônes Bus avec flèche de direction === */

/* Le wrapper Leaflet ne doit pas clipper la flèche qui dépasse du cercle */
.custom-bus-icon {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    overflow: visible !important;
}

/* La bulle rouge (le cercle avec le numéro de ligne) */
.bus-bubble {
    position: absolute;
    inset: 0;
    background-color: var(--tcl-red);
    color: white;
    border: 2.5px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    box-shadow: 0 3px 8px rgba(0,0,0,0.35);
    z-index: 1;
    transition: transform 0.15s ease;
}
.custom-bus-icon:hover .bus-bubble {
    transform: scale(1.15);
}

/* La flèche SVG positionnée au-dessus de la bulle */
.bus-arrow {
    position: absolute;
    /* Centré horizontalement, dépasse du bord supérieur du wrapper */
    left: 50%;
    top: 0;
    transform-origin: center bottom; /* On tourne autour du bas (= centre du cercle) */
    transform: translateX(-50%);
    z-index: 2;
    pointer-events: none;
    transition: transform 0.4s ease-out;
    /* La flèche pointe vers le haut par défaut (bearing 0 = Nord) */
}

/* === Alertes & divers === */
.alert-item { 
    background: #fff5f5; border-left: 4px solid var(--tcl-red); 
    padding: 15px; margin-bottom: 12px; border-radius: 8px;
}

.alert-meta {
    font-size: 0.8em;
    color: #666;
    background: #e9ecef;
    padding: 4px 8px;
    border-radius: 6px;
    display: inline-block;
    margin: 8px 0;
    font-weight: 600;
}

.close-modal {
    position: absolute; top: 18px; right: 20px;
    font-size: 1.6em; cursor: pointer; color: #aaa; line-height: 1;
}
.close-modal:hover { color: #333; }

/* === NOUVEAU: Bouton de rafraichissement des arrêts === */
.refresh-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.3em;
    padding: 0 4px;
    outline: none;
    transition: transform 0.3s;
    color: #555;
}

.refresh-btn:hover {
    color: var(--tcl-red);
}

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

.spin-anim {
    animation: spin 0.5s linear;
}