@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&display=swap');

:root {
    --rb-blue: #004a99;
    --rb-green: #8cc63f;
    --sidebar-width: 380px;
}

/* Reset general */
body, html { 
    margin: 0; 
    padding: 0; 
    height: 100%; 
    font-family: 'Outfit', sans-serif; 
    background: #f8fafc; 
    overflow: hidden; 
}

/* ==========================================
   LOADER: CENTRADO MATEMÁTICO ABSOLUTO
   ========================================== */
.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9); 
    z-index: 99999; 
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    pointer-events: all;
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f1f5f9;
    border-top: 5px solid var(--rb-blue);
    border-right: 5px solid var(--rb-green);
    border-radius: 50%;
    animation: spin 0.8s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.loader-content p {
    margin: 0;
    font-weight: 600;
    color: var(--rb-blue);
    font-size: 0.9rem;
}

/* ==========================================
   SIDEBAR Y LAYOUT
   ========================================== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: white;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 15px rgba(0,0,0,0.05);
    transition: width 0.3s ease;
}

/* Contenedor principal de la cabecera con línea verde inferior */
.header {
    background: #ffffff;
    display: flex;
    flex-direction: column;
    border-bottom: 3px solid var(--rb-green);
}

/* Zona superior: Fondo blanco para cuidar la transparencia del logo */
.brand-img {
    width: 100%;
    max-width: 260px;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 12px auto; /* Centrado interno con margen equilibrado */
}

/* Zona inferior: Franja azul enmarcada arriba y abajo con líneas verdes delgadas */
.header small { 
    background: linear-gradient(135deg, var(--rb-blue) 0%, #002d5e 100%);
    color: #ffffff;
    font-size: 0.68rem; 
    font-weight: 600; 
    letter-spacing: 1px;
    text-transform: uppercase;
    text-align: center;
    padding: 6px 15px;
    width: 100%;
    box-sizing: border-box;
    display: block;
    border-top: 3px solid var(--rb-green); /* Nueva línea verde superior idéntica para enmarcarlo */
}

.search-container { 
    padding: 10px 15px; 
    background: #fff; 
    border-bottom: 1px solid #f1f5f9; 
}

.row-inputs { display: flex; gap: 8px; margin-bottom: 8px; }

.input-group { flex: 1; position: relative; }
.input-group label { 
    font-size: 0.6rem; 
    font-weight: 700; 
    color: #64748b; 
    text-transform: uppercase; 
}

.input-group input { 
    width: 100%; 
    padding: 7px 10px; 
    border: 1px solid #e2e8f0; 
    border-radius: 6px; 
    font-size: 0.75rem; 
    margin-top: 2px; 
    box-sizing: border-box; 
    font-family: inherit;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.03);
}

.time-container { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    margin-bottom: 12px; 
}

.input-tip { 
    color: #64748b; 
    font-style: italic; 
    padding-top: 12px; 
    font-size: 0.7rem; 
}

.btn-primary {
    width: 100%; 
    padding: 9px; 
    background: var(--rb-blue); 
    color: white;
    border: none; 
    border-radius: 6px; 
    font-weight: 700; 
    cursor: pointer; 
    font-size: 0.75rem;
    transition: background 0.2s;
}

.btn-primary:hover { background: #003a7a; }

/* ==========================================
   TABS Y RESULTADOS (Modificados -2px)
   ========================================== */
.options-tabs { display: flex; padding: 8px; gap: 6px; background: #f8fafc; }

.tab-btn {
    flex: 1; 
    padding: 6px; 
    border: 2px solid #e2e8f0; 
    background: white;
    border-radius: 8px; 
    cursor: pointer; 
    text-align: center; 
    transition: 0.2s;
    display: flex; 
    flex-direction: column; 
    align-items: center;
}

.tab-btn strong { font-size: 0.72rem; }
.tab-btn span { font-size: 0.43rem; color: #64748b; }
.tab-btn.active { 
    border-color: var(--rb-blue); 
    background: var(--rb-blue); 
    color: white; 
}
.tab-btn.active span { color: rgba(255,255,255,0.8); }

.results-container { flex-grow: 1; padding: 15px; overflow-y: auto; }
.empty-state { text-align: center; margin-top: 20px; color: #64748b; font-size: 0.72rem; }

.summary-badge {
    background: #f1f5f9; 
    padding: 10px; 
    border-radius: 8px; 
    margin-bottom: 20px;
    display: flex; 
    justify-content: space-around; 
    font-size: 0.62rem; 
    font-weight: 700;
}

/* ==========================================
   LÍNEA DE TIEMPO (Modificados -2px)
   ========================================== */
.leg-item { 
    display: flex; 
    gap: 12px; 
    margin-bottom: 0px; 
    padding-bottom: 24px; 
    position: relative; 
}

.leg-icon { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    width: 24px; 
    flex-shrink: 0; 
    position: relative;
}

.icon-circle {
    width: 24px; 
    height: 24px; 
    border-radius: 50%; 
    background: white; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    font-size: 11px; 
    border: 2px solid; 
    z-index: 5; 
    position: relative;
    box-sizing: border-box;
}

.leg-line { 
    width: 4px; 
    position: absolute;
    top: 12px;      
    height: calc(100% + 15px); 
    left: 50%;
    transform: translateX(-50%);
    z-index: 1; 
    margin: 0; 
}

.leg-item:last-child .leg-line { display: none; }

.leg-details b { font-size: 0.68rem; display: block; margin-bottom: 2px; line-height: 1.2; }
.leg-details div { font-size: 0.58rem; color: #475569; line-height: 1.1; }

.exit-instruction {
    margin-top: 8px; 
    padding: 7px 10px; 
    border-radius: 8px; 
    border: 1px solid; 
    font-size: 0.58rem; 
    font-weight: 600;
}

/* ==========================================
   MAPA Y AUTOCOMPLETADO
   ========================================== */
#map { 
    height: 100vh; 
    width: calc(100% - var(--sidebar-width)); 
    margin-left: var(--sidebar-width); 
    z-index: 1; 
    transition: margin-left 0.3s ease, width 0.3s ease;
}

.marker-label { 
    background: white; 
    border: 2px solid #334155; 
    border-radius: 4px; 
    padding: 1px 6px; 
    font-weight: 800; 
    font-size: 9px; 
}

.autocomplete-items { 
    position: absolute; 
    background: white; 
    z-index: 3000; 
    left: 0; 
    right: 0; 
    top: 100%; 
    border-radius: 0 0 8px 8px; 
    box-shadow: 0 5px 15px rgba(0,0,0,0.1); 
    max-height: 150px; 
    overflow-y: auto; 
}

.autocomplete-item { 
    padding: 8px 10px; 
    cursor: pointer; 
    border-bottom: 1px solid #f1f5f9; 
    font-size: 0.7rem; 
}

.autocomplete-item:hover { background: #f8fafc; }

/* ==========================================
   BANNER DE BIENVENIDA - FINAL AJUSTADO
   ========================================== */
.banner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.banner-content {
    background: white;
    padding: 22px;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    /* Garantiza siempre 20px de margen en móviles */
    width: calc(100% - 40px); 
    box-sizing: border-box;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    font-family: 'Outfit', sans-serif;
}

.banner-content p {
    margin-bottom: 15px;
    font-size: 1rem;
    color: #334155;
    font-weight: 400;
    line-height: 1.3;
}

.banner-content a {
    display: inline-block;
    text-decoration: none;
    margin: 0;
}

.banner-content img {
    width: 240px;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.banner-hint {
    font-size: 0.7rem !important;
    color: #94a3b8 !important;
    margin-top: 8px !important;
    margin-bottom: 10px !important;
    font-style: normal !important;
    font-weight: 400 !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#close-banner {
    display: block;
    margin: 0 auto;
    padding: 5px 20px;
    background: #991b1b;
    color: white;
    border: 1px solid #991b1b;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 400;
    font-size: 0.85rem;
    transition: background 0.3s;
    font-family: 'Outfit', sans-serif;
}

#close-banner:hover {
    background: #7f1515;
}

@media (max-width: 1024px) {

    :root { --sidebar-width: 300px;}

    html, body {
        height: auto !important; 
        min-height: 100dvh !important; 
        width: 100vw !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow-y: auto !important; 
        overflow-x: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        background-color: #ffffff !important;
    }

    body.has-results { overflow-y: auto !important; }

    .sidebar { display: contents !important; }

    .header {
        order: 1 !important;
        width: 100% !important;
        background-color: #ffffff !important;
        z-index: 50 !important;
        flex-shrink: 0 !important;
    }
    
    .brand-img {
        max-width: 300px !important;
        width: 100% !important;
        margin: 15px auto !important;
    }

    .header small {
        padding: 6px 10px !important;  
        font-size: 0.7rem !important;
    }
    
    .search-container {
        order: 2 !important;
        width: 100% !important;
        padding: 10px 15px !important;
        box-sizing: border-box !important;
        background-color: #ffffff !important;
        border-bottom: none !important;
        z-index: 50 !important;
        flex-shrink: 0 !important;
    }

    .row-inputs {
        display: flex !important;
        flex-direction: row !important;
        gap: 6px !important;
    }

    .input-group input, #dep-time {
        -webkit-appearance: none !important; 
        appearance: none !important;
        padding: 8px 10px !important;
        font-size: 16px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 6px !important;
        outline: none !important;
    }

    #dep-time { color: #000000 !important; }

    #dep-time::-webkit-calendar-picker-indicator {
        filter: invert(0) !important;
    }

    .time-container {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 2px !important;
        margin-top: 8px !important;
        width: 100% !important;
    }
    
    .time-container .input-group { width: 100% !important; }

    .input-tip {
        padding-top: 0 !important;
        font-size: 0.75rem !important;
    }

    .btn-primary {
        padding: 12px !important;
        font-size: 0.85rem !important;
        margin-top: -4px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    #map {
        order: 3 !important;
        position: relative !important;
        width: 100% !important;
        height: 40vh !important;
        height: 40dvh !important;
        min-height: 250px !important;
        margin: 0 0 8px 0 !important;
        z-index: 40 !important;
        border-radius: 0 !important;
        flex-shrink: 0 !important;
    }

    #options-tabs-container {
        order: 4 !important;
        width: 100% !important;
        padding: 0 15px !important;
        box-sizing: border-box !important;
        flex-shrink: 0 !important;
    }
    
    .results-container {
        order: 5 !important;
        width: 100% !important;
        padding: 10px 15px 30px 15px !important;
        box-sizing: border-box !important;
        overflow-y: visible !important;
        height: auto !important;
        flex-grow: 1 !important;
    }

    /* Aumentos de letra */
    .options-tabs .tab-btn strong { font-size: 0.95rem !important; }
    .options-tabs .tab-btn span { font-size: 0.65rem !important; }
    .leg-details b { font-size: 0.78rem !important; }
    .leg-details div { font-size: 0.68rem !important; }
    .exit-instruction { font-size: 0.68rem !important; }

    /* Reducción automática para modo horizontal (pantallas con poca altura) */
    @media (max-height: 500px) {
        .options-tabs .tab-btn strong { font-size: 0.75rem !important; }
        .options-tabs .tab-btn span { font-size: 0.55rem !important; }
        .leg-details b { font-size: 0.65rem !important; }
        .leg-details div { font-size: 0.55rem !important; }
        .exit-instruction { font-size: 0.55rem !important; }
    }

    .loader-content {
        padding-left: 20px !important;
        padding-right: 20px !important;
        box-sizing: border-box !important;
        width: 100% !important;
    }
}