/* ============================================================
   HEADER COMPONENT
   Source: docs/wireframes/header.html — class names copied verbatim.
   Tokens come from base.css :root — no hardcoded colours or spacing.
   ============================================================ */

/* ---------- Shipping bar ---------- */
.shipping-bar {
  background: var(--color-accent);
  color: var(--color-text-inverse);
  text-align: center;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 0.4rem var(--space-4);
}

/* ---------- Site header ---------- */
.site-header {
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-4) var(--container-pad);
  /* Sit above .primary-nav (z-index 200) so the typeahead dropdown
     overlays the nav links instead of hiding behind them. */
  position: relative;
  z-index: 500;
}
.site-header-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex: 1;
  min-width: 0;
}

/* ---------- Logo ---------- */
.site-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  flex-shrink: 0;
}
.site-logo-img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  flex-shrink: 0;
}
.site-logo-name {
  display: block;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.2;
}
.site-logo-sub {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  line-height: 1.4;
}

/* ---------- Search bar (home page only) ---------- */
.search-bar {
  flex: 1;
  min-width: 180px;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}
.search-bar input {
  width: 100%;
  padding: 0.55rem 1rem 0.55rem 2.5rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-full);
  font-family: var(--font-primary);
  font-size: var(--text-sm);
  background: var(--color-bg-subtle);
  color: var(--color-text-primary);
  transition: border-color 0.15s, background 0.15s;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-bg-surface);
}
.search-bar input::placeholder { color: var(--color-text-hint); }
.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-hint);
  display: flex;
  align-items: center;
  pointer-events: none;
}

/* When search is hidden, actions hug the right edge */
.header-right:has(.search-bar[hidden]) { justify-content: flex-end; }

/* ---------- Typeahead dropdown ---------- */
.typeahead-dropdown {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 60vh;
  overflow-y: auto;
}
.typeahead-dropdown:empty { display: none; }

.typeahead-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
}
.typeahead-item a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  text-decoration: none;
  color: var(--color-text-primary);
}
.typeahead-item a:hover,
.typeahead-item a:focus {
  background: var(--color-bg-subtle);
}
.typeahead-thumb {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}
.typeahead-thumb-empty {
  background: var(--color-bg-subtle);
}
.typeahead-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.typeahead-name {
  font-size: var(--text-sm);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.typeahead-cat {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}
.typeahead-prices {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  flex-shrink: 0;
}
.typeahead-price {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
}
.typeahead-oos {
  margin-left: 0.4rem;
  color: var(--color-error);
  font-weight: 500;
}
.typeahead-footer {
  display: block;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--color-border);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}
.typeahead-footer:hover,
.typeahead-footer:focus {
  background: var(--color-bg-subtle);
}

/* ---------- Header actions (account, cart) ---------- */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  flex-shrink: 0;
}
.header-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-family: var(--font-primary);
  cursor: pointer;
  border: none;
  background: none;
  transition: color 0.15s;
}
.header-action:hover { color: var(--color-primary); }

.cart-badge { position: relative; display: inline-flex; }
.cart-count {
  position: absolute;
  top: -5px;
  right: -8px;
  background: var(--color-accent);
  color: var(--color-text-inverse);
  font-size: 10px;
  font-weight: 700;
  border-radius: var(--radius-full);
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Primary nav ---------- */
.primary-nav {
  background: var(--color-primary);
  position: relative;
  z-index: 200;
}
.primary-nav-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--container-pad);
  display: flex;
  justify-content: center;
}
.primary-nav ul {
  list-style: none;
  display: flex;
  align-items: center;
}
.primary-nav ul > li { position: relative; }

.primary-nav ul > li > a {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.65rem var(--space-5);
  color: var(--color-text-inverse);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background 0.15s;
  white-space: nowrap;
}
.primary-nav ul > li > a:hover { background: var(--color-primary-dark); }

.nav-chevron {
  width: 10px;
  height: 7px;
  transition: transform 0.2s ease;
  flex-shrink: 0;
  opacity: 0.8;
}
.primary-nav ul > li:hover .nav-chevron { transform: rotate(180deg); }

/* ---------- Dropdowns (CSS-only, hover) ---------- */
.dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  z-index: 300;
}
.primary-nav ul > li:hover .dropdown,
.primary-nav ul > li:focus-within .dropdown { display: block; }

.dropdown-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-text-hint);
  padding: 0.65rem 1rem 0.3rem;
}
.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  color: var(--color-text-primary);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 400;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  gap: var(--space-4);
}
.dropdown-item:hover { background: var(--color-bg-subtle); color: var(--color-primary); }
.dropdown-item.is-bold { font-weight: 600; color: var(--color-primary); }
.dropdown-item.is-accent { font-weight: 600; color: var(--color-accent); }

.dropdown-divider {
  height: 1px;
  background: var(--color-border);
  margin: 0.25rem 0;
}

.sub-arrow {
  width: 8px;
  height: 8px;
  transform: rotate(-90deg);
  color: var(--color-text-hint);
  flex-shrink: 0;
  opacity: 0.55;
}

/* ---------- Sub-dropdowns ---------- */
.dropdown-group { position: relative; }
.sub-dropdown {
  display: none;
  position: absolute;
  top: -1px;
  left: 100%;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 400;
}
.dropdown-group:hover .sub-dropdown,
.dropdown-group:focus-within .sub-dropdown { display: block; }
.sub-dropdown a {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--color-text-primary);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.sub-dropdown a:hover { background: var(--color-bg-subtle); color: var(--color-primary); }

/* ---------- Account user menu (logged in) ---------- */
.header-account { position: relative; }
.header-user-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 180px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2) 0;
  z-index: 300;
}
.header-account:hover .header-user-menu,
.header-account:focus-within .header-user-menu { display: block; }
.header-user-menu-form { margin: 0; }
.header-user-menu-item {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-4);
  text-align: left;
  background: none;
  border: none;
  font-family: var(--font-primary);
  font-size: var(--text-sm);
  color: var(--color-text-primary);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.header-user-menu-item:hover { background: var(--color-bg-subtle); color: var(--color-primary); }

/* ---------- Narrow screens ----------
   Interim until the mobile hamburger nav (deferred, see design-handover.md
   "Known mobile gaps"): wrap instead of overflowing horizontally. */
@media (max-width: 640px) {
  .site-header-inner { flex-wrap: wrap; gap: var(--space-3); }
  .header-right { flex-basis: 100%; justify-content: flex-end; }
  .search-bar { min-width: 0; }
  .primary-nav ul { flex-wrap: wrap; justify-content: center; }
  .primary-nav ul > li > a { padding: 0.65rem var(--space-3); }
}
