/* ============================================================
   mobile.css v2 — Responsive overrides v4 (refonte ciblée)
   Chargé APRÈS les <style> inline pour gagner sur la spécificité.

   v2 ajoute des overrides pour les sélecteurs spécifiques aux
   pages publiques (landing, pricing, auth-*) qui n'étaient pas
   capturés par v1 :
     - .hero-title, .pricing-title, .reassure-title, .auth-title,
       .feature-title, .workflow-title, .plans-grid, .plan-*,
       .auth-card, .oauth-grid, .reassure-* etc.
     - Forced word-break/overflow-wrap sur tous les titres
     - Réduction agressive des paddings hero (56px → 18px)
     - clamp() override pour empêcher les fonts énormes en mobile

   Breakpoints :
     - 1024px : tablette landscape
     - 768px  : tablette portrait / mobile large
     - 520px  : mobile standard
     - 380px  : iPhone SE / petits Android
   ============================================================ */

/* ============================================================
   Globals — éviter overflow horizontal partout + word break
   ============================================================ */
html, body { max-width: 100vw; overflow-x: hidden; }
* { -webkit-tap-highlight-color: rgba(255,122,24,0.15); }

/* Tous les titres : empêcher le débordement horizontal sur mobile */
@media (max-width: 768px) {
  h1, h2, h3, h4,
  [class*="-title"],
  [class*="-headline"],
  .h-1, .h-2, .h-3,
  .editorial {
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
    hyphens: auto !important;
    max-width: 100% !important;
  }
}

/* Touch targets minimum 44x44 (Apple HIG / WCAG 2.5.5) */
@media (hover:none) and (pointer:coarse) {
  .btn, .btn-icon, button, a.btn, .topnav-links a, .side-nav a {
    min-height: 44px;
  }
  .btn-sm { min-height: 38px; padding: 8px 12px; }
}

/* ============================================================
   1024px — tablette landscape
   ============================================================ */
@media (max-width: 1024px) {
  .hero-grid { grid-template-columns: 1fr !important; gap: 28px !important; }
  .kpis { grid-template-columns: repeat(2, 1fr) !important; }
  .main-grid { grid-template-columns: 1fr !important; gap: 16px !important; }
  .quick-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .plans-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 16px !important; }
}

/* ============================================================
   768px — mobile large / tablette portrait — LE GROS DU TRAVAIL
   ============================================================ */
@media (max-width: 768px) {
  /* Page padding global */
  .page { padding: 16px 12px 64px !important; }

  /* ----------------------------------------------------------
     HERO (toutes pages : home, landing, analyze, etc.)
     ---------------------------------------------------------- */
  .hero {
    padding: 24px 18px !important;
    border-radius: 18px !important;
    margin-bottom: 18px !important;
  }
  .hero-grid {
    grid-template-columns: 1fr !important;
    gap: 22px !important;
  }
  .hero-copy { width: 100% !important; }
  .hero h1,
  .hero-title,
  .hero h1 .editorial {
    font-size: clamp(22px, 7vw, 30px) !important;
    line-height: 1.1 !important;
    letter-spacing: -0.02em !important;
    margin-bottom: 12px !important;
  }
  .hero h1 .editorial,
  .hero-title .editorial {
    font-size: clamp(18px, 5.5vw, 24px) !important;
    display: block !important;
  }
  .hero p,
  .hero-lead {
    font-size: 14px !important;
    line-height: 1.5 !important;
    margin-bottom: 16px !important;
    max-width: 100% !important;
  }
  .hero-actions { flex-wrap: wrap !important; gap: 8px !important; width: 100%; }
  .hero-actions .btn { flex: 1 1 100% !important; justify-content: center !important; }
  .hero-meta { flex-wrap: wrap !important; gap: 10px !important; font-size: 12px !important; }

  /* ----------------------------------------------------------
     PRICING (page /pricing)
     ---------------------------------------------------------- */
  .pricing-hero { padding: 12px 0 24px !important; }
  .pricing-title {
    font-size: clamp(22px, 7vw, 30px) !important;
    line-height: 1.1 !important;
    margin: 12px 0 14px !important;
    letter-spacing: -0.02em !important;
  }
  .pricing-title .editorial {
    font-size: clamp(18px, 5.5vw, 24px) !important;
    display: block !important;
  }
  .pricing-lead {
    font-size: 14px !important;
    line-height: 1.5 !important;
    padding: 0 4px !important;
  }
  .plans-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .plan {
    padding: 18px 16px !important;
    border-radius: 14px !important;
    max-width: 100% !important;
  }
  .plan-price-val {
    font-size: 32px !important;
  }
  .plan-features li {
    font-size: 13px !important;
    padding: 6px 0 !important;
  }
  /* Reassure section (sous les plans) */
  .reassure-title {
    font-size: 22px !important;
    line-height: 1.2 !important;
    margin-bottom: 8px !important;
  }
  .reassure-body { font-size: 13.5px !important; }
  .reassure-item { padding: 14px !important; }

  /* Trial banner */
  .trial-banner {
    font-size: 12px !important;
    padding: 8px 12px !important;
    flex-wrap: wrap;
  }

  /* ----------------------------------------------------------
     LANDING — sections
     ---------------------------------------------------------- */
  .feature-title,
  .workflow-title,
  .section-title {
    font-size: clamp(20px, 6vw, 26px) !important;
    line-height: 1.15 !important;
  }
  .features-grid,
  .workflow-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
  .feature, .workflow-step {
    padding: 18px !important;
  }

  /* ----------------------------------------------------------
     AUTH (login, register, forgot, reset)
     ---------------------------------------------------------- */
  .auth-wrap {
    padding: 16px 12px !important;
    min-height: auto !important;
  }
  .auth-card {
    padding: 22px 18px !important;
    border-radius: 14px !important;
    max-width: 100% !important;
    margin: 0 auto !important;
  }
  .auth-brand {
    margin-bottom: 16px !important;
    gap: 8px !important;
  }
  .auth-brand img, .auth-brand svg {
    width: 32px !important; height: 32px !important;
  }
  .auth-title {
    font-size: 22px !important;
    margin-bottom: 4px !important;
  }
  .auth-sub {
    font-size: 13.5px !important;
    margin-bottom: 14px !important;
  }
  .oauth-grid {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }
  .oauth-btn {
    padding: 11px 14px !important;
    font-size: 13.5px !important;
  }
  .auth-footer {
    font-size: 13px !important;
    margin-top: 14px !important;
  }
  .trust-row {
    gap: 8px !important;
    padding: 8px 12px !important;
    font-size: 11.5px !important;
  }
  .trust-row > * { flex: 1 1 auto; }

  /* ----------------------------------------------------------
     KPI cards (overview, stats, admin)
     ---------------------------------------------------------- */
  .kpis {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    margin-bottom: 20px !important;
  }
  .kpi { padding: 14px !important; border-radius: 12px !important; }
  .kpi-label { font-size: 9.5px !important; letter-spacing: .14em !important; }
  .kpi-value { font-size: 22px !important; }
  .kpi-spark { width: 48px !important; height: 24px !important; right: 10px !important; top: 10px !important; }

  /* ----------------------------------------------------------
     Track rows (library, home recently analyzed)
     ---------------------------------------------------------- */
  .track-row {
    grid-template-columns: 36px 1fr 60px !important;
    gap: 10px !important;
    padding: 8px 10px !important;
  }
  .track-row .track-mini-wave,
  .track-row .track-key,
  .track-row .track-action {
    display: none !important;
  }
  .track-cover { width: 36px !important; height: 36px !important; }
  .track-bpm { font-size: 11px !important; }

  /* ----------------------------------------------------------
     Activity feed, quick actions, main grid
     ---------------------------------------------------------- */
  .main-grid { grid-template-columns: 1fr !important; gap: 16px !important; }
  .activity { padding: 14px !important; }
  .act-title { font-size: 12.5px !important; }
  .quick-grid {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    padding: 14px !important;
  }
  .quick { padding: 12px !important; }

  /* ----------------------------------------------------------
     TOPNAV — compact mobile
     ---------------------------------------------------------- */
  .topnav {
    padding: 0 12px !important;
    gap: 8px !important;
    height: 52px !important;
  }
  .topnav-brand .chip { display: none !important; }
  .topnav-actions .btn:not(.btn-primary) { padding: 6px 8px !important; }
  .topnav-sep { display: none !important; }

  /* Page header générique */
  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }
  .page-title { font-size: 24px !important; }
  .page-title .editorial { font-size: 20px !important; }
  .page-actions { flex-wrap: wrap !important; gap: 8px !important; width: 100%; }
  .page-actions .btn { flex: 1 1 auto; justify-content: center; }

  /* ----------------------------------------------------------
     Side nav (settings, admin) → horizontal scroll
     ---------------------------------------------------------- */
  .layout-with-side {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .side-nav {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    padding: 8px !important;
    gap: 4px !important;
    border-radius: 12px !important;
  }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-nav a {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
  }

  /* ----------------------------------------------------------
     Sections, tables, library, mix-studio
     ---------------------------------------------------------- */
  .sec { padding: 16px !important; border-radius: 14px !important; }
  .sec-head h3, .sec-head h2 { font-size: 15px !important; }
  table { display: block; overflow-x: auto; max-width: 100%; }
  .lib-controls, .lib-toolbar { flex-wrap: wrap !important; gap: 8px !important; }
  .lib-search { flex: 1 1 100% !important; min-width: 0 !important; }
  .waveform-container, .wave-canvas, canvas.waveform {
    max-width: 100% !important;
    height: auto !important;
  }
  .studio-grid, .builder-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Modals */
  .modal, .modal-content {
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100vh - 80px) !important;
  }
  .cf-palette {
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100vh - 80px) !important;
  }

  /* Live now widget */
  .live-now { padding: 14px !important; }
  .live-cover { width: 44px !important; height: 44px !important; }

  /* Forms inputs */
  .field, .form-row { width: 100% !important; }
  .input, select, textarea, input[type] {
    font-size: 16px !important; /* prevent iOS zoom */
  }

  /* Section headings & spacing */
  h1 { font-size: 24px !important; }
  h2 { font-size: 19px !important; }
  h3 { font-size: 16px !important; }
  .h-2 { font-size: 22px !important; }
  .h-3 { font-size: 17px !important; }

  /* Grids génériques */
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .row, .row-between { flex-wrap: wrap !important; }

  /* Stats / charts */
  .chart-container, .recharts-wrapper { max-width: 100% !important; }
}

/* ============================================================
   520px — mobile standard (iPhone 14, Pixel 7)
   ============================================================ */
@media (max-width: 520px) {
  .page { padding: 12px 10px 56px !important; }

  /* Hero */
  .hero { padding: 20px 14px !important; }
  .hero h1, .hero-title { font-size: clamp(20px, 7vw, 26px) !important; }
  .hero h1 .editorial, .hero-title .editorial {
    font-size: clamp(16px, 5.5vw, 22px) !important;
  }
  .hero p, .hero-lead { font-size: 13.5px !important; }

  /* Pricing */
  .pricing-title { font-size: clamp(20px, 7vw, 26px) !important; }
  .pricing-title .editorial { font-size: clamp(16px, 5.5vw, 22px) !important; }

  /* Auth */
  .auth-card { padding: 20px 14px !important; }
  .auth-title { font-size: 20px !important; }

  /* KPIs */
  .kpis { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .kpi { padding: 12px !important; }
  .kpi-value { font-size: 19px !important; }

  /* Topnav */
  .topnav-brand span:last-child { display: none !important; }
  .topnav-actions .btn:not(.btn-primary) span { display: none; }
  .topnav-actions .btn-primary { padding: 8px 10px !important; }

  /* Page title */
  .page-title { font-size: 20px !important; }
  .page-title .editorial { font-size: 16px !important; }

  /* Track row */
  .track-row { grid-template-columns: 32px 1fr 50px !important; }
  .track-cover { width: 32px !important; height: 32px !important; }

  /* Sections */
  .sec { padding: 14px !important; }

  /* Buttons full width */
  .auth-card .btn-primary { width: 100% !important; }
}

/* ============================================================
   380px — iPhone SE / petits Android
   ============================================================ */
@media (max-width: 380px) {
  .page { padding: 10px 8px 56px !important; }
  .hero { padding: 16px 12px !important; }
  .hero h1, .hero-title { font-size: clamp(18px, 7vw, 23px) !important; }
  .hero h1 .editorial, .hero-title .editorial {
    font-size: clamp(14px, 5.5vw, 18px) !important;
  }
  .pricing-title { font-size: clamp(18px, 7vw, 23px) !important; }
  .auth-card { padding: 16px 12px !important; }
  .auth-title { font-size: 18px !important; }
  .kpis { grid-template-columns: 1fr !important; }
  .kpi { padding: 12px !important; }
  .topnav { padding: 0 8px !important; gap: 6px !important; }
  .topnav-brand { font-size: 13px !important; }
  .topnav-brand .mark { width: 24px !important; height: 24px !important; }
}

/* ============================================================
   Landscape mobile
   ============================================================ */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .topnav { height: 44px !important; }
  .page { padding: 12px 16px 40px !important; }
  .hero { padding: 14px 18px !important; margin-bottom: 12px !important; }
  .hero h1, .hero-title { font-size: 22px !important; margin-bottom: 8px !important; }
  .kpis {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 14px !important;
  }
}

/* ============================================================
   Safe-area iOS (notch / home indicator)
   ============================================================ */
@supports (padding: max(0px)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .topnav {
    padding-left: max(12px, env(safe-area-inset-left)) !important;
    padding-right: max(12px, env(safe-area-inset-right)) !important;
  }
  .page {
    padding-bottom: max(56px, calc(56px + env(safe-area-inset-bottom))) !important;
  }
}

/* ============================================================
   Performance — désactiver effets coûteux mobile
   ============================================================ */
@media (max-width: 768px) {
  .cf-spot, [data-cf-spot] { background-image: none !important; }
  .cf-stagger > * { animation-delay: 0s !important; }
  /* Réduire les radial-gradient lourds dans les hero */
  .hero::before { opacity: 0.3 !important; }
}
