/* ==========================================================================
   HEADER — Accent bar, logo, navigation, account menu, cart.

   Table of contents (jump to the matching `---------- HEADING` comment):

     ACCENT BAR                    L5    top thin accent strip
     HEADER CONTAINER              L13   outer wrapper + sticky behavior
     HEADER CONTENT                L31   flex layout for header rows
     BRANDING / LOGO               L41   site logo + linked title
     MOBILE MENU TOGGLE            L60   burger button + animation
     ACCOUNT NAV                   L115  user menu (login/dashboard)
     CART                          L160  cart link + item-count badge
     INSTITUTIONAL ADMIN           L208  hide commerce affordances
     MOBILE (≤ 768px)              L215  small-screen header overrides
     DESKTOP GRID (≥ 769px)        L345  two-row desktop grid layout
     WIDE DESKTOP (≥ 1100px)       L413  large-screen spacing tweaks
   ========================================================================== */

/* ---------- ACCENT BAR ---------- */

.otb-accent-bar {
  background: var(--color-primary);
  height: var(--accent-bar-height);
  width: 100%;
}

/* ---------- HEADER CONTAINER ---------- */

.otb-header {
  background: var(--header-bg);
  position: relative;
  width: 100%;
}

.otb-header .otb-container {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  min-height: var(--header-min-height);
  position: relative;
  max-width: var(--container-max-width);
  margin: 0 auto;
}

/* ---------- HEADER CONTENT ---------- */
/* Desktop (≥769px): Two-row CSS grid — utility row (account + cart) above
   main navigation row (logo + nav + search). Gives search and nav room to
   breathe, and provides a natural home for future IP-auth status indicator.
   Mobile (≤768px): Hidden; content moves to full-screen drawer via JS. */

.otb-header__content {
  flex: 1;
}

/* ---------- BRANDING / LOGO ---------- */

.otb-branding {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.otb-branding__logo {
  display: block;
  line-height: 1;
}

.otb-branding__logo img {
  display: block;
  height: 60px;
  width: auto;
}

/* ---------- MOBILE MENU TOGGLE ---------- */

.otb-menu-toggle {
  display: none;
  position: relative;
  z-index: var(--z-sticky-header);
  background: transparent;
  border: none;
  border-radius: 0;
  padding: var(--spacing-xs);
  cursor: pointer;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  -webkit-appearance: none;
  appearance: none;
}

.otb-menu-toggle__icon {
  display: block;
  width: 24px;
  height: 18px;
  position: relative;
}

.otb-menu-toggle__icon span {
  display: block;
  position: absolute;
  height: 2px;
  width: 100%;
  background: var(--color-header-text);
  border-radius: 2px;
  left: 0;
  transition: 0.25s ease-in-out;
}

.otb-menu-toggle__icon span:nth-child(1) { top: 0; }
.otb-menu-toggle__icon span:nth-child(2) { top: 8px; }
.otb-menu-toggle__icon span:nth-child(3) { top: 16px; }

/* Animated X when open — center line is at 50% of icon height */
.otb-menu-toggle[aria-expanded="true"] .otb-menu-toggle__icon span:nth-child(1) {
  top: 50%;
  transform: translateY(-50%) rotate(135deg);
}
.otb-menu-toggle[aria-expanded="true"] .otb-menu-toggle__icon span:nth-child(2) {
  opacity: 0;
  left: -60px;
}
.otb-menu-toggle[aria-expanded="true"] .otb-menu-toggle__icon span:nth-child(3) {
  top: 50%;
  transform: translateY(-50%) rotate(-135deg);
}

/* ---------- ACCOUNT NAV ---------- */

.otb-account-nav ul.menu {
  display: flex;
  align-items: center;
  gap: 0;
  list-style: none;
  margin: 0;
  padding: 0;
}

.otb-account-nav li {
  display: inline-block;
  margin: 0;
  padding: 0;
}

.otb-account-nav a {
  display: inline-block;
  text-decoration: none;
  font-weight: var(--font-weight-normal);
  font-size: var(--font-size-xs);
  color: var(--color-nav-text-on-dark);
  padding: var(--spacing-xs);
  white-space: nowrap;
}

.otb-account-nav a:hover,
.otb-account-nav a:focus-visible {
  color: var(--color-nav-text-on-dark-hover);
  text-decoration: underline;
}

.otb-account-nav a.is-active,
.otb-account-nav ul.menu a.is-active {
  color: var(--color-white);
  text-decoration: underline;
}

.otb-account-nav li + li {
  margin-left: var(--spacing-xs);
  padding-left: var(--spacing-xs);
  border-left: 1px solid var(--color-gray-600);
}

/* ---------- CART ---------- */

.otb-cart {
  display: flex;
  align-items: center;
}

.otb-cart__link {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  text-decoration: none;
  font-weight: var(--font-weight-normal);
  font-size: var(--font-size-xs);
  color: var(--color-nav-text-on-dark);
  padding: var(--spacing-xs);
  white-space: nowrap;
}

.otb-cart__link:hover,
.otb-cart__link:focus-visible {
  color: var(--color-nav-text-on-dark-hover);
  text-decoration: underline;
}

.otb-cart__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.otb-cart__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--color-primary-btn);
  color: var(--color-white);
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  line-height: 1;
  margin-left: -6px;
  margin-top: -8px;
}

/* ---------- INSTITUTIONAL ADMIN — HIDE COMMERCE ---------- */
/* Institutional admins don't need commerce features */

.user-institutional-admin .otb-cart {
  display: none;
}

/* ---------- MOBILE (≤ 768px) ---------- */

@media (max-width: 768px) {
  .otb-accent-bar {
    display: none;
  }

  .otb-header {
    background: transparent;
    width: 100%;
    max-width: 100%;
  }

  /* Hide everything in the header except the toggle button */
  .otb-header__content {
    display: none;
  }

  .otb-header .otb-container {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    min-height: 0;
    padding: 0 10px;
    gap: 0;
  }

  .otb-menu-toggle {
    display: flex;
    width: 48px;
    height: 48px;
    padding: 8px;
  }

  .otb-menu-toggle__icon {
    width: 32px;
    height: 32px;
  }

  .otb-menu-toggle__icon span {
    height: 3px;
  }

  .otb-menu-toggle__icon span:nth-child(1) { top: 3px; }
  .otb-menu-toggle__icon span:nth-child(2) { top: 15px; }
  .otb-menu-toggle__icon span:nth-child(3) { top: 27px; }

  /* Full-screen drawer — lives outside header content flow */
  .otb-mobile-drawer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-surface-overlay);
    z-index: var(--z-mobile-drawer);
    padding-top: 60px;
    overflow-y: auto;
  }

  .otb-mobile-drawer.is-open {
    display: block;
  }

  .otb-mobile-drawer .menu--root {
    width: 100%;
  }

  /* Drawer: search — full width */
  .otb-mobile-drawer .otb-header__search {
    display: block;
    padding: var(--spacing-md) 20px;
    border-bottom: 1px solid var(--color-border-dark-subtle);
  }

  .otb-mobile-drawer .otb-search {
    width: 100%;
    position: relative;
  }

  .otb-mobile-drawer .otb-search .otb-search__input {
    width: 100%;
    max-width: 100%;
    font-size: var(--font-size-sm);
    padding: var(--spacing-xs) 2.5rem var(--spacing-xs) var(--spacing-sm);
  }

  /* Drawer: account nav */
  .otb-mobile-drawer .otb-account-nav {
    display: block;
    padding: var(--spacing-md) 20px;
    border-top: 1px solid var(--color-border-dark-subtle);
  }

  .otb-mobile-drawer .otb-account-nav ul.menu {
    flex-direction: column;
    gap: 0;
  }

  .otb-mobile-drawer .otb-account-nav li {
    display: block;
  }

  .otb-mobile-drawer .otb-account-nav li + li {
    border-left: none;
    margin-left: 0;
    padding-left: 0;
  }

  .otb-mobile-drawer .otb-account-nav a {
    display: block;
    padding: var(--spacing-xs) 0;
    font-size: var(--font-size-sm);
  }

  /* Drawer: logo — top-left, matching burger button position */
  .otb-mobile-drawer .otb-branding {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    padding: 8px 10px;
  }

  .otb-mobile-drawer .otb-branding__logo img {
    height: 40px;
  }
}

/* ---------- DESKTOP GRID (≥ 769px) ---------- */
/* Two-row grid: logo + nav span full height (centered), right column
   stacks utility bar (top) and search (below). Inspired by the legacy
   site layout. Nav hover highlights still reach the accent bar. */

@media (min-width: 769px) {
  .otb-header__content {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    grid-template-rows: auto 1fr;
    column-gap: 0;
    row-gap: 0;
    width: 100%;
  }

  /* --- Left side: logo + nav span both rows, vertically centered --- */

  .otb-header__content .otb-branding {
    grid-row: 1 / -1;
    grid-column: 1;
    align-self: center;
  }

  .otb-header__content .otb-primary-nav {
    grid-row: 1 / -1;
    grid-column: 2;
    align-self: center;
    margin-left: var(--spacing-sm);
  }

  /* --- Right side row 1: utility bar (cart + account, top-aligned) --- */

  .otb-header__content .otb-cart {
    grid-row: 1;
    grid-column: 3;
    align-self: start;
    justify-self: end;
    padding-top: 6px;
  }

  .otb-header__content .otb-account-nav {
    grid-row: 1;
    grid-column: 4;
    align-self: start;
    padding-top: 6px;
  }

  .otb-header__content .otb-account-nav a {
    font-size: var(--font-size-2xs);
    padding: 1px 5px;
  }

  .otb-header__content .otb-cart__link {
    font-size: var(--font-size-2xs);
    padding: 1px 5px;
  }

  /* --- Right side row 2: search (centered in remaining space) --- */

  .otb-header__content .otb-header__search {
    grid-row: 2;
    grid-column: 3 / -1;
    justify-self: end;
    align-self: start;
    padding-top: 12px;
  }
}

/* ---------- WIDE DESKTOP (≥ 1100px) ---------- */

@media (min-width: 1100px) {
  .otb-branding__logo img {
    height: 70px;
  }

  .otb-header__content .otb-primary-nav {
    margin-left: var(--spacing-lg);
  }
}
