/* ============================================================
   Header — top utility bar + main bar
   Overlay over hero (state A) → frosted on scroll (state B)
   → solid white on hover or mega open (state C)
   See DESIGN-RULES.md §5
   ============================================================ */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-header);

  /* === Color tokens scoped to the header. Per-state overrides change
         only these vars; the rules below all read from them. === */
  --h-bg:     transparent;
  --h-ink:    var(--white);
  --h-muted:  rgba(255, 255, 255, 0.72);
  --h-faint:  rgba(255, 255, 255, 0.55);
  --h-border: rgba(255, 255, 255, 0.14);
  --h-tint:   rgba(255, 255, 255, 0.10);
  --h-blur:   0px;

  background: var(--h-bg);
  border-bottom: 1px solid var(--h-border);
  -webkit-backdrop-filter: saturate(150%) blur(var(--h-blur));
          backdrop-filter: saturate(150%) blur(var(--h-blur));
  transition: background var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              -webkit-backdrop-filter var(--dur) var(--ease),
              backdrop-filter var(--dur) var(--ease);
}

/* State B — scrolled. Applies whenever the page has scrolled past STICK_AT,
   regardless of cursor position. State C (below) overrides via specificity /
   later source order when a mega trigger is hovered or a panel is open. */
.site-header.is-stuck,
body.has-light-intro .site-header {
  --h-bg:     linear-gradient(180deg, rgba(255,255,255,0.92) 0%, rgba(255,255,255,0.78) 100%);
  --h-ink:    var(--ink);
  --h-muted:  var(--graphite);
  --h-faint:  var(--smoke);
  --h-border: var(--border);
  --h-tint:   var(--paper);
  --h-blur:   14px;
}

/* State C — a mega trigger is being hovered, or a mega is open.
   Note: triggered ONLY by hover on a data-mega item, NOT by hovering
   the whole header. Plain links don't flip the bar. */
.site-header:has(.primary-nav__item[data-mega] > .primary-nav__link:hover),
.site-header.has-mega-open {
  --h-bg:     var(--white);
  --h-ink:    var(--ink);
  --h-muted:  var(--graphite);
  --h-faint:  var(--smoke);
  --h-border: var(--border);
  --h-tint:   var(--paper);
  --h-blur:   0px;
}

/* ============== Top utility bar ============== */
.topbar {
  background: transparent;
  border-bottom: 1px solid var(--h-border);
  font-size: var(--fs-13);
  color: var(--h-muted);
  transition: border-color var(--dur) var(--ease),
              color var(--dur) var(--ease);
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  gap: var(--sp-6);
}

.topbar__cluster {
  display: flex;
  align-items: center;
  gap: var(--sp-6);
}

.topbar__item {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--h-muted);
  transition: color var(--dur-fast) var(--ease);
  white-space: nowrap;
}

a.topbar__item:hover { color: var(--h-ink); }

.topbar__item svg {
  width: 14px;
  height: 14px;
  color: var(--h-faint);
  flex-shrink: 0;
  transition: color var(--dur-fast) var(--ease);
}

.topbar__divider {
  width: 1px;
  height: 14px;
  background: var(--h-border);
  transition: background var(--dur) var(--ease);
}

/* Social cluster */
.topbar__socials {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}

.social-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--h-faint);
  border-radius: var(--r-1);
  transition: color var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
}

.social-icon:hover {
  color: var(--h-ink);
  background: var(--h-tint);
}

.social-icon svg { width: 14px; height: 14px; }

/* Language switcher */
.lang-switch {
  display: inline-flex;
  align-items: center;
  font-size: var(--fs-12);
  font-weight: 500;
  color: var(--h-muted);
  letter-spacing: 0.02em;
  gap: var(--sp-1);
}

.lang-switch__btn {
  padding: 2px 6px;
  border-radius: var(--r-1);
  color: var(--h-muted);
  transition: color var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
}

.lang-switch__btn:hover { color: var(--h-ink); }

.lang-switch__btn.is-active {
  color: var(--h-ink);
  font-weight: 600;
}

.lang-switch__sep {
  color: var(--h-border);
  user-select: none;
  transition: color var(--dur) var(--ease);
}

/* Tablet / phone: topbar shows phone + lang only, collapses on scroll */
@media (max-width: 1279.98px) {
  .topbar {
    max-height: var(--topbar-h);
    overflow: hidden;
    transition: max-height var(--dur) var(--ease),
                opacity var(--dur) var(--ease),
                border-color var(--dur) var(--ease);
  }

  .site-header.is-stuck .topbar {
    max-height: 0;
    opacity: 0;
    border-bottom-color: transparent;
  }

  /* Hide everything in topbar except phone + lang switcher */
  .topbar__divider,
  .topbar__socials,
  .topbar__item:not(.topbar__item--phone) { display: none; }

  .topbar__cluster { gap: var(--sp-2); }
}

/* ============== Main bar ============== */
.mainbar {
  position: relative;
}

.mainbar__inner {
  display: flex;
  align-items: center;
  height: var(--header-h);
  gap: var(--sp-6);
  transition: height var(--dur) var(--ease);
}

.site-header.is-stuck .mainbar__inner {
  height: var(--header-h-sticky);
}

/* ---- Logo ---- */
.logo {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--h-ink);
  flex-shrink: 0;
}

.logo__stack {
  position: relative;
  display: inline-block;
  width: 85px;
  height: 85px;
  flex-shrink: 0;
  transition: width var(--dur) var(--ease),
              height var(--dur) var(--ease);
}

.site-header.is-stuck .logo__stack {
  width: 48px;
  height: 48px;
}

.logo__mark {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity var(--dur) var(--ease);
}

.logo__mark--default { opacity: 1; }
.logo__mark--alt     { opacity: 0; }

/* When the header bar is light (scrolled, mega-trigger hovered, or mega open),
   swap to the wordmark version. Same conditions as state B + C. */
.site-header.is-stuck .logo__mark--default,
.site-header.has-mega-open .logo__mark--default,
.site-header:has(.primary-nav__item[data-mega] > .primary-nav__link:hover) .logo__mark--default,
body.has-light-intro .site-header .logo__mark--default {
  opacity: 0;
}

.site-header.is-stuck .logo__mark--alt,
.site-header.has-mega-open .logo__mark--alt,
.site-header:has(.primary-nav__item[data-mega] > .primary-nav__link:hover) .logo__mark--alt,
body.has-light-intro .site-header .logo__mark--alt {
  opacity: 1;
}

/* ---- Primary nav ---- */
.primary-nav {
  display: flex;
  align-items: stretch;
  height: 100%;
  flex: 1;
  justify-content: flex-start;
  min-width: 0;
}

.primary-nav__list {
  display: flex;
  align-items: stretch;
  gap: var(--sp-1);
  height: 100%;
}

.primary-nav__item {
  display: flex;
  align-items: stretch;
  height: 100%;
  position: relative;
}

.primary-nav__link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  font-size: var(--fs-14);
  font-weight: 500;
  color: var(--h-ink);
  height: 100%;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease);
}

/* ---- Text roller: visible label slides up, red duplicate slides in ---- */
.primary-nav__roller {
  display: inline-block;
  height: 1.2em;
  line-height: 1.2;
  overflow: hidden;
  vertical-align: middle;
  position: relative;
}

.primary-nav__roller-line {
  display: block;
  height: 1.2em;
  line-height: 1.2;
  transition: transform var(--dur-slow) var(--ease),
              color var(--dur-fast) var(--ease);
  will-change: transform;
}

.primary-nav__roller-line:nth-child(2) { color: var(--red); }

.primary-nav__link:hover                   .primary-nav__roller-line,
.primary-nav__link[aria-expanded="true"]   .primary-nav__roller-line,
.primary-nav__item.is-active .primary-nav__link .primary-nav__roller-line {
  transform: translateY(-100%);
}

.primary-nav__chevron {
  width: 12px;
  height: 12px;
  color: var(--h-muted);
  transition: transform var(--dur) var(--ease),
              color var(--dur-fast) var(--ease);
}

.primary-nav__link[aria-expanded="true"] .primary-nav__chevron {
  transform: rotate(180deg);
  color: var(--h-ink);
}

/* ---- Active page indicator (no-roller fallback) ----
   Used when nav item links to (or has mega over) the current page.
   Adds red text + 2px red underline anchored to bottom of mainbar.
   Works alongside the roller transform above when roller markup exists. */
.primary-nav__item.is-active > .primary-nav__link {
  color: var(--red);
}

.primary-nav__item.is-active > .primary-nav__link::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 0;
  height: 2px;
  background: var(--red);
  border-radius: 1px 1px 0 0;
  pointer-events: none;
}

.primary-nav__item.is-active > .primary-nav__link .primary-nav__chevron {
  color: var(--red);
}

/* ---- Right cluster ---- */
.header__cluster {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

/* Icon button (search, hamburger) */
.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--h-ink);
  border-radius: var(--r-2);
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}

.icon-btn:hover { background: var(--h-tint); }

.icon-btn svg { width: 20px; height: 20px; }

/* Inline search field (replaces icon when toggled) */
.search-field {
  display: none;
  align-items: center;
  gap: var(--sp-2);
  height: 40px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--h-border);
  border-radius: var(--r-pill);
  background: var(--h-tint);
  width: 240px;
  color: var(--h-ink);
  transition: border-color var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}

.search-field.is-open { display: inline-flex; }
.search-field:focus-within {
  background: var(--white);
  border-color: var(--ink);
  color: var(--ink);
}

.search-field svg { width: 16px; height: 16px; color: var(--h-muted); }
.search-field input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  font-size: var(--fs-14);
  min-width: 0;
  color: inherit;
}
.search-field input::placeholder { color: var(--h-faint); }

/* CTA button */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 var(--sp-5);
  border-radius: var(--r-pill);
  font-size: var(--fs-14);
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}

.btn--primary {
  background: var(--red);
  color: var(--white);
}

.btn--primary:hover { background: var(--red-deep); }

.btn--primary .btn__arrow {
  transition: transform var(--dur) var(--ease);
}

.btn--primary:hover .btn__arrow { transform: translateX(2px); }

.btn--ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}

.btn--ghost:hover {
  border-color: var(--ink);
  background: var(--paper);
}

.btn svg { width: 14px; height: 14px; }

/* ============== Responsive: header ============== */

/* Tablet — ≤1279px: nav იშლება, ჰედერი მცირდება, topbar collapse-დება scroll-ზე */
@media (max-width: 1279.98px) {
  :root {
    --header-h: 64px;
    --header-h-sticky: 52px;
  }

  .primary-nav { display: none; }
  .header__search-btn { display: none; }

  .mainbar__inner {
    gap: var(--sp-3);
    justify-content: space-between;
  }

  .logo__stack { width: 40px; height: 40px; }
  .site-header.is-stuck .logo__stack { width: 32px; height: 32px; }

  .header__cluster { gap: var(--sp-2); }

  .header__cta {
    height: 34px;
    padding: 0 13px;
    font-size: var(--fs-13);
    gap: 6px;
  }
  .header__cta .btn__arrow { width: 12px; height: 12px; }

  .header__menu-btn { width: 36px; height: 36px; }
}

/* Phone — ≤767px: topbar სრულად ქრება, ჰედერი ერთ კომპაქტურ ზოლად რჩება */
@media (max-width: 767.98px) {
  :root {
    --header-h: 52px;
    --header-h-sticky: 48px;
    --topbar-h: 0px;
  }

  .topbar { display: none; }

  .mainbar__inner { gap: var(--sp-2); }

  .logo__stack { width: 30px; height: 30px; }
  .site-header.is-stuck .logo__stack { width: 28px; height: 28px; }

  .header__cta {
    height: 30px;
    padding: 0 11px;
    font-size: 12.5px;
    gap: 5px;
  }
  .header__cta .btn__arrow { width: 10px; height: 10px; }

  .header__menu-btn { width: 32px; height: 32px; }
  .header__menu-btn svg { width: 18px; height: 18px; }
}

@media (max-width: 379.98px) {
  /* Ულტრა-ვიწრო ეკრანი: ისარი ქრება, ჰედერი კიდევ უფრო კომპაქტური */
  :root {
    --header-h: 48px;
    --header-h-sticky: 44px;
  }
  .logo__stack { width: 28px; height: 28px; }
  .site-header.is-stuck .logo__stack { width: 26px; height: 26px; }
  .header__cta {
    padding: 0 10px;
    height: 28px;
  }
  .header__cta .btn__arrow { display: none; }
  .header__menu-btn { width: 30px; height: 30px; }
  .header__menu-btn svg { width: 16px; height: 16px; }
}

@media (min-width: 1280px) {
  .header__menu-btn { display: none; }
}
