/**
 * TASJILONLINE — Mobile Optimization Patch
 * =========================================
 * Corrige :
 *   1. Déformations générales sur smartphone (viewport, overflow, flex)
 *   2. Cartes des packs (pricing-card) — hauteur uniforme, layout propre
 *   3. Footer minimisé sur smartphone (accordéon collapsible)
 *
 * Compatible : Chrome Android, Safari iOS, Samsung Internet, Firefox Mobile
 * Breakpoints couverts : 480px, 640px, 768px
 */

/* ===================================================================
 * 0 — SOCLE ANTI-DÉFORMATION UNIVERSEL
 * =================================================================== */

/* Aucun débordement horizontal */
html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    width: 100% !important;
}

/* Box-sizing global */
*, *::before, *::after {
    box-sizing: border-box !important;
}

/* Images / vidéos ne débordent jamais */
img, video, iframe, svg, canvas, picture {
    max-width: 100% !important;
    height: auto;
}

/* Inputs anti-zoom iOS */
input, select, textarea {
    font-size: max(16px, 1rem) !important;
    -webkit-appearance: none;
    appearance: none;
}

/* ===================================================================
 * 1 — HEADER / TOPBAR
 * =================================================================== */

/* La topbar disparaît proprement sur mobile */
@media (max-width: 768px) {
    .topbar {
        display: none !important;
    }

    /* Le header collé en haut sans conflit */
    .site-header,
    .header {
        position: sticky !important;
        top: 0 !important;
        z-index: 1000 !important;
        height: 64px !important;
        min-height: 64px !important;
    }

    .header-inner,
    .header-container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        gap: 0.5rem !important;
        align-items: center !important;
        height: 64px !important;
    }

    .logo-img {
        height: 46px !important;
        width: auto !important;
        max-width: calc(100vw - 80px) !important;
        object-fit: contain !important;
        flex-shrink: 1 !important;
    }

    .mobile-menu-btn {
        flex-shrink: 0 !important;
        min-width: 44px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 1002 !important;
    }
}

/* ===================================================================
 * 2 — HERO — anti-débordement + padding-top correct
 * =================================================================== */

@media (max-width: 768px) {
    /* Le hero ne passe pas SOUS le header fixe */
    .hero-tawjihi,
    .hero,
    .hero-duke,
    .hero-conztru,
    .hero-section {
        padding-top: calc(64px + 2rem) !important;
    }

    .page-header {
        padding-top: calc(64px + 2.5rem) !important;
    }

    /* Hero grid : empilé verticalement */
    .hero-grid {
        grid-template-columns: 1fr !important;
        gap: 2rem !important;
        text-align: center !important;
    }

    /* Illustration hero */
    .hero-illu-wrap {
        max-width: min(320px, 100%) !important;
        margin: 0 auto !important;
    }
    .hero-illu-wrap img,
    .hero-illu-wrap svg {
        max-width: 100% !important;
        margin: 0 auto !important;
    }

    /* Boutons CTA empilés */
    .hero-cta-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }
    .hero-cta-row .btn {
        width: 100% !important;
        justify-content: center !important;
        min-height: 52px !important;
        border-radius: 14px !important;
    }

    /* Stats hero : 3 en rangée */
    .hero-stats {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.5rem !important;
        margin: 0 auto !important;
        max-width: 100% !important;
    }
    .hero-stat-block { text-align: center; }
    .hero-stat-block .num { justify-content: center !important; font-size: 1.4rem !important; }
    .hero-stat-block .lbl { font-size: 0.68rem !important; }

    /* Badges flottants cachés */
    .floating-badge { display: none !important; }
}

@media (max-width: 480px) {
    .hero-tawjihi h1,
    .hero h1 {
        font-size: clamp(1.5rem, 6vw, 1.85rem) !important;
        line-height: 1.25 !important;
    }
    .hero-stats {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.35rem !important;
    }
    .hero-stat-block .num { font-size: 1.2rem !important; }
    .hero-stat-block .lbl { font-size: 0.62rem !important; }
}

/* ===================================================================
 * 3 — SEARCH BAR
 * =================================================================== */

@media (max-width: 768px) {
    .search-section {
        margin-top: -1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
    .search-card {
        padding: 1rem !important;
        margin: 0 !important;
        border-radius: 14px !important;
    }
    .search-form {
        flex-direction: column !important;
        gap: 0.6rem !important;
    }
    .search-input-wrap { width: 100% !important; }
    .search-input {
        width: 100% !important;
        border-radius: 10px !important;
    }
    .search-btn {
        width: 100% !important;
        border-radius: 10px !important;
        justify-content: center !important;
    }
}

/* ===================================================================
 * 4 — CARTES DES PACKS (pricing-card)
 * Problème : hauteurs inégales, text tronqué, featured scale brisée
 * =================================================================== */

/* Desktop : hauteur uniforme, alignement propre */
.pricing-grid {
    align-items: stretch !important;
}

.pricing-card {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    min-height: 420px !important;
    position: relative !important;
    overflow: visible !important;       /* pour le badge "Populaire" */
}

/* Badge "Populaire" ne sort plus du card */
.pricing-badge {
    position: absolute !important;
    top: -14px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    white-space: nowrap !important;
    z-index: 2 !important;
}

/* Corps du card : le texte description prend l'espace disponible */
.pricing-card .price {
    margin: 0.75rem 0 !important;
    line-height: 1.1 !important;
}

.pricing-card > p {
    flex-grow: 0 !important;
    min-height: 50px !important;        /* hauteur minimale uniforme */
    font-size: 0.9rem !important;
    line-height: 1.6 !important;
}

/* Liste features : pousse le bouton vers le bas */
.pricing-features {
    flex-grow: 1 !important;
    margin-bottom: 1.5rem !important;
}

.pricing-features li {
    align-items: flex-start !important;
    padding: 0.4rem 0 !important;
}

/* Bouton toujours en bas */
.pricing-card .btn {
    margin-top: auto !important;
    width: 100% !important;
    justify-content: center !important;
}

/* Featured : ne scale plus (cause layout shift) */
.pricing-card.featured {
    transform: none !important;
    border-width: 2px !important;
}
.pricing-card.featured:hover {
    transform: translateY(-6px) !important;
}

/* === MOBILE : carousel swipe natif === */
@media (max-width: 768px) {
    .pricing-grid {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        scroll-snap-type: x mandatory !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 1rem !important;
        padding: 0.5rem 1rem 1.5rem !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
        margin: 0 -1rem !important;
        align-items: stretch !important;
    }
    .pricing-grid::-webkit-scrollbar { display: none !important; }

    .pricing-card {
        flex: 0 0 calc(100vw - 4rem) !important;
        max-width: calc(100vw - 4rem) !important;
        min-height: auto !important;
        scroll-snap-align: center !important;
        scroll-snap-stop: always !important;
        transform: none !important;
    }
    .pricing-card.featured {
        transform: none !important;
    }
    .pricing-card.featured:hover {
        transform: none !important;
    }

    /* Boutons carousel desktop cachés sur mobile */
    .carousel-btn,
    .pricing-carousel .carousel-btn,
    .carousel-arrow {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .pricing-card {
        flex: 0 0 calc(100vw - 3rem) !important;
        max-width: calc(100vw - 3rem) !important;
        padding: 1.75rem 1.25rem !important;
    }
    .pricing-card .price {
        font-size: 2.25rem !important;
    }
}

/* ===================================================================
 * 5 — CARTES ÉCOLES (ecole-card)
 * Problème : image déformée, info-grid débordante sur mobile
 * =================================================================== */

.ecole-card {
    display: flex !important;
    flex-direction: column !important;
}

.ecole-card-image {
    height: 160px !important;
    min-height: 160px !important;
    max-height: 160px !important;
    overflow: hidden !important;
}

.ecole-card-image img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;     /* logo pas déformé */
    max-width: 100% !important;
    padding: 0.75rem !important;
}

/* Info grid : 3 colonnes → 2 colonnes sur petit */
@media (max-width: 480px) {
    .ecole-card-info-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .ecole-card-info-grid .ecole-info-item:last-child {
        grid-column: span 2 !important;
        text-align: center !important;
    }
}

/* Carousel mobile */
@media (max-width: 768px) {
    .ecoles-grid {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        scroll-snap-type: x mandatory !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 1rem !important;
        padding: 0.5rem 1rem 1.5rem !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
        margin: 0 -1rem !important;
        grid-template-columns: unset !important;
    }
    .ecoles-grid::-webkit-scrollbar { display: none !important; }

    .ecoles-grid .ecole-card {
        flex: 0 0 calc(100vw - 4rem) !important;
        max-width: calc(100vw - 4rem) !important;
        scroll-snap-align: center !important;
        scroll-snap-stop: always !important;
    }
}

@media (max-width: 480px) {
    .ecoles-grid .ecole-card {
        flex: 0 0 calc(100vw - 3rem) !important;
        max-width: calc(100vw - 3rem) !important;
    }
}

/* ===================================================================
 * 6 — SECTIONS GÉNÉRALES
 * =================================================================== */

@media (max-width: 768px) {
    .container, .container-wide {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        max-width: 100vw !important;
    }

    .section,
    section[class*="section"] {
        padding-top: 3rem !important;
        padding-bottom: 3rem !important;
    }

    .section-header {
        margin-bottom: 2.5rem !important;
        padding: 0 0.5rem !important;
    }

    /* Toutes grids desktop → 1 col sur mobile */
    .services-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .how-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.25rem !important;
    }

    .stats-row-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.5rem !important;
    }
}

@media (max-width: 480px) {
    .container, .container-wide {
        padding-left: 0.85rem !important;
        padding-right: 0.85rem !important;
    }

    .how-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 1rem !important;
    }

    .how-step-num {
        width: 64px !important;
        height: 64px !important;
        font-size: 1.25rem !important;
    }

    .how-step-card h4 { font-size: 0.88rem !important; }
    .how-step-card p  { font-size: 0.78rem !important; }
}

/* ===================================================================
 * 7 — FOOTER MINIMISÉ SUR SMARTPHONE
 * Stratégie : afficher seulement la marque + copyright + WhatsApp
 *             masquer les colonnes de liens et services
 *             remplacer par accordéon minimal
 * =================================================================== */

/* ── Desktop & tablette : footer normal ── */
.footer-mobile-toggle { display: none; }

/* ── Smartphone (≤ 768px) ── */
@media (max-width: 768px) {

    /* Footer compact : fond + padding réduit */
    .site-footer {
        padding-top: 2.5rem !important;
        margin-top: 3rem !important;
    }

    /* Grid footer → 1 seule colonne compacte */
    .footer-grid {
        grid-template-columns: 1fr !important;
        gap: 0 !important;
        padding: 0 1.25rem !important;
        margin-bottom: 0 !important;
    }

    /* ── Colonne BRAND : toujours visible ── */
    .footer-brand {
        text-align: center !important;
        padding-bottom: 1.5rem !important;
        border-bottom: 1px solid rgba(255,255,255,0.08) !important;
        margin-bottom: 0 !important;
    }
    .footer-brand h3 { font-size: 1.15rem !important; }
    .footer-brand p {
        font-size: 0.85rem !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
    }
    .footer-social { justify-content: center !important; }

    /* ── Colonnes LIENS & SERVICES : accordéon ── */
    .footer-col:not(.footer-brand) {
        border-bottom: 1px solid rgba(255,255,255,0.06) !important;
        padding: 0 !important;
    }

    /* Header accordéon (h4) */
    .footer-col:not(.footer-brand) h4 {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0.9rem 0 !important;
        margin: 0 !important;
        cursor: pointer !important;
        user-select: none !important;
        font-size: 0.9rem !important;
        transition: color 0.2s !important;
    }
    .footer-col:not(.footer-brand) h4::after {
        /* Remplacer la ligne déco par une flèche accordéon */
        content: '+' !important;
        position: static !important;
        width: auto !important;
        height: auto !important;
        background: none !important;
        border-radius: 0 !important;
        font-size: 1.1rem !important;
        font-weight: 400 !important;
        color: var(--orange, #f97316) !important;
        transition: transform 0.25s ease !important;
    }
    .footer-col:not(.footer-brand) h4.open::after {
        transform: rotate(45deg) !important;
    }

    /* Contenu accordéon : masqué par défaut */
    .footer-col:not(.footer-brand) .footer-links,
    .footer-col:not(.footer-brand) .footer-contact-row,
    .footer-col:not(.footer-brand) .footer-col-body {
        max-height: 0 !important;
        overflow: hidden !important;
        transition: max-height 0.35s ease !important;
        padding-bottom: 0 !important;
    }
    .footer-col:not(.footer-brand) h4.open + .footer-links,
    .footer-col:not(.footer-brand) h4.open + .footer-contact-row,
    .footer-col:not(.footer-brand) h4.open + .footer-col-body {
        max-height: 400px !important;
        padding-bottom: 1rem !important;
    }

    /* Liens footer légèrement plus grands */
    .footer-links a {
        padding: 0.3rem 0 !important;
        font-size: 0.88rem !important;
        min-height: 36px !important;
        display: flex !important;
        align-items: center !important;
    }

    /* Ligne contact alignée */
    .footer-contact-row {
        justify-content: flex-start !important;
        text-align: start !important;
    }

    /* Bottom bar : empilé */
    .footer-bottom {
        flex-direction: column !important;
        text-align: center !important;
        gap: 0.75rem !important;
        padding: 1.25rem 1rem !important;
        font-size: 0.8rem !important;
    }
    .footer-bottom-links {
        justify-content: center !important;
        gap: 1rem !important;
        flex-wrap: wrap !important;
    }

    /* Bouton scroll-to-top bien positionné */
    .scroll-top-btn {
        bottom: 1.25rem !important;
        width: 44px !important;
        height: 44px !important;
    }
}

/* Très petit mobile : footer encore plus compact */
@media (max-width: 480px) {
    .site-footer { padding-top: 2rem !important; }
    .footer-brand p {
        font-size: 0.82rem !important;
        -webkit-line-clamp: 1 !important;
    }
    .footer-col:not(.footer-brand) h4 {
        font-size: 0.85rem !important;
        padding: 0.8rem 0 !important;
    }
}

/* ===================================================================
 * 8 — MODAL RESPONSIVE
 * =================================================================== */

@media (max-width: 640px) {
    .modal-overlay {
        padding: 1rem !important;
        align-items: flex-end !important;
    }
    .modal {
        max-width: 100% !important;
        width: 100% !important;
        max-height: calc(100dvh - 2rem) !important;
        border-radius: 18px 18px 0 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .form-row,
    .declare-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    .modal-body { padding: 1.25rem !important; }
    .modal-header { padding: 1rem 1.25rem !important; }
}

/* ===================================================================
 * 9 — SAFARI iOS : safe area + 100vh bug
 * =================================================================== */

@supports (-webkit-touch-callout: none) {
    .hero, .hero-tawjihi, .hero-duke {
        min-height: -webkit-fill-available;
    }
    .nav-desktop {
        padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
    }
    .footer-bottom {
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* ===================================================================
 * 10 — TOUCH FEEDBACK (remplace hover sur appareils tactiles)
 * =================================================================== */

@media (hover: none) and (pointer: coarse) {
    .ecole-card:hover,
    .pricing-card:hover,
    .service-card-light:hover,
    .how-step-card:hover {
        transform: none !important;
    }
    .ecole-card:active,
    .pricing-card:active {
        transform: scale(0.98) !important;
        opacity: 0.92 !important;
        transition: transform 0.1s, opacity 0.1s !important;
    }
    .btn:active,
    .btn-ecole-main:active,
    .declare-btn:active {
        opacity: 0.82 !important;
        transform: scale(0.97) !important;
        transition: opacity 0.1s, transform 0.1s !important;
    }
}

/* ===================================================================
 * 11 — TYPOGRAPHIE ANTI-DÉBORDEMENT
 * =================================================================== */

@media (max-width: 768px) {
    h1, h2, h3, h4, h5, h6,
    p, span, a, li, label, button {
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
        -webkit-hyphens: auto;
    }
}

/* ===================================================================
 * 12 — SÉCURITÉ : éléments avec width fixe inline → ajustés
 * =================================================================== */

@media (max-width: 768px) {
    [style*="width: 500px"],
    [style*="width: 600px"],
    [style*="width: 700px"],
    [style*="width: 800px"],
    [style*="width: 1000px"],
    [style*="width: 1200px"] {
        width: 100% !important;
        max-width: 100% !important;
    }
    [style*="margin-left: -"],
    [style*="margin-right: -"] {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
}
