/* =============================================================================
 * SERIGRAPHIE-BOUTIQUE — Header v0.2.0
 * =============================================================================
 * Dépendances : tokens.css, buttons.css, inputs.css
 *
 * Structure :
 * 1. Top bar (trust stack : livraison + Trusted Shops + langues)
 * 2. Main header : logo + nav univers + search + profile pill + cart
 * 3. Sticky au scroll (le main header reste, la top bar disparaît)
 *
 * Accessibilité :
 * - <header role="banner">
 * - <nav role="navigation" aria-label="Principale">
 * - skip-link pour clavier (à inclure en Sprint D5)
 * ============================================================================= */

/* ---------------------------------------------------------------------------
 * Container global
 * ------------------------------------------------------------------------- */
.sb-header {
  width: 100%;
  background-color: var(--sb-color-paper);
  border-bottom: 1px solid var(--sb-color-cendre);
  position: relative;
  z-index: var(--sb-z-sticky);
}

/* Sticky au scroll — on cache la topbar pour gagner de la hauteur */
.sb-header.is-sticky {
  position: sticky;
  top: 0;
  box-shadow: var(--sb-shadow-sm);
}

.sb-header.is-sticky .sb-header__topbar {
  display: none;
}

.sb-header.is-sticky .sb-header__main {
  padding-top: var(--sb-sp-3);
  padding-bottom: var(--sb-sp-3);
}

/* ---------------------------------------------------------------------------
 * TOP BAR — trust stack
 * ------------------------------------------------------------------------- */
.sb-header__topbar {
  background-color: var(--sb-color-ink);
  color: var(--sb-color-paper);
  font-size: var(--sb-fs-xs);
  line-height: 1;
}

.sb-header__topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sb-sp-4);
  padding: var(--sb-sp-2) var(--sb-sp-6);
  max-width: var(--sb-container-max-width);
  margin: 0 auto;
}

.sb-header__topbar-left,
.sb-header__topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sb-sp-4);
}

.sb-header__trust-stars {
  color: var(--sb-color-warning);
  letter-spacing: -2px;
  font-weight: var(--sb-fw-medium);
}

.sb-header__topbar a {
  color: inherit;
  text-decoration: none;
}

.sb-header__topbar a:hover {
  color: var(--sb-color-accent);
}

.sb-header__lang-switcher {
  display: inline-flex;
  gap: var(--sb-sp-2);
  align-items: center;
}

.sb-header__lang-switcher a {
  opacity: 0.6;
  padding: 0 var(--sb-sp-1);
}

.sb-header__lang-switcher a.is-active {
  opacity: 1;
  font-weight: var(--sb-fw-medium);
}

/* ---------------------------------------------------------------------------
 * MAIN HEADER — logo + nav + search + icons
 * ------------------------------------------------------------------------- */
.sb-header__main {
  max-width: var(--sb-container-max-width);
  margin: 0 auto;
  padding: var(--sb-sp-4) var(--sb-sp-6);
  display: flex;
  align-items: center;
  gap: var(--sb-sp-6);
  transition: padding var(--sb-duration-normal) var(--sb-ease-out);
}

/* La nav prend l'espace central disponible */
.sb-header__nav {
  flex: 1;
  min-width: 0;
}

/* ---------------------------------------------------------------------------
 * LOGO
 * ------------------------------------------------------------------------- */
.sb-logo {
  display: flex;
  align-items: center;
  gap: var(--sb-sp-2);
  text-decoration: none;
  color: var(--sb-text-primary);
  flex-shrink: 0;
}

/* Version simplifiée "dot" — le vrai logo A.BUISINE s'insère via <img> */
.sb-logo__dot {
  width: 28px;
  height: 28px;
  background-color: var(--sb-color-ink);
  border-radius: var(--sb-radius-pill);
  position: relative;
  flex-shrink: 0;
}

.sb-logo__dot::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 5px;
  width: 18px;
  height: 18px;
  border-radius: var(--sb-radius-pill);
  background-color: var(--sb-color-accent);
}

.sb-logo__text {
  display: flex;
  flex-direction: column;
  line-height: 1;
  gap: 3px;
}

.sb-logo__brand {
  font-size: var(--sb-fs-md);
  font-weight: var(--sb-fw-medium);
  letter-spacing: var(--sb-ls-wide);
}

.sb-logo__baseline {
  font-size: var(--sb-fs-micro);
  color: var(--sb-text-secondary);
  letter-spacing: var(--sb-ls-wider);
  text-transform: uppercase;
}

/* Alternative logo : image vraie */
.sb-logo__img {
  height: 40px;
  width: auto;
  display: block;
}

/* ---------------------------------------------------------------------------
 * NAV PRINCIPALE — les 4 univers + ressources
 * ------------------------------------------------------------------------- */
.sb-header__nav {
  display: flex;
  gap: var(--sb-sp-6);
  align-items: center;
}

.sb-header__nav a {
  font-size: var(--sb-fs-sm);
  font-weight: var(--sb-fw-medium);
  color: var(--sb-text-primary);
  text-decoration: none;
  padding: var(--sb-sp-2) 0;
  border-bottom: 2px solid transparent;
  transition: border-color var(--sb-duration-fast) var(--sb-ease-out);
}

.sb-header__nav a:hover,
.sb-header__nav a.is-current {
  border-bottom-color: var(--sb-color-accent);
}

/* Highlight de l'univers correspondant au profil détecté */
.sb-header__nav a.is-your-universe {
  position: relative;
}

.sb-header__nav a.is-your-universe::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 4px;
  border-radius: var(--sb-radius-pill);
  background-color: var(--sb-color-accent);
}

/* ---------------------------------------------------------------------------
 * SHORTCUT PILL "Continuer en X" — apparaît uniquement si profil détecté
 * Positionné entre logo et nav. CTA orange = signal fort mais discret.
 * ------------------------------------------------------------------------- */
.sb-header__shortcut {
  display: none;
  align-items: center;
  gap: var(--sb-sp-2);
  padding: var(--sb-sp-2) var(--sb-sp-4);
  background-color: var(--sb-color-accent);
  color: var(--sb-text-on-accent);
  border-radius: var(--sb-radius-pill);
  font-size: var(--sb-fs-xs);
  font-weight: var(--sb-fw-medium);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition:
    background-color var(--sb-duration-fast) var(--sb-ease-out),
    transform var(--sb-duration-fast) var(--sb-ease-out);
}

.sb-header.has-profile .sb-header__shortcut {
  display: inline-flex;
}

.sb-header__shortcut:hover {
  background-color: var(--sb-color-accent-hover);
  transform: translateX(2px);
}

.sb-header__shortcut:focus-visible {
  outline: none;
  box-shadow: var(--sb-shadow-focus);
}

.sb-header__shortcut-icon {
  font-size: var(--sb-fs-sm);
  line-height: 1;
  transition: transform var(--sb-duration-fast) var(--sb-ease-out);
}

.sb-header__shortcut:hover .sb-header__shortcut-icon {
  transform: translateX(3px);
}

@media (prefers-reduced-motion: reduce) {
  .sb-header__shortcut,
  .sb-header__shortcut:hover,
  .sb-header__shortcut-icon,
  .sb-header__shortcut:hover .sb-header__shortcut-icon {
    transition: none;
    transform: none;
  }
}

/* Sur mobile, le shortcut reste visible mais compact */
@media (max-width: 767px) {
  .sb-header__shortcut {
    padding: var(--sb-sp-1) var(--sb-sp-3);
    font-size: 11px;
  }
}

/* ---------------------------------------------------------------------------
 * SEARCH BAR (compacte dans header)
 * ------------------------------------------------------------------------- */
.sb-header__search {
  position: relative;
  width: 240px;
}

.sb-header__search .sb-input {
  height: 40px;
  min-height: 40px;
  padding: var(--sb-sp-2) var(--sb-sp-4) var(--sb-sp-2) 36px;
  font-size: var(--sb-fs-xs);
}

.sb-header__search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--sb-text-secondary);
  pointer-events: none;
}

/* ---------------------------------------------------------------------------
 * PROFILE PILL — indicateur univers détecté / reset
 * ------------------------------------------------------------------------- */
.sb-profile-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sb-sp-2);
  padding: var(--sb-sp-2) var(--sb-sp-3);
  background-color: var(--sb-color-paper);
  border: 1px solid var(--sb-color-cendre);
  border-radius: var(--sb-radius-pill);
  font-size: var(--sb-fs-micro);
  font-weight: var(--sb-fw-medium);
  color: var(--sb-text-secondary);
  cursor: pointer;
  transition:
    border-color var(--sb-duration-fast) var(--sb-ease-out),
    background-color var(--sb-duration-fast) var(--sb-ease-out);
}

.sb-profile-pill__dot {
  width: 8px;
  height: 8px;
  border-radius: var(--sb-radius-pill);
  background-color: var(--sb-color-cendre);
}

.sb-profile-pill.is-active {
  border-color: var(--sb-color-accent);
  background-color: var(--sb-color-accent-soft);
  color: var(--sb-text-primary);
}

.sb-profile-pill.is-active .sb-profile-pill__dot {
  background-color: var(--sb-color-accent);
}

.sb-profile-pill:hover {
  border-color: var(--sb-color-graphite);
}

/* ---------------------------------------------------------------------------
 * ICONS (compte + panier)
 * ------------------------------------------------------------------------- */
.sb-header__icons {
  display: flex;
  gap: var(--sb-sp-2);
  align-items: center;
}

.sb-header__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--sb-radius-sm);
  color: var(--sb-text-primary);
  cursor: pointer;
  position: relative;
  transition: background-color var(--sb-duration-fast) var(--sb-ease-out);
}

.sb-header__icon-btn:hover {
  background-color: var(--sb-color-cendre-soft);
}

.sb-header__icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--sb-shadow-focus);
}

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

/* Badge compteur panier positionné */
.sb-header__cart-count {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background-color: var(--sb-color-accent);
  color: var(--sb-text-on-accent);
  font-size: 10px;
  font-weight: var(--sb-fw-medium);
  border-radius: var(--sb-radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ---------------------------------------------------------------------------
 * RESET HINT BAR (apparaît sous le header si profil détecté)
 * Affiché uniquement sur les premières visites — dismissible manuellement (×)
 * OU auto-fermé après 3 visites dans l'univers préféré
 * (classes pilotées par adaptive-home.js : .has-profile ET .show-reset-hint)
 * ------------------------------------------------------------------------- */
.sb-header__reset-hint {
  padding: var(--sb-sp-3) var(--sb-sp-6);
  background-color: var(--sb-color-accent-soft);
  border-top: 1px solid var(--sb-color-accent-tint);
  font-size: var(--sb-fs-xs);
  color: var(--sb-text-secondary);
  text-align: center;
  display: none;
  position: relative;
}

/* N'apparaît QUE si le profil est actif ET que le hint n'a pas été dismissé */
.sb-header.has-profile.show-reset-hint .sb-header__reset-hint {
  display: block;
}

.sb-header__reset-hint strong {
  color: var(--sb-text-primary);
  font-weight: var(--sb-fw-medium);
}

.sb-header__reset-hint a {
  color: var(--sb-color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: var(--sb-fw-medium);
  cursor: pointer;
}

/* Bouton × pour fermer définitivement le hint */
.sb-header__reset-hint__close {
  position: absolute;
  top: 50%;
  right: var(--sb-sp-3);
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--sb-radius-pill);
  color: var(--sb-text-secondary);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: background-color var(--sb-duration-fast) var(--sb-ease-out);
}

.sb-header__reset-hint__close:hover {
  background-color: rgba(0, 0, 0, 0.06);
  color: var(--sb-text-primary);
}

.sb-header__reset-hint__close:focus-visible {
  outline: none;
  box-shadow: var(--sb-shadow-focus);
}

/* ---------------------------------------------------------------------------
 * MOBILE BURGER — toggle du menu mobile
 * ------------------------------------------------------------------------- */
.sb-header__burger {
  display: none;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--sb-text-primary);
}

.sb-header__burger svg {
  width: 22px;
  height: 22px;
}

/* ---------------------------------------------------------------------------
 * RESPONSIVE
 * ------------------------------------------------------------------------- */
@media (max-width: 1023px) {
  .sb-header__search {
    width: 180px;
  }
  .sb-header__nav {
    gap: var(--sb-sp-4);
  }
  .sb-header__nav a {
    font-size: var(--sb-fs-xs);
  }
}

@media (max-width: 767px) {
  /* Top bar : réduire la marge + passer le right (Trusted Shops) sur single line */
  .sb-header__topbar-inner {
    flex-wrap: nowrap;
    gap: var(--sb-sp-2);
    padding: var(--sb-sp-1) var(--sb-sp-3);
    font-size: 10px;
  }
  .sb-header__topbar-right {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
    min-width: 0;
  }

  .sb-header__main {
    padding: var(--sb-sp-3) var(--sb-sp-4);
    gap: var(--sb-sp-2);
  }
  /* Logo prend l'espace disponible au centre, icons à droite non-compressibles */
  .sb-logo {
    flex: 1 1 auto;
    min-width: 0;
  }
  .sb-header__icons {
    flex: 0 0 auto;
    margin-left: auto;
  }
  .sb-header__nav,
  .sb-header__search,
  .sb-profile-pill {
    display: none;
  }
  .sb-header__burger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
  }
  .sb-header__topbar-inner {
    padding: var(--sb-sp-2) var(--sb-sp-4);
    font-size: 10px;
  }
  .sb-header__topbar-left {
    display: none;          /* trop long en mobile, on garde juste le trust */
  }
}

/* --- Very small mobile (<640px) : on sacrifie le shortcut pill pour garantir
 * que les icônes compte + panier restent visibles à droite. Le burger + le
 * dot orange sur l'univers préféré suffisent à rappeler le profil actif. */
@media (max-width: 640px) {
  .sb-header.has-profile .sb-header__shortcut {
    display: none;
  }
  /* Logo condensé : on masque la baseline ("sérigraphie · boutique") pour
   * gagner ~60px de largeur horizontale sur petits écrans */
  .sb-logo__baseline {
    display: none;
  }
  .sb-logo__brand {
    font-size: var(--sb-fs-sm);
  }
  /* Hint bar : on laisse la place au bouton × à droite */
  .sb-header__reset-hint {
    padding: var(--sb-sp-3) var(--sb-sp-10) var(--sb-sp-3) var(--sb-sp-4);
    text-align: left;
    line-height: var(--sb-lh-snug);
  }
  /* Top bar très compact : on garde uniquement le left (SAV FR · Made · 1897)
   * et on cache le right (Trusted Shops 4,85 / 5 · 201 avis) qui prend
   * 4 lignes en wrapping sur un écran ~380px. L'info trust reste visible
   * via le badge Trusted Shops ePages flottant bas-droit de la page. */
  .sb-header__topbar-right {
    display: none;
  }
  .sb-header__topbar-left {
    display: block;
    font-size: 10px;
    letter-spacing: 0;
  }
  .sb-header__topbar-inner {
    justify-content: center;
  }
}
