/**
 * ASDF mobile header & navigation drawer.
 *
 * Shipped as its own stylesheet, not just appended to style.css: header.php
 * deploys instantly while style.css is often still served from cache, and the
 * drawer markup renders naked without these rules. A distinct file URL cannot
 * be stale on an existing install.
 */

/* ===================================================================
   Mobile header & navigation drawer
   -------------------------------------------------------------------
   Replaces the old layout where .header-container used space-between on
   three children, leaving the search icon stranded in mid-air, and the
   drawer had no close button and no real backdrop (it faked one with
   box-shadow: 0 0 0 100vw, which cannot be tapped).
   =================================================================== */
.mobile-nav-head,
.mobile-nav-foot { display: none; }

.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 4, 26, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s ease;
  z-index: 999;
}
.nav-backdrop.is-visible { opacity: 1; visibility: visible; }

@media (max-width: 768px) {

  /* ---- Header row: logo left, search + burger grouped right ------- */
  .header-container {
    align-items: center;
    padding: 0 18px;
  }
  .logo-area { flex: 0 1 auto; min-width: 0; }
  .header-logo-img { height: 44px; width: auto; }

  /* margin-left:auto pins the pair to the right edge, so the search icon
     is anchored beside the burger instead of floating mid-row. */
  .header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 2px;
  }

  .search-trigger,
  .menu-toggle {
    width: 44px;               /* full 44px touch target */
    height: 44px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: transparent;
    transition: background-color 0.2s ease;
  }
  .search-trigger:active,
  .menu-toggle:active { background: var(--bg-lavender, #f4ecf5); }

  .menu-toggle {
    flex-direction: column;
    gap: 5px;
    margin-left: 4px;
  }
  .menu-toggle .bar {
    width: 22px;
    height: 2px;
    border-radius: 2px;
    background: var(--primary-purple, #5e1062);
    transition: transform 0.3s ease, opacity 0.2s ease;
  }
  /* Burger morphs into a close cross while the drawer is open. */
  .menu-toggle.active .bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .menu-toggle.active .bar:nth-child(2) { opacity: 0; }
  .menu-toggle.active .bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* ---- Drawer ----------------------------------------------------- */
  .main-nav {
    width: min(360px, 86vw);
    right: calc(-1 * min(360px, 86vw));
    padding: 0 0 calc(20px + env(safe-area-inset-bottom, 0px));
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overscroll-behavior: contain;
  }
  .main-nav.active {
    right: 0;
    /* Real backdrop element now handles the dimming, so drop the old
       0 0 0 100vw shadow hack. */
    box-shadow: -18px 0 44px rgba(20, 4, 26, 0.18);
  }

  .mobile-nav-head {
    display: flex !important; /* beats the inline display:none in header.php */
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-lavender, #dfd2e3);
    position: sticky;
    top: 0;
    background: var(--white, #fff);
    z-index: 2;
  }
  .mobile-nav-head img { height: 38px; width: auto; }

  .mobile-nav-close {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 50%;
    background: var(--bg-lavender, #f4ecf5);
    color: var(--primary-purple, #5e1062);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ---- Nav list --------------------------------------------------- */
  .nav-list { padding: 6px 0 4px; }
  .nav-list > li { width: 100%; border-bottom: 1px solid #f3eef5; }
  .nav-list > li:last-child { border-bottom: 0; }

  .nav-item {
    font-size: 16px;
    font-weight: 600;
    padding: 15px 18px;
    width: 100%;
    color: var(--text-dark, #2a252c);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .nav-item.active { color: var(--primary-purple, #5e1062); }

  /* ---- Dropdowns become accordions -------------------------------- */
  .nav-dropdown-wrap { position: relative; }
  .dropdown-trigger .chevron {
    transition: transform 0.3s ease;
    flex: 0 0 auto;
  }
  .nav-dropdown-wrap.is-open > .dropdown-trigger .chevron { transform: rotate(-135deg); }
  .nav-dropdown-wrap.is-open > .dropdown-trigger { color: var(--primary-purple, #5e1062); }

  .main-nav .nav-dropdown {
    position: static;
    width: auto;
    max-width: none;
    transform: none;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #faf7fb;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
  }
  .nav-dropdown-wrap.is-open > .nav-dropdown { max-height: 1400px; }

  /* Hover must not open the panel on touch — only the accordion class does. */
  .nav-dropdown-wrap:hover > .nav-dropdown { max-height: 0; }
  .nav-dropdown-wrap.is-open:hover > .nav-dropdown { max-height: 1400px; }

  .main-nav .dropdown-item {
    padding: 13px 18px 13px 32px;
    font-size: 14.5px;
    border-top: 1px solid #f0eaf2;
  }

  /* Mega panel collapses to a single readable column inside the drawer. */
  .main-nav .nav-dropdown.mega-menu { padding: 4px 0 10px; }
  .main-nav .mega-grid {
    grid-template-columns: 1fr !important;
    max-width: none;
    padding: 0;
    gap: 0;
  }
  .main-nav .mega-col { padding: 12px 18px; border-top: 1px solid #f0eaf2; }
  .main-nav .mega-col-title { font-size: 14.5px; gap: 10px; }
  .main-nav .mega-col-icon { width: 30px; height: 30px; border-radius: 8px; }
  .main-nav .mega-sublist { margin: 8px 0 0 40px; gap: 0; }
  .main-nav .mega-sublist a { padding: 9px 0; font-size: 14px; }
  .main-nav .mega-col-desc { margin: 6px 0 0 40px; font-size: 12.5px; }

  /* ---- Drawer footer CTA ------------------------------------------ */
  .mobile-nav-foot {
    display: block !important; /* beats the inline display:none in header.php */
    margin-top: auto;
    padding: 18px;
    border-top: 1px solid var(--border-lavender, #dfd2e3);
  }
  .mobile-nav-donate {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 14px 20px;
    border-radius: 40px;
    background: var(--primary-purple, #5e1062);
    color: var(--white, #fff);
    font-weight: 700;
    font-size: 15px;
    text-decoration: none;
    transition: background-color 0.2s ease;
  }
  .mobile-nav-donate:hover { background: var(--primary-purple-hover, #4c0a50); }

  .mobile-nav-contact {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
  }
  .mobile-nav-contact a {
    color: var(--text-light, #6d6470);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  body.nav-open { overflow: hidden; }
}

@media (max-width: 768px) {
  /* The dropdown parents are <li> that sized to their content, so "Our
     Solutions" / "Media" rendered ~174px wide while plain items filled the
     drawer — the highlight then looked like a stray floating pill. */
  .main-nav .nav-dropdown-wrap {
    display: block;
    width: 100%;
  }
  .main-nav .nav-list > li > .nav-item {
    width: 100%;
    box-sizing: border-box;
  }

  /* Full-bleed rows read cleaner in a drawer than rounded pills. */
  .main-nav .nav-item { border-radius: 0; }

  /* The expand affordance was hidden on mobile, so an accordion row looked
     identical to a plain link. */
  .main-nav .dropdown-trigger .chevron {
    display: inline-block !important; /* theme hides it with !important on mobile */
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    border-top: 0;
    border-left: 0;
    transform: rotate(45deg);
    margin-left: 10px;
    opacity: 0.55;
    transition: transform 0.3s ease, opacity 0.2s ease;
  }
  .main-nav .nav-dropdown-wrap.is-open > .dropdown-trigger .chevron {
    transform: rotate(-135deg);
    opacity: 1;
  }
}
