/* =====================================================================
   RUTAS TEMÁTICAS — Rediseño UI/UX
   Mejoras aplicadas:
   - Sistema de elevación material (sombras suaves en capas)
   - Jerarquía tipográfica clara (H3 → subtitle → meta)
   - Microinteracciones con easing natural (cubic-bezier)
   - Indicador de color con gradient lateral
   - Stats bar con divisores y números prominentes
   - Stagger animation al renderizar lista
   - Touch targets ≥ 56px (cómodo para móvil)
   ===================================================================== */

/* ---------------------------------------------------------------------
   0. FIX HEADER OVERFLOW — Permitir que paneles dropdown se muestren
   El header tenía overflow:hidden que recortaba los paneles de
   notificaciones y "cerca de ti" al desplegarse hacia abajo
   --------------------------------------------------------------------- */
#app-header {
    overflow: visible !important;
}

/* Asegurar que los botones del header siguen respetando el border-radius
   redondeado — usando un wrapper interno con clip-path no necesario
   porque los botones son individuales y no se desbordan */

/* ---------------------------------------------------------------------
   1. STATS BAR — Encabezado de estadísticas con jerarquía
   --------------------------------------------------------------------- */
/* Sidebar sin padding superior — para que la stats-bar quede a la misma altura
   que el top-float-bar (search/opciones/filtros) */
#sidebar {
    padding-top: 0 !important;
}

.stats-bar {
    background: #ffffff !important;
    border: 1px solid rgba(14, 79, 166, 0.12);
    border-radius: 16px;
    padding: 16px 14px !important;
    box-shadow:
        0 1px 2px rgba(10, 61, 128, 0.06),
        0 6px 16px rgba(10, 61, 128, 0.10);
    margin-top: 0 !important;
    position: relative;
    overflow: hidden;
}

/* Detalle decorativo: línea superior azul (acento de marca) */
.stats-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 16px;
    right: 16px;
    height: 3px;
    background: linear-gradient(90deg,
        transparent 0%,
        #0e4fa6 30%,
        #1465c4 50%,
        #0e4fa6 70%,
        transparent 100%);
    border-radius: 0 0 3px 3px;
}

/* Divisores verticales sutiles entre stats */
.stats-bar .stat {
    flex: 1;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    gap: 4px !important;
    padding: 4px 8px;
    position: relative;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.stats-bar .stat:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 20%;
    bottom: 20%;
    width: 1px;
    background: rgba(0, 0, 0, 0.08);
}

.stats-bar .stat:hover {
    transform: translateY(-2px);
}

.stats-bar .stat i {
    font-size: 18px !important;
    color: #0e4fa6;
    margin-bottom: 2px;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stats-bar .stat:hover i {
    transform: scale(1.15);
}

.stats-bar .stat span {
    font-size: 12.5px !important;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.3;
    text-align: center;
}

/* Número resaltado (primer "número" del span) — usando ::first-letter trick */
.stats-bar .stat span {
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------
   2. SECCIÓN "RUTAS TEMÁTICAS" — Glassmorphism (frosted glass)
   --------------------------------------------------------------------- */
#sidebar .sidebar-section:has(#route-buttons) {
    background: #ffffff !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: 1px solid rgba(14, 79, 166, 0.12) !important;
    border-radius: 20px !important;
    margin-top: 16px;
    padding: 10px 14px 14px !important;
    box-shadow:
        0 1px 2px rgba(10, 61, 128, 0.06),
        0 12px 32px rgba(10, 61, 128, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 1);
    overflow: hidden;
    position: relative;
}

/* Patrón decorativo sutil — puntos azul muy claro */
#sidebar .sidebar-section:has(#route-buttons)::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle, rgba(14, 79, 166, 0.04) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
    opacity: 0.6;
    z-index: 0;
}

/* Asegurar que el contenido quede sobre el patrón */
#sidebar .sidebar-section:has(#route-buttons) > * {
    position: relative;
    z-index: 1;
}

/* Highlight sutil arriba */
#sidebar .sidebar-section:has(#route-buttons)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.4) 50%,
        transparent 100%);
    pointer-events: none;
}

#sidebar .sidebar-section:has(#route-buttons) > .sidebar-section-header {
    padding: 10px 6px 14px !important;
    background: transparent !important;
    border-bottom: 1px solid rgba(14, 79, 166, 0.12);
    margin-bottom: 14px;
}

/* Header en azul de marca sobre fondo blanco */
#toggle-routes-section,
#toggle-routes-section *,
#toggle-routes-section h2,
#toggle-routes-section h2 i,
#sidebar #toggle-routes-section,
#sidebar #toggle-routes-section h2,
#sidebar #toggle-routes-section h2 i {
    color: #0e4fa6 !important;
}

/* Botón de toggle (chevron / +) */
#sidebar .sidebar-section:has(#route-buttons) .sidebar-section-arrow {
    background: rgba(14, 79, 166, 0.08) !important;
    border-color: rgba(14, 79, 166, 0.2) !important;
    color: #0e4fa6 !important;
}

#sidebar .sidebar-section:has(#route-buttons):not(.collapsed) .sidebar-section-arrow {
    background: rgba(14, 79, 166, 0.12) !important;
    border-color: rgba(14, 79, 166, 0.3) !important;
}

#sidebar .sidebar-section:has(#route-buttons) .sidebar-section-header:hover .sidebar-section-arrow {
    background: rgba(14, 79, 166, 0.18) !important;
}

#sidebar .sidebar-section:has(#route-buttons) > .sidebar-section-header h2 {
    font-size: 15px !important;
    font-weight: 700 !important;
    letter-spacing: -0.01em;
    color: var(--text-heading) !important;
    display: flex;
    align-items: center;
    gap: 10px;
}

#sidebar .sidebar-section:has(#route-buttons) > .sidebar-section-header h2 i {
    color: var(--accent);
    font-size: 16px;
}

/* Chevron toggle button — más limpio */
#sidebar .sidebar-section:has(#route-buttons) .sidebar-section-arrow {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    font-size: 11px;
    color: var(--text-secondary);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

#sidebar .sidebar-section:has(#route-buttons):not(.collapsed) .sidebar-section-arrow {
    background: var(--bg-section);
    border-color: rgba(15, 91, 167, 0.2);
    color: var(--accent);
}

#sidebar .sidebar-section:has(#route-buttons) .sidebar-section-header:hover .sidebar-section-arrow {
    background: var(--bg-section-hover);
    transform: scale(1.05);
}

/* ---------------------------------------------------------------------
   3. ROUTE CARDS — Tarjetas premium
   --------------------------------------------------------------------- */
#route-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 2px;
}

.route-card {
    background: rgba(14, 79, 166, 0.85) !important;
    border: 1px solid rgba(14, 79, 166, 0.5) !important;
    border-radius: 14px !important;
    padding: 14px 16px !important;
    margin-bottom: 0 !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    gap: 14px;
    border-left: 1px solid rgba(14, 79, 166, 0.5) !important;
    position: relative;
    overflow: hidden;
    transition:
        transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        box-shadow 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        border-color 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        background 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow:
        0 1px 2px rgba(10, 61, 128, 0.12),
        0 4px 14px rgba(10, 61, 128, 0.22) !important;
    min-height: 64px;
    will-change: transform;
    isolation: isolate;
}

.route-card,
.route-card * {
    color: #ffffff !important;
}

.route-card .route-card-info h3 {
    color: #ffffff !important;
    font-weight: 600 !important;
}

.route-card .route-card-info p {
    color: rgba(255, 255, 255, 0.75) !important;
}

/* Indicador de color lateral (se rellena con el inline-style del border-left) */
.route-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--route-color, var(--accent));
    transition:
        width 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0.85;
}

/* Tomar el color del border-left inline (que el JS pinta) y proyectarlo al ::before */
.route-card[style*="border-left"] {
    border-left-width: 1px !important;
    border-left-style: solid !important;
}

/* Glow sutil en hover */
.route-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.5) 100%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: -1;
}

.route-card:hover {
    transform: translateY(-3px) !important;
    background: rgba(14, 79, 166, 0.95) !important;
    box-shadow:
        0 6px 12px rgba(10, 61, 128, 0.25),
        0 16px 32px rgba(10, 61, 128, 0.4) !important;
    border-color: rgba(14, 79, 166, 0.8) !important;
}

.route-card:hover::before {
    width: 5px;
    opacity: 1;
}

.route-card:hover::after {
    opacity: 1;
}

.route-card:active {
    transform: translateY(-1px) !important;
    transition-duration: 0.1s !important;
}

/* ---------------------------------------------------------------------
   4. ICONO DE LA RUTA — Container con tinte de color
   --------------------------------------------------------------------- */
.route-card-icon {
    width: 48px !important;
    height: 48px !important;
    border-radius: 12px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 22px !important;
    flex-shrink: 0;
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.5),
        0 1px 2px rgba(0, 0, 0, 0.04);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    z-index: 1;
}

.route-card:hover .route-card-icon {
    transform: scale(1.08) rotate(-3deg);
}

/* ---------------------------------------------------------------------
   5. INFO DE LA RUTA — Tipografía con jerarquía
   --------------------------------------------------------------------- */
.route-card-info {
    flex: 1;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.route-card-info h3 {
    font-size: 14.5px !important;
    font-weight: 600 !important;
    color: var(--text-heading) !important;
    margin-bottom: 4px !important;
    letter-spacing: -0.005em;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.route-card-info p {
    font-size: 12px !important;
    font-weight: 500;
    color: var(--text-secondary) !important;
    letter-spacing: 0.01em;
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Iconito de "paradas" delante del texto si existe */
.route-card-info p::before {
    content: '\f041'; /* fa-map-marker-alt */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 9px;
    opacity: 0.55;
    margin-right: 2px;
}

/* Si el JS ya inserta un ícono, el ::before queda oculto */
.route-card-info p:has(i)::before {
    display: none;
}

/* ---------------------------------------------------------------------
   6. CHEVRON DE NAVEGACIÓN — Indicador de "click para entrar"
   --------------------------------------------------------------------- */
.route-card::part(after-chevron) {
    /* Reservado por si se quiere extender */
}

/* Añadir chevron flotante como pista visual */
.route-card .route-card-info::after {
    content: '\f054'; /* fa-chevron-right */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    font-size: 11px;
    color: var(--text-secondary);
    opacity: 0;
    transition:
        opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.route-card:hover .route-card-info::after {
    opacity: 0.6;
    transform: translateY(-50%) translateX(0);
}

/* ---------------------------------------------------------------------
   7. STAGGER ANIMATION — Aparición secuencial al cargar
   --------------------------------------------------------------------- */
@keyframes route-card-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#route-buttons .route-card {
    animation: route-card-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

#route-buttons .route-card:nth-child(1) { animation-delay: 0.04s; }
#route-buttons .route-card:nth-child(2) { animation-delay: 0.08s; }
#route-buttons .route-card:nth-child(3) { animation-delay: 0.12s; }
#route-buttons .route-card:nth-child(4) { animation-delay: 0.16s; }
#route-buttons .route-card:nth-child(5) { animation-delay: 0.20s; }
#route-buttons .route-card:nth-child(6) { animation-delay: 0.24s; }
#route-buttons .route-card:nth-child(7) { animation-delay: 0.28s; }
#route-buttons .route-card:nth-child(8) { animation-delay: 0.32s; }
#route-buttons .route-card:nth-child(9) { animation-delay: 0.36s; }

/* Respetar preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
    #route-buttons .route-card {
        animation: none;
    }
    .route-card,
    .route-card-icon,
    .stats-bar .stat {
        transition: none !important;
    }
}

/* ---------------------------------------------------------------------
   8. ACCESIBILIDAD — Foco visible
   --------------------------------------------------------------------- */
.route-card:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 3px rgba(15, 91, 167, 0.25),
        0 4px 12px rgba(0, 0, 0, 0.08) !important;
    border-color: var(--accent) !important;
}

/* ---------------------------------------------------------------------
   9. DARK MODE — Ajustes específicos
   --------------------------------------------------------------------- */
html:not([data-theme="light"]) #sidebar .sidebar-section:has(#route-buttons) {
    background: #ffffff !important;
    border-color: rgba(14, 79, 166, 0.12) !important;
    box-shadow:
        0 1px 2px rgba(10, 61, 128, 0.06),
        0 12px 32px rgba(10, 61, 128, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 1);
}

html:not([data-theme="light"]) #sidebar .sidebar-section:has(#route-buttons)::before {
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(14, 79, 166, 0.2) 50%,
        transparent 100%);
}

html:not([data-theme="light"]) .route-card {
    background: rgba(14, 79, 166, 0.85) !important;
    border-color: rgba(14, 79, 166, 0.5) !important;
}

html:not([data-theme="light"]) .route-card:hover {
    background: rgba(14, 79, 166, 0.95) !important;
    border-color: rgba(14, 79, 166, 0.8) !important;
    box-shadow:
        0 6px 12px rgba(10, 61, 128, 0.25),
        0 16px 32px rgba(10, 61, 128, 0.4) !important;
}

html:not([data-theme="light"]) .route-card .route-card-info h3 {
    color: #ffffff !important;
}

html:not([data-theme="light"]) .route-card .route-card-info p {
    color: rgba(255, 255, 255, 0.75) !important;
}

html:not([data-theme="light"]) .stats-bar {
    background: var(--bg-card) !important;
    border-color: rgba(255, 255, 255, 0.08);
}

html:not([data-theme="light"]) .route-card::after {
    background: linear-gradient(135deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.04) 100%);
}

/* ---------------------------------------------------------------------
   10. RESPONSIVE — Ajuste mobile
   --------------------------------------------------------------------- */
@media (max-width: 768px) {
    /* Logo del header — tamaño reducido para móvil */
    .header-logo {
        height: 48px !important;
        max-width: 220px !important;
    }

    .route-card {
        padding: 12px 14px !important;
        min-height: 60px;
    }

    .route-card-icon {
        width: 44px !important;
        height: 44px !important;
        font-size: 20px !important;
    }

    .route-card-info h3 {
        font-size: 14px !important;
    }

    .stats-bar {
        padding: 12px 8px !important;
    }

    .stats-bar .stat span {
        font-size: 11.5px !important;
    }

    .stats-bar .stat i {
        font-size: 16px !important;
    }
}

@media (max-width: 480px) {
    .header-logo {
        height: 42px !important;
        max-width: 180px !important;
    }
}

/* ---------------------------------------------------------------------
   FIX — Panel "Cerca de ti" en móvil
   El styles.css base lo oculta junto con el botón. Lo re-mostramos
   cuando NO tiene la clase .hidden (igual que el panel de notificaciones)
   --------------------------------------------------------------------- */
@media (max-width: 768px) {
    /* Panel "Cerca de ti" debe poder mostrarse en móvil */
    #nearby-panel {
        display: flex !important;
        position: fixed !important;
        top: calc(var(--header-height) + 16px) !important;
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-width: none !important;
        max-height: 70vh !important;
        z-index: 2200 !important;
        background: var(--bg-secondary, #ffffff);
        border: 1px solid var(--border-color, rgba(0, 0, 0, 0.08));
        border-radius: 16px;
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
        overflow: hidden;
        flex-direction: column;
    }

    /* Cuando tiene la clase .hidden, sí ocultarlo */
    #nearby-panel.hidden {
        display: none !important;
    }
}

/* Sombras suaves en cards de rutas móviles (carrusel inferior) */
@media (max-width: 768px) {
    .mobile-route-card {
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08),
                    0 2px 6px rgba(0, 0, 0, 0.06) !important;
    }

    .mobile-route-card:active {
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06) !important;
    }

    /* ----------------------------------------------------------------
       BÚSQUEDA EN MÓVIL — Resultados a pantalla completa
       y ocultar carrusel de rutas cuando se buscan resultados
       ---------------------------------------------------------------- */

    /* Resultados de búsqueda ocupan todo el ancho disponible en móvil
       (no quedan limitados al ancho del input de búsqueda) */
    #top-float-bar #search-results:not(.hidden) {
        position: fixed !important;
        left: 8px !important;
        right: 8px !important;
        top: calc(var(--header-height) + 60px) !important;
        width: auto !important;
        max-width: none !important;
        max-height: calc(100vh - var(--header-height) - 80px) !important;
        height: auto;
        background: #ffffff !important;
        border-radius: 16px !important;
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22) !important;
        border: 1px solid rgba(0, 0, 0, 0.08);
        z-index: 1500;
        overflow-y: auto;
    }

    /* Ocultar carrusel inferior de rutas cuando hay resultados visibles */
    body:has(#top-float-bar #search-results:not(.hidden)) .mobile-route-carousel,
    body:has(#search-results:not(.hidden)) .mobile-route-carousel {
        opacity: 0;
        pointer-events: none;
        transform: translateY(20px);
        transition: opacity 0.2s ease, transform 0.25s ease;
    }

    /* Botón "Volver a rutas" / Satélite también se oculta para no obstruir */
    body:has(#top-float-bar #search-results:not(.hidden)) #map-layer-toggle {
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }
}
