/*!
 * SMB Afrique Éditions — Responsive overrides (mobile-first)
 * Chargé sur toutes les pages HTML. N'altère pas le design desktop.
 * Cible : mobile (≤640px), tablette (641-1024px).
 */

/* ── Base universal fixes ───────────────────────────────────── */
html, body {
  max-width: 100vw;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
* {
  -webkit-tap-highlight-color: rgba(212, 175, 55, 0.18);
}
img, video, canvas, svg {
  max-width: 100%;
  height: auto;
}
table {
  max-width: 100%;
}

/* ─────────────────────────────────────────────────────────────
   MOBILE — ≤ 640px
   ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {

  /* Body padding réduit */
  body { font-size: 14px; }

  /* Headings */
  h1 { font-size: clamp(24px, 7vw, 34px) !important; line-height: 1.15 !important; }
  h2 { font-size: clamp(18px, 5vw, 24px) !important; }
  h3 { font-size: clamp(16px, 4.5vw, 20px) !important; }

  /* Conteneurs principaux : padding interne */
  .container, .wrap, .main, main, section,
  .hero, .topbar, .tb, .navbar { padding-left: 14px !important; padding-right: 14px !important; }

  /* ── Grilles : forcer 1 colonne pour les grilles multi-cols ── */
  .stats-grid, .sg,
  .grid-2, .grid-3, .grid-4,
  .book-grid, .audience-grid, .fr3,
  .pay-grid, .wallet-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  /* Grilles 2 colonnes spéciales (côté gauche/droite) → empilé */
  [style*="grid-template-columns:1fr 380px"],
  [style*="grid-template-columns: 1fr 380px"],
  [style*="grid-template-columns:280px 1fr"],
  [style*="grid-template-columns: 280px 1fr"],
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4,1fr)"],
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns: repeat(3,1fr)"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Tables : scroll horizontal natif ── */
  .tbl-wrap, .tw, .table-wrap, .pnb { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.dt, table { font-size: 11px !important; min-width: 540px; }
  table.dt th, table.dt td, table th, table td { padding: 6px 8px !important; }

  /* Cards stats */
  .stat-card, .sc, .kpi, .panel, .pnl { padding: 14px !important; }
  .sc-val, .sc-v, .stat-val { font-size: 22px !important; }

  /* Boutons : tappables (≥44px) */
  .btn, button, .btn-gold, .btn-outline, .btn-gd, .btn-ol, .btn-sm {
    min-height: 40px;
    padding: 9px 14px !important;
    font-size: 12px !important;
  }
  .btn-sm { min-height: 32px; padding: 6px 10px !important; }

  /* ── Navigation top : burger menu fallback ── */
  .nav-links, .tb-links, .navbar-links {
    display: none !important;
  }
  .nav-links.open, .tb-links.open, .navbar-links.open {
    display: flex !important;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #050505;
    border-top: 1px solid rgba(212,175,55,0.22);
    padding: 12px;
    gap: 8px;
    z-index: 9000;
  }
  .nav-burger, .tb-burger, .navbar-burger {
    display: inline-flex !important;
    background: transparent;
    border: 1px solid rgba(212,175,55,0.4);
    color: #D4AF37;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 18px;
    cursor: pointer;
  }

  /* Sidebar dashboards : collapsible */
  .sidebar, .side-nav, .sb, .pay-tabs {
    flex-wrap: wrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .pay-tabs { display: flex !important; gap: 6px !important; }
  .pay-tab { flex: 0 0 auto !important; padding: 8px 12px !important; font-size: 11px !important; }

  /* Forms */
  input, select, textarea {
    font-size: 16px !important; /* prevent iOS zoom on focus */
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Forms : 3-col → 1-col */
  .fr3 > .fg, .form-row > .fg { width: 100% !important; }

  /* Modals & overlays : full-screen mobile */
  .modal, .smb-auth-card, .modal-content {
    width: 95vw !important;
    max-width: 95vw !important;
    margin: 12px !important;
    padding: 22px 18px !important;
  }

  /* Footer */
  footer, .footer { padding: 24px 14px !important; }
  .footer-grid, footer > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* HORIZON floating chat — repositionnement */
  #smb-horizon-fab, #smb-ai-btn {
    bottom: 14px !important;
    right: 14px !important;
    width: 52px !important;
    height: 52px !important;
  }

  /* Hide non-essential decoration on small screens */
  .decoration, .deco, .ornament { display: none !important; }

  /* Catalogue / book cards */
  .book-card, .livre-card { width: 100% !important; }

  /* Padding bottom pour ne pas chevaucher le chat HORIZON */
  body { padding-bottom: 80px; }
}

/* ─────────────────────────────────────────────────────────────
   TABLETTE — 641px → 1024px
   ───────────────────────────────────────────────────────────── */
@media (min-width: 641px) and (max-width: 1024px) {
  .stats-grid, .sg, .grid-4, .audience-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px !important;
  }
  [style*="grid-template-columns:1fr 380px"],
  [style*="grid-template-columns: 1fr 380px"] {
    grid-template-columns: 1fr !important;
  }
  table.dt, table { font-size: 12px; }
  .container, main, section { padding-left: 24px !important; padding-right: 24px !important; }
}

/* ─────────────────────────────────────────────────────────────
   TRÈS PETITS ÉCRANS — ≤ 380px
   ───────────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  h1 { font-size: 22px !important; }
  .sc-val, .sc-v { font-size: 18px !important; }
  .btn, button { font-size: 11px !important; padding: 8px 10px !important; }
}

/* ─────────────────────────────────────────────────────────────
   Helper utility — affiché uniquement sur mobile
   ───────────────────────────────────────────────────────────── */
.mobile-only { display: none; }
@media (max-width: 640px) { .mobile-only { display: inline-flex; } }
.desktop-only { display: inline-flex; }
@media (max-width: 640px) { .desktop-only { display: none !important; } }
