/* ================================================================
   DataHints DS — Navigation Component
   Requires: tokens.css
   ================================================================ */

  /* ────────────────────────────────────────────────────────────
     NAVIGATION TOKENS
  ──────────────────────────────────────────────────────────── */
  :root {
    --nav-height: 64px;
    --nav-top: var(--sp-3);        /* floating offset from viewport edge */
    --nav-h-pad: var(--sp-5);      /* inner horizontal padding */
  }

  /* ────────────────────────────────────────────────────────────
     NAV BASE — shared structure
  ──────────────────────────────────────────────────────────── */
  .dh-nav {
    position: fixed;
    top: var(--nav-top);
    left: var(--sp-4);
    right: var(--sp-4);
    z-index: 50;
    height: var(--nav-height);

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 var(--nav-h-pad);
    border-radius: var(--r-md);
    border: 1px solid var(--border);

    background: var(--bg-card); /* fallback: no color-mix or backdrop-filter */
    background: color-mix(in srgb, var(--bg-card) 80%, transparent);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);

    box-shadow: var(--shadow-md);
    transition:
      background var(--ease-base),
      border-color var(--ease-base),
      box-shadow var(--ease-base);
  }

  /* scrolled: tighten background */
  .dh-nav.is-scrolled {
    border-color: var(--border-s);
    box-shadow: var(--shadow-lg);
  }

  /* max-width cap — keeps nav aligned with page content */
  .dh-nav-inner {
    width: 100%;
    max-width: var(--max-w);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  /* ────────────────────────────────────────────────────────────
     LOGO / WORDMARK
  ──────────────────────────────────────────────────────────── */
  .dh-nav-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
    cursor: pointer;
    opacity: 1;
    transition: opacity var(--ease-fast);
  }
  .dh-nav-logo:hover { opacity: 0.8; }
  .dh-nav-logo:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: var(--r-xs); }

  .dh-nav-logo-img {
    height: 26px;
    width: auto;
    display: block;
  }
  /* White logo for dark theme (default), black for light */
  .dh-nav-logo-img--white { display: block; }
  .dh-nav-logo-img--black { display: none; }
  [data-theme="light"] .dh-nav-logo-img--white { display: none; }
  [data-theme="light"] .dh-nav-logo-img--black { display: block; }

  /* ────────────────────────────────────────────────────────────
     DESKTOP NAV LINKS
  ──────────────────────────────────────────────────────────── */
  .dh-nav-links {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
    list-style: none;
    margin: 0; padding: 0;
  }

  .dh-nav-link {
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--fg-2);
    text-decoration: none;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--r-xs);
    transition:
      color var(--ease-fast),
      background var(--ease-fast);
    cursor: pointer;
    white-space: nowrap;
  }
  .dh-nav-link:hover {
    color: var(--fg);
    background: var(--bg-card-h);
  }
  .dh-nav-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .dh-nav-link.is-active {
    color: var(--accent-text);
    background: transparent;
    box-shadow: inset 0 -2px 0 var(--accent);
  }

  /* ────────────────────────────────────────────────────────────
     NAV RIGHT — theme toggle + CTA
  ──────────────────────────────────────────────────────────── */
  .dh-nav-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    flex-shrink: 0;
  }

  /* Theme toggle button */
  .dh-nav-theme {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border-radius: var(--r-xs);
    border: 1px solid var(--border-s);
    background: transparent;
    color: var(--fg-3);
    cursor: pointer;
    transition:
      color var(--ease-fast),
      background var(--ease-fast),
      border-color var(--ease-fast);
    flex-shrink: 0;
  }
  .dh-nav-theme:hover {
    color: var(--fg);
    background: var(--bg-card-h);
    border-color: var(--border-a);
  }
  .dh-nav-theme:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .dh-nav-theme svg { width: 16px; height: 16px; }

  /* CTA button — intentional nav-specific size (8px/18px between btn-sm and btn-md).
     Uses same tokens as .dh-btn-primary. If buttons.css is loaded, these rules win via
     specificity; nav CTA does not depend on buttons.css being present. */
  .dh-nav-cta {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    font-family: var(--font-sans); font-weight: 600;
    font-size: 0.875rem; padding: 8px 18px;
    border: none; border-radius: var(--r-xs); cursor: pointer;
    text-decoration: none; white-space: nowrap;
    background: var(--accent-fill);
    color: var(--on-accent);
    box-shadow: var(--shadow-sm);
    transition:
      background var(--ease-fast),
      box-shadow var(--ease-fast),
      transform var(--ease-fast);
  }
  .dh-nav-cta:hover {
    background: var(--accent-fill-h);
    box-shadow: var(--shadow-md), var(--shadow-glow);
  }
  .dh-nav-cta:active { transform: translateY(1px); }
  .dh-nav-cta:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

  /* ────────────────────────────────────────────────────────────
     HAMBURGER BUTTON — mobile only
  ──────────────────────────────────────────────────────────── */
  .dh-nav-burger {
    display: none;
    align-items: center; justify-content: center;
    width: 40px; height: 40px;
    border-radius: var(--r-xs);
    border: 1px solid var(--border-s);
    background: transparent;
    color: var(--fg-2);
    cursor: pointer;
    transition:
      color var(--ease-fast),
      background var(--ease-fast),
      border-color var(--ease-fast);
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }
  .dh-nav-burger:hover {
    color: var(--fg);
    background: var(--bg-card-h);
    border-color: var(--border-a);
  }
  .dh-nav-burger:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  /* Animated 3-line icon */
  .burger-icon {
    width: 18px; height: 14px;
    position: relative;
    display: flex; flex-direction: column;
    justify-content: space-between;
  }
  .burger-line {
    display: block;
    height: 1.5px; width: 100%;
    background: currentColor;
    border-radius: 2px;
    transform-origin: center;
    transition:
      transform 0.2s ease,
      opacity 0.2s ease,
      width 0.2s ease;
  }

  /* Open state → X */
  .dh-nav-burger[aria-expanded="true"] .burger-line:nth-child(1) {
    transform: translateY(6.25px) rotate(45deg);
  }
  .dh-nav-burger[aria-expanded="true"] .burger-line:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
  }
  .dh-nav-burger[aria-expanded="true"] .burger-line:nth-child(3) {
    transform: translateY(-6.25px) rotate(-45deg);
  }

  /* ────────────────────────────────────────────────────────────
     MOBILE DRAWER
  ──────────────────────────────────────────────────────────── */
  .dh-nav-drawer {
    display: none;             /* rendered via JS class toggle on mobile */
    position: fixed;
    inset: 0;
    /* Must sit above `.dh-nav` (z-index: 50). The floating nav otherwise
       paints on top of the panel and clips the drawer header on mobile. */
    z-index: 60;
    pointer-events: none;
  }

  /* Backdrop */
  .dh-nav-backdrop {
    position: absolute;
    inset: 0;
    background: var(--overlay-bg);
    opacity: 0;
    transition: opacity var(--ease-base);
    cursor: pointer;
  }

  /* Slide-in panel */
  .dh-nav-panel {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: min(320px, 88vw);
    background: var(--bg-elevated);
    border-left: 1px solid var(--border-s);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--ease-base);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Open state */
  .dh-nav-drawer.is-open {
    pointer-events: auto;
  }
  .dh-nav-drawer.is-open .dh-nav-backdrop {
    opacity: 1;
  }
  .dh-nav-drawer.is-open .dh-nav-panel {
    transform: translateX(0);
  }

  /* Panel header */
  .dh-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-5) var(--sp-5);
    border-bottom: 1px solid var(--border-s);
    flex-shrink: 0;
  }

  .dh-drawer-close {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border-radius: var(--r-xs);
    border: 1px solid var(--border-s);
    background: transparent;
    color: var(--fg-3);
    cursor: pointer;
    transition: color var(--ease-fast), background var(--ease-fast), border-color var(--ease-fast);
  }
  .dh-drawer-close:hover { color: var(--fg); background: var(--bg-card-h); border-color: var(--border-a); }
  .dh-drawer-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .dh-drawer-close svg { width: 16px; height: 16px; }

  /* Panel links */
  .dh-drawer-links {
    list-style: none;
    margin: 0; padding: var(--sp-4) var(--sp-4);
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
    flex: 1;
  }

  .dh-drawer-link {
    display: flex; align-items: center;
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 500;
    color: var(--fg-2);
    text-decoration: none;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-xs);
    transition: color var(--ease-fast), background var(--ease-fast);
    cursor: pointer;
    min-height: 48px;          /* 48px touch target */
  }
  .dh-drawer-link:hover { color: var(--fg); background: var(--bg-card); }
  .dh-drawer-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .dh-drawer-link.is-active { color: var(--accent-text); background: transparent; border-left: 2px solid var(--accent); padding-left: calc(var(--sp-4) - 2px); }

  .dh-drawer-divider {
    height: 1px; background: var(--border-s);
    margin: var(--sp-3) 0;
    border: none;
  }

  /* Panel footer */
  .dh-drawer-footer {
    padding: var(--sp-5) var(--sp-5);
    border-top: 1px solid var(--border-s);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    flex-shrink: 0;
  }

  .dh-drawer-cta {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%;
    font-family: var(--font-sans); font-weight: 600;
    font-size: 0.9375rem; padding: 13px 22px;
    border: none; border-radius: var(--r-xs); cursor: pointer;
    text-decoration: none; white-space: nowrap;
    background: var(--accent-fill);
    color: var(--on-accent);
    box-shadow: var(--shadow-sm);
    transition: background var(--ease-fast), box-shadow var(--ease-fast);
    min-height: 48px;
  }
  .dh-drawer-cta:hover { background: var(--accent-fill-h); box-shadow: var(--shadow-md), var(--shadow-glow); }
  .dh-drawer-cta:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

  .dh-drawer-theme {
    display: flex; align-items: center; justify-content: space-between;
    font-family: var(--font-mono); font-size: 0.75rem;
    color: var(--fg-3);
    padding: 0 var(--sp-1);
  }
  .dh-drawer-theme-btn {
    display: flex; align-items: center; gap: var(--sp-2);
    background: var(--bg-card); border: 1px solid var(--border-s);
    border-radius: var(--r-pill);
    padding: var(--sp-2) var(--sp-3);
    font-family: var(--font-mono); font-size: 0.6875rem;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--fg-2); cursor: pointer;
    transition: border-color var(--ease-fast), color var(--ease-fast), background var(--ease-fast);
  }
  .dh-drawer-theme-btn:hover { border-color: var(--border-a); color: var(--fg); background: var(--bg-card-h); }
  .dh-drawer-theme-btn svg { width: 13px; height: 13px; }

  /* ────────────────────────────────────────────────────────────
     RESPONSIVE — show burger, hide desktop links
  ──────────────────────────────────────────────────────────── */
  @media (max-width: 767px) {
    .dh-nav-links { display: none; }
    .dh-nav-cta   { display: none; }
    .dh-nav-theme { display: none; }
    .dh-nav-burger { display: flex; }
    .dh-nav-drawer { display: block; }
  }

  /* ────────────────────────────────────────────────────────────
     DROPDOWN — desktop L2 / L3
  ──────────────────────────────────────────────────────────── */

  /* Every <li> in the desktop bar is a positioning context */
  .dh-nav-item {
    position: relative;
  }

  /* Parent row: link + chevron side-by-side */
  .dh-nav-parent-wrap {
    display: flex;
    align-items: center;
  }

  /* Chevron toggle button */
  .dh-nav-chevron-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    margin-left: -6px;         /* pull tight against link's right padding */
    background: transparent;
    border: none;
    color: var(--fg-3);
    cursor: pointer;
    border-radius: var(--r-xs);
    transition: color var(--ease-fast);
    flex-shrink: 0;
  }
  .dh-nav-chevron-btn:hover { color: var(--fg); }
  .dh-nav-chevron-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .dh-nav-chevron-btn svg { width: 13px; height: 13px; }

  /* Transparent bridge fills the gap between the nav item and the dropdown panel.
     Without it the hover state is lost while the mouse crosses the visual gap. */
  .dh-nav-item--has-dropdown::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: var(--sp-2);
  }

  /* Chevron rotation when dropdown is open */
  .dh-nav-chevron {
    transition: transform var(--ease-base);
  }
  .dh-nav-item--has-dropdown:hover .dh-nav-chevron,
  .dh-nav-item--has-dropdown.is-open .dh-nav-chevron {
    transform: rotate(180deg);
  }

  /* Dropdown panel */
  .dh-nav-dropdown {
    position: absolute;
    top: calc(100% + var(--sp-2));
    left: 0;
    min-width: 200px;
    list-style: none;
    margin: 0;
    padding: var(--sp-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-s);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    z-index: 60;
    /* hidden by default */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    pointer-events: none;
    transition:
      opacity var(--ease-fast),
      transform var(--ease-fast),
      visibility 0s var(--ease-fast);
  }

  /* Visible: hover or JS .is-open */
  .dh-nav-item--has-dropdown:hover .dh-nav-dropdown,
  .dh-nav-item--has-dropdown.is-open .dh-nav-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
    transition:
      opacity var(--ease-fast),
      transform var(--ease-fast),
      visibility 0s;
  }

  /* L2 link inside dropdown */
  .dh-nav-dropdown-item {
    display: flex;
    align-items: center;
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--fg-2);
    text-decoration: none;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--r-xs);
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--ease-fast), background var(--ease-fast);
  }
  .dh-nav-dropdown-item:hover {
    color: var(--fg);
    background: var(--bg-card-h);
  }
  .dh-nav-dropdown-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .dh-nav-dropdown-item.is-active {
    color: var(--accent-text);
  }

  /* L3 sub-list — indented with accent rail */
  .dh-nav-subnav {
    list-style: none;
    margin: var(--sp-1) 0 var(--sp-1) calc(var(--sp-3) + 2px);
    padding: 0 0 0 var(--sp-3);
    border-left: 1px solid var(--border-s);
  }
  .dh-nav-dropdown-item--sub {
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--fg-3);
    padding-top: var(--sp-1);
    padding-bottom: var(--sp-1);
  }
  .dh-nav-dropdown-item--sub:hover { color: var(--fg); }

  /* Visual separator between consecutive dropdown groups */
  .dh-nav-dropdown-group + .dh-nav-dropdown-group {
    border-top: 1px solid var(--border-s);
    margin-top: var(--sp-2);
    padding-top: var(--sp-2);
  }

  /* ────────────────────────────────────────────────────────────
     DRAWER ACCORDION — mobile L2 / L3
  ──────────────────────────────────────────────────────────── */

  /* Parent row: link + chevron toggle */
  .dh-drawer-parent-wrap {
    display: flex;
    align-items: center;
  }
  .dh-drawer-parent-wrap .dh-drawer-link {
    flex: 1;
  }

  /* Chevron toggle button */
  .dh-drawer-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    flex-shrink: 0;
    background: transparent;
    border: none;
    color: var(--fg-3);
    cursor: pointer;
    border-radius: var(--r-xs);
    transition: color var(--ease-fast);
    -webkit-tap-highlight-color: transparent;
  }
  .dh-drawer-toggle:hover { color: var(--fg); }
  .dh-drawer-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .dh-drawer-toggle svg { width: 14px; height: 14px; }

  /* Chevron rotation + colour when open */
  .dh-drawer-item.is-open > .dh-drawer-parent-wrap .dh-drawer-toggle {
    color: var(--accent-text);
  }
  .dh-drawer-item.is-open > .dh-drawer-parent-wrap .dh-nav-chevron {
    transform: rotate(180deg);
  }

  /* L2 sub-list */
  .dh-drawer-subnav {
    list-style: none;
    margin: 0;
    padding: 0 0 var(--sp-2) calc(var(--sp-4) + var(--sp-2));
    display: none;
    flex-direction: column;
    gap: 2px;
  }
  .dh-drawer-item.is-open > .dh-drawer-subnav {
    display: flex;
  }

  /* L2 sub-links */
  .dh-drawer-sublink {
    display: flex;
    align-items: center;
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--fg-2);
    text-decoration: none;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--r-xs);
    min-height: 40px;
    transition: color var(--ease-fast), background var(--ease-fast);
  }
  .dh-drawer-sublink:hover { color: var(--fg); background: var(--bg-card); }
  .dh-drawer-sublink:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .dh-drawer-sublink.is-active { color: var(--accent-text); }

  /* L3 sub-sub-list */
  .dh-drawer-subsubnav {
    list-style: none;
    margin: 2px 0 0 0;
    padding: 0 0 0 var(--sp-4);
    border-left: 1px solid var(--border-s);
    display: none;
    flex-direction: column;
    gap: 2px;
  }
  .dh-drawer-subitem--has-children.is-open > .dh-drawer-subsubnav {
    display: flex;
  }

  /* L3 links — slightly smaller weight */
  .dh-drawer-sublink--l3 {
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--fg-3);
    min-height: 36px;
  }
  .dh-drawer-sublink--l3:hover { color: var(--fg); }
  .dh-drawer-sublink--l3.is-active { color: var(--accent-text); }
