/* =====================================================================
   Menú de navegación Maquiauto
   - Escritorio (≥64.0625em): desplegables bajo cada elemento padre,
     con animación suave y soporte de teclado (:focus-within).
   - Móvil (<64.0625em): panel desplegable bajo la cabecera con los
     submenús en acordeón y el buscador integrado.
   ===================================================================== */

.header__container {
    position: relative; /* ancla del botón hamburguesa y del panel móvil */
}

/* La flecha de fondo del CSS de 2016 apuntaba a un arrow.svg que ya no
   existe en el tema; se sustituye por la flecha dibujada en CSS de abajo */
.menu-item-has-children,
.current-menu-item {
    background-image: none;
}

/* ---- Flecha indicadora en elementos con submenú ---- */
.header-menu .menu-item-has-children > a::after {
    border-bottom: 2px solid currentColor;
    border-right: 2px solid currentColor;
    content: "";
    display: inline-block;
    height: 7px;
    margin-left: .6em;
    transform: rotate(45deg);
    transition: transform .25s ease;
    vertical-align: 2px;
    width: 7px;
}

.header-menu .menu-item-has-children.js-open > a::after {
    transform: rotate(225deg);
}

/* ---- Botón hamburguesa (solo móvil) ---- */
.nav-toggle {
    background: none;
    border: 0;
    cursor: pointer;
    display: block;
    height: 44px;
    padding: 10px;
    position: absolute;
    right: 0.9375rem;
    top: 28px;
    width: 44px;
    z-index: 20;
}

.nav-toggle__bar {
    background: #333;
    border-radius: 1px;
    display: block;
    height: 2px;
    margin: 5px auto;
    transition: transform .25s ease, opacity .2s ease;
    width: 22px;
}

.header.nav-open .nav-toggle__bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.header.nav-open .nav-toggle__bar:nth-child(2) {
    opacity: 0;
}

.header.nav-open .nav-toggle__bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* =====================================================================
   Escritorio
   ===================================================================== */
@media only screen and (min-width: 64.0625em) {
    .nav-toggle {
        display: none;
    }

    .header-menu > li {
        position: relative; /* referencia para posicionar el submenú hijo */
        transition: background-color .22s ease;
    }

    /* El hover del elemento superior usa el mismo gris oscuro que el
       desplegable, para que menú y submenú se lean como una sola pieza */
    .header-menu li:hover,
    .header-menu li.js-open,
    .header-menu li:focus-within {
        background-color: #333;
    }

    .header-menu li:hover > a,
    .header-menu li:focus-within > a {
        color: #fff;
    }

    .header-menu .sub-menu {
        background: #333;
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
        left: 0;
        list-style: none;
        margin: 0;
        max-width: 340px;
        min-width: 230px;
        opacity: 0;
        padding: .4em 0;
        pointer-events: none;
        position: absolute;
        text-align: left;
        top: 100%;
        transform: translateY(10px);
        transition: opacity .22s ease, transform .22s ease, visibility .22s;
        visibility: hidden;
        width: max-content;
        z-index: 50;
    }

    .header-menu li.js-open > .sub-menu,
    .header-menu li:focus-within > .sub-menu {
        opacity: 1;
        pointer-events: auto;
        transform: none;
        visibility: visible;
    }

    /* Los últimos elementos alinean su submenú a la derecha del padre,
       para que no se salga por el borde de la ventana */
    .header-menu > li:nth-last-child(-n+2) .sub-menu {
        left: auto;
        right: 0;
    }

    .header-menu .sub-menu li {
        display: block;
        margin: 0;
        position: relative;
        width: 100%;
    }

    .header-menu .sub-menu li a {
        color: #ddd;
        display: block;
        font-size: .75em;
        letter-spacing: 1px;
        line-height: 1.5;
        padding: .8em 1.6em;
        transition: background-color .2s ease, color .2s ease;
        white-space: normal;
    }

    .header-menu .sub-menu li a:hover {
        background: #404040;
        color: #fff;
    }

    .header-menu .sub-menu .current-menu-item > a {
        background: #3a3a3a;
        box-shadow: inset 3px 0 0 #fc0f10;
        color: #fff;
    }

    /* Submenús de segundo nivel (nietos): se despliegan hacia la derecha */
    .header-menu .sub-menu .sub-menu {
        left: 100%;
        top: -.4em;
        transform: translateX(8px);
    }

    .header-menu .sub-menu li.js-open > .sub-menu,
    .header-menu .sub-menu li:focus-within > .sub-menu {
        transform: none;
    }

    /* ...salvo en los últimos elementos, donde saldrían de la pantalla */
    .header-menu > li:nth-last-child(-n+2) .sub-menu .sub-menu {
        left: auto;
        right: 100%;
    }

    /* Dentro del desplegable la flecha apunta hacia la derecha */
    .header-menu .sub-menu .menu-item-has-children > a::after {
        float: right;
        margin-top: 5px;
        transform: rotate(-45deg);
    }

    .header-menu .sub-menu .menu-item-has-children.js-open > a::after {
        transform: rotate(-45deg);
    }
}

/* =====================================================================
   Móvil / tablet
   ===================================================================== */
@media only screen and (max-width: 64em) {
    .header {
        position: relative;
        z-index: 10;
    }

    /* Neutraliza el posicionamiento de la retícula para que el logo, el
       teléfono, la hamburguesa y el panel se anclen a la cabecera entera */
    .header__container .row,
    .header__container .column {
        position: static;
    }

    .header__logo {
        left: 0.9375rem;
    }

    /* Teléfono: solo el icono, como botón de "llamar" junto a la hamburguesa */
    .header__telephone-link {
        align-items: center;
        display: flex;
        height: 44px;
        justify-content: center;
        position: absolute;
        right: 70px;
        top: 28px;
        width: 44px;
    }

    .header__telephone-icon {
        height: 1.4em;
        margin: 0;
        width: 1.4em;
    }

    .header__telephone-number {
        display: none;
    }

    /* Botón del antiguo menú sidr (2016), sustituido por .nav-toggle */
    .menu--right {
        display: none;
    }

    /* ---- Panel desplegable ---- */
    .header__container .menu--header {
        background: #2e2e2e;
        box-shadow: 0 14px 28px rgba(0, 0, 0, 0.28);
        display: block;
        left: 0;
        max-height: calc(100vh - 100px);
        opacity: 0;
        overflow-y: auto;
        padding: 0 0 .75em;
        position: absolute;
        right: 0;
        top: 100%;
        transform: translateY(-8px);
        transition: opacity .22s ease, transform .22s ease, visibility .22s;
        visibility: hidden;
        z-index: 99;
    }

    .header.nav-open .menu--header {
        opacity: 1;
        transform: none;
        visibility: visible;
    }

    /* Buscador dentro del panel */
    .header__container .sidebar-search-form {
        background: none;
        display: block;
        margin: 0;
        padding: 1em 1.5em .5em;
    }

    .header-search-form-input {
        -webkit-appearance: none;
        appearance: none;
        background: #fff;
        border: 0;
        border-radius: 4px;
        font-size: 16px; /* evita el zoom automático de iOS al enfocar */
        height: 42px;
        padding: 0 1em;
        width: 100%;
    }

    /* ---- Lista del menú ---- */
    .header-menu {
        margin: 0;
        text-align: left;
    }

    .header-menu li {
        display: block;
        margin: 0;
    }

    .header-menu li:hover,
    .header-menu li.active,
    .header-menu li.active:hover {
        background: none;
    }

    .header-menu a {
        color: #ddd;
        display: block;
        line-height: 48px;
        padding: 0 1.5em;
    }

    .header-menu a:hover {
        color: #fff;
    }

    .header-menu .current-menu-item > a {
        background: rgba(0, 0, 0, 0.25);
        box-shadow: inset 3px 0 0 #fc0f10;
        color: #fff;
    }

    /* La flecha queda alineada al borde derecho de la fila */
    .header-menu .menu-item-has-children > a {
        align-items: center;
        display: flex;
        justify-content: space-between;
    }

    .header-menu .menu-item-has-children > a::after {
        flex: none;
        margin-left: 1em;
    }

    /* ---- Submenús en acordeón ---- */
    .header-menu .sub-menu {
        background: #262626;
        display: none;
        margin: 0;
        padding: .25em 0;
    }

    .header-menu .menu-item-has-children.js-open > .sub-menu {
        display: block;
    }

    .header-menu .sub-menu a {
        font-size: .9em;
        line-height: 40px;
        padding-left: 2.5em;
    }

    .header-menu .sub-menu .sub-menu {
        background: #202020;
    }

    .header-menu .sub-menu .sub-menu a {
        padding-left: 3.75em;
    }
}
