/* ======================================================
   HEADER MODERNO – SIGv (v2)
   Variable-driven · Unificado con theme_base
   ------------------------------------------------------
   Marcado:  componentes/header_moderno.php
             (header_publico.php es la misma pieza sin sesión)
   Colores:  variables --header-* de include/theme_base.php,
             sobrescritas por header en include/header_tema.php
   Aquí NO se fijan colores de marca: todo sale de variables.
====================================================== */

/* ======================================================
   1. VARIABLES LOCALES
====================================================== */
.header-moderno {
    /* Barra */
    --hm-texto:        var(--header-menu-text, var(--color-primario, #2c3e50));
    --hm-hover:        var(--header-menu-hover-bg, rgba(15, 23, 42, 0.06));
    --hm-acento:       var(--header-menu-active-bg, var(--color-secundario, #1abc9c));
    --hm-acento-texto: var(--header-menu-active-text, #ffffff);
    --hm-borde:        var(--header-borde, rgba(15, 23, 42, 0.08));

    /* Desplegables y panel móvil: superficie propia para que el
       texto SIEMPRE tenga contraste, sea cual sea el fondo del header */
    --hm-panel:        var(--header-drop-bg, #ffffff);
    --hm-panel-texto:  var(--header-drop-text, var(--color-texto, #1f2937));
    --hm-panel-hover:  rgba(15, 23, 42, 0.06);
    --hm-panel-sombra: 0 4px 10px rgba(15, 23, 42, 0.08), 0 18px 44px rgba(15, 23, 42, 0.18);

    --hm-peligro:      #c0392b;
    --hm-radio:        14px;
    --hm-alto:         72px;   /* lo actualiza el JS con la altura real */
}

/* ======================================================
   2. BARRA
====================================================== */
.header-moderno {
    position: sticky;
    top: 0;
    z-index: 9999;
    width: 100%;
    background: var(--header-bg, #ffffff);
    border-bottom: 1px solid var(--hm-borde);
    box-shadow: var(--header-shadow, 0 1px 0 rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.06));
    transition: box-shadow .25s ease;
    font-family: var(--header-font, var(--font-general, system-ui, sans-serif));
    -webkit-user-select: none;
    user-select: none;
}

.header-moderno.hm-scrolled {
    box-shadow: var(--header-shadow, 0 2px 6px rgba(15, 23, 42, 0.08), 0 10px 28px rgba(15, 23, 42, 0.12));
}

.header-moderno *,
.header-moderno *::before,
.header-moderno *::after {
    box-sizing: border-box;
}

.header-moderno .hm-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 8px 20px;
    min-height: 64px;
}

/* ======================================================
   3. MARCA (logo + títulos)
====================================================== */
.header-moderno .hm-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 0 1 auto;
    text-decoration: none;
    color: inherit;
    border-radius: 12px;
}

.header-moderno .hm-logo {
    height: clamp(44px, 5vw, 54px);
    width: auto;
    flex: 0 0 auto;
    object-fit: contain;
    border-radius: 10px;
    padding: 3px;
    background: #ffffff;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.06);
}

.header-moderno .hm-titles {
    display: flex;
    flex-direction: column;
    gap: 2px;
    line-height: 1.15;
    min-width: 0;
}

.header-moderno .hm-title {
    font-size: clamp(17px, 2.4vw, 21px);
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--header-title-color, var(--color-primario));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-moderno .hm-sub {
    font-size: 12px;
    color: var(--header-subtitle-color, #7f8c8d);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ======================================================
   4. MENÚ – ESCRITORIO
====================================================== */
.header-moderno .hm-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
    flex: 0 0 auto;
}

/* Enlace de la barra (también es el botón de cada grupo) */
.header-moderno .hm-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--hm-texto);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background .18s ease, color .18s ease;
}

.header-moderno .hm-link > i:first-child {
    font-size: 13px;
    opacity: .85;
}

.header-moderno .hm-link:hover,
.header-moderno .hm-group.open > .hm-link {
    background: var(--hm-hover);
}

.header-moderno .hm-link.activo {
    background: var(--hm-acento);
    color: var(--hm-acento-texto);
    font-weight: 600;
}

.header-moderno .hm-link.activo > i:first-child {
    opacity: 1;
}

/* Grupo activo y abierto a la vez: conserva el color activo */
.header-moderno .hm-group.open > .hm-link.activo {
    background: var(--hm-acento);
}

.header-moderno .hm-caret {
    font-size: 10px;
    opacity: .7;
    transition: transform .2s ease;
}

.header-moderno .hm-group.open > .hm-group-btn .hm-caret {
    transform: rotate(180deg);
}

/* Foco visible con teclado */
.header-moderno a:focus-visible,
.header-moderno button:focus-visible {
    outline: 2px solid var(--hm-acento);
    outline-offset: 2px;
}

/* ---------- Estilo de menú: SUBRAYADO ---------- */
.header-moderno[data-hm-menu="subrayado"] .hm-link {
    border-radius: 8px;
    position: relative;
}

.header-moderno[data-hm-menu="subrayado"] .hm-link.activo {
    background: transparent;
    color: var(--hm-texto);
}

.header-moderno[data-hm-menu="subrayado"] .hm-link.activo::after {
    content: "";
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 2px;
    height: 3px;
    border-radius: 3px;
    background: var(--hm-acento);
}

/* ======================================================
   5. DESPLEGABLES
====================================================== */
.header-moderno .hm-group {
    position: relative;
}

.header-moderno .hm-drop {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 240px;
    padding: 8px;
    border-radius: var(--hm-radio);
    background: var(--hm-panel);
    color: var(--hm-panel-texto);
    border: 1px solid rgba(15, 23, 42, 0.06);
    box-shadow: var(--hm-panel-sombra);

    /* Cerrado */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity .16s ease, transform .16s ease, visibility .16s;
}

.header-moderno .hm-drop-right {
    left: auto;
    right: 0;
}

.header-moderno .hm-group.open > .hm-drop {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.header-moderno .hm-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--hm-panel-texto);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.25;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s ease;
}

.header-moderno .hm-item > i:first-child {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: var(--hm-panel-hover);
    font-size: 13px;
}

.header-moderno .hm-item:hover {
    background: var(--hm-panel-hover);
}

.header-moderno .hm-item.activo {
    font-weight: 600;
}

.header-moderno .hm-item.activo > i:first-child {
    background: var(--hm-acento);
    color: var(--hm-acento-texto);
}

/* Secciones que requieren sesión (variante pública) */
.header-moderno .bloqueado > span {
    opacity: .6;
}

.header-moderno .hm-lock {
    margin-left: auto;
    padding-left: 10px;
    font-size: 11px;
    opacity: .5;
}

/* Cerrar sesión */
.header-moderno .hm-item.logout {
    color: var(--hm-peligro);
}

.header-moderno .hm-item.logout > i:first-child {
    background: rgba(192, 57, 43, 0.10);
}

.header-moderno .hm-item.logout:hover {
    background: rgba(192, 57, 43, 0.08);
}

/* ======================================================
   6. USUARIO / INICIAR SESIÓN
====================================================== */
.header-moderno .hm-user {
    margin-left: 8px;
    padding-left: 10px;
    border-left: 1px solid var(--hm-borde);
}

.header-moderno .hm-user-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 5px 12px 5px 5px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--hm-texto);
    font: inherit;
    cursor: pointer;
    transition: background .18s ease;
}

.header-moderno .hm-user-btn:hover,
.header-moderno .hm-user.open > .hm-user-btn {
    background: var(--hm-hover);
}

.header-moderno .hm-avatar {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--hm-acento);
    color: var(--hm-acento-texto);
    font-size: 14px;
}

.header-moderno .hm-user-txt {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.15;
    text-align: left;
}

.header-moderno .hm-user-txt strong {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.header-moderno .hm-user-txt small {
    font-size: 11px;
    opacity: .7;
    text-transform: capitalize;
    white-space: nowrap;
}

.header-moderno .hm-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--hm-acento);
    color: var(--hm-acento-texto);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: filter .18s ease, transform .18s ease;
}

.header-moderno .hm-cta:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

/* ======================================================
   7. BOTÓN DE MENÚ Y FONDO (solo móvil)
====================================================== */
.header-moderno .hm-burger {
    display: none;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: var(--hm-acento);
    color: var(--hm-acento-texto);
    font-size: 18px;
    cursor: pointer;
}

.header-moderno .hm-backdrop {
    display: none;
}

/* ======================================================
   8. PANTALLAS INTERMEDIAS
   Se compacta antes de pasar al menú móvil
====================================================== */
@media (max-width: 1180px) {
    .header-moderno .hm-sub {
        display: none;
    }
    .header-moderno .hm-link {
        padding: 9px 11px;
    }
    .header-moderno .hm-link > i:first-child {
        display: none;
    }
}

/* ======================================================
   9. MÓVIL – panel bajo el header
====================================================== */
@media (max-width: 960px) {

    .header-moderno .hm-container {
        padding: 8px 14px;
    }

    .header-moderno .hm-sub {
        display: block;
    }

    .header-moderno .hm-burger {
        display: inline-flex;
    }

    /* Panel: cuelga del header (top: 100%), no usa alturas fijas */
    .header-moderno .hm-nav {
        display: none;
        position: absolute;
        top: calc(100% + 8px);
        right: 12px;
        left: auto;
        z-index: 2;
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        width: min(330px, calc(100vw - 24px));
        max-height: calc(100vh - var(--hm-alto) - 24px);
        max-height: calc(100dvh - var(--hm-alto) - 24px);
        margin: 0;
        padding: 10px;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        border-radius: 16px;
        background: var(--header-menu-overlay-bg, var(--hm-panel));
        color: var(--header-menu-overlay-text, var(--hm-panel-texto));
        border: 1px solid rgba(15, 23, 42, 0.06);
        box-shadow: var(--hm-panel-sombra);
    }

    .header-moderno .hm-nav.open {
        display: flex;
        animation: hmEntrar .18s ease;
    }

    /* Fondo oscuro detrás del panel */
    .header-moderno.hm-abierto .hm-backdrop {
        display: block;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        height: 100vh;
        z-index: 1;
        background: rgba(15, 23, 42, 0.45);
    }

    /* Dentro del panel todo usa los colores del panel */
    .header-moderno .hm-link,
    .header-moderno .hm-item {
        width: 100%;
        justify-content: flex-start;
        gap: 12px;
        padding: 11px 12px;
        border-radius: 10px;
        color: inherit;
        font-size: 15px;
        white-space: normal;
    }

    .header-moderno .hm-link:hover,
    .header-moderno .hm-item:hover {
        background: var(--hm-panel-hover);
    }

    .header-moderno .hm-link > i:first-child {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 30px;
        height: 30px;
        border-radius: 9px;
        background: var(--hm-panel-hover);
    }

    .header-moderno .hm-link.activo,
    .header-moderno[data-hm-menu="subrayado"] .hm-link.activo {
        background: var(--hm-acento);
        color: var(--hm-acento-texto);
    }

    .header-moderno .hm-link.activo > i:first-child {
        background: transparent;
    }

    .header-moderno[data-hm-menu="subrayado"] .hm-link.activo::after {
        display: none;
    }

    /* Los grupos van abiertos: el botón pasa a ser un rótulo */
    .header-moderno .hm-group {
        position: static;
        margin-top: 6px;
        padding-top: 6px;
        border-top: 1px solid rgba(15, 23, 42, 0.08);
    }

    .header-moderno .hm-group-btn.hm-link,
    .header-moderno .hm-group-btn.hm-link.activo,
    .header-moderno[data-hm-menu="subrayado"] .hm-group-btn.hm-link.activo {
        padding: 6px 12px 4px;
        background: transparent;
        color: inherit;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: .08em;
        text-transform: uppercase;
        opacity: .6;
        cursor: default;
        pointer-events: none;
    }

    .header-moderno .hm-group-btn.hm-link > i {
        display: none;
    }

    .header-moderno .hm-drop,
    .header-moderno .hm-drop-right {
        position: static;
        min-width: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        color: inherit;
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        transform: none;
        transition: none;
    }

    .header-moderno .hm-item {
        color: inherit;
    }

    .header-moderno .hm-item.logout {
        color: var(--hm-peligro);
    }

    /* Usuario: tarjeta al final del panel */
    .header-moderno .hm-user {
        margin-left: 0;
        padding-left: 0;
        border-left: 0;
    }

    .header-moderno .hm-user-btn {
        width: 100%;
        padding: 8px 12px;
        color: inherit;
        cursor: default;
        pointer-events: none;
    }

    .header-moderno .hm-user-btn .hm-caret {
        display: none;
    }

    .header-moderno .hm-cta {
        justify-content: center;
        margin: 8px 0 0;
        padding: 13px 18px;
        border-radius: 12px;
        font-size: 15px;
    }
}

@keyframes hmEntrar {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .header-moderno,
    .header-moderno * {
        transition: none !important;
        animation: none !important;
    }
}
