/* =============================================================================
   Nav dropdown component — Trade Journal AI
   Created 2026-05-24 with the Product/Resources/Company restructure.
   Shared across all public pages with the full primary nav. Pages with a
   minimal header (press, contact, error, legal, auth) do NOT load this.
   Style tokens (--color-*) inherit from each page's existing root :root vars.
   ============================================================================= */

/* Container -------------------------------------------------------------- */
.nav-links {
  display: flex;
  align-items: center;
  gap: 24px;
}

/* Dropdown wrapper ------------------------------------------------------- */
.nav-dropdown { position: relative; }

.nav-dropdown-trigger {
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--color-ink-2, #1c2420);
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 6px 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s ease;
}
.nav-dropdown-trigger:hover,
.nav-dropdown-trigger:focus-visible,
.nav-dropdown-trigger[aria-expanded="true"],
.nav-dropdown.is-current > .nav-dropdown-trigger {
  color: var(--color-primary, #0081E8);
  outline: none;
}
.nav-dropdown-caret {
  font-size: 0.65rem;
  line-height: 1;
  transition: transform 0.15s ease;
  display: inline-block;
}
.nav-dropdown-trigger[aria-expanded="true"] .nav-dropdown-caret {
  transform: rotate(180deg);
}

/* Dropdown panel --------------------------------------------------------- */
.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 10px);
  /* Center under the trigger — left:50% positions the menu's left edge at
     the trigger midpoint, then translateX(-50%) shifts it back by half its
     own width, so it sits perfectly centered. (2026-05-24 — was previously
     left:0 + right:0 fallback for last-of-type, which caused Company to
     hang off the left.) */
  left: 50%;
  transform: translateX(-50%);
  /* Safety net: never extend past the viewport edges on narrower screens. */
  max-width: calc(100vw - 32px);
  background: var(--color-card, #ffffff);
  border: 1px solid var(--color-line, #e6e4dc);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.10), 0 2px 6px rgba(0,0,0,0.04);
  padding: 12px;
  display: none;
  z-index: 1000;
}

/* Single-column variant (Product — 3 items). Wider panel for breathing room. */
.nav-dropdown-menu.nav-dropdown-cols-1 {
  min-width: 380px;
  display: none;
  grid-template-columns: 1fr;
}

/* Two-column variant (Resources, Company). */
.nav-dropdown-menu.nav-dropdown-cols-2 {
  min-width: 540px;
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
}

/* Card-style variant for Company dropdown — bigger boxes, colored left
   accent bar per item, subtle hover lift. (2026-05-24) Adds pizzazz
   without using full icon squares (which are reserved for Product). */
.nav-dropdown-menu.nav-dropdown-cards {
  min-width: 620px;
  padding: 16px;
  gap: 8px;
}
.nav-dropdown-cards .nav-dropdown-item {
  background: var(--color-paper, #f7f6f2);
  border: 1px solid transparent;
border-radius: 10px;
  padding: 14px 16px 14px 14px;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.14s ease, box-shadow 0.14s ease;
}
.nav-dropdown-cards .nav-dropdown-item .nav-dropdown-title {
  font-size: 1rem;
}
.nav-dropdown-cards .nav-dropdown-item:hover {
  background: var(--color-card, #ffffff);
  border-top-color: var(--color-line, #e6e4dc);
  border-right-color: var(--color-line, #e6e4dc);
  border-bottom-color: var(--color-line, #e6e4dc);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
}
/* Per-item left-accent color rotation (5 items, 5 colors) */

/* Item — title + description card layout */
.nav-dropdown-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 10px;
  text-decoration: none;
  transition: background 0.14s ease;
}

/* Iconed variant — Product dropdown only. Two-column grid: colored icon
   square on the left, title + description on the right. (2026-05-24) */
.nav-dropdown-item.has-icon {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
}
.nav-dropdown-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-dropdown-icon svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}
.nav-dropdown-icon-blue  { background: rgba(0, 129, 232, 0.10);  color: #0081E8; }
.nav-dropdown-icon-green { background: rgba(26, 139, 98, 0.10);  color: #1a8b62; }
.nav-dropdown-icon-amber { background: rgba(255, 167, 55, 0.18); color: #b87013; }
.nav-dropdown-item-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.nav-dropdown-title {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--color-ink, #0f1411);
  line-height: 1.25;
  display: block;
}
.nav-dropdown-desc {
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--color-muted, #5a5e59);
  line-height: 1.45;
  display: block;
}

/* Hover + active states */
.nav-dropdown-item:hover,
.nav-dropdown-item:focus-visible {
  background: var(--color-line-soft, #f0eee5);
  outline: none;
}
.nav-dropdown-item:hover .nav-dropdown-title,
.nav-dropdown-item:focus-visible .nav-dropdown-title {
  color: var(--color-primary, #0081E8);
}
.nav-dropdown-item.is-current {
  background: rgba(0, 129, 232, 0.06);
}
.nav-dropdown-item.is-current .nav-dropdown-title {
  color: var(--color-primary, #0081E8);
}

/* Open state — flip display:none → grid */
.nav-dropdown:hover .nav-dropdown-menu.nav-dropdown-cols-1,
.nav-dropdown-trigger[aria-expanded="true"] + .nav-dropdown-menu.nav-dropdown-cols-1,
.nav-dropdown:hover .nav-dropdown-menu.nav-dropdown-cols-2,
.nav-dropdown-trigger[aria-expanded="true"] + .nav-dropdown-menu.nav-dropdown-cols-2 {
  display: grid;
}

/* Legacy fallback for any older flat-link dropdowns (shouldn't trigger
   anymore since the rich markup is now sitewide, but kept defensively). */
.nav-dropdown-menu > a:not(.nav-dropdown-item) {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  font-family: 'Montserrat', sans-serif;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--color-ink-2, #1c2420);
  text-decoration: none;
}
.nav-dropdown-menu > a:not(.nav-dropdown-item):hover {
  background: var(--color-line-soft, #f0eee5);
  color: var(--color-primary, #0081E8);
}

/* Open states: hover (desktop) OR aria-expanded=true (click/keyboard) */
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown-trigger[aria-expanded="true"] + .nav-dropdown-menu {
  display: block;
}

/* A tiny invisible bridge between trigger and menu so cursor can travel
   without the menu collapsing. The 10px gap above leaves a "void" that
   would otherwise close on hover. */
.nav-dropdown-menu::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 0;
  right: 0;
  height: 10px;
}

/* Mobile drawer accordion ----------------------------------------------- */
/* Repurposes the existing .mobile-drawer container; we add accordion
   sections inside. The drawer toggle (hamburger) JS continues to manage
   show/hide of the outer drawer; this CSS just styles the new inner
   structure. */
.mobile-drawer-section {
  border-top: 1px solid var(--color-line, #e6e4dc);
  padding: 14px 0;
}
.mobile-drawer-section:first-child { border-top: 0; }
.mobile-drawer-section-label {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted, #5a5e59);
  padding: 0 4px 8px;
}
.mobile-drawer-section a {
  display: block;
  padding: 10px 4px;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-ink-2, #1c2420);
  text-decoration: none;
}
.mobile-drawer-section a.is-current {
  color: var(--color-primary, #0081E8);
}

/* Mobile behavior --------------------------------------------------------
   On pages WITH a hamburger menu, hide the desktop dropdown triggers and
   let the hamburger drawer take over. On pages WITHOUT a hamburger (some
   legacy broker landings + a few comparison pages don't have one yet),
   the dropdowns stay visible so mobile users still have nav — they
   click-toggle via the existing JS handler. Adam to backfill hamburgers
   on those 10 pages later for visual consistency. */
@media (max-width: 860px) {
  body:has(.nav-hamburger) .nav-dropdown { display: none; }
  /* Compact spacing for pages WITHOUT hamburger so 3 dropdowns + Pricing
     fit without wrapping awkwardly. */
  body:not(:has(.nav-hamburger)) .nav-links { gap: 14px; }
  body:not(:has(.nav-hamburger)) .nav-dropdown-trigger,
  body:not(:has(.nav-hamburger)) .nav-links > a { font-size: 0.78rem; }
}

/* Dark theme overrides --------------------------------------------------- */
html[data-theme="dark"] .nav-dropdown-menu {
  background: var(--color-card);
  border-color: var(--color-line);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
}

/* Mobile drawer overlay (2026-07-01) --------------------------------------
   The mobile menu wouldn't scroll (and later wouldn't open) because
   .mobile-drawer is nested in header.site-header, whose backdrop-filter
   creates a containing block that traps position:fixed, inside a sticky
   wrapper that hijacks internal scroll. nav-dropdown.js (wireMobileDrawer)
   relocates the drawer to <body> and sets --drawer-top to the header height
   when it opens.
   This rule + the JS inline styles are intentionally BELT-AND-SUSPENDERS:
   whichever of the two is live, the open drawer is pinned as a fixed,
   self-scrolling overlay beneath the header. That way a JS/CSS version skew
   on deploy can't leave the menu half-wired (which is exactly what broke it
   on 2026-07-01 — a stale JS shipped without the matching CSS). z-index sits
   above the sticky CTA bar (60). Applies only once the drawer is out of the
   header; the JS guarantees that by moving it to <body>. */
@media (max-width: 900px) {
  .mobile-drawer:not([hidden]) {
    position: fixed;
    top: var(--drawer-top, 60px);
    left: 0;
    right: 0;
    bottom: 0;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--color-paper, #f7f6f2);
    z-index: 70;
    padding-bottom: 40px;
  }
}
