/**
 * BPC Triathlon - Optimisations Mobile Avancées
 * Améliore l'expérience utilisateur sur tous les appareils mobiles
 *
 * Note: Ce fichier complète bpc-modern.css et mobile-optimizations.css
 * Les !important sont utilisés uniquement pour les typographies et animations critiques
 */

/* ==================== VARIABLES UNIFIÉES ==================== */

@media (max-width: 768px) {
  :root {
    /* Utilise les mêmes variables que mobile-optimizations.css */
    --bpc-mobile-radius: 14px;
    --bpc-mobile-gap: 18px;
    --bpc-mobile-padding: 16px;

    /* Alias pour compatibilité */
    --radius: var(--bpc-mobile-radius);
    --spacing-md: 24px;
    --spacing-sm: 16px;
    --spacing-lg: 48px;
  }
}

/* ==================== OPTIMISATIONS GÉNÉRALES ==================== */

/* Amélioration du smooth scroll pour mobile */
@media (max-width: 768px) {
  html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }

  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }
}

/* ==================== TYPOGRAPHIE MOBILE ==================== */

@media (max-width: 768px) {
  /* Titres optimisés pour mobile */
  h1 {
    font-size: clamp(1.75rem, 5vw, 2.5rem) !important;
    line-height: 1.2 !important;
    word-wrap: break-word;
    hyphens: auto;
  }

  h2 {
    font-size: clamp(1.5rem, 4vw, 2rem) !important;
    line-height: 1.3 !important;
  }

  h3 {
    font-size: clamp(1.25rem, 3.5vw, 1.5rem) !important;
    line-height: 1.4 !important;
  }

  /* Paragraphes lisibles */
  p {
    font-size: clamp(0.95rem, 2.5vw, 1.1rem);
    line-height: 1.6;
    max-width: 100%;
  }

  /* Liens tactiles */
  a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 8px;
  }
}

/* ==================== BOUTONS ET CTA ==================== */

@media (max-width: 768px) {
  /* Tous les boutons avec targets tactiles - Complément zones tactiles */
  .btn-primary,
  .btn-secondary,
  .btn-ghost,
  .btn,
  button[type="button"],
  button[type="submit"] {
    min-height: 48px;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 12px;
    width: auto;
    max-width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  /* CTA pleine largeur sur très petits écrans */
  @media (max-width: 480px) {
    .btn-primary,
    .btn-hero {
      width: 100%;
      max-width: none;
    }
  }

  /* Espacement entre boutons groupés */
  .cta-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
  }

  .cta-buttons > * {
    flex: 1 1 100%;
  }
}

/* ==================== CARTES ET CONTENEURS ==================== */

@media (max-width: 768px) {
  /* Cartes optimisées */
  .card,
  .article-card,
  .pricing-card,
  .stat-card,
  .comparison-card {
    border-radius: 12px;
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
  }

  /* Images dans les cartes */
  .card img,
  .article-card img {
    width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: 8px;
  }

  /* Spacing réduit pour mobile */
  .container {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* ==================== GRILLES ADAPTATIVES ==================== */

@media (max-width: 768px) {
  /* Grilles en une colonne - Complément de mobile-optimizations.css */
  .grid-2,
  .grid-3,
  .grid-4,
  .comparison-grid,
  .pricing-grid,
  .blog-grid,
  .stats-grid {
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
  }

  /* Grid items pleine largeur */
  .grid-2 > *,
  .grid-3 > *,
  .grid-4 > * {
    width: 100%;
  }
}

/* ==================== TABLEAUX RESPONSIFS ==================== */

@media (max-width: 768px) {
  /* Transformation des tableaux en cartes */
  .dates-table thead {
    display: none;
  }

  .dates-table,
  .dates-table tbody,
  .dates-table tr,
  .dates-table td {
    display: block;
    width: 100%;
  }

  .dates-table tr {
    margin-bottom: 16px;
    border: 1px solid var(--bpc-border-light, #e0e0e0);
    border-radius: 12px;
    padding: 16px;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }

  .dates-table td {
    padding: 8px 0;
    border: none;
    text-align: left !important;
  }

  .dates-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--bpc-primary);
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    text-transform: uppercase;
  }
}

/* ==================== NAVIGATION MOBILE ==================== */

@media (max-width: 768px) {
  /* Header sticky optimisé */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 12px 0;
  }

  .site-header .container {
    padding: var(--header-padding-block-mobile, 8px) var(--header-padding-inline-mobile, 16px);
  }

  /* Logo plus petit sur mobile - Complément header responsive */
  .brand .logo {
    width: 50px;
    height: 50px;
  }

  .brand .logo img {
    width: 50px;
    height: 50px;
  }

  /* Menu hamburger accessible */
  .header-menu-toggle {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  /* Menu glissant - Largeur unifiée avec mobile-optimizations.css */
  .sliding-menu {
    width: min(100%, 420px);
    max-width: 100%;
  }
}

/* ==================== IMAGES ET MÉDIAS ==================== */

@media (max-width: 768px) {
  /* Images responsive */
  img {
    max-width: 100%;
    height: auto;
    display: block;
  }

  /* Carousel optimisé */
  .carousel-slide img {
    aspect-ratio: 4/3;
    object-fit: cover;
    width: 100%;
    height: auto;
  }

  /* Galerie responsive */
  .gallery-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .gallery-item img {
    aspect-ratio: 16/9;
    width: 100%;
    height: auto;
  }
}

/* ==================== FORMULAIRES ==================== */

@media (max-width: 768px) {
  /* Champs de formulaire accessibles */
  input,
  textarea,
  select {
    min-height: 48px;
    font-size: 16px; /* Évite le zoom iOS */
    padding: 12px 16px;
    border-radius: 8px;
    width: 100%;
    max-width: 100%;
    -webkit-appearance: none;
    appearance: none;
  }

  /* Labels plus visibles */
  label {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
  }
}

/* ==================== ESPACEMENT MOBILE ==================== */

@media (max-width: 768px) {
  /* Sections avec spacing réduit */
  section {
    padding: var(--spacing-lg) 0;
  }

  /* Hero section compact */
  .hero {
    padding: var(--spacing-lg) 0;
  }

  /* Marges réduites */
  .section--water,
  .section--sand {
    padding: var(--spacing-md) 0;
  }
}

/* ==================== SAFE AREAS (iOS) ==================== */

@media (max-width: 768px) {
  /* Padding pour les encoches iPhone */
  body {
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
  }

  /* Menu toggle et sticky CTA avec safe-area - Position unifiée avec mobile-optimizations.css */
  .menu-toggle {
    bottom: var(--menu-toggle-bottom-mobile, calc(18px + env(safe-area-inset-bottom, 0)));
    right: var(--menu-toggle-right-mobile, 16px);
    width: var(--menu-toggle-size-mobile, 48px);
    height: var(--menu-toggle-size-mobile, 48px);
    font-size: var(--menu-toggle-font-mobile, 18px);
  }

  .mobile-sticky-cta {
    bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom, 0)) !important;
    left: calc(16px + env(safe-area-inset-left, 0));
    right: calc(16px + env(safe-area-inset-right, 0));
  }
}

/* ==================== PERFORMANCES ==================== */

@media (max-width: 768px) {
  /* Réduction des animations coûteuses */
  *,
  *::before,
  *::after {
    animation-duration: 0.3s !important;
    transition-duration: 0.3s !important;
  }

  /* Désactivation des animations complexes sur scroll */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }

  /* Will-change pour animations fluides */
  .carousel-container,
  .sliding-menu {
    will-change: transform;
  }
}

/* ==================== ACCESSIBILITÉ TACTILE ==================== */

@media (max-width: 768px) {
  /* Zones de toucher minimum 44x44px */
  a,
  button,
  input[type="checkbox"],
  input[type="radio"],
  .carousel-dot,
  .carousel-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 12px;
  }

  /* Focus visible pour navigation clavier */
  a:focus-visible,
  button:focus-visible {
    outline: 3px solid var(--bpc-accent);
    outline-offset: 2px;
    border-radius: 4px;
  }

  /* Suppression tap highlight */
  * {
    -webkit-tap-highlight-color: transparent;
  }
}

/* ==================== LISTE ET BADGES ==================== */

@media (max-width: 768px) {
  /* Badges et tags lisibles */
  .badge,
  .badge-accent,
  .article-tag,
  .level-badge {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 20px;
    white-space: nowrap;
  }

  /* Listes avec bon spacing */
  ul,
  ol {
    padding-left: 24px;
  }

  li {
    margin-bottom: 8px;
    line-height: 1.6;
  }

  /* Listes tick */
  .tick li {
    padding-left: 32px;
    position: relative;
  }
}

/* ==================== MODAL ET OVERLAY ==================== */

@media (max-width: 768px) {
  /* Modal plein écran sur mobile */
  .modal,
  .popup {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    margin: 0;
  }

  /* Overlay sombre */
  .menu-overlay,
  .modal-overlay {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
  }
}

/* ==================== FOOTER ==================== */

@media (max-width: 768px) {
  footer {
    padding: var(--spacing-lg) var(--spacing-md);
  }

  footer .container {
    padding: 0 16px;
  }

  footer h3 {
    font-size: 16px;
    margin-bottom: 12px;
  }

  footer ul {
    padding: 0;
  }

  footer li {
    margin-bottom: 8px;
  }
}

/* ==================== OPTIMISATIONS TRÈS PETITS ÉCRANS ==================== */

@media (max-width: 380px) {
  /* Réductions supplémentaires pour petits écrans */
  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .btn-primary {
    font-size: 14px;
    padding: 10px 16px;
  }

  .container {
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* ==================== LANDSCAPE MODE ==================== */

@media (max-width: 768px) and (orientation: landscape) {
  /* Hero moins haut en landscape */
  .hero {
    padding: var(--spacing-md) 0;
  }

  /* Grilles en 2 colonnes en landscape */
  .comparison-grid,
  .pricing-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-sm);
  }
}

/* ==================== PRINT (BONUS) ==================== */

@media print {
  /* Masquer éléments non imprimables */
  .menu-toggle,
  .sliding-menu,
  .mobile-sticky-cta,
  .carousel-btn,
  .header-menu-toggle {
    display: none;
  }

  /* Optimisations impression */
  * {
    background: white;
    color: black;
  }

  a {
    text-decoration: underline;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }
}
