/* =====================================================
 * TAONSA Tech — Mobile Enhancements (additif, ne change pas le design)
 * Charge ce fichier APRÈS style.css.
 * Toutes les règles sont préfixées et opt-in pour ne rien casser.
 * ===================================================== */

/* ---------- Touch targets : tous les boutons icône ≥ 44x44 sur tactile ---------- */
@media (hover: none) and (pointer: coarse) {
  button:not([class*="w-"]):not([class*="h-"]),
  a[role="button"]:not([class*="w-"]):not([class*="h-"]) {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ---------- Tap highlight cohérent (cyan TAONSA, pas le default brun iOS) ---------- */
* {
  -webkit-tap-highlight-color: rgba(13, 148, 136, 0.18);
}

/* Élements interactifs : feedback tactile visible */
@media (hover: none) and (pointer: coarse) {
  a:active,
  button:active,
  [role="button"]:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
}

/* ---------- Smooth scroll natif sur tous les ancrages ---------- */
html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px; /* sticky header offset */
}

/* ---------- Mobile : éviter le zoom auto sur focus input (iOS) ---------- */
@media (max-width: 640px) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="search"],
  input[type="password"],
  textarea,
  select {
    font-size: 16px !important; /* iOS ne zoom pas si ≥ 16px */
  }
}

/* ---------- Selection couleur brand ---------- */
::selection {
  background: rgba(13, 148, 136, 0.25);
  color: #0f4f4a;
}

/* ---------- Scrollbar discrète sur desktop, invisible sur mobile ---------- */
@media (min-width: 1024px) {
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 6px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
  }
}

/* ---------- Mobile bottom navigation (FAB-like, fixe) ---------- */
.taonsa-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 35;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  padding: 6px 4px max(6px, env(safe-area-inset-bottom)) 4px;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
}
@media (min-width: 1024px) {
  .taonsa-bottom-nav { display: none; }
}
.taonsa-bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  font-size: 0.75rem; /* FIX 2026-05-21 : 10px sub-WCAG bumped a 12px (0.75rem) */
  font-weight: 600;
  color: #64748b;
  text-decoration: none;
  gap: 2px;
  border-radius: 12px;
  min-height: 52px;
  transition: color 0.2s ease, background 0.2s ease;
}
.taonsa-bottom-nav a i {
  font-size: 1.25rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
  line-height: 1;
}
.taonsa-bottom-nav a:hover,
.taonsa-bottom-nav a:focus-visible {
  color: #0d9488;
  background: #f0fdfa;
}
.taonsa-bottom-nav a.active {
  color: #0d9488;
}
.taonsa-bottom-nav a.active i {
  transform: scale(1.1);
}
.taonsa-bottom-nav a .badge {
  position: absolute;
  top: 4px;
  margin-left: 16px;
  background: #ef4444;
  color: white;
  font-size: 0.75rem; /* FIX 2026-05-21 : 9px sub-WCAG bumped a 12px (0.75rem) */
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
}
.taonsa-bottom-nav a .badge.hidden {
  display: none;
}

/* Quand la bottom-nav est présente, ajouter du padding bas au body sur mobile */
@media (max-width: 1023px) {
  /* ----------------------------------------------------------------
     FIX 2026-05-22 (audit P1.1 + P3.6) : zone de degagement pour FAB
     ----------------------------------------------------------------
     Empile en bas-droite : bottom-nav (64px) + WhatsApp (60px @ bottom 76)
     + chatbot toggle (60px @ bottom 148) => zone occupee ~210px du bas.
     AVANT : padding-bottom calc(64px + safe-area) = couvrait seulement la
     bottom-nav, mais les cards produit en bas-droite restaient sous les FAB
     => le CTA "Acheter" devenait inaccessible (bug audit utilisateur P1.1).
     APRES : 220px = (chatbot toggle 60 + bottom 148 = 208px) + 12px tampon.
     ---------------------------------------------------------------- */
  body.has-bottom-nav {
    padding-bottom: calc(220px + env(safe-area-inset-bottom, 0px));
  }
  /* Décaler les flotteurs au-dessus de la bottom-nav pour éviter le chevauchement */
  body.has-bottom-nav .whatsapp-float {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
  body.has-bottom-nav .taonsa-chat-toggle {
    bottom: calc(148px + env(safe-area-inset-bottom, 0px));
  }
  body.has-bottom-nav #scrollTopBtn {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
  /* Auto-hide en descendant : transform porté par classe ajoutée par JS */
  .taonsa-bottom-nav {
    transition: transform 0.25s ease;
    will-change: transform;
  }
  .taonsa-bottom-nav.taonsa-bottom-nav-hidden {
    transform: translateY(110%);
  }
}

/* ---------- Skeleton loader (pour produits en chargement) ---------- */
.taonsa-skeleton {
  background: linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%);
  background-size: 200% 100%;
  animation: taonsa-shimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
}
@keyframes taonsa-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Améliorations grille produits sur mobile (espace optimisé) ---------- */
@media (max-width: 640px) {
  /* Cards produits : padding plus serré sur très petit écran */
  .product-card .product-info {
    padding: 10px;
  }
  /* Boutons "Ajouter au panier" : un peu plus compacts */
  .add-to-cart-btn {
    padding: 8px 12px;
    font-size: 0.75rem; /* FIX 2026-05-21 : unifie en rem Tailwind scale */
  }
}

/* ---------- Mode "réduire mouvement" : désactiver les animations ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Sticky CTA mobile (sur fiche produit) ---------- */
.taonsa-sticky-cta {
  position: fixed;
  bottom: 64px; /* au-dessus de la bottom-nav */
  left: 0;
  right: 0;
  z-index: 30;
  background: white;
  border-top: 1px solid #e5e7eb;
  padding: 10px max(12px, env(safe-area-inset-left));
  box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.08);
  display: flex;
  gap: 8px;
}
@media (min-width: 1024px) {
  .taonsa-sticky-cta { display: none; }
}

/* ---------- Image lazy : placeholder pendant chargement ---------- */
img[loading="lazy"]:not([src]),
img[loading="lazy"][src=""] {
  background: #f1f5f9;
  min-height: 100px;
}

/* ---------- Card hover/tap mobile : pas de hover-lift, juste outline cyan ---------- */
@media (hover: none) and (pointer: coarse) {
  .product-card:hover {
    transform: none;
  }
  .product-card:active {
    box-shadow: 0 0 0 2px #14b8a6, 0 4px 12px rgba(13, 148, 136, 0.15);
  }
}

/* ---------- Form inputs : focus visible amélioré ---------- */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid #14b8a6;
  outline-offset: 2px;
}

/* ---------- Badges promo / vedette : plus visibles sur mobile ---------- */
@media (max-width: 640px) {
  .sale-badge,
  [class*="bg-red-500"][class*="rounded-full"] {
    font-weight: 700;
    letter-spacing: 0.5px;
  }
}

/* ---------- Mode sombre auto (suit le system, opt-in via class) ---------- */
@media (prefers-color-scheme: dark) {
  body.taonsa-auto-dark {
    background: #0f172a;
    color: #e2e8f0;
  }
  body.taonsa-auto-dark .bg-white {
    background: #1e293b;
  }
}
