:root {
    /* Color Palette - Premium Dark Mode */
    --bg-dark: #0f172a;
    --bg-panel: rgba(15, 23, 42, 0.75);
    --bg-panel-hover: rgba(30, 41, 59, 0.85);
    --border-color: rgba(255, 255, 255, 0.1);
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --accent-start: #10b981; /* Green */
    --accent-end: #ef4444;   /* Red */
    
    --alert-warning: #f59e0b;
    --alert-danger: #ef4444;
    
    --blur-amount: 12px;
    --border-radius: 16px;
    --transition-speed: 0.3s;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden; /* Prevent scrolling, app-like feel */
}

/* Map Container */
#map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    z-index: 1;
}

/* Remove default Leaflet controls on mobile or adjust them */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3) !important;
    border-radius: 8px !important;
    overflow: hidden;
}
.leaflet-bar a {
    background-color: var(--bg-panel) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
    backdrop-filter: blur(var(--blur-amount));
}
.leaflet-bar a:hover {
    background-color: var(--bg-panel-hover) !important;
}

/* UI Overlay */
.ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none; /* Let clicks pass through to map */
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 16px;
}

/* Re-enable pointer events for interactive elements */
.ui-overlay > * {
    pointer-events: auto;
}

/* Glassmorphism Panel */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

/* Header */
.app-header {
    align-self: flex-start;
    max-width: 400px;
    padding: 16px 20px;
}
.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}
.app-header h1 span {
    color: var(--accent-primary);
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.8; transform: scale(0.98); }
    100% { opacity: 1; }
}

.app-header p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Routing Panel */
.routing-panel {
    align-self: flex-start;
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 20;
}
.input-group:not(.time-group):focus-within {
    z-index: 30;
}

.icon-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}
.start-dot { background-color: var(--accent-start); }
.end-dot { background-color: var(--accent-end); }

.route-line-visual {
    position: absolute;
    left: 25.5px; /* Aligned with dots */
    top: 36px;
    bottom: 96px; /* Space for button */
    width: 2px;
    background: repeating-linear-gradient(to bottom, var(--text-muted) 0, var(--text-muted) 4px, transparent 4px, transparent 8px);
    z-index: 10;
}

/* Vertical Time Slider Styling */
.vertical-slider-panel {
    --rail-len: 210px; /* largo del recorrido; lo consume .vertical-slider */
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 12px;
    z-index: 1000;
    pointer-events: auto;
    border-radius: 12px;
}
.slider-label-vertical {
    font-size: 0.85rem;
    text-align: center;
    color: var(--text-main);
    line-height: 1.2;
    margin-bottom: 12px;
    min-width: 62px;
}
.vertical-slider-wrapper {
    display: flex;
    height: var(--rail-len);
    align-items: stretch;
    justify-content: center;
}
.slider-ticks-vertical {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-right: 10px;
    text-align: right;
    font-weight: 500;
}
/* El carril: caja posicionada que le da al slider rotado un espacio propio.
   No usamos writing-mode porque Chromium < 120 lo ignora en <input type=range>
   (verificado en Huawei Browser 17 / Chrome 114: computed = horizontal-tb).
   La rotacion funciona igual en todos los navegadores y conserva el hit-test. */
.slider-rail {
    position: relative;
    width: 30px;
    height: 100%;
    flex: 0 0 30px;
}
.vertical-slider {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--rail-len);
    height: 30px;
    margin: 0;
    padding: 0;
    transform: translate(-50%, -50%) rotate(-90deg);
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    touch-action: none; /* el arrastre es nuestro, no un gesto de scroll */
}
.vertical-slider::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.25);
}
.vertical-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 22px;
    width: 22px;
    border-radius: 50%;
    background: var(--accent-primary);
    border: 2px solid #fff;
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.6);
    margin-top: -8px; /* (6 - 22) / 2 para centrar sobre la pista */
}
.vertical-slider::-moz-range-track {
    height: 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.25);
}
.vertical-slider::-moz-range-thumb {
    height: 22px;
    width: 22px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--accent-primary);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.6);
}
.vertical-slider:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 4px;
}

input[type="text"] {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    color: var(--text-main);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color var(--transition-speed);
}
input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: rgba(0, 0, 0, 0.4);
}
input[type="text"]::placeholder {
    color: var(--text-muted);
}

input[type="datetime-local"] {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text-main);
    font-size: 0.9rem;
    font-family: inherit;
    color-scheme: dark;
}

.time-group {
    margin-top: 10px;
    margin-left: 24px; /* Align with inputs */
}
.time-icon {
    font-size: 1.1rem;
    opacity: 0.8;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 10px;
    color: white;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Pista de interaccion bajo el campo de busqueda */
.map-hint {
    margin-top: 9px;
    margin-left: 24px; /* alineada con el campo, no con el punto de color */
    font-size: 0.74rem;
    color: var(--text-muted);
    line-height: 1.35;
}

/* Boton de destino opcional (pronostico radial) */
.radial-btn {
    margin-top: 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 9px 12px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}
.radial-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}
.radial-btn:active {
    transform: scale(0.98);
}

/* El elemento trae right:0 en atributo style, asi que el boton quedaba
   pegado al borde de la pantalla. El respiro se da con padding. */
#route-status {
    padding-right: calc(12px + env(safe-area-inset-right));
}

/* Barra de estado de la ruta: el nombre cede espacio, el boton nunca */
#route-status-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* Cancelar la ruta y empezar otra. Va con texto, no solo una equis: es la
   salida del estado "ruta fijada" y tiene que leerse como una accion. */
.cancel-route-btn {
    flex: 0 0 auto;
    pointer-events: auto;
    margin-left: 12px;
    padding: 7px 14px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    background: rgba(15, 23, 42, 0.85);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    text-shadow: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    transition: background 0.2s, transform 0.1s;
}
.cancel-route-btn:hover {
    background: rgba(239, 68, 68, 0.9);
    border-color: rgba(255, 255, 255, 0.5);
}
.cancel-route-btn:active {
    transform: scale(0.96);
}

/* Puntero de mira mientras falta colocar un punto (solo aplica en escritorio) */
.leaflet-container.picking {
    cursor: crosshair;
}

.suggestions-box {
    position: absolute;
    top: 100%;
    left: 24px;
    right: 0;
    margin-top: 4px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 2000;
}
.suggestion-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.suggestion-item:last-child {
    border-bottom: none;
}
.suggestion-item:hover {
    background: var(--bg-panel-hover);
}

.primary-btn {
    margin-top: 20px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background var(--transition-speed), transform 0.1s;
    font-family: inherit;
}
.primary-btn:hover {
    background: var(--accent-hover);
}
.primary-btn:active {
    transform: scale(0.98);
}
.primary-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Indicador de carga: centrado sobre el mapa, independiente del panel de ruta */
#route-loader {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1500;
    pointer-events: none;
}

/* Loader Animation */
.loader {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.timeline-container::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
}
.timeline-container::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

.timeline-item {
    display: flex;
    align-items: stretch;
    margin-bottom: 16px;
}
.timeline-time {
    width: 50px;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding-top: 4px;
    text-align: right;
    margin-right: 12px;
}
.timeline-node {
    width: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: 16px;
}
.node-circle {
    width: 12px;
    height: 12px;
    background: var(--accent-primary);
    border-radius: 50%;
    flex-shrink: 0;
}
.node-line {
    flex-grow: 1;
    width: 2px;
    background: var(--border-color);
    margin-top: 4px;
    margin-bottom: -16px; /* Connect to next item */
}
.timeline-item:last-child .node-line {
    display: none;
}

.timeline-content {
    flex-grow: 1;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.weather-info {
    display: flex;
    align-items: center;
    gap: 12px;
}
.weather-icon {
    font-size: 1.5rem;
}
.weather-details h4 {
    font-size: 0.95rem;
    margin-bottom: 2px;
}
.weather-details p {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.weather-temp {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Alerts */
.alerts-panel {
    align-self: flex-start;
    width: 100%;
    max-width: 400px;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 100;
}
.alert-card {
    background: rgba(239, 68, 68, 0.9);
    backdrop-filter: blur(var(--blur-amount));
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
    animation: slideUp 0.3s ease-out;
}
.alert-card.warning {
    background: rgba(245, 158, 11, 0.9);
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}
.alert-icon {
    font-size: 1.2rem;
}
.alert-text h4 {
    font-size: 0.9rem;
    font-weight: 600;
}
.alert-text p {
    font-size: 0.8rem;
    opacity: 0.9;
}

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

.hidden {
    display: none !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .app-header {
        max-width: 100%;
        padding: 12px 16px;
    }
    .routing-panel {
        max-width: 100%;
    }
    .weather-panel {
        max-width: 100%;
        margin-top: auto;
    }
    .alerts-panel {
        max-width: 100%;
    }
    .vertical-slider-panel {
        top: 170px; /* Anclado bajo los inputs para que el teclado no lo empuje */
        bottom: auto;
        right: 10px;
        --rail-len: 180px;
        padding: 12px 10px;
    }
    .quick-report-btn {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
    }
    .quick-report-group {
        left: 10px;
        bottom: calc(20px + env(safe-area-inset-bottom));
        max-width: 180px;
        gap: 6px;
    }
    /* En vertical los botones ocupan dos filas: la franja de estado va encima.
       Lleva !important porque el elemento trae bottom en atributo style. */
    #route-status {
        bottom: calc(134px + env(safe-area-inset-bottom)) !important;
    }
}

/* Reporting UI */
.floating-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    padding: 12px 20px;
    background: var(--alert-warning);
    color: #fff;
    border: none;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4);
    cursor: pointer;
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
    pointer-events: auto;
}
.floating-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.6);
}
.floating-btn:active {
    transform: translateY(0);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    pointer-events: auto;
}
.modal-content {
    width: 90%;
    max-width: 400px;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: slideUp 0.3s ease-out;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}
.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}
.close-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.close-btn:hover {
    opacity: 1;
}

.report-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.report-option-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 10px;
    color: var(--text-main);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.report-option-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}
.report-option-btn .emoji {
    font-size: 2rem;
}

.report-msg {
    text-align: center;
    color: var(--accent-start);
    font-weight: 600;
    font-size: 1rem;
    padding: 10px;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 8px;
}
/* Quick Report Group */
.quick-report-group {
    position: fixed;
    bottom: 20px;
    left: 20px; /* Movido a la izquierda para no sobreponerse al scroll */
    display: flex;
    gap: 10px;
    z-index: 1000;
}
.quick-report-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    background: var(--panel-bg);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
.quick-report-btn:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.15);
}
.global-report-msg {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background: var(--success);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}
/* User Report Marker on Map */
.user-report-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(239, 68, 68, 0.95);
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.8);
    position: relative;
    z-index: 1000;
}
.user-report-marker::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: rgba(239, 68, 68, 0.95) transparent transparent transparent;
}
/* Ensure the quick report group wraps nicely on small screens */
.quick-report-group {
    max-width: 250px;
    flex-wrap: wrap;
    justify-content: flex-start;
}
/* ============================================================
   HORIZONTAL (landscape)
   En apaisado el alto util baja a ~300px CSS. La estrategia es:
   columna izquierda angosta para los controles, el resto para el
   mapa, y el slider tumbado sobre el eje ancho de la pantalla.
   ============================================================ */
@media (orientation: landscape) and (max-height: 520px) {
    .ui-overlay {
        padding: 8px 10px;
        padding-left: calc(10px + env(safe-area-inset-left));
        padding-right: calc(10px + env(safe-area-inset-right));
        gap: 8px;
    }

    /* Cabecera compacta: titulo y logo en una sola franja baja */
    .app-header {
        max-width: 320px;
        padding: 8px 12px;
        border-radius: 10px;
    }
    .app-header h1 {
        font-size: 1rem;
        letter-spacing: -0.2px;
    }
    .app-header img {
        height: 22px !important;
    }
    #emergency-banner {
        margin-top: 6px !important;
        padding: 4px 8px !important;
        font-size: 0.72rem !important;
    }

    /* Panel de ruta: angosto, no a todo lo ancho */
    .routing-panel {
        max-width: 320px;
        padding: 10px 12px;
        border-radius: 10px;
    }
    .routing-panel input[type="text"] {
        padding: 8px 12px;
        font-size: 0.88rem;
    }
    .icon-btn {
        padding: 6px 8px;
        font-size: 1rem;
    }
    .suggestions-box {
        max-height: 130px;
    }
    .radial-btn {
        margin-top: 8px;
        padding: 7px 10px;
        font-size: 0.78rem;
    }
    .map-hint {
        margin-top: 6px;
        font-size: 0.68rem;
    }

    /* Slider tumbado: usa el eje ancho, se ancla arriba a la derecha
       donde no compite con nada (el panel de ruta ya se oculto). */
    .vertical-slider-panel {
        --rail-len: 250px;
        top: 8px;
        bottom: auto;
        right: calc(10px + env(safe-area-inset-right));
        flex-direction: row;
        align-items: center;
        gap: 12px;
        padding: 8px 14px;
    }
    .slider-label-vertical {
        margin-bottom: 0;
        font-size: 0.78rem;
        min-width: 58px;
    }
    .vertical-slider-wrapper {
        height: auto;
        width: var(--rail-len);
        flex-direction: column-reverse; /* pista arriba, marcas debajo */
        align-items: stretch;
    }
    /* row-reverse porque el HTML lista +72 primero y aqui "Ahora" va a la izquierda */
    .slider-ticks-vertical {
        flex-direction: row-reverse;
        justify-content: space-between;
        margin-right: 0;
        margin-top: 2px;
        font-size: 0.62rem;
    }
    .slider-rail {
        width: 100%;
        height: 30px;
        flex: 0 0 30px;
    }
    .vertical-slider {
        transform: translate(-50%, -50%); /* sin rotar: ya es horizontal */
    }

    /* Botones de reporte: una sola fila, abajo, sin envolver ni tapar nada */
    .quick-report-group {
        left: 50%;
        transform: translateX(-50%);
        bottom: calc(8px + env(safe-area-inset-bottom));
        max-width: none;
        flex-wrap: nowrap;
        justify-content: center;
        gap: 8px;
    }
    .quick-report-btn {
        width: 34px;
        height: 34px;
        font-size: 1rem;
    }

    /* La franja de estado sube por encima de los botones */
    #route-status {
        bottom: calc(50px + env(safe-area-inset-bottom)) !important;
        left: calc(10px + env(safe-area-inset-left)) !important;
        font-size: 0.9rem !important;
    }

    .alerts-panel {
        max-width: 320px;
    }
    .alert-card {
        padding: 8px 12px;
    }
    .global-report-msg {
        bottom: 50px;
        padding: 6px 14px;
        font-size: 0.85rem;
    }
}