/* ==========================================================================
   Header — site-wide header, sticky behaviour, megamenu, floating CTA
   Depends: tokens.css, base.css
   Breakpoint: ≤ 640px = mobile (Decision 10)
   ========================================================================== */

/* --------------------------------------------------------------------------
   Site header shell
   -------------------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  width: 100%;
  background: rgba(247, 248, 250, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  box-shadow: none;
  z-index: calc(var(--z-mobile-menu) + 10);
  transition: box-shadow 200ms ease, background 200ms ease;
}

/* Sticky state — scroll past 100 px threshold (toggled by header.js) */
.site-header.is-sticky {
  background: rgba(247, 248, 250, 0.97);
  box-shadow: var(--shadow-md);
}

/* --------------------------------------------------------------------------
   Inner container
   -------------------------------------------------------------------------- */

.header__inner {
  display: flex;
  align-items: center;
  gap: var(--gap);
  height: 72px;
  max-width: 1980px;
  margin: 0 auto;
  padding: 0 var(--pad);
  transition: height 200ms ease;
}

.site-header.is-sticky .header__inner {
  height: 64px;
}

/* --------------------------------------------------------------------------
   Logo
   -------------------------------------------------------------------------- */

.header__logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
}

.header__logo:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: var(--r-xs);
}

.header__logo-text {
  font-weight: 700;
  font-size: 20px;
  color: var(--accent);
  letter-spacing: -0.02em;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Desktop navigation (hidden on mobile ≤ 640px)
   -------------------------------------------------------------------------- */

.header__nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  position: relative;
}

.header__nav-link {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--r-xs);
  transition: color 150ms ease, background 150ms ease;
  white-space: nowrap;
}

.header__nav-link:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.header__nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Megamenu trigger button
   -------------------------------------------------------------------------- */

.header__catalog-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  background: none;
  border: none;
  border-radius: var(--r-xs);
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease;
  white-space: nowrap;
}

.header__catalog-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.header__catalog-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.header__catalog-btn .icon--chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: transform 200ms ease;
}

/* Rotate chevron when menu open */
.header__catalog-btn[aria-expanded="true"] .icon--chevron {
  transform: rotate(180deg);
}

/* --------------------------------------------------------------------------
   Megamenu panel (shown via aria-expanded on trigger — Decision 12)
   -------------------------------------------------------------------------- */

.megamenu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 560px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  padding: var(--gap);
  z-index: calc(var(--z-mobile-menu) + 5);
}

/* Hidden by default; shown when trigger aria-expanded="true" */
.megamenu[hidden] {
  display: none;
}

.megamenu__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.megamenu__tile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: var(--r-sm);
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  transition: background 150ms ease, color 150ms ease;
}

.megamenu__tile:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.megamenu__tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.megamenu__tile-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Desktop actions: phone + CTA + search (hidden on mobile ≤ 640px)
   -------------------------------------------------------------------------- */

.header__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.header__phone-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}

.header__phone {
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  text-decoration: none;
  transition: color 150ms ease;
  white-space: nowrap;
}

.header__phone:hover {
  color: var(--accent);
}

.header__phone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

.header__phone-caption {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.header__search {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-xs);
  color: var(--muted);
  text-decoration: none;
  transition: color 150ms ease, background 150ms ease;
}

.header__search:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.header__search:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.header__search svg {
  width: 20px;
  height: 20px;
}

/* --------------------------------------------------------------------------
   Mobile controls: phone icon + burger (hidden on desktop > 640px)
   -------------------------------------------------------------------------- */

.header__mobile-controls {
  display: none;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.header__phone-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--r-xs);
  color: var(--ink);
  text-decoration: none;
  transition: color 150ms ease, background 150ms ease;
}

.header__phone-icon:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.header__phone-icon:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.header__phone-icon svg {
  width: 22px;
  height: 22px;
}

/* Burger button */
.burger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--r-xs);
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease;
}

.burger:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.burger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.burger svg {
  width: 24px;
  height: 24px;
}

/* --------------------------------------------------------------------------
   No-JS fallback nav (shown only when html.no-js)
   -------------------------------------------------------------------------- */

.mobile-nav-fallback {
  display: none; /* shown by base.css: html.no-js .mobile-nav-fallback { display: block } */
  padding: 12px var(--pad);
  background: var(--bg-card);
  border-top: 1px solid var(--line);
}

.mobile-nav-fallback nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mobile-nav-fallback a {
  display: inline-block;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--r-xs);
  min-height: 44px;
  transition: color 150ms ease, background 150ms ease;
}

.mobile-nav-fallback a:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.mobile-nav-fallback a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Hide burger when no-js — user cannot open menu without JS */
html.no-js .burger {
  display: none;
}

html.no-js .header__mobile-controls .header__phone-icon {
  display: inline-flex; /* keep phone link accessible without JS */
}

/* --------------------------------------------------------------------------
   Floating CTA — mobile only (≤ 640px), fixed bottom-right
   -------------------------------------------------------------------------- */

.floating-cta {
  display: none !important; /* hidden on desktop by default — !important beats .btn { display: inline-flex } in button.css */
}

/* --------------------------------------------------------------------------
   Categories bar — second row below main header row
   Reference: old/design_unpacked/index.html .hdr-cats-row
   Hidden on mobile ≤ 640px (categories accessible via mobile menu)
   -------------------------------------------------------------------------- */

.header__cats-row {
  border-top: 1px solid var(--line);
  background: rgba(247, 248, 250, 0.65);
}

.header__cats-inner {
  display: flex;
  align-items: center;
  height: 52px;
  max-width: 1980px;
  margin: 0 auto;
  padding: 0 var(--pad);
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.header__cats-inner::-webkit-scrollbar {
  display: none;
}

/* "All categories" pill — dark background, left-most */
.header__cat-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--bg-dark);
  color: var(--ink-light);
  font: 600 14px/1 var(--sans);
  white-space: nowrap;
  text-decoration: none;
  margin-right: 8px;
  transition: background 160ms, color 160ms;
}

.header__cat-all:hover {
  background: var(--accent);
}

.header__cat-all:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

.header__cat-all svg {
  flex-shrink: 0;
}

/* Category list container */
.header__cats-list {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

/* Individual category link */
.header__cat {
  display: inline-flex;
  align-items: center;
  padding: 0 16px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 8px;
  background: transparent;
  font: 500 14px/1 var(--sans);
  color: var(--ink);
  white-space: nowrap;
  text-decoration: none;
  transition: background 160ms, color 160ms;
}

.header__cat:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.header__cat:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* Active/current category */
.header__cat.is-active {
  background: var(--bg-dark);
  color: var(--ink-light);
}

.header__cat.is-active:hover {
  background: var(--bg-dark);
}

/* --------------------------------------------------------------------------
   Responsive: mobile ≤ 640px
   -------------------------------------------------------------------------- */

@media (max-width: 640px) {
  .header__cats-row {
    display: none; /* categories accessible via mobile menu */
  }

  .header__nav {
    display: none;
  }

  .header__actions {
    display: none;
  }

  .header__mobile-controls {
    display: flex;
  }

  /* Floating CTA visible on mobile */
  .floating-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: calc(16px + var(--cookie-banner-h, 0px));
    right: 16px;
    z-index: var(--z-floating-cta);
    padding: 14px 20px;
    border-radius: var(--r-sm);
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    box-shadow: var(--shadow-lg);
  }

  .floating-cta:focus-visible {
    outline: 2px solid var(--bg-card);
    outline-offset: 3px;
  }
}
