/* ==========================================================================
   1. RESETEO Y CONFIGURACIÓN GENERAL
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif; /* Puedes cambiarla luego por una tipografía corporativa */
    background-color: #ffffff;
    color: #333333;
    overflow-x: hidden;
}

/* Contenedor global alineado con el estilo Interbank */
.container {
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Botones base */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 5px;
    text-decoration: none;
    font-weight: bold;
    font-size: 14px;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.btn-green { background-color: #00b965; color: white; }
.btn-green:hover { background-color: #009852; }

.btn-blue { background-color: #0033a0; color: white; margin-left: 10px; }
.btn-blue:hover { background-color: #002270; }


/* ==========================================================================
   2. DISEÑO DE LA CABECERA (HEADER)
   ========================================================================== */
.site-header {
    position: fixed; /* Mantiene la cabecera flotando arriba */
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    transition: transform 0.3s ease; /* Para el efecto de ocultado suave */
}

/* Nivel 1: Barra Azul */
.top-bar {
    background-color: #0033a0;
    padding: 8px 0;
    transition: margin-top 0.3s ease, opacity 0.2s ease;
}

.segment-nav a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 12px;
    font-weight: bold;
    margin-right: 20px;
    text-transform: uppercase;
}

.segment-nav a.active, .segment-nav a:hover {
    color: #ffffff;
}

/* Nivel 2: Menú Blanco Principal */
.main-menu {
    background-color: #ffffff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    padding: 15px 0;
}

.main-menu-content {
    display: flex;
    justify-content: space-between;
    align-items: center; /* Esto centra verticalmente el Logo, el Menú y las Acciones */
}

.header-actions {
    display: flex;
    align-items: center; /* Centra verticalmente botones, íconos y el portal */
    gap: 15px;           /* Controla la separación uniforme entre cada elemento */
}

.logo img {
    height: 4.5rem;   /* Se adapta proporcionalmente al tamaño de letra base del sitio */
    width: auto;
    max-width: 100%;
    display: block;
}

.btn-transparencia {
    display: flex;
    align-items: center;
    height: 4rem; /* Dale una altura máxima similar a la de los botones "Banca por Internet" */
}

.btn-transparencia img {
    height: 100%;  /* Ocupará los 40px de alto del contenedor */
    width: auto;    /* Mantendrá su proporción sin deformarse */
}


.main-nav ul {
    display: flex;
    list-style: none;
}

.main-nav ul li a {
    color: #333333;
    text-decoration: none;
    font-size: 14px;
    font-weight: bold;
    margin: 0 15px;
    transition: color 0.2s;
}

.main-nav ul li a:hover { color: #00b965; }

.header-actions {
    display: flex;
    align-items: center;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    margin-right: 15px;
}

/* Clase que aplicará JS cuando el usuario baje la página */
.site-header.scrolled .top-bar {
    margin-top: -35px; /* Empuja la barra azul hacia arriba fuera de la pantalla */
    opacity: 0;
    pointer-events: none;
}

/* ==========================================================================
   ESTILOS PARA EL MEGA MENÚ POR PESTAÑAS EN "NOSOTROS" (UI/UX MODERN)
   ========================================================================== */

/* Posicionamiento base relativo */
.main-menu .container {
    position: relative;
}

/* 1. El contenedor padre debe abarcar toda el área sin espacios vacíos */
.main-nav ul li.has-megamenu {
    position: relative !important;
    padding-bottom: 20px !important; /* Estira el área activa hacia abajo */
    margin-bottom: -20px !important; /* Compensa la altura en la maquetación */
}

.nav-link-main {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.caret {
    font-size: 11px;
    transition: transform 0.3s ease;
}

.has-megamenu:hover .caret {
    transform: rotate(180deg);
}

/* 1. Estado Base: Oculto por defecto y SIN interacción del mouse */
.megamenu-panel {
    position: absolute;
    top: 100% !important;
    left: 0 !important;
    /* El ancho se ajusta al contenido de la pestaña activa (ver punto 5) */
    width: max-content;
    max-width: calc(100vw - 40px) !important;
    background: #ffffff;
    box-shadow: 0 20px 40px rgba(0, 31, 77, 0.15);
    border-top: 4px solid #00a3e0;
    border-radius: 0 0 16px 16px;
    z-index: 1100;

    /* Control de visibilidad para evitar que quede atascado */
    opacity: 0;
    visibility: hidden;
    pointer-events: none; /* CRÍTICO: Inhabilita clicks y hover cuando está oculto */
    transform: translateY(-8px);
    
    /* Transición rápida de salida para cerrar de inmediato al retirar el cursor */
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
}

.has-megamenu:hover .megamenu-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* 2. Ajustar la altura para que NUNCA se corte el contenido de abajo */
.megamenu-container {
    display: flex;
    max-width: 100%;
    margin: 0 auto;
    padding: 18px 20px !important;/* Padding interno equilibrado */
    gap: 20px !important;
}
/* 3. Columna izquierda de pestañas con ancho fijo adecuado */
.megamenu-tabs {
    width: 260px !important;
    flex-shrink: 0;
    border-right: 1px solid #e2e8f0;
    padding-right: 15px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tab-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    background: transparent;
    transition: all 0.25s ease;
}

.tab-icon {
    font-size: 20px;
}

.tab-info {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.tab-info strong {
    font-size: 13px;
    color: #001f4d;
    font-weight: 700;
    text-transform: uppercase;
}

.tab-info small {
    font-size: 11px;
    color: #64748b;
    font-weight: 400;
}

.tab-arrow {
    color: #cbd5e1;
    font-size: 14px;
    transition: transform 0.2s ease, color 0.2s ease;
}

.tab-item:hover,
.tab-item.active {
    background: #f0f7ff;
}

.tab-item.active .tab-info strong {
    color: #0082b3;
}

.tab-item.active .tab-arrow,
.tab-item:hover .tab-arrow {
    color: #00a3e0;
    transform: translateX(4px);
}

/* 4. Columna derecha de contenidos dinámicos */
.megamenu-contents {
    flex-grow: 1;
    padding: 0 5px;
}

.tab-content {
    display: none;
    animation: fadeInTab 0.8s ease forwards;
}

.tab-content.active {
    display: block;
}

@keyframes fadeInTab {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Entrada escalonada: las tarjetas aparecen una tras otra, subiendo suavemente.
   "backwards" solo aplica el estado inicial durante el retraso, así no bloquea el hover */
.tab-content.active .subnav-card {
    animation: cardRiseIn 0.6s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.tab-content.active .subnav-card:nth-child(2) { animation-delay: 0.06s; }
.tab-content.active .subnav-card:nth-child(3) { animation-delay: 0.12s; }
.tab-content.active .subnav-card:nth-child(4) { animation-delay: 0.18s; }
.tab-content.active .subnav-card:nth-child(5) { animation-delay: 0.24s; }
.tab-content.active .subnav-card:nth-child(6) { animation-delay: 0.30s; }
.tab-content.active .subnav-card:nth-child(n+7) { animation-delay: 0.36s; }

@keyframes cardRiseIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Respeta a usuarios que prefieren menos movimiento */
@media (prefers-reduced-motion: reduce) {
    .tab-content,
    .tab-content.active .subnav-card {
        animation: none;
    }
}

.content-header {
    margin-bottom: 18px;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 10px;
}

.content-header h4 {
    font-size: 17px;
    color: #001f4d;
    margin: 0 0 4px 0;
    font-weight: 800;
}

.content-header p {
    font-size: 12px;
    color: #64748b;
    margin: 0;
}

/* 5. GRID DINÁMICO SEGÚN LA CANTIDAD DE TARJETAS
   El panel (width: max-content) toma el ancho de la pestaña activa, así que la caja
   crece a medida que se agregan tarjetas, hasta llegar al tamaño completo de "Organización":
     - 1 a 2 tarjetas -> en la primera fila, tarjetas compactas (caja más angosta)
     - 3 tarjetas     -> una sola columna, una debajo de otra (como Transparencia)
     - 4 tarjetas     -> cuadrícula de 2 x 2 (como Entidad)
     - 5 o más        -> 3 columnas con tarjetas anchas (diseño completo, como Organización) */
.subnav-grid {
    --cols: 3;
    --card-w: 15.5rem;
}

.subnav-grid:not(:has(> :nth-child(5))) {
    --card-w: 11rem;
}
.subnav-grid:has(> :only-child)              { --cols: 1; }
.subnav-grid:has(> :nth-child(2):last-child) { --cols: 2; }
.subnav-grid:has(> :nth-child(3):last-child) { --cols: 1; --card-w: 15.5rem; }
.subnav-grid:has(> :nth-child(4):last-child) { --cols: 2; }

.subnav-grid {
    display: grid !important;
    grid-template-columns: repeat(var(--cols), var(--card-w)) !important;
    gap: 12px !important;
    align-items: stretch !important; /* Fuerza a que todas las tarjetas de la misma fila midan lo mismo de alto */
}

/* 6. DISEÑO DE TARJETA MEJORADO (UI/UX) */
/* Anula la regla global ".main-nav ul li a" (margin 0 15px, font-size 14px),
   que también alcanza a las tarjetas y las desborda de su celda del grid */
.main-nav ul li .megamenu-panel a.subnav-card {
    margin: 0;
    font-size: inherit;
    min-width: 0;
}

.subnav-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    text-decoration: none;
    background: #ffffff;
    height: 100%; /* Ocupa el 100% de la fila */
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.subnav-icon {
    font-size: 16px;
    padding: 6px;
    background: #f1f5f9;
    border-radius: 8px;
    flex-shrink: 0; /* Impide que el icono se deforme si el texto es largo */
}

/* Tipografía y jerarquía */
.subnav-card div {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0; /* Necesario para recortar/ajustar texto en Grid sin desbordar */
}

.subnav-card strong {
    display: block;
    font-size: 12.5px;
    line-height: 1.25;
    color: #001f4d;
    font-weight: 700;
    margin-bottom: 2px;
    overflow-wrap: anywhere; /* Corta palabras largas antes que salirse de la tarjeta */
}


.subnav-card p {
    font-size: 11px;
    color: #64748b;
    margin: 0;
    line-height: 1.2;
    /* Recorte limpio a 2 líneas en textos largos */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Efectos de Hover profesional */
.subnav-card:hover {
    border-color: #00a3e0;
    background: #f8fafc;
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(0, 163, 224, 0.1);
}
.subnav-card:hover strong {
    color: #00a3e0;
}

/* 3. Ajuste preciso del Puente Invisible (Evita falsos activadores) */
.megamenu-panel::before {
    content: '';
    position: absolute;
    top: -10px; /* Reducido de -25px a -10px para evitar cierres falsos fuera de rango */
    left: 0;
    width: 100%;
    height: 10px;
    background: transparent;
}

/* 2. Estado Activo: Solo cuando se sobrevuela el LI padre */
.main-nav ul li.has-megamenu:hover > .megamenu-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto; /* Habilita interacción solo al estar abierto */
    transform: translateY(0);
    
    /* Transición de entrada suave */
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.25s ease,
                width 0.5s cubic-bezier(0.4, 0, 0.2, 1),   /* Cambio de tamaño suave entre pestañas */
                height 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mientras la caja cambia de tamaño, recorta el contenido para que no se salga del fondo blanco */
.megamenu-panel.is-resizing {
    overflow: hidden;
}

/* ESTADO ACTIVO (VISIBLE) */
.main-nav ul li.has-megamenu:hover .megamenu-panel,
.megamenu-panel:hover {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) !important; /* Se despliega suavemente hacia abajo */
    pointer-events: auto !important;
}
/* ==========================================================================
   RESPONSIVE DEL HEADER: MENÚ HAMBURGUESA EN CELULAR Y TABLET (<= 1100px)
   En escritorio (> 1100px) el header se mantiene exactamente igual.
   La lógica del botón está en includes/header.php.
   ========================================================================== */
.menu-toggle {
    display: none;
}

@media (max-width: 1100px) {
    .site-header .main-menu {
        padding: 10px 0;
    }

    .site-header .main-menu-content {
        flex-wrap: wrap;
    }

    .site-header .logo img {
        height: 3.2rem;
    }

    /* Botón de tres líneas que se convierte en una X al abrir */
    .site-header .menu-toggle {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 44px;
        height: 44px;
        padding: 11px 10px;
        border: 0;
        border-radius: 10px;
        background: #eef5ff;
        cursor: pointer;
    }

    .site-header .menu-toggle span {
        display: block;
        width: 100%;
        height: 2.5px;
        border-radius: 2px;
        background: #0033a0;
        transition: transform 0.25s ease, opacity 0.2s ease;
    }

    .site-header.menu-open .menu-toggle span:nth-child(1) { transform: translateY(7.5px) rotate(45deg); }
    .site-header.menu-open .menu-toggle span:nth-child(2) { opacity: 0; }
    .site-header.menu-open .menu-toggle span:nth-child(3) { transform: translateY(-7.5px) rotate(-45deg); }

    .site-header .menu-toggle:focus-visible {
        outline: 3px solid #00a3e0;
        outline-offset: 2px;
    }

    /* Panel desplegable: enlaces en lista y botones al final */
    .site-header .main-nav,
    .site-header .header-actions {
        display: none;
        width: 100%;
    }

    .site-header.menu-open .main-nav {
        display: block;
        max-height: calc(100vh - 190px);
        overflow-y: auto;
        margin-top: 10px;
        border-top: 1px solid #e2e8f0;
    }

    .site-header.menu-open .header-actions {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 12px;
        padding: 12px 0 4px;
        border-top: 1px solid #e2e8f0;
    }

    .site-header .main-nav ul {
        flex-direction: column;
    }

    /* Solo los enlaces principales (no las tarjetas del mega menú) */
    .site-header .main-nav > ul > li > a {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 0;
        padding: 14px 4px;
        font-size: 15px;
        border-bottom: 1px solid #f1f5f9;
    }

    .site-header .header-actions .btn-blue {
        margin-left: 0;
    }

    .site-header .btn-transparencia {
        height: 3rem;
    }

    /* "Nosotros" como acordeón: se abre con toque, no con hover */
    .site-header .main-nav ul li.has-megamenu {
        padding-bottom: 0 !important;
        margin-bottom: 0 !important;
    }

    .site-header .has-megamenu:hover .caret {
        transform: none;
    }

    .site-header .has-megamenu.is-open .caret {
        transform: rotate(180deg);
    }

    .site-header .megamenu-panel {
        display: none;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 6px 0 10px;
        border-top: 0;
        border-radius: 12px;
        background: #f6faff;
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transform: none;
    }

    .site-header .has-megamenu.is-open .megamenu-panel {
        display: block;
    }

    .site-header .megamenu-panel::before {
        display: none;
    }

    .site-header .megamenu-container {
        flex-direction: column;
        padding: 10px !important;
        gap: 10px !important;
    }

    /* Pestañas en una fila deslizable */
    .site-header .megamenu-tabs {
        width: 100% !important;
        flex-direction: row;
        overflow-x: auto;
        padding: 0 0 4px;
        border-right: 0;
    }

    .site-header .tab-item {
        flex: 0 0 auto;
        padding: 9px 12px;
        background: #ffffff;
        border: 1px solid #e2e8f0;
    }

    .site-header .tab-item.active {
        border-color: #00a3e0;
    }

    .site-header .tab-info small,
    .site-header .tab-arrow {
        display: none;
    }

    .site-header .subnav-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Tablet: las tarjetas del mega menú en 2 columnas */
@media (min-width: 600px) and (max-width: 1100px) {
    .site-header .subnav-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

/* Celular pequeño */
@media (max-width: 400px) {
    .site-header .logo img {
        height: 2.8rem;
    }

    .site-header .segment-nav a {
        font-size: 11px;
        margin-right: 14px;
    }
}
