/* ==========================================================================
   Mobile Navigation Drawer (LYC-160 / REQ-39 / FR-28)

   The drawer is a right-side panel, 320px wide, that slides in below 1024px.
   It replaces the desktop mega-menu overlay on mobile. All surfaces use
   semantic tokens from _tokens.css; no raw hex, px font sizes, or font family
   strings appear below.
   ========================================================================== */

/* Base (closed / desktop): keep the markup in the DOM so JS + screen readers
   can reach it, but fully hide visually when the viewport is >=1024px. The
   [hidden] attribute already hides it on page load; this keeps it hidden when
   JS toggles it off on desktop too. */
.mobile-drawer {
  display: none;
}

.mobile-drawer[hidden] {
  display: none;
}

/* ---- Mobile viewport: drawer active ---- */
@media (max-width: 1023px) {

  .mobile-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(320px, 88vw);
    max-width: 320px;
    height: 100dvh;
    background: var(--color-quarter-white);
    color: var(--color-black);
    z-index: 1100; /* above mega-menu (1000) and sticky header */
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: -12px 0 32px rgba(4, 5, 3, 0.18);
    border-left: 1px solid var(--color-rule);
    transform: translateX(100%);
    transition: transform 300ms ease;
    display: flex;
    flex-direction: column;
    padding: 24px 22.5px 32px;
    gap: 22px;
  }

  .mobile-drawer[hidden] {
    /* Keep it off-canvas before JS runs; screen-reader hidden too. */
    display: none;
  }

  /* Slide in when JS removes the [hidden] attribute and adds drawer-open. */
  body.drawer-open .mobile-drawer:not([hidden]) {
    transform: translateX(0);
  }

  /* Body scroll lock while drawer is open. */
  body.drawer-open {
    overflow: hidden;
    touch-action: none;
  }

  /* Respect reduced motion: no slide animation. */
  @media (prefers-reduced-motion: reduce) {
    .mobile-drawer {
      transition: none;
    }
  }

  /* -- Close button (top-right) --
   * Wired via data-drawer-close, handled by mobile-nav.js:244. Absolutely
   * positioned so it sits above the scrolling nav list without consuming
   * list vertical space. 44x44 hit target per LYC-561 mobile parity. */
  .mobile-drawer__close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    padding: 0;
    color: var(--color-black);
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.15s ease, color 0.15s ease;
    z-index: 2;
  }
  .mobile-drawer__close:hover,
  .mobile-drawer__close:focus-visible {
    background: rgba(4, 5, 3, 0.06);
    color: var(--color-claret);
  }
  .mobile-drawer__close:focus-visible {
    outline: 2px solid var(--color-claret);
    outline-offset: 2px;
  }
  .mobile-drawer__close svg {
    display: block;
  }

  /* -- Inner nav wrapper -- */
  .mobile-drawer .mobile-nav {
    display: block;
    flex: 1 1 auto;
    /* Add top padding so the first nav item clears the absolutely-positioned
     * close button. */
    padding-top: 56px;
  }

  .mobile-drawer .mobile-nav ul,
  .mobile-drawer .mobile-nav li {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  /* -- Top-level items -- */
  .mobile-nav__item {
    border-bottom: 1px solid var(--color-rule);
  }

  .mobile-nav__link,
  .mobile-submenu-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: var(--btn-height);
    padding: 14px 4px;
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: var(--text-lg);
    line-height: var(--leading-snug);
    color: var(--color-black);
    background: transparent;
    border: 0;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
  }

  .mobile-nav__link:hover,
  .mobile-submenu-toggle:hover {
    color: var(--color-accent);
  }

  .mobile-nav__link:focus-visible,
  .mobile-submenu-toggle:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: var(--tag-radius);
  }

  /* LYC-607: Registry-A driven category cards in the drawer. Mirrors the
   * desktop mega-menu grid (icon + eyebrow + name) but stacks one per row
   * to fit the mobile viewport. */
  .mobile-nav__eyebrow {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 0 4px 12px;
    border-bottom: 1px solid var(--color-rule-strong, var(--color-rule));
    margin-bottom: 4px;
  }
  .mobile-nav__eyebrow-label {
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-shuttle-gray);
  }
  .mobile-nav__eyebrow-link {
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-claret);
    text-decoration: none;
    white-space: nowrap;
  }
  .mobile-nav__eyebrow-link:hover,
  .mobile-nav__eyebrow-link:focus-visible {
    text-decoration: underline;
  }

  .mobile-nav__list--categories {
    margin-bottom: 8px;
  }
  .mobile-nav__list--utility {
    border-top: 1px solid var(--color-rule);
    padding-top: 4px;
    margin-top: 8px;
  }

  .mobile-nav__link--category {
    align-items: center;
    gap: 14px;
    padding: 12px 4px;
    justify-content: flex-start;
  }
  .mobile-nav__icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    color: var(--color-claret);
  }
  .mobile-nav__cat-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 1 auto;
    min-width: 0;
  }
  .mobile-nav__eyebrow-tag {
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-shuttle-gray);
    line-height: 1.2;
  }
  .mobile-nav__name {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: var(--text-lg);
    line-height: 1.2;
    color: var(--color-black);
  }
  .mobile-nav__link--category:hover .mobile-nav__name,
  .mobile-nav__link--category:focus-visible .mobile-nav__name {
    color: var(--color-claret);
  }

  /* Chevron rotates when expanded. */
  .mobile-submenu-toggle__chevron {
    flex-shrink: 0;
    margin-left: 12px;
    color: var(--color-text-muted);
    transition: transform 200ms ease;
  }

  .mobile-submenu-toggle[aria-expanded="true"] .mobile-submenu-toggle__chevron {
    transform: rotate(180deg);
    color: var(--color-accent);
  }

  .mobile-submenu-toggle[aria-expanded="true"] {
    color: var(--color-accent);
  }

  @media (prefers-reduced-motion: reduce) {
    .mobile-submenu-toggle__chevron {
      transition: none;
    }
  }

  /* -- Sub-level (accordion panel) -- */
  .mobile-submenu {
    padding: 4px 0 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-left: 2px solid var(--color-rule);
    margin: 0 0 10px 8px;
  }

  .mobile-submenu[hidden] {
    display: none;
  }

  .mobile-nav__child-link {
    display: block;
    padding: 10px 8px;
    min-height: var(--btn-height);
    font-family: var(--font-ui);
    font-weight: 400;
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--color-text-muted);
    text-decoration: none;
  }

  .mobile-nav__child-link:hover {
    color: var(--color-accent);
  }

  .mobile-nav__child-link:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: var(--tag-radius);
  }

  /* -- Drawer CTA block at the bottom -- */
  .mobile-drawer-cta {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--color-rule);
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .mobile-drawer-cta .btn,
  .mobile-drawer-cta a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: var(--btn-height);
    padding: 12px 18px;
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: var(--text-base);
    line-height: var(--leading-snug);
    border-radius: var(--btn-radius);
    text-decoration: none;
  }

  .mobile-drawer-cta .btn-primary {
    background: var(--color-accent);
    color: var(--color-white);
    border: var(--btn-border) solid var(--color-accent);
  }

  .mobile-drawer-cta .btn-primary:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
  }

  .mobile-drawer-cta .btn-primary:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
  }
}

/* Above the mobile breakpoint: the drawer stays hidden regardless of JS. */
@media (min-width: 1024px) {
  .mobile-drawer {
    display: none !important;
  }

  body.drawer-open {
    overflow: auto;
    touch-action: auto;
  }
}
