/* =============================================================================
 * SONOYA - nb-product-card.css
 * -----------------------------------------------------------------------------
 * LA CARD PRODUIT CANONIQUE. Composant unique, utilise par TOUTES les pages.
 *
 * REGLE ABSOLUE (D-030) : il n'existe qu'un seul markup de card produit sur tout
 * le site. Il est genere par templates/layout/components/product-card.php via
 * renderProductCard(). Ne JAMAIS redefinir une card dans un CSS de page.
 *
 * Structure :
 *   .nb-product-card
 *     __link
 *       __media          badges (haut gauche), vues (bas droite), quick actions
 *                        (cascade au hover), overlay vendeur glassmorphism
 *       __body           titre, note, prix, ventes, barre de stock flash
 *     __cta              ajouter au panier, pleine largeur
 *
 * Variantes de rendu (attribut PHP $variant) :
 *   default | sponsored | flash | new | bestseller | trending
 *
 * Variantes de layout (classe CSS) :
 *   --list      ligne horizontale (listing en mode liste)
 *
 * Sur mobile (hover: none) : l'overlay vendeur est masque, les quick actions
 * restent visibles.
 * ============================================================================= */

@layer components {
  /* ---- Base card ---- */
  .nb-product-card {
    /* Container query (D-011 #6) : la card s'adapte a la largeur de SON conteneur,
       pas du viewport. Une meme card est donc lisible dans un rail etroit comme
       dans une grande cellule de grille, sans code specifique a la page. */
    container-type: inline-size;
    container-name: product-card;
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--nb-color-surface);
    border: 1px solid var(--nb-color-border);
    border-radius: var(--nb-radius-md);
    overflow: hidden;
    transition: border-color var(--nb-dur-fast) var(--nb-ease-standard),
                box-shadow var(--nb-dur-fast) var(--nb-ease-standard);
  }
  .nb-product-card:hover {
    border-color: var(--nb-color-border-hover);
    box-shadow: var(--nb-shadow-sm);
  }
  .nb-product-card__link { display: flex; flex-direction: column; flex: 1; color: var(--nb-color-text); text-decoration: none; }
  .nb-product-card__link:hover { color: var(--nb-color-text); }
  .nb-product-card__media {
    position: relative;
    aspect-ratio: 1;
    background: var(--nb-color-surface-sunk) center / cover no-repeat;
    overflow: hidden;
  }
  .nb-product-card__media img { width: 100%; height: 100%; object-fit: cover; transition: transform var(--nb-dur-slow) var(--nb-ease-out-quart); }
  .nb-product-card__noimg {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: var(--nb-space-1);
    color: var(--nb-color-text-muted);
    font-size: 0.75rem;
    text-align: center;
  }
  .nb-product-card__noimg .ph { font-size: 2rem; }
  .nb-product-card:hover .nb-product-card__media img { transform: scale(1.04); }
  /* Pile de badges haut-gauche : remise / nouveau / rang / sponsorise, puis Sonoya Prime dessous */
  .nb-product-card__tl {
    position: absolute;
    top: var(--nb-space-2);
    left: var(--nb-space-2);
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    pointer-events: none;
    & > .nb-product-card__discount,
    & > .nb-product-card__badge-new,
    & > .nb-product-card__badges,
    & > .nb-product-card__rank { position: static; }
  }
  .nb-product-card__prime {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    background: oklch(68% 0.22 145);
    color: oklch(18% 0.05 145);
    font-size: 0.64rem;
    font-weight: var(--nb-fw-bold);
    line-height: 1.3;
    border-radius: var(--nb-radius-xs);
    white-space: nowrap;
  }
  .nb-product-card__prime .ph-fill { font-size: 0.8rem; }
  .nb-product-card__discount {
    position: absolute;
    top: var(--nb-space-2);
    left: var(--nb-space-2);
    padding: 2px 6px;
    background: var(--nb-color-danger);
    color: white;
    font-size: 0.66rem;
    font-weight: var(--nb-fw-bold);
    border-radius: var(--nb-radius-xs);
    font-variant-numeric: tabular-nums;
    z-index: 2;
    line-height: 1.3;
  }
  .nb-product-card__badge-new {
    position: absolute;
    top: var(--nb-space-2);
    left: var(--nb-space-2);
    padding: 2px 6px;
    background: var(--nb-color-info);
    color: white;
    font-size: 0.6rem;
    font-weight: var(--nb-fw-bold);
    border-radius: var(--nb-radius-xs);
    letter-spacing: var(--nb-ls-wider);
    z-index: 2;
    line-height: 1.3;
  }
  .nb-product-card__badges {
    position: absolute;
    top: var(--nb-space-2);
    left: var(--nb-space-2);
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    z-index: 2;
    pointer-events: none;
  }
  .nb-product-card__badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    font-size: 0.6rem;
    font-weight: var(--nb-fw-bold);
    text-transform: uppercase;
    letter-spacing: var(--nb-ls-wider);
    border-radius: var(--nb-radius-xs);
    line-height: 1.3;
  }
  .nb-product-card__badge--sponsored {
    background: oklch(55% 0.18 145);
    color: white;
    padding: 3px 10px;
    font-size: 0.56rem;
    letter-spacing: var(--nb-ls-wider);
    border-radius: var(--nb-radius-pill);
    box-shadow: 0 2px 8px oklch(55% 0.18 145 / 0.3);
  }
  .nb-product-card__views {
    position: absolute;
    bottom: var(--nb-space-2);
    right: var(--nb-space-2);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: oklch(0% 0 0 / 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    color: white;
    font-size: 0.6rem;
    font-weight: var(--nb-fw-semibold);
    font-variant-numeric: tabular-nums;
    border-radius: var(--nb-radius-pill);
    z-index: 2;
    pointer-events: none;
  }
  .nb-product-card__views > i { font-size: 0.72rem; }
  .nb-product-card__rank {
    position: absolute;
    top: var(--nb-space-2);
    left: var(--nb-space-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: var(--nb-color-accent);
    color: white;
    font-family: var(--nb-font-heading);
    font-size: 0.72rem;
    font-weight: var(--nb-fw-heavy);
    border-radius: 50%;
    z-index: 2;
    letter-spacing: -0.02em;
  }
  .nb-product-card__body {
    padding: var(--nb-space-2) var(--nb-space-3) var(--nb-space-3);
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
  }
  .nb-product-card__title {
    font-size: 0.78rem;
    font-weight: var(--nb-fw-medium);
    line-height: 1.35;
    color: var(--nb-color-text-strong);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.35em;
    margin: 0;
  }
  .nb-product-card__rating {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.66rem;
    line-height: 1;
  }
  .nb-product-card__stars {
    color: var(--nb-color-star);
    letter-spacing: 0.03em;
    font-variant-numeric: tabular-nums;
  }
  .nb-product-card__rating-count {
    color: var(--nb-color-text-faint);
    font-variant-numeric: tabular-nums;
  }
  .nb-product-card__prices {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: auto;
  }
  .nb-product-card__price {
    font-family: var(--nb-font-heading);
    font-size: 0.95rem;
    font-weight: var(--nb-fw-heavy);
    color: var(--nb-color-accent);
    font-variant-numeric: tabular-nums;
    letter-spacing: var(--nb-ls-tight);
    line-height: 1;
  }
  .nb-product-card__currency {
    font-size: 0.6rem;
    font-weight: var(--nb-fw-semibold);
    color: var(--nb-color-text-faint);
    text-transform: uppercase;
    letter-spacing: var(--nb-ls-wide);
    margin-inline-start: 2px;
  }
  .nb-product-card__price-old {
    font-size: 0.72rem;
    color: var(--nb-color-text-faint);
    text-decoration: line-through;
    font-variant-numeric: tabular-nums;
  }
  .nb-product-card__sold {
    font-size: 0.66rem;
    color: var(--nb-color-text-faint);
    font-variant-numeric: tabular-nums;
  }
  .nb-product-card__stock {
    display: flex;
    flex-direction: column;
    gap: 3px;
  }
  .nb-product-card__stock-bar {
    height: 4px;
    background: var(--nb-color-surface-sunk);
    border-radius: var(--nb-radius-pill);
    overflow: hidden;
  }
  .nb-product-card__stock-bar span {
    display: block;
    height: 100%;
    background: var(--nb-color-danger);
    border-radius: var(--nb-radius-pill);
  }
  .nb-product-card__stock-text {
    font-size: 0.6rem;
    color: var(--nb-color-danger);
    font-weight: var(--nb-fw-bold);
    letter-spacing: var(--nb-ls-wide);
    text-transform: uppercase;
  }
  /* ---- CTA principal seul en bas (largeur full) ---- */
  .nb-product-card__cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--nb-space-2);
    margin: 0 var(--nb-space-3) var(--nb-space-3);
    padding: var(--nb-space-2) var(--nb-space-3);
    background: var(--nb-color-text);
    color: var(--nb-color-text-inverse);
    font-family: var(--nb-font-body);
    font-size: 0.72rem;
    font-weight: var(--nb-fw-bold);
    text-transform: uppercase;
    letter-spacing: var(--nb-ls-wide);
    border: 0;
    border-radius: var(--nb-radius-md);
    cursor: pointer;
    transition: background var(--nb-dur-fast) var(--nb-ease-standard),
                color var(--nb-dur-fast) var(--nb-ease-standard);
  }
  .nb-product-card__cta:hover {
    background: var(--nb-color-accent);
    color: var(--nb-color-accent-contrast);
  }
  .nb-product-card__cta > svg { flex-shrink: 0; }


  /* ===============================================
   * ADAPTATION A LA LARGEUR DU CONTENEUR
   * -----------------------------------------------
   * Une seule card, trois densites. Aucune page ne redefinit ces regles.
   *
   * Largeurs reelles mesurees dans le site :
   *   160px  grille 2 colonnes a 360px           -> serree
   *   175px  grille 2 colonnes a 390px           -> serree
   *   205px  grille 3 colonnes a 1024px (sidebar)-> serree
   *   217px  grille 2 colonnes a 480px           -> serree
   *   230px  grille 3 colonnes a 768px           -> confortable
   *   252px  grille 4 colonnes a 1440px          -> confortable
   *   288px  grille 3 colonnes a 1280px          -> large
   *   294px  grille 5 colonnes a 1920px          -> large
   *
   * Regle de conception : on ne sacrifie JAMAIS un signal d'achat (prix, note,
   * nombre de ventes, CTA). On ne reduit que la typographie et les espacements.
   * =============================================== */

  /* ---- Card serree (<= 219px) : densite maximale, tout reste lisible ---- */
  @container product-card (max-width: 219px) {
    .nb-product-card__body {
      padding: var(--nb-space-2);
      gap: 5px;
    }
    .nb-product-card__title {
      font-size: 0.74rem;
      line-height: 1.3;
      min-height: 2.2em;
    }
    .nb-product-card__rating { font-size: 0.62rem; gap: 3px; }
    .nb-product-card__price { font-size: 0.92rem; }
    .nb-product-card__currency { font-size: 0.55rem; }
    .nb-product-card__price-old { font-size: 0.64rem; }
    .nb-product-card__sold { font-size: 0.6rem; }
    /* Le libelle du CTA ne doit JAMAIS passer sur deux lignes */
    .nb-product-card__cta {
      margin: 0 var(--nb-space-2) var(--nb-space-2);
      padding: var(--nb-space-2) var(--nb-space-1);
      font-size: 0.64rem;
      letter-spacing: 0;
      gap: 5px;
      white-space: nowrap;
    }
    .nb-product-card__cta > svg { width: 12px; height: 12px; }
  }

  /* ---- Card tres serree (<= 179px) : telephones 360-400px en 2 colonnes ----
     Marge critique pour le CTA : on recupere de la place sur les marges
     laterales plutot que de rogner encore la typographie. */
  @container product-card (max-width: 179px) {
    .nb-product-card__cta {
      margin-inline: var(--nb-space-1-5);
      padding-inline: 2px;
      font-size: 0.62rem;
      gap: 4px;
    }
    .nb-product-card__cta > svg { width: 11px; height: 11px; }
  }

  /* ---- Card confortable (220px - 279px) ---- */
  @container product-card (min-width: 220px) {
    .nb-product-card__title { font-size: 0.84rem; }
    .nb-product-card__price { font-size: 1.02rem; }
    .nb-product-card__cta {
      font-size: 0.72rem;
      white-space: nowrap;
    }
  }

  /* ---- Card large (>= 280px) ---- */
  @container product-card (min-width: 280px) {
    .nb-product-card__body {
      padding: var(--nb-space-3) var(--nb-space-4) var(--nb-space-4);
      gap: var(--nb-space-2);
    }
    .nb-product-card__title {
      font-size: 0.92rem;
      font-weight: var(--nb-fw-semibold);
    }
    .nb-product-card__price { font-size: 1.14rem; }
    .nb-product-card__cta {
      margin: 0 var(--nb-space-4) var(--nb-space-4);
      padding: var(--nb-space-3);
      font-size: 0.78rem;
    }
  }

  /* ---- Colonne de 3 badges flottants top-right sur le media ----
     [wishlist]  toujours visible
     [quickview] apparait au hover (cascade 50ms)
     [compare]   apparait au hover (cascade 100ms) */
  .nb-product-card__quick-actions {
    position: absolute;
    top: var(--nb-space-2);
    right: var(--nb-space-2);
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 4;
  }
  .nb-product-card__quick-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: oklch(100% 0 0 / 0.85);
    color: var(--nb-color-text-muted);
    border: 1px solid oklch(100% 0 0 / 0.6);
    border-radius: 50%;
    cursor: pointer;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    transition: color var(--nb-dur-fast) var(--nb-ease-standard),
                background var(--nb-dur-fast) var(--nb-ease-standard),
                border-color var(--nb-dur-fast) var(--nb-ease-standard),
                transform var(--nb-dur-fast) var(--nb-ease-spring),
                opacity var(--nb-dur-fast) var(--nb-ease-standard);
  }
  .nb-product-card__quick-btn:hover {
    color: white;
    background: var(--nb-color-accent);
    border-color: var(--nb-color-accent);
    transform: scale(1.10);
  }
  .nb-product-card__quick-btn:active { transform: scale(0.95); }

  /* Variante wishlist : hover -> danger red, active -> permanent red */
  .nb-product-card__quick-btn--wishlist:hover {
    background: var(--nb-color-danger);
    border-color: var(--nb-color-danger);
  }
  .nb-product-card__quick-btn--wishlist.is-active {
    color: white;
    background: var(--nb-color-danger);
    border-color: var(--nb-color-danger);
  }
  .nb-product-card__quick-btn--wishlist.is-active > svg { fill: white; }

  /* Variante hover-only (quickview + compare) : caches par defaut, apparaissent en cascade */
  .nb-product-card__quick-btn--hover {
    opacity: 0;
    transform: translateY(-6px) scale(0.85);
    pointer-events: none;
  }
  .nb-product-card:hover .nb-product-card__quick-btn--hover {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }
  /* Cascade delay pour un effet en chaine */
  .nb-product-card:hover .nb-product-card__quick-btn--hover:nth-of-type(2) { transition-delay: 40ms; }
  .nb-product-card:hover .nb-product-card__quick-btn--hover:nth-of-type(3) { transition-delay: 80ms; }

  [data-theme="dark"] .nb-product-card__quick-btn {
    background: oklch(20% 0.014 60 / 0.85);
    border-color: oklch(100% 0 0 / 0.15);
    color: var(--nb-color-text);
  }

  /* ================================================================
   * OVERLAY VENDEUR AU HOVER - Glassmorphism, remonte du bas
   * Uniquement info vendeur riche (nom, verified, rating+votes, followers, produits, location)
   * ================================================================ */
  .nb-product-card__seller-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 75%;
    background: oklch(100% 0 0 / 0.78);
    -webkit-backdrop-filter: blur(14px) saturate(180%);
    backdrop-filter: blur(14px) saturate(180%);
    border-top: 1px solid oklch(100% 0 0 / 0.4);
    transform: translateY(102%);
    opacity: 0;
    transition: transform var(--nb-dur-normal) var(--nb-ease-out-expo),
                opacity var(--nb-dur-fast) var(--nb-ease-standard);
    z-index: 3;
    pointer-events: none;
  }
  .nb-product-card:hover .nb-product-card__seller-overlay {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  [data-theme="dark"] .nb-product-card__seller-overlay {
    background: oklch(15% 0.010 60 / 0.82);
    border-top-color: oklch(100% 0 0 / 0.10);
  }

  .nb-product-card__seller-inner {
    display: flex;
    align-items: flex-start;
    gap: var(--nb-space-3);
    padding: var(--nb-space-3);
    color: var(--nb-color-text);
    text-decoration: none;
  }
  .nb-product-card__seller-inner:hover { color: var(--nb-color-text); }

  .nb-product-card__seller-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: var(--nb-color-accent);
    color: var(--nb-color-accent-contrast);
    font-family: var(--nb-font-heading);
    font-size: 0.82rem;
    font-weight: var(--nb-fw-heavy);
    border-radius: 50%;
    border: 2px solid oklch(100% 0 0 / 0.9);
    flex-shrink: 0;
    letter-spacing: -0.02em;
    overflow: hidden;
  }
  .nb-product-card__seller-avatar > img { width: 100%; height: 100%; object-fit: cover; }

  .nb-product-card__seller-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1;
  }
  .nb-product-card__seller-name {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-family: var(--nb-font-body);
    font-size: 0.78rem;
    font-weight: var(--nb-fw-bold);
    color: var(--nb-color-text-strong);
    line-height: 1.2;
    min-width: 0;
  }
  .nb-product-card__seller-name-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }
  .nb-product-card__seller-verified {
    color: var(--nb-color-info);
    flex-shrink: 0;
    width: 12px;
    height: 12px;
  }

  .nb-product-card__seller-row {
    display: inline-flex;
    align-items: center;
    gap: var(--nb-space-2);
    font-size: 0.66rem;
    color: var(--nb-color-text-muted);
    line-height: 1.3;
    flex-wrap: wrap;
  }
  .nb-product-card__seller-stat {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .nb-product-card__seller-stat > svg {
    flex-shrink: 0;
    opacity: 0.7;
  }
  .nb-product-card__seller-stat b {
    color: var(--nb-color-text-strong);
    font-weight: var(--nb-fw-bold);
    font-variant-numeric: tabular-nums;
  }
  .nb-product-card__seller-stat--rating > svg {
    color: var(--nb-color-star);
    opacity: 1;
  }
  .nb-product-card__seller-stat--followers > svg,
  .nb-product-card__seller-stat--products > svg {
    color: var(--nb-color-accent);
    opacity: 1;
  }
  .nb-product-card__seller-stat--location > svg {
    color: var(--nb-color-danger);
    opacity: 0.85;
  }
  .nb-product-card__seller-stat--location {
    font-style: normal;
    color: var(--nb-color-text);
  }

  /* Sur mobile pas de :hover — on masque l'overlay et on force la visibilite des 3 badges */
  @media (hover: none) {
    .nb-product-card__seller-overlay { display: none; }
    .nb-product-card__quick-btn--hover {
      opacity: 1;
      transform: none;
      pointer-events: auto;
    }
  }


  /* ===============================================
   * VARIANTE --list : ligne horizontale
   * Utilisee par le listing catalogue en mode liste.
   * Le markup est IDENTIQUE : seule la classe change.
   * =============================================== */
  .nb-product-card--list { flex-direction: row; }
  .nb-product-card--list .nb-product-card__link {
    flex-direction: row;
    flex: 1;
    min-width: 0;
  }
  .nb-product-card--list .nb-product-card__media {
    flex: 0 0 124px;
    aspect-ratio: 1;
  }
  @media (min-width: 768px) {
    .nb-product-card--list .nb-product-card__media { flex-basis: 200px; }
  }
  .nb-product-card--list .nb-product-card__body {
    flex: 1;
    min-width: 0;
    gap: var(--nb-space-2);
  }
  .nb-product-card--list .nb-product-card__title {
    -webkit-line-clamp: 2;
    line-clamp: 2;
    min-height: 0;
    font-size: var(--nb-fs-md);
  }
  /* En liste, l'overlay vendeur devient un bandeau permanent sous le titre */
  .nb-product-card--list .nb-product-card__seller-overlay {
    position: static;
    opacity: 1;
    transform: none;
    background: var(--nb-color-surface-alt);
    border-radius: var(--nb-radius-sm);
    padding: var(--nb-space-2);
    pointer-events: auto;
  }
  .nb-product-card--list .nb-product-card__cta {
    align-self: center;
    flex-shrink: 0;
    margin: var(--nb-space-3);
  }
  @media (max-width: 479px) {
    .nb-product-card--list .nb-product-card__cta {
      margin: var(--nb-space-2);
      padding-inline: var(--nb-space-2);
    }
    .nb-product-card--list .nb-product-card__seller-overlay { display: none; }
  }
}
