/**
 * nav-menu.css — JS-enhanced navigation layer   (issue #84)
 *
 * This file is ONLY loaded alongside nav-menu.js.  Every rule here depends on
 * a class or attribute set by JavaScript; none of them are meaningful without
 * the script.  Structural nav CSS (colours, layout, dropdown boxes) lives in
 * style.css and functions as the no-JS fallback.
 *
 * Enqueued by functions.php with 'michael-cards-pro-style' as a dependency.
 */

/* ==========================================================================
   0. MOBILE / TOUCH BASELINE
   Applied as soon as JS enhances the nav.
   ========================================================================== */

/* Eliminate the 300ms synthetic-click delay on iOS Safari for the entire nav.
   touch-action:manipulation still allows panning (scrolling long sub-menus) but
   disables double-tap zoom so taps are dispatched immediately. */
.main-navigation.js-nav-enhanced {
    touch-action: manipulation;
}

/* Issue #64 / mobile regression: safe CSS default for flyout sub-menus.
   When .menu-open is first added, the sub-menu flashes at its stylesheet
   default position (left:100% from style.css ul ul ul) for one frame before
   positionSubmenu() fires in requestAnimationFrame.  On narrow viewports
   left:100% pushes the flyout off-screen right.
   Override to right-anchor (right:0; left:auto) so the flyout stays within
   the viewport even before JS sets the final position.
   Specificity 0,5,0 beats style.css .main-navigation ul ul ul (0,1,3).
   positionSubmenu() overrides this safely via inline styles:
     sub.style.right = 'auto'; sub.style.left = '…px'; */
.main-navigation.js-nav-enhanced .menu-item-has-children > .sub-menu .sub-menu {
    right: 0;
    left: auto;
}

/* ==========================================================================
   1. NO-JS FALLBACK SUPPRESSION
   Once nav-menu.js runs it adds .js-nav-enhanced to <nav>.  These rules kill
   the CSS pseudo-element arrows and CSS-:hover menus so JS is the sole driver.
   ========================================================================== */

/* Suppress ::after chevrons injected by style.css — JS injects real .menu-arrow elements instead */
.main-navigation.js-nav-enhanced .menu-item-has-children > a::after {
    display: none;
}
.main-navigation.js-nav-enhanced ul ul .menu-item-has-children > a::after {
    display: none;
}

/* style.css shifts padding-left from 24px → 30px on hover, causing text reflow.
   Hold it at the base value so only colour/border change on hover. */
.main-navigation.js-nav-enhanced ul ul a:hover {
    padding-left: 24px;
}

/* Issue #93: reduce all menu item vertical padding by 30%.
   style.css is not intercepted, so we override here with js-nav-enhanced specificity. */
.main-navigation.js-nav-enhanced ul > li > a {
    padding-top: 14px;    /* was 20px */
    padding-bottom: 14px;
}
.main-navigation.js-nav-enhanced ul ul a {
    padding-top: 11px;    /* was 16px */
    padding-bottom: 11px;
}

/* Issue #93: overflow menu items need enough right padding to clear the
   position:absolute .menu-arrow--nested button (min-width:34px + 8px padding = ~50px).
   style.css sets only 24px, causing text to intrude into the arrow touch area. */
.main-navigation.js-nav-enhanced .pq-overflow-menu > li > a {
    padding-right: 52px;  /* matches portaled sub — clears arrow touch area */
}

/* JS is now the sole authority for sub-menu visibility.
   CSS :hover would still show menus; this kills it while JS is present.
   Specificity (0,5,0) beats the li:hover > ul rule (0,2,2). */
.main-navigation.js-nav-enhanced .menu-item-has-children:not(.menu-open) > .sub-menu {
    display: none !important;
}

/* ==========================================================================
   2. OPEN-STATE STYLING
   Applied to root items when .menu-open or .panel-open is set by JS.
   ========================================================================== */

/* Root item link stays red while its flyout is open (not just while hovered) */
.main-navigation .nav-inner > ul > li.menu-open > a,
.main-navigation .nav-inner > ul > li.panel-open > a {
    background: #c41e3a;
    color: white;
}

/* Show sub-menu when JS has toggled .menu-open */
.main-navigation .menu-item-has-children.menu-open > .sub-menu {
    display: flex !important;
}

/* ==========================================================================
   3. INJECTED ARROW INDICATORS
   nav-menu.js injects two kinds of arrow:
     .menu-arrow--top    <span> appended inside top-level <a>
     .menu-arrow--nested <button> inserted after sub-level <a>
   ========================================================================== */

/* TOP-LEVEL ARROW — sits inline after the label text inside the <a>.
   Rotates ▼ → ▲ when the menu is open (.menu-open on the parent <li>). */
.main-navigation .nav-inner > ul > li > a > .menu-arrow--top {
    display: inline-block;
    margin-left: 8px;
    opacity: 0.85;
    transition: transform 0.3s ease;
    vertical-align: middle;
}
.main-navigation .nav-inner > ul > li > a > .menu-arrow--top > svg {
    display: block;  /* no inline baseline gap */
    width: 0.65em;
    height: 0.65em;
}
/* ARROW_MODE='glyph': size the icon span to match the svg path's visual weight */
.main-navigation .nav-inner > ul > li > a > .menu-arrow--top > .menu-arrow-icon {
    display: inline-block;
    font-size: 0.65em;
    line-height: 1;
}
.main-navigation .nav-inner > ul > li.menu-open > a > .menu-arrow--top {
    transform: rotate(180deg);
}

/* NESTED ARROW BUTTON — position:absolute on the right of each dropdown row.
   Independent touch target: expands submenus without following the link (req #12). */
.main-navigation .menu-arrow--nested {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    min-width: 34px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #888;
    z-index: 1;
    transition: color 0.3s ease;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    touch-action: manipulation;
    font-size: inherit; /* em on child svg resolves against row font-size, not UA button default */
}
/* Nested arrows point right by default (▶), flip left (◀) when expanded —
   same 180° rotation convention as the top-level ▼→▲ arrow.
   Size set here in CSS em — resolves against the inherited font-size of the button
   consistently on all platforms (unlike SVG attribute em on iOS Safari). */
.main-navigation .menu-arrow--nested > svg {
    transform: rotate(-90deg);
    display: block;
    flex-shrink: 0;
    width: 0.65em;
    height: 0.65em;
}
/* ARROW_MODE='glyph': size the icon span to match the svg path's visual weight.
   display:inline-block is required for transform to apply to an inline element.
   Rotates ▼ → ▶ (right-pointing) on default, ◀ (left-pointing) when expanded. */
.main-navigation .menu-arrow--nested > .menu-arrow-icon {
    display: inline-block;
    font-size: 0.65em;
    line-height: 1;
    pointer-events: none;
    transform: rotate(-90deg);
    transition: transform 0.3s ease;
}
.main-navigation ul ul li:hover > .menu-arrow--nested,
.main-navigation ul ul li.menu-open > .menu-arrow--nested {
    color: #c41e3a;
}
.main-navigation ul ul li.menu-open > .menu-arrow--nested > .menu-arrow-icon {
    transform: rotate(90deg);
}
.main-navigation .menu-arrow--nested:hover {
    background: rgba(196, 30, 58, 0.1);
    color: #c41e3a;
}
.main-navigation .menu-arrow--nested[aria-expanded="true"] {
    background: rgba(196, 30, 58, 0.14);
    color: #c41e3a;
}
.main-navigation .menu-arrow--nested:focus {
    outline: 2px solid rgba(255,255,255,0.6);
    outline-offset: 2px;
}

/* ==========================================================================
   4. DRAG-MODE HIGHLIGHT   (req #14)
   Items under the cursor glow during a press-and-drag.
   CSS :hover covers desktop; the class handles touch drag.
   ========================================================================== */
.main-navigation .menu-drag-highlight > a {
    background: #c41e3a !important;
    color: white !important;
}

/* ==========================================================================
   5. OVERFLOW MENU — JS AUTHORITY
   JS is now the sole authority for overflow visibility.
   Without this, closeOverflow()'s state would be overridden by CSS :hover.
   ========================================================================== */

/* Suppress CSS :hover on overflow — JS (.pq-open) is the only show/hide signal */
.main-navigation.js-nav-enhanced .pq-overflow-item:not(.pq-open) .pq-overflow-menu {
    display: none !important;
}
/* Cloned items: nav-menu.js clears inline display:none before appending,
   so only the .pq-open container rule (in style.css) is needed. */
.pq-overflow-item.pq-open .pq-overflow-menu > li {
    display: block !important;
}

/* ==========================================================================
   6. QUERY-CARDS MEGA-PANEL   (issue #23 / #15)
   CSS class "query-cards" = internal hook. User-visible label = "Ask Cards".
   Panel visibility is driven by .is-open (JS) and .panel-open (JS).
   ========================================================================== */

/* Issue #15 / #94 — card-back icon left of the Ask Cards nav label.
   Uses the actual card-back image. functions.php can override background-image
   via wp_add_inline_style when tcard_options['image_back'] is set. */
.main-navigation .menu-item.query-cards > a::before,
.main-navigation .menu-item.query-cards > span::before {
    content: '';
    display: inline-block;
    /* Size = two lines of nav text (font-size 15px × line-height 1.2 × 2 lines) + 10%.
       Width is proportional to the card-back image aspect ratio.
       functions.php always injects the real card-back URL via wp_add_inline_style,
       overriding this fallback SVG. */
    width: 1.65em;  /* 2.64em × 0.625 (card aspect ratio) ≈ 24.75 px at 15 px font-size */
    height: 2.64em; /* (2 lines × 1.2 line-height × 1em) × 1.1 ≈ 39.6 px at 15 px font-size */
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 16'%3E%3Crect width='10' height='16' rx='1.5' fill='%23800020'/%3E%3Crect x='.75' y='.75' width='8.5' height='14.5' rx='1' fill='none' stroke='%23c8a000' stroke-width='.6'/%3E%3Cpath d='M5 3.5L7 6.5L5 9.5L3 6.5Z' fill='%23c8a000'/%3E%3Cpath d='M5 6.5L7 9.5L5 12.5L3 9.5Z' fill='%23c8a000'/%3E%3C/svg%3E") no-repeat center;
    background-size: contain;
    margin-right: 6px;
    vertical-align: middle;
    align-self: center;
    flex-shrink: 0;
    opacity: 0.85;
    transition: opacity 0.15s;
}
.main-navigation .menu-item.query-cards.panel-open > a::before,
.main-navigation .menu-item.query-cards.panel-open > span::before {
    opacity: 1;
}

/* Panel container — positioned relative to .nav-inner */
.nav-inner {
    position: relative;
}
.query-cards-panel {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 9999;
    background: #E3F2FD;
    border-top: 3px solid #90CAF9;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    border-radius: 0 0 8px 8px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    visibility: hidden;
}
.query-cards-panel.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    visibility: visible;
}
.query-cards-panel-inner {
    position: relative;
    max-width: 520px;
    margin: 0 auto;
    padding: 32px 24px 28px;
}
.query-cards-panel-title {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #c41e3a;
    margin: 0 0 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}
.query-cards-panel-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 18px;
    color: #888;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
.query-cards-panel-close:hover,
.query-cards-panel-close:focus {
    color: #c41e3a;
    background: rgba(196, 30, 58, 0.07);
}
.main-navigation .menu-item.query-cards.panel-open > a,
.main-navigation .menu-item.query-cards.panel-open > span {
    background: #c41e3a;
    color: #ffffff;
}

@media (max-width: 768px) {
    .query-cards-panel {
        /* Keep position:absolute (from base rule) so the panel overlays content
           instead of flowing in-document and pushing page content down. */
        border-radius: 0;
        transform: none;
        transition: opacity 0.2s ease, visibility 0.2s ease;
    }
    .query-cards-panel.is-open {
        transform: none;
    }
}

/* Ask Cards flyout — form element overrides (Issue #22) */
.query-cards-panel-form .mtarot-form {
    width: 100%;
    box-sizing: border-box;
}
.query-cards-panel-form .mtarot-form center {
    display: block;
    text-align: center;
}
.query-cards-panel-form select#tlayout {
    max-width: 100%;
    width: 100%;
    padding: 6px 10px;
    font-size: 0.9rem;
    border: 1px solid #90CAF9;
    border-radius: 4px;
    margin-bottom: 10px;
    background-color: #EFF8FF;
}
.query-cards-panel-form .mtarot-question-prompt {
    font-size: 0.875rem;
    color: #555;
    margin: 8px 0;
}
.query-cards-panel-form .mtarot-question {
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box;
    padding: 8px 12px;
    font-size: 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin: 4px 0 10px;
    display: block !important;
    text-align: left !important;
}
.query-cards-panel-form .mtarot-ask {
    background: #c41e3a;
    color: #ffffff;
    border: none;
    padding: 10px 28px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 4px;
    transition: background 0.15s ease;
}
.query-cards-panel-form .mtarot-ask:hover,
.query-cards-panel-form .mtarot-ask:focus {
    background: #a3172f;
}

/* ==========================================================================
   7. VERTICAL SCROLL-CLAMPED SUBMENUS   (issue #92)
   When positionSubmenu() determines a flyout is too tall for the viewport:
     · adds .sub-menu--clamped and --nmm-sub-clamp via inline style
     · appends .nmm-scroll-arrow--up / --down <div> elements to document.body
       with position:fixed, sized and placed at the sub-menu's top/bottom edges
   Arrows are completely outside the <ul> scroll container so they can never
   overlap menu items and never affect scrollHeight or scrollTop.
   ========================================================================== */

/* Clamped container: scroll internally, suppress native scrollbar. */
.sub-menu.sub-menu--clamped {
    max-height: var(--nmm-sub-clamp, 200px) !important;
    overflow-y: auto !important;
    overflow-anchor: none;
    scrollbar-width: none;    /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}
.sub-menu.sub-menu--clamped::-webkit-scrollbar {
    display: none;            /* Chrome/Safari */
}

/* Fixed-position scroll arrows — injected into document.body by JS.
   All layout is set via inline styles; these rules provide the hover state
   and ensure display:flex when JS sets display. */
.nmm-scroll-arrow {
    display: flex; /* overridden to none by JS at boundaries */
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
}

/* ==========================================================================
   8. PORTALED SUB-SUBMENUS   (issue #115 — iOS Safari compositing clip)

   On iOS Safari, position:fixed descendants of position:fixed ancestors are
   clipped at the parent's compositing layer boundary.  positionSubmenu() fixes
   this by teleporting nested subs into a neutral portal host on <body> and
   marking them with .sub-menu--portaled.

   Rules here are depth-generic: they match any portaled sub at any nesting
   level.  They must not rely on nav DOM ancestry (there is none in the host).
   ========================================================================== */

/* Box styling — JS overrides display with inline display:flex when shown. */
.sub-menu--portaled {
    display: none;
    flex-direction: column;
    background: #ffffff;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    border-top: none;
    border-left: 4px solid #c41e3a;
    border-radius: 0 8px 8px 0;
    min-width: 200px;
    max-width: min(300px, calc(100vw - 40px));
    overflow: visible;
}

/* Direct children of any portaled sub. */
.sub-menu--portaled > li {
    display: flex;
    align-items: center;
    width: 100%;
    border-bottom: 1px solid #f0f0f0;
    position: relative;
}
.sub-menu--portaled > li:last-child {
    border-bottom: none;
}
.sub-menu--portaled > li > a {
    flex: 1;
    min-width: 0;
    padding: 11px 52px 11px 16px;  /* right side clears the 44px arrow + 8px gap; 11px matches ul ul a vertical padding (issue #93) */
    color: #1a1a1a;
    font-size: 14px;
    text-transform: none;
    font-weight: 600;
    display: block;
    background: transparent;
    border-left: 4px solid transparent;
    text-decoration: none;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.sub-menu--portaled > li > a:hover,
.sub-menu--portaled > li > a:focus {
    background: #f8f8f8;
    color: #c41e3a;
    border-left-color: #c41e3a;
}
.sub-menu--portaled > li > .menu-arrow--nested {
    font-size: inherit;
    position: static;        /* override position:absolute from .main-navigation context */
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
    padding: 0;
    /* Reset browser default <button> chrome */
    border: none;
    border-radius: 0;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    touch-action: manipulation;
}
.sub-menu--portaled > li > .menu-arrow--nested > svg {
    transform: rotate(-90deg);
    display: block;
    flex-shrink: 0;
    pointer-events: none;
    width: 0.65em;
    height: 0.65em;
}
/* ARROW_MODE='glyph' */
.sub-menu--portaled > li > .menu-arrow--nested > .menu-arrow-icon {
    display: inline-block;
    font-size: 0.65em;
    line-height: 1;
    pointer-events: none;
    transform: rotate(-90deg);
    transition: transform 0.3s ease;
}
.sub-menu--portaled > li.menu-open > .menu-arrow--nested > .menu-arrow-icon {
    transform: rotate(90deg);
}
.sub-menu--portaled > li:hover > .menu-arrow--nested,
.sub-menu--portaled > li.menu-open > .menu-arrow--nested {
    color: #c41e3a;
}

/* Sub-menus nested INSIDE a portaled sub that haven't been portaled yet
   (no .main-navigation ancestor means the normal hide rule never fires).
   Use plain display:none (no !important) so JS inline display:flex wins
   the moment positionSubmenu() portals and shows the sub. */
.sub-menu--portaled .sub-menu:not(.sub-menu--portaled) {
    display: none;
}

