/*
 * header.css — site header, primary nav, mobile toggle, header search.
 * Uses the CSS-only :checked pattern for mobile so nav works without JS.
 */

.site-header {
  background: var(--color-paper);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header__inner {
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--space-4) var(--gutter);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-5);
}

/* ---- Brand mark — "DX Insights Lab" editorial masthead ---- *
 *
 * Three-piece typographic lock-up, no badge/gradient-tile:
 *   .brand__monogram     — "DX" in display serif, brand-teal ink.
 *   .brand__rule         — hairline accent rule (teal → warm orange)
 *                           that sits beneath the monogram at rest and
 *                           extends full-width on hover, visually
 *                           connecting monogram + wordmark.
 *   .brand__wordmark     — two-line stacked label: "Insights" in
 *                           refined italic serif, "Lab" in tracked
 *                           uppercase sans. Reads like a magazine
 *                           masthead or a lab-journal bylabel.
 *
 * The warm-orange accent is deliberate — it echoes the hero imagery
 * and the orange bloom on the /about page's glass card so the whole
 * site feels like one palette.
 */
.brand {
  --brand-accent-warm: #ea580c;
  display: inline-grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto 3px;
  column-gap: 14px;
  row-gap: 4px;
  align-items: center;
  text-decoration: none;
  color: var(--color-ink);
  line-height: 1;
}

/* Uploaded-logo variant — the <a> carries a single <img>. We unset the
   grid rows so the image sits naturally in the header row, and cap its
   max height so tall / square / wide logos all render at the same
   visual weight without pushing the nav out of alignment. */
.brand.brand--image {
  display: inline-flex;
  align-items: center;
  grid-template-columns: none;
  grid-template-rows: none;
  padding-block: 4px;      /* breathing room vs. nav baseline */
}
.brand__image {
  display: block;
  max-height: 44px;        /* hard ceiling — matches .share-btn height */
  width: auto;
  max-width: 220px;        /* wide wordmarks can't eat the whole row */
  object-fit: contain;
  transition: transform .25s ease, filter .25s ease;
}
.brand.brand--image:hover .brand__image {
  transform: scale(1.03);
  filter: saturate(1.1);
}
@media (max-width: 680px) {
  .brand__image { max-height: 36px; max-width: 160px; }
}
@media (max-width: 520px) {
  .brand__image { max-height: 32px; max-width: 128px; }
}

/* Row 1, column 1 — the big serif DX. */
.brand__monogram {
  grid-column: 1;
  grid-row: 1;
  font-family: var(--font-serif);
  font-weight: 700;
  font-style: italic;
  font-size: 1.9rem;
  line-height: 1;
  letter-spacing: -.015em;
  color: var(--color-brand, #0f4c4a);
  background: linear-gradient(135deg, var(--color-brand, #0f4c4a) 0%, #0a3f3d 70%);
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
  transition: letter-spacing .3s ease;
}
.brand:hover .brand__monogram { letter-spacing: 0; }

/* Row 1, column 2 — stacked wordmark sits to the right of DX, between
   the two rows of it are vertically aligned with the DX x-height. */
.brand__wordmark {
  grid-column: 2;
  grid-row: 1;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}
.brand__wordmark-top {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1rem;
  line-height: 1;
  color: var(--color-ink);
  letter-spacing: .01em;
}
.brand__wordmark-bot {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: .7rem;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: .28em;
  color: var(--color-ink-muted);
  transition: color .3s ease, letter-spacing .3s ease;
}
.brand:hover .brand__wordmark-bot {
  color: var(--color-brand, #0f4c4a);
  letter-spacing: .32em;
}

/* Row 2 — the accent rule, spanning both columns. Starts short
   (covering only the DX), extends to full-width on hover. Colour is
   a gradient from brand teal to warm hero-orange, so the rule feels
   like a hand-drawn editor's mark rather than a plain underline. */
.brand__rule {
  grid-column: 1 / -1;
  grid-row: 2;
  height: 3px;
  width: 100%;
  background: linear-gradient(90deg,
    var(--color-brand, #0f4c4a) 0%,
    var(--color-brand, #0f4c4a) 30%,
    var(--brand-accent-warm) 75%,
    var(--brand-accent-warm) 100%);
  border-radius: 3px;
  transform: scaleX(.28);      /* at rest: a short mark under the DX */
  transform-origin: left center;
  transition: transform .45s cubic-bezier(.2,.8,.2,1),
              filter .3s ease;
  filter: saturate(.9);
}
.brand:hover .brand__rule {
  transform: scaleX(1);        /* on hover: extends across the wordmark */
  filter: saturate(1.15);
}

@media (prefers-reduced-motion: reduce) {
  .brand__monogram,
  .brand__wordmark-bot,
  .brand__rule { transition: none; }
  .brand:hover .brand__rule { transform: scaleX(1); }
}

/* ---- Primary nav (desktop) ---- */

.primary-nav__list {
  display: flex;
  gap: var(--space-5);
  list-style: none;
  margin: 0;
  padding: 0;
  justify-content: center;
}

.primary-nav__item > a {
  font-size: var(--type-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  padding: var(--space-2) 0;
  color: var(--color-ink);
}

/* 2nd-level submenu — absolute drop; visible on hover/focus */
.primary-nav__item.has-children {
  position: relative;
}
.primary-nav__submenu {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--color-paper);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-pop);
  min-width: 180px;
  padding: var(--space-2) 0;
  margin: 0;
  list-style: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity var(--transition-fast),
              transform var(--transition-fast),
              visibility var(--transition-fast);
}
.primary-nav__item.has-children:hover > .primary-nav__submenu,
.primary-nav__item.has-children:focus-within > .primary-nav__submenu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.primary-nav__submenu a {
  display: block;
  padding: var(--space-2) var(--space-4);
  font-size: var(--type-sm);
}

/* ---- Header search ---- */

.header-search {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.header-search input[type="search"] {
  padding: 8px var(--space-3);
  font: inherit;
  font-size: var(--type-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-paper);
  width: 180px;
  transition: width var(--transition-base), border var(--transition-base);
}
.header-search input[type="search"]:focus {
  outline: none;
  border-color: var(--color-ink);
  width: 240px;
}
.header-search button {
  border: 0;
  background: var(--color-cta);
  color: var(--color-cta-ink);
  padding: 8px var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

/* ---- Mobile hamburger (CSS-only toggle) ---- */

.nav-toggle { display: none; }

.nav-toggle-label {
  display: none;
  width: 28px; height: 22px;
  cursor: pointer;
  flex-direction: column;
  justify-content: space-between;
  grid-column: 3;
}
.nav-toggle-label span {
  display: block;
  height: 2px;
  background: var(--color-ink);
  border-radius: 2px;
}

/* Breakpoint mirrors the --bp-md reference in tokens.css. */
@media (max-width: 900px) {
  .site-header__inner {
    grid-template-columns: auto 1fr auto;
  }

  .nav-toggle-label { display: flex; }

  .primary-nav,
  .header-search {
    grid-column: 1 / -1;
    display: none;
  }

  .nav-toggle:checked ~ .primary-nav,
  .nav-toggle:checked ~ .header-search {
    display: block;
  }

  .primary-nav__list {
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4) 0;
    border-top: 1px solid var(--color-border);
  }

  .primary-nav__submenu {
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    box-shadow: none;
    border: 0;
    padding-left: var(--space-4);
  }

  .header-search {
    padding: var(--space-3) 0 var(--space-4);
    justify-self: stretch;
  }
  .header-search input[type="search"] {
    width: 100%;
  }
}

@media (max-width: 520px) {
  /* Very narrow screens: keep the DX monogram + accent rule but hide
     the "Insights Lab" wordmark to stay single-line. Full name still
     available to screen readers via the aria-label on .brand. */
  .brand__wordmark { display: none; }
  .brand { grid-template-columns: auto; column-gap: 0; }
  .brand__monogram { font-size: 1.6rem; }
}
