/**
 * Unified site header (SOM-223).
 *
 * Replaces four divergent hand-maintained headers. Written once here and
 * stamped into every page by scripts/build-header.js.
 *
 * WHY A NEW CLASS NAMESPACE (.tbc-*)
 * ----------------------------------
 * Every page carries its own inline copy of the old `.site-nav` CSS, and page
 * <style> blocks would win over this file on specificity ties. Rather than
 * surgically deleting ~120 lines of CSS from 105 files across four variants —
 * the riskiest possible way to do this — the new header uses its own prefix.
 * No `.site-nav` element is emitted any more, so the old rules match nothing.
 * Stripping that now-dead CSS is deliberate follow-up work, not part of this
 * change.
 *
 * THE BUG THIS FIXES
 * ------------------
 * The old header was `display:flex; justify-content:space-between` with the
 * nav in an `overflow-x:auto` box whose scrollbar was hidden. Above 1400px the
 * container was max-width capped, so the nav had a FIXED width and "Blog" was
 * clipped at every desktop size — with every affordance that would have
 * revealed it removed. Below capacity the same rule sprayed the Region/Lang
 * controls apart.
 *
 * The rules here never clip: the top row holds five items, categories live in
 * a dropdown, and everything collapses to a sheet below 900px. Colours are
 * flat throughout, per the project's design rule.
 *
 * Variables are read with fallbacks because not every page defines the full
 * palette.
 */

.tbc-header {
  background: var(--primary, #4A6B4D);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  font-family: inherit;
}

.tbc-header__inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.tbc-header__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  text-decoration: none;
  font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
  flex: 0 0 auto;
}
.tbc-header__brand:hover { opacity: 0.9; }

/* The mark is decorative — "True Baby Cost" stays real text beside it (SOM-173).
   Using logo-nav.svg, which bakes the wordmark into the image, would have cost
   a selectable, translatable, crawlable H-level brand string for no visual
   gain. alt="" + aria-hidden keeps screen readers from announcing it twice. */
.tbc-header__mark {
  width: 30px;
  height: 30px;
  display: block;
  flex: 0 0 auto;
}

/* `margin-left:auto` on the globe does the alignment instead of
   space-between, so slack collects in exactly one place rather than being
   distributed into every gap. That is what made the blog page's Region and
   Lang controls drift 86px apart. */
.tbc-header__menu {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 1 auto;
  min-width: 0;
}

.tbc-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 0 1 auto;
  min-width: 0;
}

.tbc-nav__item { position: relative; }

.tbc-nav__link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  background: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.tbc-nav__link:hover,
.tbc-nav__link:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}
.tbc-nav__link.is-active {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-weight: 600;
}

.tbc-nav__emoji { font-size: 1rem; line-height: 1; }

.tbc-nav__caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  margin-left: 2px;
  transition: transform 0.15s;
}
[aria-expanded='true'] > .tbc-nav__caret { transform: rotate(180deg); }

/* ─── Categories dropdown ─────────────────────────────────────────────── */

.tbc-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  margin: 0;
  padding: 8px;
  list-style: none;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  display: none;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 2px;
  z-index: 1001;
}
.tbc-nav__item.is-open > .tbc-dropdown { display: grid; }

.tbc-dropdown__link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text, #1f2933);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}
.tbc-dropdown__link:hover,
.tbc-dropdown__link:focus-visible {
  background: var(--bg, #f4f6f4);
}
.tbc-dropdown__link.is-active {
  background: var(--bg, #f4f6f4);
  font-weight: 600;
}

/* ─── Region / language ───────────────────────────────────────────────── */

.tbc-globe {
  position: relative;
  margin-left: auto;
  flex: 0 0 auto;
}

.tbc-globe__toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.tbc-globe__toggle:hover { background: rgba(255, 255, 255, 0.22); }

.tbc-globe__panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  padding: 12px;
  display: none;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
  z-index: 1001;
}
.tbc-globe.is-open > .tbc-globe__panel { display: flex; }

.tbc-globe__label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted, #6b7280);
  font-weight: 600;
}

/* Kept as real <select> elements with their original ids — js/market.js binds
   to #marketSelect and #langSelect, and moving them inside a popover must not
   change that contract. */
.tbc-globe__panel select {
  padding: 7px 9px;
  border: 1px solid #d8dee3;
  border-radius: 8px;
  font-size: 0.88rem;
  background: #fff;
  color: var(--text, #1f2933);
  font-family: inherit;
  width: 100%;
}

/* ─── Hamburger ───────────────────────────────────────────────────────── */

.tbc-header__burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 0 8px;
  margin-left: auto;
  background: none;
  border: 0;
  cursor: pointer;
  flex: 0 0 auto;
}
.tbc-header__burger span {
  display: block;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
.tbc-header__burger[aria-expanded='true'] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.tbc-header__burger[aria-expanded='true'] span:nth-child(2) { opacity: 0; }
.tbc-header__burger[aria-expanded='true'] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ─── Collapse ────────────────────────────────────────────────────────────
   900px, not 768px. The old header collapsed at 768px but overflowed long
   before that, so tablet widths silently lost links. Measured: brand (~170px)
   + five items (~470px) + globe (~90px) + padding needs ~780px, so 900px
   leaves genuine headroom rather than sitting on the boundary. */
@media (max-width: 900px) {
  .tbc-header__burger { display: flex; }

  .tbc-header__menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 12px 16px 18px;
    background: var(--primary, #4A6B4D);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
    max-height: calc(100vh - 60px);
    overflow-y: auto;
  }
  .tbc-header.is-open .tbc-header__menu { display: flex; }

  .tbc-nav { flex-direction: column; align-items: stretch; gap: 2px; }
  .tbc-nav__link { padding: 11px 12px; font-size: 0.95rem; }
  .tbc-nav__link.tbc-nav__toggle { width: 100%; justify-content: space-between; }

  /* Categories are always expanded in the sheet — a dropdown inside a
     drop-down panel is a worse interaction than simply showing the six. */
  .tbc-dropdown {
    position: static;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: rgba(0, 0, 0, 0.12);
    box-shadow: none;
    margin: 2px 0 6px;
  }
  .tbc-dropdown__link { color: rgba(255, 255, 255, 0.92); }
  .tbc-dropdown__link:hover,
  .tbc-dropdown__link:focus-visible,
  .tbc-dropdown__link.is-active { background: rgba(255, 255, 255, 0.16); }
  .tbc-nav__item.is-open > .tbc-dropdown { display: grid; }
  .tbc-nav__caret { display: none; }

  .tbc-globe { margin-left: 0; margin-top: 6px; }
  .tbc-globe__toggle { width: 100%; justify-content: center; }
  .tbc-globe__panel { position: static; width: 100%; margin-top: 6px; }
}

@media (max-width: 380px) {
  .tbc-header__brand { font-size: 1.05rem; }
  .tbc-dropdown { grid-template-columns: 1fr; }
}

/* The old header was hidden when printing; keep that. */
@media print {
  .tbc-header { display: none !important; }
}
