@use '../abstracts' as *;

// ============================================================
// Site header — the same on every view
// ============================================================

.min-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  max-width: 680px; // the home's text column; the same column on every view
  padding: 6px 0 0;
  margin: 0 auto 88px;

  @include below(mobile) {
    margin-bottom: 56px;
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }
}

.min-brand {
  margin: 0;
  font-family: $font-serif;
  font-size: 19px;
  font-weight: 400;
  line-height: inherit;

  a {
    color: var(--ink);
    text-decoration: none;
  }
}

// A logo, when set, replaces the name
.custom-logo-link {
  display: block;
  line-height: 0;
}

.custom-logo {
  width: auto;
  max-height: 44px;
}

// ---- Menu (wp_nav_menu, all levels) ----
// A top-level parent opens one panel below it; deeper levels sit indented
// inside the same panel, so nothing flies out sideways (inc/navigation.php).
.min-nav {
  .menu {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 22px;
    list-style: none;

    @include below(mobile) { gap: 4px 18px; }
  }

  .menu > li {
    position: relative;
    display: flex;
    align-items: center;
  }

  // In the template the a is a flex item (blockified); here it sits in an li
  a {
    display: block;
    font-size: 14.5px;
    color: var(--ink-faint);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.28s ease;

    &:hover { color: var(--ink); }
  }

  // Direct children only, so the colour cannot leak into sub-levels (PLAYBOOK §13)
  .current-menu-item > a,
  .current_page_item > a,
  .current-menu-ancestor > a,
  .current_page_ancestor > a,
  .current_page_parent > a { color: var(--ink); }

  // ---- The toggle after a parent's link ----
  .submenu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-left: 1px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--ink-faint);
    cursor: pointer;
    transition: color 0.28s ease, background 0.28s ease;

    svg {
      width: 10px;
      height: 10px;
      fill: none;
      stroke: currentColor;
      stroke-width: 1.6;
      stroke-linecap: round;
      stroke-linejoin: round;
      transition: transform 0.28s ease;
    }

    &:hover { color: var(--ink); background: var(--glass); }
    &[aria-expanded="true"] svg { transform: rotate(180deg); }
  }

  // ---- The panel ----
  .menu > li > ul {
    position: absolute;
    top: calc(100% + 10px);
    left: -18px;
    z-index: 70;
    min-width: 210px;
    max-width: min(290px, calc(100vw - 36px));
    max-height: min(70vh, 28rem); // a long or deep menu scrolls inside the panel
    overflow-y: auto;
    padding: 10px 0;
    list-style: none;
    background: var(--card-solid);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-soft);
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
  }

  // Opens on hover where there is one, and on the toggle everywhere
  @media (hover: hover) {
    .menu > li:hover > ul {
      opacity: 1;
      visibility: visible;
      transform: none;
      transition-delay: 0s;
    }

    // Bridges the gap between the item and the panel, so the pointer can
    // cross it. On the item, not the panel: the panel scrolls, which would
    // clip a pseudo-element hanging outside it.
    .menu > li:has(> ul)::after {
      content: "";
      position: absolute;
      top: 100%;
      left: -18px;
      right: -18px;
      height: 12px;
    }
  }

  .menu > li.is-open > ul {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition-delay: 0s;
  }

  // navigation.js: the panel would run past the right edge — align it right
  .menu > li.is-flipped > ul {
    left: auto;
    right: -18px;
  }

  // Inside the panel
  .menu ul a {
    padding: 6px 20px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink-soft);
    white-space: normal;
    overflow-wrap: anywhere;

    &:hover { color: var(--ink); background: var(--glass); }

    // The panel scrolls, which would clip a ring drawn outside the link
    &:focus-visible { outline-offset: -3px; border-radius: 8px; }
  }

  .menu ul ul {
    padding-left: 14px;
    list-style: none;
  }

  .menu ul .current-menu-item > a,
  .menu ul .current_page_item > a { color: var(--accent-deep); }
}
