/* AreaWise — Mobile header navigation (≤520px)
   Compact header (logo + search icon + hamburger), expandable search that reuses
   the existing #headerSearch autocomplete, a right-side drawer, a hidden
   horizontal topic-tab bar, and hidden Leaflet zoom controls. */

/* Desktop / tablet: mobile-only controls are hidden */
.mobile-nav-actions { display: none; }
.mobile-nav-drawer,
.mobile-nav-backdrop { display: none; }
.mobile-topic-nav { display: none; }
.mobile-ai-popover,
.mobile-ai-backdrop { display: none; }
.education-fab { display: none; }
.school-top-picks--drawer { display: none; }

@media (max-width: 520px) {

  /* ── Compact header: logo left, search + menu right ── */
  .site-header .site-nav,
  .site-header .actions { display: none !important; }
  .site-header .header-search { display: none; }

  .mobile-nav-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
  }

  .mobile-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    background: transparent;
    color: var(--ink);
    border-radius: 10px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-nav-btn:hover { background: var(--surface-2); }
  .mobile-nav-btn:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
  .mobile-nav-btn svg { width: 22px; height: 22px; }

  /* ── Topic navigation bar (below header, above map; horizontal scroll) ── */
  .mobile-topic-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-padding-left: 12px;
    scroll-padding-right: 12px;
    padding: 8px 12px;
    background: #fff;
    border-bottom: 1px solid var(--line, #e5e9e6);
    scrollbar-width: none;
  }
  .mobile-topic-nav::-webkit-scrollbar { display: none; }

  .mobile-topic-chip {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: var(--surface-2, #eef1ef);
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-topic-chip.active {
    background: var(--ink, #0b1c30);
    color: #fff;
  }
  .mobile-topic-chip:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: 2px;
  }

  /* ── AI Area Insights: green sparkles icon in the header ── */
  .mobile-ai-btn { color: var(--green-strong); }
  .mobile-ai-btn:hover { color: var(--green); }

  /* ── Google sign-in: compact multicolour G icon on a clean white button ── */
  .mobile-google-btn { background: #fff; border: 1px solid #dadce0; border-radius: 50%; }
  .mobile-google-btn:hover { background: #f8f9fa; }
  .mobile-google-btn[hidden] { display: none; }

  /* One-shot attention pulse after a successful Area→Area search (never loops). */
  .mobile-ai-btn.ai-pulse { animation: ai-pulse 1.6s ease-out; }
  @keyframes ai-pulse {
    0%   { transform: scale(1); filter: none; }
    25%  { transform: scale(1.22); filter: drop-shadow(0 0 7px var(--green-strong)); }
    55%  { transform: scale(1.06); filter: drop-shadow(0 0 3px var(--green-strong)); }
    100% { transform: scale(1); filter: none; }
  }
  @media (prefers-reduced-motion: reduce) {
    .mobile-ai-btn.ai-pulse { animation: none; }
  }

  /* Remove the separate AI Area Insights row on mobile (now in the header).
     Also target #areaBackLink directly so the bundle's hidden=false (which
     re-shows the row) cannot win over this hide. */
  .ai-insights,
  #areaBackLink { display: none !important; }

  /* ── AI confirmation popover (above the map / Leaflet) ── */
  body.mobile-ai-open { overflow: hidden; }

  .mobile-ai-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .42);
    z-index: 7000;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
  }
  .mobile-ai-backdrop.open { opacity: 1; visibility: visible; }

  .mobile-ai-popover {
    display: block;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(340px, calc(100vw - 32px));
    z-index: 7001;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 18px 50px rgba(16, 24, 40, .28);
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
  }
  .mobile-ai-popover.open { opacity: 1; visibility: visible; }

  .mobile-ai-title { margin: 0 0 8px; font-size: 18px; font-weight: 800; color: var(--ink); }
  .mobile-ai-message { margin: 0 0 18px; font-size: 14px; line-height: 1.5; color: var(--muted); }
  .mobile-ai-actions { display: flex; gap: 10px; justify-content: flex-end; }
  .mobile-ai-cancel,
  .mobile-ai-confirm {
    min-height: 44px;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-ai-cancel { background: var(--surface-2, #f3f6f4); border: 1px solid var(--line, #e1e7e3); color: var(--ink); }
  .mobile-ai-confirm { background: var(--green); border: 1px solid var(--green); color: #fff; }
  .mobile-ai-cancel:focus-visible,
  .mobile-ai-confirm:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

  @media (prefers-reduced-motion: reduce) {
    .mobile-ai-backdrop,
    .mobile-ai-popover { transition: none; }
  }

  /* Search icon ⇄ close icon when the panel is open */
  .mobile-search-close { display: none; }
  .site-header.search-open .mobile-search-icon { display: none; }
  .site-header.search-open .mobile-search-close { display: block; }

  /* ── Expandable search (drops below the sticky header) ── */
  .site-header.search-open .header-search {
    display: flex;
    position: absolute;
    top: calc(100% + 6px);
    left: 15px;
    right: 15px;
    height: 48px;
    z-index: 1400;
    background: var(--surface);
    border-color: var(--line);
    box-shadow: 0 12px 32px rgba(16, 24, 40, .18);
  }
  .site-header.search-open .header-search input { font-size: 16px; }
  .site-header.search-open .header-search .suggestions { top: 52px; }

  /* ── Hamburger drawer ── */
  body.mobile-nav-open { overflow: hidden; }

  .mobile-nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .42);
    z-index: 6000;
    opacity: 0;
    visibility: hidden;
    transition: opacity .24s ease, visibility .24s ease;
  }
  .mobile-nav-backdrop.open { opacity: 1; visibility: visible; }

  .mobile-nav-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 84vw;
    width: min(84vw, 320px);
    max-width: 100%;
    background: var(--surface);
    z-index: 6001;
    transform: translateX(105%);
    visibility: hidden;
    transition: transform .26s ease, visibility .26s ease;
    box-shadow: -18px 0 45px rgba(16, 24, 40, .18);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav-drawer.open { transform: translateX(0); visibility: visible; }

  .mobile-nav-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--line);
  }
  .mobile-nav-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--navy);
    letter-spacing: -.01em;
  }
  .mobile-nav-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    font-size: 26px;
    line-height: 1;
    color: var(--ink);
    border-radius: 10px;
    cursor: pointer;
  }
  .mobile-nav-close:hover { background: var(--surface-2); }

  .mobile-nav-list {
    display: flex;
    flex-direction: column;
    padding: 8px 10px 20px;
  }

  .mobile-nav-group {
    display: block;
    padding: 14px 16px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .mobile-nav-item {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 8px;
    padding: 13px 16px;
    border: 0;
    background: transparent;
    text-align: left;
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
  }
  .mobile-nav-item:hover { background: var(--surface-2); }
  .mobile-nav-item:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
  .mobile-nav-item.active { background: var(--green-soft); color: var(--green-strong); }
  .mobile-google-item { align-items: center; gap: 10px; font-weight: 600; }
  .mobile-google-item svg { width: 18px; height: 18px; flex: 0 0 auto; }

  .mobile-account-user { padding: 12px 16px 4px; }
  .mobile-account-user b { display: block; font-size: 15px; color: var(--navy); }
  .mobile-account-user span { display: block; font-size: 12.5px; color: var(--muted); }

  /* ── Remove the horizontal topic-tab bar below the map ── */
  .area-tabs-shell { display: none !important; }

  /* Land topic content below the sticky header after menu selection */
  .area-tab-stage { scroll-margin-top: 78px; }
  body.ws-schools-active .school-mobile-details .school-profile-head { scroll-margin-top: 78px; }
  body.ws-schools-active .school-mobile-details .school-accordion > summary { scroll-margin-top: 78px; }

  /* ── Hide Leaflet zoom controls; keep pinch/drag/selection ── */
  .leaflet-control-zoom { display: none !important; }

  /* ── Floating Education control (replaces the horizontal map trigger) ── */
  body.ws-schools-active .school-drawer-trigger { display: none !important; }
  body.ws-schools-active #schoolTopPicks { display: none !important; }

  /* Remove the large floating school cards (carousel) from the mobile map —
     markers, popups and the Education drawer stay. */
  body.ws-schools-active .school-map-carousel-shell { display: none !important; }

  /* ── School filter chips: drop the legacy 58px zoom-control offset and give a
     clean 12px inset. Chips scroll within their own strip — never the page. ── */
  body.ws-schools-active .school-map-tools {
    left: 12px !important;
    right: 12px !important;
  }
  body.ws-schools-active .school-map-filters {
    min-width: 0;
    -webkit-overflow-scrolling: touch;
    scroll-padding-left: 12px;
    scroll-padding-right: 12px;
  }

  /* ── Taller Education map: fill the first screen (dvh with vh fallback) so the
     Selected School section begins near the bottom of the viewport. The offset
     now covers the ~70px header + ~61px topic bar + ~56px 'SELECTED SCHOOL' peek
     (the separate AI Insights row is gone). ── */
  body.ws-schools-active .area-map-top #areaMap {
    height: 56vh !important;
    height: calc(100dvh - 187px) !important;
    min-height: 390px !important;
    max-height: 760px !important;
  }

  .education-fab {
    position: fixed;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2000;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 9px;
    background: var(--navy, #10233d);
    color: #fff;
    border: 0;
    border-radius: 999px;
    box-shadow: 0 6px 20px rgba(16, 24, 40, .28);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  body.ws-schools-active .education-fab { display: flex; }
  .education-fab:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
  .education-fab.is-hidden { display: none !important; }

  .education-fab-label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
  }
  .education-fab-count {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    background: #fff;
    color: var(--navy, #10233d);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
  }

  .education-fab { transition: background-color .2s ease, padding .2s ease, box-shadow .2s ease, border-radius .2s ease; }

  /* Scroll-aware compact mode: past 120px the tab shrinks to a circular count
     indicator pinned near the bottom-left corner (safe-area aware). */
  .education-fab.is-compact {
    top: auto;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    transform: none;
    padding: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 50%;
    gap: 0;
  }
  .education-fab.is-compact .education-fab-label { display: none; }
  .education-fab.is-compact .education-fab-count {
    min-width: 48px;
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    background: var(--navy, #10233d);
    color: #fff;
    font-size: 16px;
    font-weight: 800;
    box-shadow: 0 6px 20px rgba(16, 24, 40, .28);
  }
  @media (prefers-reduced-motion: reduce) { .education-fab { transition: none; } }

  /* ── AreaWise Picks group inside the Nearby Education drawer ── */
  .school-top-picks--drawer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 2px;
    border-bottom: 1px solid #edf1ef;
  }
  .school-top-picks--drawer .tp-head {
    padding: 2px 6px;
    text-transform: none;
    letter-spacing: 0;
    white-space: normal;
    color: var(--green-strong, #087a3c);
  }
  .school-top-picks--drawer .tp-chip {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    white-space: normal;
    text-align: left;
  }
  .school-top-picks--drawer .tp-chip b { flex: 0 0 auto; }
  .school-top-picks--drawer .tp-chip span { text-align: right; }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-nav-drawer,
  .mobile-nav-backdrop { transition: none; }
}
