/* ============================================
   LA MEUTE — MOBILE UX FIXES
   Charger APRÈS tous les autres CSS pour gagner la cascade.
   Cible: smartphones (≤ 768px) — règles critiques seulement.
   ============================================ */

/* ------------------------------------------------------------------
   -1. Bouton "Mon profil" du hero index : visible UNIQUEMENT sur mobile (et si user connecté)
------------------------------------------------------------------ */
/* Toujours caché par défaut (PC ou non-connecté) */
.hero-profile-btn { display: none !important; }

/* Visible UNIQUEMENT si user connecté ET mobile */
@media (max-width: 640px) {
    .hero-profile-btn.is-visible {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }
}

/* ------------------------------------------------------------------
   0. Comportements globaux mobile
------------------------------------------------------------------ */
html {
    -webkit-text-size-adjust: 100%;    /* Empêche iOS de gonfler le texte en landscape */
    text-size-adjust: 100%;
}

body {
    -webkit-tap-highlight-color: rgba(217, 119, 6, 0.15);
}

* {
    -webkit-touch-callout: default;
}

/* Boutons / liens : retour visuel propre au tap, pas de surlignage bleu */
button, a, [role="button"], .btn, label.profil-upload-btn, label[class*="upload"] {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;       /* Supprime le délai 300ms historique */
}

/* ------------------------------------------------------------------
   1. ANTI-ZOOM iOS — forcer 16px sur tous les champs en mobile
   iOS Safari/Chrome zoome au focus dès qu'un champ a font-size < 16px.
------------------------------------------------------------------ */
@media (max-width: 768px) {
    input,
    select,
    textarea,
    .form-group input,
    .form-group select,
    .form-group textarea,
    .insc-form input,
    .insc-form select,
    .profil-form input,
    .profil-form select,
    .auth-form input {
        font-size: 16px !important;
        line-height: 1.4 !important;
    }

    /* Inputs file (PPS, certif médical…) : 16px aussi sinon zoom */
    input[type="file"] {
        font-size: 16px !important;
    }
}

/* ------------------------------------------------------------------
   2. TOUCH TARGETS — minimum 44×44 px (Apple HIG) ou 48×48 (Material)
   On vise 44 px sur toutes les zones tactiles courantes en mobile.
------------------------------------------------------------------ */
@media (max-width: 768px) {

    /* Boutons primaires : déjà ~50px en btn-large, on assure les btn-sm */
    .btn.btn-sm,
    .btn-sm,
    .btn-nav-auth {
        min-height: 44px !important;
        padding: 10px 18px !important;
        font-size: 0.85rem !important;
    }

    /* Toggle menu burger */
    .nav-toggle {
        width: 44px;
        height: 44px;
        padding: 10px;
    }

    /* Topbar inscription/profil : lien retour + nav links + logout */
    .insc-topbar-back,
    .topbar-nav-link,
    .btn-logout {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    /* Liens documents (Flyer, Règlement) sur les cards d'événements */
    .insc-doc-link {
        min-height: 44px;
        padding: 10px 14px !important;
    }

    /* Dots de carousel : zone tactile élargie via padding (visuel reste petit) */
    .carousel-dot {
        width: 28px !important;
        height: 28px !important;
        padding: 10px;
        background-clip: content-box !important;
        position: relative;
    }
    .carousel-dot::before {
        content: '';
        position: absolute;
        inset: 0;
    }

    /* Onglets profil : assez gros pour le pouce */
    .profil-tab {
        min-height: 44px;
    }

    /* Boutons upload documents */
    .profil-upload-btn {
        min-height: 40px;
        padding: 10px 16px !important;
    }

    /* Modal close (× en haut à droite) */
    .modal-close {
        width: 44px !important;
        height: 44px !important;
        font-size: 1.6rem !important;
    }

    /* User name dans topbar — peut être tronqué */
    .user-name {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ------------------------------------------------------------------
   3. LISIBILITÉ — relever les fontes < 12px
------------------------------------------------------------------ */
@media (max-width: 768px) {
    .app-download-label,
    .blog-card-category,
    .insc-event-card .insc-event-badge,
    .footer-bottom p,
    small {
        font-size: 12px !important;
        line-height: 1.5;
    }

    /* Section titles trop gros sur petit écran */
    .section-title {
        font-size: clamp(1.6rem, 7vw, 2.4rem) !important;
        line-height: 1.1;
    }

    /* Description sections plus aérée */
    .section-description {
        font-size: 0.95rem;
        line-height: 1.6;
    }
}

/* ------------------------------------------------------------------
   4. SCROLLABLES — momentum natif iOS
------------------------------------------------------------------ */
@media (max-width: 768px) {
    .profil-tabs,
    .events-grid,
    .testimonials-track,
    .insc-events-grid,
    [data-scrollable] {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        scrollbar-width: thin;
    }
}

/* ------------------------------------------------------------------
   5. FORMULAIRES — espace pouce + colonnes empilées
------------------------------------------------------------------ */
@media (max-width: 640px) {
    /* form-row → toujours 1 colonne sur petit écran (au lieu de 2 serrées) */
    .form-row {
        grid-template-columns: 1fr !important;
        display: grid !important;
        gap: var(--space-md) !important;
    }

    .form-group label {
        font-size: 0.85rem;
        margin-bottom: 6px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 12px 14px !important;
        border-radius: 8px;
    }
}

/* ------------------------------------------------------------------
   6. MODALS — centré sur mobile avec marges, tous boutons accessibles
------------------------------------------------------------------ */
/* Handle masqué partout (artefact d'une ancienne version bottom-sheet) */
.modal-handle { display: none !important; }

@media (max-width: 640px) {
    /* Conteneur centré avec marges */
    .modal {
        padding: 16px !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Contenu : compact, max 360px de large (au lieu de 420), padding réduit */
    .modal-content,
    .auth-modal-content {
        max-width: 360px !important;
        width: 100% !important;
        margin: 0 !important;
        border-radius: 14px !important;
        max-height: calc(100vh - 32px) !important;
        max-height: calc(100dvh - 32px) !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 20px 18px !important;
    }

    /* Close button : discret, accessible */
    .modal-close {
        position: absolute !important;
        top: 12px !important;
        right: 12px !important;
        width: 36px !important;
        height: 36px !important;
        font-size: 1.4rem !important;
        background: rgba(0,0,0,0.05) !important;
        color: var(--color-charcoal) !important;
        border: none !important;
        z-index: 2;
    }
    .modal-close:hover { background: rgba(0,0,0,0.1) !important; }

    /* Inputs : look card propre */
    .modal-content input,
    .modal-content select,
    .modal-content textarea {
        background: #f9fafb !important;
        border: 1.5px solid #e5e7eb !important;
        border-radius: 10px !important;
        padding: 12px 14px !important;
        transition: border-color 0.15s ease, background 0.15s ease;
    }
    .modal-content input:focus,
    .modal-content select:focus,
    .modal-content textarea:focus {
        outline: none !important;
        border-color: var(--color-ochre) !important;
        background: white !important;
        box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.12) !important;
    }
    .modal-content label,
    .modal-content .form-group > label {
        font-size: 0.78rem !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
        color: var(--color-charcoal) !important;
        margin-bottom: 6px !important;
        display: block;
    }

    /* Header modale : très compact */
    .auth-modal-header,
    .modal-content > div[style*="text-align:center"] {
        margin-bottom: 14px !important;
        padding-right: 40px;
    }
    .auth-modal-header h2,
    .modal-content h2 {
        font-size: 1.2rem !important;
        margin-bottom: 4px !important;
    }
    .auth-modal-subtitle {
        font-size: 0.8rem !important;
        line-height: 1.4 !important;
    }

    /* Form auth super compact */
    .auth-form .form-group,
    .modal-content .form-group {
        margin-bottom: 10px !important;
    }
    .auth-separator {
        margin: 10px 0 !important;
        font-size: 0.75rem !important;
    }
    .btn-google {
        padding: 10px 12px !important;
        font-size: 0.85rem !important;
        min-height: 42px !important;
    }
    .auth-toggle {
        margin-top: 12px !important;
        font-size: 0.8rem !important;
    }
    .modal-content .btn-full,
    .modal-content button[type="submit"] {
        padding: 12px 16px !important;
        font-size: 0.9rem !important;
        min-height: 44px !important;
    }
}


/* ------------------------------------------------------------------
   7. PROFIL — meilleurs espacements card
------------------------------------------------------------------ */
@media (max-width: 640px) {
    .profil-main {
        padding-top: 90px;
    }

    .profil-insc-card {
        padding: var(--space-md) !important;
        gap: var(--space-sm) !important;
    }

    .profil-tabs {
        position: sticky;
        top: 72px;
        z-index: 50;
    }
}

/* ------------------------------------------------------------------
   8. SAFE AREA — iPhone notch + home indicator
------------------------------------------------------------------ */
@supports (padding: max(0px)) {
    .footer,
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
    .container {
        padding-left: max(var(--space-md), env(safe-area-inset-left));
        padding-right: max(var(--space-md), env(safe-area-inset-right));
    }
}

/* ------------------------------------------------------------------
   9bis. POLISH MOBILE — densifier sans rogner la lisibilité
------------------------------------------------------------------ */
@media (max-width: 640px) {
    /* Hero inscription : trop haut sur mobile (120px+40px de padding) */
    .insc-hero {
        padding: 90px 0 28px !important;
    }
    .insc-hero h1.section-title {
        font-size: clamp(1.6rem, 8vw, 2.4rem) !important;
        margin-bottom: 6px !important;
    }
    .insc-hero-subtitle {
        font-size: 0.92rem !important;
        line-height: 1.4 !important;
    }
    .insc-hero .section-tag {
        font-size: 0.7rem !important;
    }

    /* Profil : padding-top excessif sous la topbar fixe */
    .profil-main {
        padding-top: 80px !important;
    }
    .profil-section-title {
        font-size: 1.1rem !important;
    }

    /* Card inscription : tight maxi sur mobile */
    .profil-insc-card {
        padding: 12px !important;
        border-radius: 10px !important;
    }
    .profil-insc-head {
        gap: 10px !important;
    }
    .profil-insc-img {
        width: 44px !important;
        height: 44px !important;
        border-radius: 8px !important;
    }
    .profil-insc-name {
        font-size: 0.95rem !important;
        line-height: 1.15 !important;
        margin-bottom: 2px !important;
    }
    .profil-insc-meta {
        font-size: 0.72rem !important;
        gap: 4px !important;
        margin-bottom: 4px !important;
    }
    .profil-insc-price {
        font-size: 1rem !important;
    }
    .profil-insc-price small {
        font-size: 0.65rem !important;
    }
    .profil-insc-status {
        gap: 4px !important;
        margin-top: 4px !important;
    }
    .profil-badge {
        font-size: 0.65rem !important;
        padding: 2px 7px !important;
    }
    .profil-insc-cta-wrap {
        margin-top: 10px !important;
        padding-top: 10px !important;
    }
    .profil-cta {
        font-size: 0.88rem !important;
        padding: 11px 14px !important;
        min-height: 42px !important;
    }

    /* Bouton Connexion topbar plus design */
    .btn-nav-auth, .insc-topbar-right .btn-sm {
        background: linear-gradient(135deg, var(--color-ochre-dark), var(--color-ochre)) !important;
        box-shadow: 0 2px 8px rgba(217, 119, 6, 0.3) !important;
    }

    /* Form inscription : moins d'espace gaspillé */
    .insc-form-section { padding: 24px 0 !important; }
    .insc-form-header {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }
    .insc-form-event-img {
        margin: 0 auto;
    }

    /* Form total : plus discret */
    .insc-total-recap {
        padding: 12px 14px !important;
        margin: 12px 0 !important;
    }

    /* Cards événements (index page) : masquer la description verbeuse, compacter */
    .event-card-description {
        display: none !important;
    }
    .event-card {
        font-size: 0.85rem;
    }
    .event-card-content {
        padding: 14px !important;
    }
    .event-card-title {
        font-size: 1.1rem !important;
        line-height: 1.2 !important;
        margin-bottom: 6px !important;
    }
    .event-card-date, .event-card-location {
        font-size: 0.78rem !important;
        margin-bottom: 4px !important;
    }
    .event-card-footer {
        margin-top: 10px !important;
    }
}

/* ------------------------------------------------------------------
   9. PERFORMANCE — réduire animations sur mobile bas de gamme
------------------------------------------------------------------ */
@media (max-width: 480px) {
    *,
    *::before,
    *::after {
        animation-duration: 0.3s !important;
        transition-duration: 0.2s !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
