/* ══════════════════════════════════════════════════════════════
   NEXA — Mobile Fixes (TemplateClient)
   Correctifs responsifs ciblés pour les pages générées.
   Chargé en dernier pour surcharger les styles de base.
   ══════════════════════════════════════════════════════════════ */

/* ── 0. ZERO SCROLL HORIZONTAL ───────────────────────────────
   RÈGLES CRITIQUES :
   - Ne JAMAIS mettre overflow-x:hidden sur html ou body
     → cela brise les position:fixed (sidebars, navbars)
   - Ne JAMAIS utiliser * { max-width: 100% }
     → cela écrase la largeur des sidebars
   On cible uniquement les vraies sources de débordement.
   ──────────────────────────────────────────────────────────── */

/* Images et médias : jamais plus larges que leur conteneur */
img, video, iframe, embed, object, canvas, svg {
  max-width: 100%;
  height: auto;
}

/* Conteneurs de page (PAS body/html — sûr pour position:fixed) */
.main-content-area,
.page-content,
.main-content {
  overflow-x: hidden;
}


/* ── 1. TABLES : scroll horizontal plutôt que clip ───────────── */
@media (max-width: 767px) {
  /* Wrappers de tables (classes communes) */
  .stk-table-wrap,
  .ui-table-wrap,
  .table-responsive,
  .nx-table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Forcer le scroll sur tout conteneur ayant overflow:hidden autour d'une table */
  div:has(> table),
  .db-card:has(> table),
  .nx-card:has(> table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Les tables elles-mêmes ne doivent pas être compressées */
  .stk-table,
  .ui-table,
  table.dataTable,
  .table {
    min-width: 560px;
  }
}

/* ── 2. NAVIGATION PUBLIQUE : mega-menu mobile ──────────────────
   Approche flux naturel : la navbar s'étend librement.
   Aucun position:absolute → aucun problème de containing block. */

@media (max-width: 992px) {

  /* Aucun clipping sur toute la chaîne navbar */
  .colored-header,
  .mega-menu,
  .mega-menu > section.menu-list-items,
  .mega-menu .container,
  .mega-menu .row,
  .mega-menu [class*="col-"] {
    overflow: visible !important;
    max-height: none !important;
  }

  /* Logo : taille max sur mobile */
  .mega-menu .menu-logo img,
  .mega-menu .site-logo {
    max-height: 60px !important;
    max-width: 160px !important;
    width: auto !important;
    height: auto !important;
  }

  /* Barre téléphone masquée sur mobile */
  .mega-menu .menu-search-bar {
    display: none !important;
  }

  /* Panel de menu : flux normal, s'affiche sous le logo, s'étend librement */
  .mega-menu .menu-links {
    position: static !important;
    display: block;
    width: 100% !important;
    clear: both;
    max-height: none !important;
    overflow: visible !important;
    background: #fff;
    border-top: 2px solid #e5e7eb;
    box-shadow: 0 6px 20px rgba(0,0,0,.1);
    z-index: auto;
  }

  /* Sous-menus : flux normal, aucune limite */
  .mega-menu .drop-down-multilevel,
  .mega-menu .drop-down {
    position: static !important;
    max-height: none !important;
    overflow: visible !important;
  }
}

/* ── TC2 navbar (position:fixed) ─── */
.nx-nav {
  max-width: 100vw;
}

/* ── TC3 navbar ───
   NE PAS mettre overflow-x:hidden sur .mn-nav : le quirk CSS
   "overflow-x:hidden + overflow-y:visible" force overflow-y:auto, ce qui
   clippe le dropdown Services en desktop et bloque le menu hamburger en mobile. */
.mn-nav {
  max-width: 100vw;
  overflow: visible !important;
}
.top-bar {
  max-width: 100vw;
  overflow-x: hidden;
}

/* ── Conteneurs de page principaux ─── */
.main-content-area,
.page-content,
.footer-top,
footer {
  max-width: 100%;
}

/* ── 3. FOOTER : 4 colonnes → 2 colonnes → 1 colonne ──────────── */
@media (max-width: 767px) {
  .footer-top .row > [class*="col-"] {
    margin-bottom: 1.5rem;
  }

  /* Newsletter form : inputs côte à côte → empilés */
  .widget-newsletter .fieldset input,
  .widget-newsletter .fieldset .submit-btn {
    width: 100% !important;
    margin-bottom: .5rem;
  }
}

/* ── 4. FORMULAIRES MULTI-COLONNES ──────────────────────────────
   Les grilles 2/3 colonnes passent en 1 colonne. */
@media (max-width: 600px) {
  .ui-form-grid,
  .ui-form-grid-3,
  .adm-form-grid,
  .db-form-row {
    grid-template-columns: 1fr !important;
  }

  /* Grilles de cartes admin */
  .adm-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── 5. PAGES ADMIN (View_administration) ────────────────────── */
@media (max-width: 767px) {
  .adm-wrap {
    padding: 1rem .75rem 3rem !important;
  }

  .adm-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)) !important;
    gap: .75rem !important;
  }
}

/* ── 6. DASHBOARD INTERNE (View_dashboard KPIs) ─────────────── */
@media (max-width: 575px) {
  .db-kpi-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: .75rem !important;
  }

  .db-wrap {
    padding: 1rem !important;
  }

  .db-h1 {
    font-size: 1.2rem !important;
  }

  /* Actions header : empiler les boutons */
  .db-card-header {
    flex-direction: column;
    align-items: flex-start !important;
  }
}

@media (max-width: 380px) {
  .db-kpi-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── 7. SIDEBAR DASHBOARD (View_template_dashboard) ─────────── */
/* Déjà géré inline avec @media(max-width:991px) dans le template.
   Ces règles corrigent des débordements résiduels. */
@media (max-width: 991px) {
  .db-main {
    min-width: 0;
    overflow-x: hidden;
  }
}

/* ── 8. PARC / VÉHICULES : grille de cartes ─────────────────── */
@media (max-width: 480px) {
  /* Les cards de véhicules passent en 1 colonne */
  .ui-veh-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── 9. FORMULAIRES PAGE PARC (filtres inline) ──────────────── */
@media (max-width: 600px) {
  /* Le filtre véhicules utilise une grille CSS inline ;
     on force les selects à pleine largeur */
  .main-content-area select,
  .main-content-area input[type="text"],
  .main-content-area input[type="search"] {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ── 10. PAGE PLANNING / RÉSERVATIONS ────────────────────────── */
@media (max-width: 767px) {
  /* Tableaux de planning larges */
  .planning-wrap,
  .reservation-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Créneaux horaires : éviter le débordement */
  .creneau-grid,
  .slots-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ── 11. PAGE ACCUEIL : hero banner ─────────────────────────── */
@media (max-width: 480px) {
  .background-rotator .heading-caption h1 {
    font-size: 22px !important;
    line-height: 1.3 !important;
  }

  .background-rotator .search-section {
    padding: 0 10px !important;
  }

  /* Bouton RDV dans le header top */
  .header-top .btn-theme {
    font-size: 12px !important;
    padding: 6px 12px !important;
  }

  .header-right .listnone {
    flex-wrap: wrap;
    gap: 4px;
  }
}

/* ── 12. PAGE PROFIL (View_template_profil) ──────────────────── */
@media (max-width: 767px) {
  .ui-page,
  .ui-page-wide {
    padding: 0 1rem !important;
  }

  /* Le header de profil avec 2 colonnes */
  .ui-header-row {
    flex-direction: column !important;
  }

  /* Stats en 2 colonnes */
  .ui-stats {
    grid-template-columns: 1fr 1fr !important;
  }
}

@media (max-width: 400px) {
  .ui-stats {
    grid-template-columns: 1fr !important;
  }
}

/* ── 13. PAGE DETAIL VÉHICULE ────────────────────────────────── */
@media (max-width: 767px) {
  /* Images de véhicule */
  .ad-archive-img img {
    width: 100% !important;
    height: auto !important;
  }

  /* Info véhicule : pas de tableau horizontal débordant */
  .ad-listing-meta {
    overflow-x: auto;
  }
}

/* ── 14. GENERAL : conteneurs avec padding trop large ────────── */
@media (max-width: 480px) {
  .section-padding {
    padding: 40px 0 !important;
  }

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

/* ── 15. TEXTES ET TITRES sur petits écrans ─────────────────── */
@media (max-width: 480px) {
  h1, .content-area h1 { font-size: 1.4rem !important; }
  h2                    { font-size: 1.2rem !important; }
  .stk-header h1,
  .adm-title,
  .db-h1                { font-size: 1.2rem !important; }

  /* Breadcrumbs trop longs */
  .stk-bc,
  .adm-bc,
  .ui-bc {
    font-size: .75rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}

/* ── 16. BOUTONS : éviter les débordements ───────────────────── */
@media (max-width: 480px) {
  .ui-btn,
  .btn-theme,
  .nx-btn {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* Groupes de boutons : wrap */
  .ui-header-row .ui-btn,
  .stk-header .ui-btn {
    display: block;
    width: 100%;
    text-align: center;
  }
}

/* ── 17. BULLE WHATSAPP : repositionnement ───────────────────── */
@media (max-width: 480px) {
  .wa-container {
    bottom: 1rem !important;
    left: 1rem !important;
  }

  .wa-bubble {
    width: 48px !important;
    height: 48px !important;
  }
}

/* ── 18. FIX : images trop larges dans les cards ────────────── */
img {
  max-width: 100%;
  height: auto;
}

/* ══════════════════════════════════════════════════════════════
   TC2 — Dark Premium : navbar mobile hamburger
   ══════════════════════════════════════════════════════════════ */

/* Hamburger button (ajouté en PHP dans View_template.php TC2) */
.nx-hamburger {
  display: none;
  background: none;
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 4px;
  transition: border-color .2s;
}
.nx-hamburger:hover { border-color: var(--primary, #e63946); color: var(--primary, #e63946); }

@media (max-width: 900px) {
  .nx-nav .nav-links,
  .nx-nav .nav-cta {
    display: none !important;
  }
  .nx-hamburger {
    display: flex !important;
  }
  /* Menu ouvert */
  .nx-nav.open .nav-links {
    display: flex !important;
    flex-direction: column;
    gap: 0;
    position: absolute;
    top: 70px; left: 0; right: 0;
    background: rgba(13,13,13,.98);
    border-top: 2px solid var(--primary, #e63946);
    padding: .5rem 0 1rem;
    z-index: 1001;
  }
  .nx-nav.open .nav-links li { width: 100%; }
  .nx-nav.open .nav-links a {
    display: block;
    padding: .75rem 1.5rem;
    color: #e0e0e0;
    font-size: .9rem;
  }
  .nx-nav.open .nav-links a:hover { color: var(--primary, #e63946); background: rgba(255,255,255,.04); }
  /* Dropdown inside mobile menu */
  .nx-nav.open .nav-links .dropdown-menu-nx {
    position: static !important;
    display: block !important;
    background: rgba(255,255,255,.05);
    border: none;
    border-top: none;
    padding-left: 1rem;
  }
  /* CTA buttons at bottom of open menu */
  .nx-nav.open .nav-cta {
    display: flex !important;
    padding: .75rem 1.5rem;
    gap: .8rem;
    background: rgba(13,13,13,.98);
  }
}

/* ══════════════════════════════════════════════════════════════
   TC3 — Épuré Moderne : navbar mobile hamburger (design v2)
   ══════════════════════════════════════════════════════════════ */

.mn-hamburger {
  display: none;
  background: transparent;
  border: 1.5px solid var(--gray2, #eef0f4);
  color: var(--text, #1a1d2e);
  width: 42px; height: 42px;
  align-items: center; justify-content: center;
  align-self: center;
  flex-shrink: 0;
  font-size: 1.05rem;
  cursor: pointer;
  border-radius: 10px;
  transition: background .2s ease, border-color .2s ease, color .2s ease;
}
.mn-hamburger:hover,
.mn-hamburger:focus {
  border-color: var(--p, #1a73e8);
  color: var(--p, #1a73e8);
  outline: none;
}
.mn-hamburger i { transition: transform .25s ease; }

/* Top bar hide on very small */
@media (max-width: 600px) {
  .top-bar { display: none; }
}

@media (max-width: 900px) {

  /* ── Navbar compacte sur mobile ── */
  .mn-nav {
    padding: 0 1rem !important;
    min-height: 60px;
  }
  .mn-nav .mn-logo img { max-height: 38px; }

  /* Masquer liens et actions par défaut */
  .mn-nav .mn-links,
  .mn-nav .mn-actions {
    display: none;
  }
  .mn-hamburger { display: flex !important; }

  /* ── État ouvert : nav s'étend en accordion ── */
  .mn-nav.open { flex-wrap: wrap; }
  .mn-nav.open .mn-hamburger {
    background: var(--p, #1a73e8);
    border-color: var(--p, #1a73e8);
    color: #fff;
  }
  .mn-nav.open .mn-hamburger i { transform: rotate(90deg); }

  /* ── Liste des liens — animation slide-down ── */
  @keyframes mn-slide-down {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .mn-nav.open .mn-links {
    display: flex !important;
    flex-direction: column;
    width: 100%;
    margin: 0 -1rem;          /* compense le padding horizontal de .mn-nav */
    padding: .5rem .75rem;
    background: #fff;
    border-top: 1px solid var(--gray2, #eef0f4);
    list-style: none;
    align-self: stretch;
    align-items: stretch;
    gap: .1rem;
    animation: mn-slide-down .22s ease;
  }
  .mn-nav.open .mn-links > li {
    width: 100%;
    display: block;
    list-style: none;
  }
  .mn-nav.open .mn-links > li > a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .8rem 1rem;
    color: var(--text, #1a1d2e);
    font-size: .93rem;
    font-weight: 500;
    text-decoration: none;
    border-radius: 8px;
    transition: background .15s ease, color .15s ease, padding-left .15s ease;
    border: none;
  }
  .mn-nav.open .mn-links > li > a:hover,
  .mn-nav.open .mn-links > li > a:focus,
  .mn-nav.open .mn-links > li > a:active {
    background: var(--gray1, #f7f8fa);
    color: var(--p, #1a73e8);
  }

  /* ── Dropdown Services (toujours déployé en mobile) ── */
  .mn-nav.open .mn-links .drop {
    display: block;
    align-self: stretch;
    height: auto;
    position: static;
  }
  .mn-nav.open .drop > a .fa-chevron-down {
    transform: rotate(180deg);
    transition: transform .2s ease;
    font-size: .65rem;
    opacity: .55;
  }
  .mn-nav.open .drop-list {
    position: static !important;
    display: block !important;
    background: transparent;
    border: none;
    border-top: none;
    box-shadow: none;
    padding: .15rem 0 .35rem;
    margin: 0;
    min-width: 0;
    list-style: none;
  }
  .mn-nav.open .drop-list li {
    list-style: none;
    width: 100%;
  }
  .mn-nav.open .drop-list li a {
    display: block;
    padding: .55rem 1rem .55rem 2.25rem;
    font-size: .85rem;
    color: var(--muted, #6b7280);
    text-decoration: none;
    border: none;
    border-radius: 6px;
    transition: background .15s ease, color .15s ease;
    position: relative;
  }
  .mn-nav.open .drop-list li a::before {
    content: '';
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    width: 5px; height: 5px;
    background: var(--gray3, #d1d5de);
    border-radius: 50%;
    transition: background .15s ease, transform .15s ease;
  }
  .mn-nav.open .drop-list li a:hover {
    color: var(--p, #1a73e8);
    background: var(--gray1, #f7f8fa);
  }
  .mn-nav.open .drop-list li a:hover::before {
    background: var(--p, #1a73e8);
    transform: translateY(-50%) scale(1.4);
  }

  /* ── Barre d'actions (boutons RDV / Mon espace) ── */
  .mn-nav.open .mn-actions {
    display: flex !important;
    flex-direction: column;
    width: 100%;
    gap: .5rem;
    margin: 0 -1rem;
    padding: .85rem 1.25rem 1rem;
    background: var(--gray1, #f7f8fa);
    border-top: 1px solid var(--gray2, #eef0f4);
    animation: mn-slide-down .26s ease;
  }
  .mn-nav.open .mn-actions .btn-nav-rdv,
  .mn-nav.open .mn-actions .btn-nav-ghost {
    width: 100%;
    text-align: center;
    justify-content: center;
    padding: .8rem 1rem;
    font-size: .9rem;
    font-weight: 600;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: .5rem;
  }
  .mn-nav.open .mn-actions .btn-nav-rdv {
    order: 1;       /* CTA principal en premier */
    box-shadow: 0 4px 14px rgba(0,0,0,.1);
  }
  .mn-nav.open .mn-actions .btn-nav-ghost {
    order: 2;
    background: #fff;
  }
}

/* ── SIDEBAR PROFIL MOBILE ──────────────────────────────────── */
#sb-burger {
  position: fixed;
  top: .75rem;
  left: .75rem;
  z-index: 1100;
  display: none;
  background: var(--sb-primary, #002457);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
#sb-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.45);
  z-index: 1090;
}
@media (max-width: 1199px) {
  .main-content { margin-left: 0 !important; }
  #sidenav-main { z-index: 1095 !important; }
}
