﻿/* ============================================================
   ew-mobile-nav.css
   Off-canvas mobile navigation for EW2027.

   Loaded AFTER site.css and calmenu.css so these rules win on
   equal specificity. This file does three things:

     1. Fixes the sub-menu bugs (fixed wide/mega widths and the
        calmenu breakpoint mismatch that overflowed the panel).
     2. Turns the existing stacked hamburger menu into a proper
        slide-out (off-canvas) panel with a backdrop + scroll lock.
     3. Keeps the desktop mega-menu completely untouched.

   No new markup classes required — it reuses .site-nav /
   .nav-toggle / .nav-menu / .nav-list / .nav-item / .nav-link /
   .nav-dropdown and the existing .is-open toggling. One optional
   element (.nav-backdrop) is added by ew-layout.js.

   Breakpoint is unified at 1100px to match site.css. Everything
   below lives inside that one media query so desktop is safe.
   ============================================================ */

@media (max-width: 1100px) {

    /* ----- 1. FIX: wide/mega dropdowns must not keep desktop widths ----- */
    /* These carry two classes (.nav-dropdown.nav-dropdown-wide), so they
       out-specify site.css's single-class `.nav-dropdown { width:100% }`.
       Match that specificity here to force full width inside the panel. */
    .nav-dropdown.nav-dropdown-wide,
    .nav-dropdown.nav-dropdown-mega {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    /* mega grid already collapses to 1fr in site.css; make sure the
       inner columns can't force a min-width wider than the screen */
    .mega-menu-grid {
        grid-template-columns: 1fr;
        min-width: 0;
    }

        .mega-menu-grid > * {
            min-width: 0;
        }

    /* ----- 2. Off-canvas panel ----- */
    /* The header bar itself stays put; only .nav-menu becomes the sliding
       panel. site.css already flips .nav-menu to column + display:none and
       shows it on .is-open — we upgrade that from "block in flow" to a
       fixed, slide-in surface. */
    .nav-menu {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: auto;
        z-index: 1200;
        width: min(88vw, 400px);
        max-width: 400px;
        height: 100dvh;
        margin: 0;
        padding: 0 0 env(safe-area-inset-bottom, 0);
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        background: var(--nav-bg);
        border-left: 1px solid var(--nav-border);
        box-shadow: var(--nav-shadow);
        /* start off-screen; slide in on .is-open */
        transform: translateX(100%);
        visibility: hidden;
        transition: transform 240ms ease, visibility 0s linear 240ms;
    }

        /* site.css toggles display:flex on .is-open; keep it flex and slide in */
        .nav-menu.is-open {
            display: flex;
            transform: translateX(0);
            visibility: visible;
            transition: transform 240ms ease;
        }

    /* Sticky panel header with a title + close button.
       The close button lives in markup as .nav-menu-close (added once). */
    .nav-menu-header {
        position: sticky;
        top: 0;
        z-index: 2;
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: var(--header-height);
        padding: 0 1rem;
        background: var(--nav-bg);
        border-bottom: 1px solid var(--nav-border);
    }

    .nav-menu-title {
        color: var(--nav-gold);
        font-family: var(--font-menu);
        font-weight: 800;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        font-size: 0.9rem;
    }

    .nav-menu-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        border: 1px solid color-mix(in srgb, var(--nav-gold) 35%, transparent);
        border-radius: var(--radius);
        background: transparent;
        color: var(--nav-gold);
        font-size: 1.5rem;
        line-height: 1;
    }

        .nav-menu-close:hover,
        .nav-menu-close:focus-visible {
            color: var(--nav-gold-hover);
            background: color-mix(in srgb, var(--nav-gold) 15%, transparent);
        }

    /* list fills the panel; each row is a comfortable tap target */
    .nav-list {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        padding: 0.5rem 0.75rem 1rem;
        gap: 0.15rem;
    }

    .nav-item {
        position: static; /* no absolute anchoring inside the panel */
    }

    /* top-level rows: 48px min, chevron on the right for items with a submenu */
    .nav-link {
        width: 100%;
        min-height: 48px;
        justify-content: space-between;
        border-radius: var(--radius);
        padding: 0.75rem 0.9rem;
        font-family: var(--font-menu);
        font-size: 0.86rem;
        font-weight: 800;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    /* chevron indicator for expandable items (uses existing .nav-item-has-menu) */
    .nav-item-has-menu > .nav-link::after {
        content: "";
        width: 0.55rem;
        height: 0.55rem;
        margin-left: 0.75rem;
        border-right: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        transform: rotate(-45deg); /* points right when closed */
        transition: transform 160ms ease;
        flex: 0 0 auto;
    }

    .nav-item.is-open > .nav-link::after {
        transform: rotate(45deg); /* points down when open */
    }

    /* ----- 3. Sub-menu panels: inline accordion inside the off-canvas ----- */
    .nav-dropdown {
        position: static;
        display: none;
        width: 100%;
        min-width: 0;
        margin: 0.15rem 0 0.5rem;
        padding: 0.35rem 0.35rem 0.35rem 0.75rem;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        background: var(--nav-panel);
        border: 1px solid color-mix(in srgb, var(--nav-gold) 20%, transparent);
        border-radius: var(--radius);
    }

    .nav-item.is-open > .nav-dropdown {
        display: block;
    }

    /* sub-links: 44px tap targets */
    .nav-dropdown-link {
        min-height: 44px;
        padding: 0.6rem 0.65rem;
    }

    /* ----- Backdrop (element added by ew-layout.js) ----- */
    .nav-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1100;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 240ms ease, visibility 0s linear 240ms;
    }

        .nav-backdrop.is-open {
            opacity: 1;
            visibility: visible;
            transition: opacity 240ms ease;
        }

    /* lock the page behind the panel */
    body.nav-open {
        overflow: hidden;
    }

    /* keep the hamburger above the backdrop so it stays tappable if needed */
    .nav-toggle {
        position: relative;
        z-index: 1300;
    }
}

/* ----- 3b. FIX: unify the calmenu interior breakpoint with the nav -----
   calmenu.css only reflows its month-grid guts at 860px, but the nav goes
   mobile at 1100px — so 861–1100px showed a desktop-width calendar inside
   the narrow panel. Re-apply the calmenu mobile reflow up to 1100px. */
@media (max-width: 1100px) {
    .nav-dropdown.calmenu {
        position: static;
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        border: 1px solid color-mix(in srgb, var(--nav-gold) 20%, transparent);
        background: var(--nav-panel);
        padding: 0.5rem;
    }

    .calmenu {
        flex-direction: column;
        gap: 14px;
        width: 100%;
        max-width: 100%;
    }

        .calmenu #MonthCal1 {
            flex-direction: column;
            gap: 14px;
            width: 100%;
        }

        .calmenu .overviewselect {
            display: none;
        }

    #days ul {
        flex-wrap: wrap;
        gap: 6px;
    }

    #days li {
        flex: 1 1 90px;
        min-width: 90px;
    }

    #Cal1, #Cal2 {
        min-width: 0;
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .nav-menu,
    .nav-menu.is-open,
    .nav-backdrop {
        transition: none;
    }
}
