﻿/* ============================================================
   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;
    }

    /* ----- 4. Header search + panel running order -----
       Markup order inside .nav-menu is  .nav-list -> #themeToggle -> .nav-utility,
       and .nav-utility wraps the social list (the search is moved to the header bar
       by ew-nav-search.js). .nav-utility is dissolved with display:contents so the
       socials can be ordered independently. Desktop is untouched: this whole block
       lives inside the 1100px query. */
    .nav-utility {
        display: contents;
    }

    /* The search is relocated INTO the header bar by ew-nav-search.js (it can't be
       moved there with CSS — .nav-menu is fixed + transformed, so it's a containing
       block its children can't escape). These rules style it in that position. */
    .site-nav > .ticker-search.ticker-search-inbar {
        flex: 1 1 auto;
        width: auto;
        min-width: 0;
        max-width: 22rem;
        margin: 0 0.75rem;
    }

    .site-nav > .ticker-search-inbar .ticker-search-box {
        width: 100%;
    }

    /* suggestion list hangs off the form, which now sits in the bar */
    .site-nav > .ticker-search-inbar .ticker-results {
        left: 0;
        right: 0;
        width: 100%;
    }

    .nav-list {
        order: 0;
    }

    /* directly below Dashboard, matching the row inset of the links above it */
    #themeToggle.theme-toggle {
        order: 1;
        align-self: flex-start;
        margin: 0 0 0.5rem 1.4rem;
    }

    /* socials stay at the bottom of the panel */
    .nav-utility .social-links {
        order: 2;
        margin-top: auto;
        justify-content: center;
        padding: 1rem 0.75rem calc(1rem + env(safe-area-inset-bottom, 0));
    }
}

/* ----- 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;
    }
}


/* ============================================================
   5. Header layout on mobile
   ------------------------------------------------------------
   ONE ROW: logo, search, hamburger.

   ew-nav-search.js relocates #getWhisper into .site-nav between the logo and
   the toggle, which is exactly the order wanted — the problem was that the
   search kept its desktop width, so it wrapped to its own line and pushed the
   hamburger down to a third. Here it shrinks to whatever is left between the
   two fixed items instead.
   ============================================================ */

@media (max-width: 1100px) {
    .site-nav {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        gap: 10px;
    }

    .site-logo {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
    }

    .nav-toggle {
        flex: 0 0 auto;
        margin-left: 0;
    }

    /* Takes the middle and gives it up first. min-width:0 is what actually lets
       it shrink — without it a flex item refuses to go below its content width,
       which is what forced the wrap. */
    #getWhisper {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none;
        margin: 0;
    }

        #getWhisper form,
        #getWhisper .nav-search,
        #getWhisper > div {
            width: 100%;
            min-width: 0;
        }

        #getWhisper input,
        #getWhisper .nav-search-input,
        #getWhisper input[type="text"],
        #getWhisper input[type="search"] {
            width: 100%;
            min-width: 0;
            height: 36px;
            padding-top: 0;
            padding-bottom: 0;
            font-size: 14px;
        }

        #getWhisper button,
        #getWhisper .nav-search-go {
            flex: 0 0 auto;
            height: 26px;
            min-width: 38px;
            padding: 0 10px;
            font-size: 11.5px;
        }

    /* the menu still drops below, full width */
    .nav-menu {
        flex: 1 1 100%;
    }
}

/* Below this the three-up row gets tight, so the placeholder goes short rather
   than the field going away. */
@media (max-width: 430px) {
    .site-nav {
        gap: 8px;
    }

    #getWhisper input,
    #getWhisper .nav-search-input,
    #getWhisper input[type="text"],
    #getWhisper input[type="search"] {
        height: 34px;
        font-size: 13px;
    }

    #getWhisper button,
    #getWhisper .nav-search-go {
        min-width: 32px;
        padding: 0 8px;
    }
}
