/**
 * YCO Menu Widget — styles front.
 *
 * Tokens --ymw-* avec repli sur les variables du thème (bleu foncé, crème,
 * Barlow) pour rester cohérent avec le reste du site, comme les autres
 * plugins yco-*.
 */

.ymw {
    --ymw-anim-duration: 350ms;
    --ymw-sans: var(--sans, 'Barlow', system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif);
    --ymw-ink: var(--bleu-fonce, #003B5E);
    --ymw-accent: var(--orange, #DC6A02);

    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* -------------------------------------------------------------------------
 * Bouton déclencheur + icône
 * ---------------------------------------------------------------------- */

.ymw-toggle {
    --ymw-icon-size: 26px;
    --ymw-icon-color: currentColor;

    position: relative;
    z-index: 100001;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 8px;
    background: transparent;
    border: 0;
    line-height: 1;
    color: var(--ymw-icon-color);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.ymw-toggle:focus-visible {
    outline: 2px solid var(--ymw-accent);
    outline-offset: 3px;
}

.ymw-toggle__label {
    font-family: var(--ymw-sans);
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
    font-size: .9em;
}

.ymw-toggle__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--ymw-icon-size);
    height: var(--ymw-icon-size);
    color: var(--ymw-icon-color);
}

.ymw-toggle__icon svg,
.ymw-toggle__icon i {
    width: var(--ymw-icon-size);
    height: var(--ymw-icon-size);
    font-size: var(--ymw-icon-size);
    color: var(--ymw-icon-color);
    fill: currentColor;
}

/* Hamburger 3 lignes animées (morph → croix) */
.ymw-bars {
    position: relative;
    display: inline-block;
    width: var(--ymw-icon-size);
    height: calc(var(--ymw-icon-size) * 0.72);
}

.ymw-bars span {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    border-radius: 2px;
    background: var(--ymw-icon-color);
    transition: transform .3s ease, opacity .2s ease, top .3s ease, background-color .2s ease;
}

.ymw-bars span:nth-child(1) { top: 0; }
.ymw-bars span:nth-child(2) { top: 50%; transform: translateY(-50%); }
.ymw-bars span:nth-child(3) { top: auto; bottom: 0; }

.ymw--morph.is-open .ymw-bars span:nth-child(1) {
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
}
.ymw--morph.is-open .ymw-bars span:nth-child(2) {
    opacity: 0;
}
.ymw--morph.is-open .ymw-bars span:nth-child(3) {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%) rotate(-45deg);
}

/* -------------------------------------------------------------------------
 * Panneau (commun) — états ouvert / fermé
 * ---------------------------------------------------------------------- */

.ymw-panel {
    visibility: hidden;
    pointer-events: none;
    z-index: 100000;
    transition: visibility var(--ymw-anim-duration);
}

.ymw.is-open .ymw-panel {
    visibility: visible;
    pointer-events: auto;
}

.ymw-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity var(--ymw-anim-duration) ease;
}

.ymw.is-open .ymw-backdrop {
    opacity: 1;
}

.ymw-panel__inner {
    position: relative;
    z-index: 1;
    box-sizing: border-box;
    background: rgba(0, 59, 94, 0.98);
    color: #fff;
    padding: 48px 32px;
    transition: transform var(--ymw-anim-duration) ease, opacity var(--ymw-anim-duration) ease;
}

.ymw-panel__close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.ymw-panel__close:focus-visible {
    outline: 2px solid var(--ymw-accent);
    outline-offset: 2px;
}

.ymw-panel__close svg,
.ymw-panel__close i {
    width: 1em;
    height: 1em;
    fill: currentColor;
}

/* -------------------------------------------------------------------------
 * Mode plein écran
 * ---------------------------------------------------------------------- */

.ymw-panel--fullscreen {
    position: fixed;
    inset: 0;
}

.ymw-panel--fullscreen .ymw-panel__inner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* -------------------------------------------------------------------------
 * Mode tiroir
 * ---------------------------------------------------------------------- */

.ymw-panel--drawer {
    position: fixed;
    inset: 0;
}

.ymw-panel--drawer .ymw-panel__inner {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 340px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.ymw--drawer-right .ymw-panel--drawer .ymw-panel__inner { right: 0; }
.ymw--drawer-left  .ymw-panel--drawer .ymw-panel__inner { left: 0; }

/* -------------------------------------------------------------------------
 * Mode déroulant
 * ---------------------------------------------------------------------- */

.ymw-panel--dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
}

.ymw-panel--dropdown .ymw-panel__inner {
    position: absolute;
    top: 8px;
    width: 320px;
    max-width: calc(100vw - 24px);
    border-radius: 8px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.ymw-panel--dropdown.ymw-panel--align-left  .ymw-panel__inner { left: 0;  right: auto; }
.ymw-panel--dropdown.ymw-panel--align-right .ymw-panel__inner { right: 0; left: auto; }

/* La croix interne est superflue en mode déroulant (le bouton hamburger
 * reste accessible) : on la masque pour un rendu plus propre. */
.ymw-panel--dropdown .ymw-panel__close {
    display: none;
}

/* -------------------------------------------------------------------------
 * Icône au-dessus du panneau (sert de fermeture)
 * Quand le hamburger se transforme en croix (morph), il reste cliquable
 * au-dessus du voile plein écran / tiroir : on lui donne un contraste clair
 * et on masque la croix interne devenue redondante.
 * ---------------------------------------------------------------------- */

.ymw--morph.ymw--mode-fullscreen.is-open .ymw-toggle,
.ymw--morph.ymw--mode-drawer.is-open .ymw-toggle {
    --ymw-icon-color: var(--ymw-open-icon-color, #fff);
}

.ymw--morph.ymw--mode-fullscreen .ymw-panel__close,
.ymw--morph.ymw--mode-drawer .ymw-panel__close {
    display: none;
}

/* -------------------------------------------------------------------------
 * Liste du menu + sous-menus en accordéon
 * ---------------------------------------------------------------------- */

.ymw-menu {
    --ymw-item-gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--ymw-item-gap);
    align-items: center;
    text-align: center;
    font-family: var(--ymw-sans);
}

.ymw-menu li {
    width: 100%;
    margin: 0;
}

.ymw-menu a {
    display: inline-block;
    padding: 6px 4px;
    color: #fff;
    text-decoration: none;
    transition: color .2s ease, opacity .2s ease;
}

.ymw-menu a:hover,
.ymw-menu a:focus {
    opacity: .85;
}

.ymw-menu .current-menu-item > a {
    font-weight: 700;
}

/* Items parents : libellé + chevron sur une ligne, sous-menu en dessous */
.ymw-menu > li.menu-item-has-children {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}

.ymw-menu > li.menu-item-has-children > .sub-menu {
    flex: 0 0 100%;
    width: 100%;
}

.ymw-sub-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8em;
    height: 1.8em;
    padding: 0;
    margin-left: 4px;
    background: transparent;
    border: 0;
    color: inherit;
    cursor: pointer;
    line-height: 1;
}

.ymw-sub-toggle:focus-visible {
    outline: 2px solid var(--ymw-accent);
    outline-offset: 2px;
    border-radius: 50%;
}

.ymw-sub-toggle svg {
    width: .7em;
    height: .7em;
    transition: transform .3s ease;
}

.ymw-menu .menu-item-has-children.is-expanded > .ymw-sub-toggle svg,
.ymw-menu .menu-item-has-children.is-expanded > * > .ymw-sub-toggle svg {
    transform: rotate(180deg);
}

.ymw-menu .sub-menu {
    list-style: none;
    margin: 0;
    padding-left: 16px;
    display: flex;
    flex-direction: column;
    gap: var(--ymw-item-gap);
    overflow: hidden;
    max-height: 0;
    transition: max-height .35s ease;
}

.ymw-menu .menu-item-has-children.is-expanded > .sub-menu {
    max-height: 80vh;
}

.ymw-menu .sub-menu a {
    font-size: .85em;
    opacity: .9;
}

/* -------------------------------------------------------------------------
 * Animations d'ouverture
 * ---------------------------------------------------------------------- */

.ymw--anim-fade .ymw-panel__inner { opacity: 0; }

.ymw--anim-slide.ymw--mode-fullscreen .ymw-panel__inner,
.ymw--anim-slide.ymw--mode-dropdown .ymw-panel__inner { transform: translateY(-16px); opacity: 0; }

.ymw--anim-slide.ymw--mode-drawer.ymw--drawer-right .ymw-panel__inner { transform: translateX(100%); }
.ymw--anim-slide.ymw--mode-drawer.ymw--drawer-left  .ymw-panel__inner { transform: translateX(-100%); }

.ymw--anim-scale .ymw-panel__inner { transform: scale(.96); opacity: 0; }

.ymw.is-open .ymw-panel__inner {
    transform: none;
    opacity: 1;
}

/* Apparition échelonnée des items */
@keyframes ymw-item-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}

.ymw--stagger.is-open .ymw-menu > li {
    animation: ymw-item-in var(--ymw-anim-duration) ease both;
}

.ymw--stagger.is-open .ymw-menu > li:nth-child(1) { animation-delay: .04s; }
.ymw--stagger.is-open .ymw-menu > li:nth-child(2) { animation-delay: .08s; }
.ymw--stagger.is-open .ymw-menu > li:nth-child(3) { animation-delay: .12s; }
.ymw--stagger.is-open .ymw-menu > li:nth-child(4) { animation-delay: .16s; }
.ymw--stagger.is-open .ymw-menu > li:nth-child(5) { animation-delay: .20s; }
.ymw--stagger.is-open .ymw-menu > li:nth-child(6) { animation-delay: .24s; }
.ymw--stagger.is-open .ymw-menu > li:nth-child(7) { animation-delay: .28s; }
.ymw--stagger.is-open .ymw-menu > li:nth-child(8) { animation-delay: .32s; }
.ymw--stagger.is-open .ymw-menu > li:nth-child(n+9) { animation-delay: .36s; }

/* -------------------------------------------------------------------------
 * Verrou de défilement + message éditeur + accessibilité
 * ---------------------------------------------------------------------- */

body.ymw-scroll-lock {
    overflow: hidden;
}

.ymw-notice {
    padding: 12px 16px;
    background: #f5efe6;
    border: 1px dashed rgba(0, 59, 94, 0.4);
    color: #003B5E;
    font-family: var(--sans, sans-serif);
    font-size: 13px;
    border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
    .ymw-panel,
    .ymw-panel__inner,
    .ymw-backdrop,
    .ymw-bars span,
    .ymw-sub-toggle svg,
    .ymw-menu .sub-menu {
        transition: none !important;
    }
    .ymw--stagger.is-open .ymw-menu > li {
        animation: none !important;
    }
}
