/* ==========================================================================
   Header + mega-menú — escrit contra part-header.php i header.js
   ========================================================================== */

.screen-reader-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--wine); outline-offset: 2px; }

.site-header { position: relative; z-index: 80; }

/* ---------- nav-item / toggle ---------- */
.nav-item { position: static; display: flex; align-items: center; }
.nav-item--drop { position: relative; }

.nav-item__toggle {
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; padding: 6px; margin-left: 5px; color: var(--ink-faint);
}
.nav-item__toggle svg {
  width: 15px; height: 15px; color: #676767;
  transition: transform .15s ease;
}
.nav-item__toggle[aria-expanded="true"] svg { transform: rotate(180deg); }

/* Nav de 7 punts (component Header del boceto): apretem l'espaiat en pantalles mitjanes. */
@media (max-width: 1280px) {
  .main-nav { gap: 18px; }
  .main-nav a { font-size: 13px; }
}

/* ---------- header-actions ---------- */
.header-login { font-family: var(--font-ui); font-weight: 500; font-size: 14px; color: var(--ink); }
.header-login:hover { color: var(--wine); }

/* Només dins del drawer (mòbil). */
.drawer-top,
.drawer-search,
.drawer-shop,
.drawer-social,
.nav-close { display: none; }

.header-cart { position: relative; }
.header-cart__count {
  position: absolute; top: -6px; right: -8px;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 2px;
  border-radius: 50%; background: var(--wine); color: #fff;
  font-family: var(--font-ui); font-weight: 700; font-size: 10px; line-height: 1;
}

.header-search-toggle summary {
  list-style: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.header-search-toggle summary::-webkit-details-marker { display: none; }
.header-search-toggle summary svg { width: 19px; height: 19px; }
.header-search-toggle[open] .header-search {
  position: absolute; top: calc(100% + 10px); right: var(--header-pad-x);
  z-index: 90; box-shadow: 0 24px 60px -12px rgba(28, 20, 24, .15);
}

/* ---------- backdrop ---------- */
.header-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(28, 20, 24, .35); }
.header-backdrop[hidden] { display: none; }

/* ---------- megamenu ---------- */
.megamenu[hidden], .nav-drop[hidden] { display: none; }

/* .main-nav a du white-space:nowrap (theme.css): dins del panell els títols han
   de poder partir-se, si no se n'ixen i el drawer scrolla en horitzontal. */
.megamenu a, .nav-drop a { white-space: normal; }

.megamenu {
  position: absolute; left: 50%; top: calc(100% + 1px);
  transform: translateX(-50%) translateY(6px);
  width: min(1240px, calc(100vw - 48px));
  background: var(--paper-card);
  border-top: 3px solid var(--wine);
  border-radius: 2px;
  box-shadow: 0 24px 60px -12px rgba(28, 20, 24, .15);
  padding: 36px 48px 40px 48px;
  z-index: 60;
  opacity: 0;
  transition: opacity .15s ease, transform .15s ease;
}
.megamenu.is-open { opacity: 1; transform: translateX(-50%) translateY(0); }

.megamenu__head {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding-bottom: 16px; margin-bottom: 26px; border-bottom: 1px solid var(--line);
}
.megamenu__title { font-family: var(--font-ui); font-size: 22px; font-weight: 600; color: var(--ink); margin: 0; }
.megamenu__headlinks { display: inline-flex; align-items: center; gap: 22px; }
.megamenu__viewall {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-ui); font-weight: 600; font-size: 14px; color: var(--wine);
}
.megamenu__viewall svg { width: 15px; height: 15px; }
.megamenu__viewall:hover { text-decoration: underline; }
.megamenu__viewall--sm { font-size: 13.5px; }

.megamenu__body { display: flex; gap: 44px; }
.megamenu__cols { flex: 1; display: flex; gap: 52px; }
.megamenu__col { flex: 1; display: flex; flex-direction: column; gap: 26px; }
.megamenu__group { display: flex; flex-direction: column; }
.megamenu__label {
  font-family: var(--font-ui); font-weight: 700; font-size: 12px; letter-spacing: 1.5px;
  color: var(--ink-faint); margin: 0 0 13px;
}
.megamenu__list { list-style: none; margin: 0; padding: 0; }
.megamenu__list li + li { margin-top: 13px; }
.megamenu__list a { font-family: var(--font-ui); font-weight: 400; font-size: 14.5px; color: var(--ink); }
.megamenu__list a:hover { color: var(--wine); }
.megamenu__list a.megamenu__more { color: var(--wine); font-weight: 600; }

.megamenu__novetats {
  width: 360px; flex-shrink: 0;
  border-left: 1px solid var(--line); padding-left: 44px;
}
.megamenu__items { list-style: none; margin: 0 0 18px; padding: 0; }
.megamenu__items li { padding: 16px 0; border-top: 1px solid var(--line); }
.megamenu__items li:first-child { padding-top: 0; border-top: 0; }

.megamenu__item { display: flex; align-items: center; gap: 14px; color: inherit; }
.megamenu__item:hover .megamenu__itemtitle { color: var(--wine); }
.megamenu__cover { width: 58px; height: 82px; object-fit: cover; border-radius: 2px; flex-shrink: 0; }
/* min-width:0 = els títols llargs encongeixen dins del flex en compte d'eixir-se'n. */
.megamenu__itemtext { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 auto; }
.megamenu__itemtitle { font-family: var(--font-ui); font-weight: 600; font-size: 14.5px; line-height: 18px; color: var(--ink); overflow-wrap: anywhere; }
.megamenu__itemprice,
.megamenu__itemprice .amount {
  font-family: var(--font-ui); font-weight: 700; font-size: 14px; color: var(--wine);
}

/* ---------- nav-drop (blog) ---------- */
.nav-drop {
  position: absolute; top: calc(100% + 8px); left: 0;
  min-width: 180px; background: var(--paper-card); border: 1px solid var(--line);
  border-radius: 2px; box-shadow: 0 24px 60px -12px rgba(28, 20, 24, .15);
  padding: 10px 0; z-index: 60;
}
.nav-drop a { display: block; padding: 10px 18px 14.5px; color: var(--ink); }
.nav-drop a:hover { background: var(--paper-2); }

@media (prefers-reduced-motion: reduce) {
  .megamenu, .main-nav, .nav-item__toggle svg { transition: none; }
}


/* ==========================================================================
   Drawer off-canvas (< 900px)
   Registre: producte. La feina de l'usuari és trobar un llibre i comprar-lo,
   així que el drawer obri amb cerca + botiga i converteix el catàleg en
   preguntes ("per edat", "per cicle") amb chips, no en una llista de 29
   enllaços. El color viu el posen les portades, no la interfície.
   ========================================================================== */
@media (max-width: 899px) {
  .main-nav {
    position: fixed; top: 0; right: 0; height: 100dvh;
    width: min(370px, 90vw); background: var(--paper);
    display: flex; flex-direction: column; align-items: stretch; gap: 0;
    padding: 0 10px 40px; transform: translateX(100%);
    transition: transform .22s cubic-bezier(.16, 1, .3, 1);
    z-index: 70; overflow-y: auto; overscroll-behavior: contain;
    border-left: 1px solid var(--line);
  }
  .main-nav.is-open { transform: translateX(0); box-shadow: -26px 0 70px -24px rgba(28, 20, 24, .3); }

  /* Capçalera del drawer: isotip (marca) + tancar. Sticky: la ✕ sempre a mà. */
  .drawer-top {
    position: sticky; top: 0; z-index: 2;
    display: flex; align-items: center; justify-content: space-between;
    padding: 13px 14px 13px 20px;
    background: var(--paper); border-bottom: 1px solid var(--line);
  }
  .drawer-top__mark { height: 19px; width: auto; display: block; }
  .nav-close {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; padding: 0;
    background: none; border: 0; color: var(--ink-soft); cursor: pointer;
    border-radius: 2px;
  }
  .nav-close:hover, .nav-close:focus-visible { color: var(--ink); background: var(--paper-2); }

  /* Cerca: primera acció, perquè en mòbil la majoria arriba buscant. */
  .drawer-search {
    display: flex; align-items: center; gap: 10px;
    margin: 18px 20px 0; padding: 0 13px; height: 46px;
    background: var(--paper-card); border: 1px solid var(--line); border-radius: 2px;
    color: var(--ink-faint);
  }
  .drawer-search:focus-within { border-color: var(--wine); color: var(--wine); }
  .drawer-search input {
    flex: 1; min-width: 0; border: 0; background: none; padding: 0;
    font-family: var(--font-ui); font-size: 15px; color: var(--ink);
  }
  .drawer-search input::placeholder { color: var(--ink-faint); }
  .drawer-search input:focus { outline: 0; }

  /* Botiga dins del menú: carret i compte, on l'usuari els busca. */
  .drawer-shop {
    display: flex; margin: 10px 20px 22px;
    border: 1px solid var(--line); border-radius: 2px; overflow: hidden;
  }
  .drawer-shop__link {
    flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 46px; padding: 0 8px; background: var(--paper-card);
    font-family: var(--font-ui); font-size: 13.5px; font-weight: 600; color: var(--ink);
    white-space: nowrap;
  }
  .drawer-shop__link + .drawer-shop__link { border-left: 1px solid var(--line); }
  .drawer-shop__link:hover { background: var(--paper-2); color: var(--wine); }
  .drawer-shop__link svg { color: var(--ink-soft); }
  .drawer-shop__count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--wine); color: #fff;
    font-size: 10.5px; font-weight: 700; line-height: 1;
  }

  /* Files de navegació */
  .main-nav > a,
  .main-nav .nav-item__link {
    display: block; padding: 14px 20px;
    font-family: var(--font-ui); font-size: 16px; font-weight: 500; color: var(--ink);
    border-bottom: 1px solid var(--line);
  }
  .main-nav > a:hover, .main-nav .nav-item__link:hover { background: var(--paper-2); }

  /* Catàleg és el punt d'entrada real: pesa més que la resta. */
  .nav-item {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; border-bottom: 1px solid var(--line);
  }
  .nav-item .nav-item__link { flex: 1; border-bottom: 0; font-size: 17px; font-weight: 600; }
  .nav-item__toggle { min-width: 44px; min-height: 44px; margin-right: 8px; color: var(--ink-soft); }

  /* L'últim punt, com a crida discreta (no un botó cridaner). */
  .main-nav > a.nav-cta { color: var(--wine); font-weight: 600; }

  /* Peu del drawer: xarxes. Tanquen el menú sense competir amb la navegació. */
  .drawer-social { display: flex; gap: 6px; padding: 18px 12px 0; }
  .drawer-social a {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; border-radius: 2px;
    color: var(--ink-faint);
  }
  .drawer-social a:hover, .drawer-social a:focus-visible { color: var(--wine); background: var(--paper-2); }

  /* --- Panell del catàleg: de llista-totxo a preguntes amb chips ---------- */
  .megamenu, .nav-drop {
    position: static; transform: none; width: 100%;
    background: var(--paper-2);
    box-shadow: none; border: 0; border-radius: 0; z-index: auto;
    padding: 18px 20px 22px; opacity: 1;
  }
  .megamenu.is-open { transform: none; }
  .megamenu__title { display: none; } /* "Categories principals" ja ho diu "Catàleg" */
  .megamenu__head { padding: 0; margin: 0 0 18px; border: 0; }
  .megamenu__viewall { font-size: 13.5px; }
  .megamenu__body { flex-direction: column; gap: 22px; }
  .megamenu__cols { flex-direction: column; gap: 22px; }
  .megamenu__col { display: contents; } /* els grups apilen directament */
  .megamenu__group { display: flex; flex-direction: column; gap: 10px; }
  .megamenu__label {
    font-family: var(--font-mono); font-size: 10px; font-weight: 700;
    letter-spacing: 1.4px; color: var(--wine); margin: 0;
  }

  /* Chips: escaneables d'un colp d'ull, en compte de 29 files iguals. */
  .megamenu__list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; align-items: flex-start; }
  /* El li ha de ser flex: si no, l'ancoratge inline-flex crea caixa de línia i el
     chip queda desalineat. El gap del flex ja separa: cal anul·lar el margin-top
     de la llista vertical d'escriptori (li + li), que si no descol·loca les files. */
  .megamenu__list li,
  .megamenu__list li + li { display: flex; margin: 0; padding: 0; border: 0; }
  .megamenu__list a {
    display: inline-flex; align-items: center; min-height: 38px; padding: 0 13px;
    background: var(--paper-card); border: 1px solid var(--line); border-radius: 999px;
    font-family: var(--font-ui); font-size: 13.5px; font-weight: 500; color: var(--ink);
    transition: border-color .15s ease, color .15s ease;
  }
  .megamenu__list a:hover, .megamenu__list a:focus-visible { border-color: var(--wine); color: var(--wine); }
  .megamenu__more { background: none; border-style: dashed; color: var(--wine); }

  /* Novetats: carrusel de portades, dalt de tot del panell (order:-1). Ací és on
     entra el color de la marca, abans que les categories. */
  .megamenu__novetats {
    order: -1;
    width: 100%; border-left: 0; padding: 0 0 20px;
    border-bottom: 1px solid var(--line);
    display: flex; flex-direction: column; gap: 12px;
  }
  .megamenu__items {
    display: flex; gap: 14px; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    margin: 0; padding: 2px 0 6px;
  }
  .megamenu__items li {
    flex: 0 0 104px; padding: 0; border: 0; scroll-snap-align: start;
  }
  .megamenu__item { flex-direction: column; align-items: stretch; gap: 9px; }
  .megamenu__cover { width: 104px; height: 148px; box-shadow: 0 6px 18px -8px rgba(28, 20, 24, .45); }
  .megamenu__itemtext { gap: 3px; }
  .megamenu__itemtitle { font-size: 13px; line-height: 16px; }
  .megamenu__itemprice, .megamenu__itemprice .amount { font-size: 12.5px; }
  .megamenu__viewall--sm { align-self: flex-start; }

  /* Barra superior: sense el text del compte no desborda a 360px. */
  .header-login { display: none; }
  .site-header { gap: 12px; padding-left: 16px; padding-right: 16px; }
  .header-actions { gap: 6px; }

  .mobile-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px;
  }
  /* L'hamburguesa NO pot portar z-index: quedaria damunt del drawer (z 70, dins
     del mateix context del header) i xocaria amb el chevron de Catàleg. */

  /* theme.css oculta .header-search a <768px: ací el reobrim a tot l'ample. */
  .header-search-toggle[open] .header-search {
    display: flex; left: 16px; right: 16px; width: auto;
  }

  body.nav-open { overflow: hidden; }
  .header-backdrop { z-index: 65; }
}
