/**
 * ADM Mobile Stability Fix
 * Empêche le scroll horizontal et le bouncing sur mobile
 * 
 * @package ADM
 * @since 2.2.1
 */

/* ========================================
   STABILITÉ MOBILE - FIX GLOBAL
   ======================================== */

/* Empêcher le scroll horizontal */
html {
    overflow-x: hidden;
    max-width: 100%;
    position: relative;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
    position: relative;
}

/* Fixer tous les containers principaux */
.adm-instagram-feed,
.adm-artists-standalone,
.adm-single-track-page,
.adm-digital-library,
.adm-page-content,
.adm-related-inner,
.adm-ar-content {
    max-width: 100%;
    overflow-x: hidden;
}

/* Empêcher le débordement des images */
img {
    max-width: 100%;
    height: auto;
}

/* Fixer les grilles qui débordent */
.adm-products-grid,
.adm-ar-grid,
.adm-feed-container,
.adm-related-grid {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* Stories bar - scroll horizontal contrôlé */
.adm-stories-wrapper {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    /* Empêcher le bounce vertical */
    overscroll-behavior-y: none;
    /* Permettre le scroll horizontal mais pas au-delà */
    overscroll-behavior-x: contain;
}

/* Feed tabs - scroll horizontal contrôlé */
.adm-feed-tabs {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: none;
    overscroll-behavior-x: contain;
}

/* ========================================
   TOUCH & MOBILE OPTIMIZATIONS
   ======================================== */

/* Empêcher le zoom sur double-tap iOS */
* {
    touch-action: manipulation;
}

/* Permettre le scroll vertical uniquement où nécessaire */
body {
    touch-action: pan-y;
    overscroll-behavior: none;
}

/* Zones de scroll horizontal intentionnel */
.adm-stories-wrapper,
.adm-feed-tabs,
.adm-horizontal-scroll {
    touch-action: pan-x;
}

/* Empêcher le pull-to-refresh sur certains éléments */
.adm-feed-post,
.adm-product-card,
.adm-ar-card {
    overscroll-behavior: none;
}

/* ========================================
   FIX ÉLÉMENTS QUI DÉBORDENT
   ======================================== */

/* Fix pour les éléments en position absolute */
.adm-price-tag,
.adm-sale-tag,
.adm-media-overlay {
    max-width: calc(100% - 24px);
}

/* Fix pour les boutons pleine largeur */
.adm-load-more-btn,
.adm-bulk-download-btn,
.adm-preview-btn,
.adm-buy-btn {
    max-width: 100%;
    box-sizing: border-box;
}

/* Fix pour les inputs */
input[type="search"],
input[type="text"],
textarea,
select {
    max-width: 100%;
    box-sizing: border-box;
}

/* ========================================
   FIX PAR BREAKPOINT
   ======================================== */

/* Mobile (< 768px) */
@media (max-width: 767px) {
    /* Padding sécurisé */
    .adm-instagram-feed,
    .adm-page-content {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    
    /* Empêcher tout débordement */
    * {
        max-width: 100%;
    }
    
    /* Fixer les marges négatives */
    .adm-hero::before,
    .adm-track-hero-bg {
        left: 0;
        right: 0;
        transform: none;
    }
    
    /* Conteneurs flex qui pourraient déborder */
    .adm-post-actions,
    .adm-track-actions,
    .adm-track-meta {
        flex-wrap: wrap;
    }
}

/* ========================================
   WEBKIT SPECIFIC (iOS)
   ======================================== */

/* Empêcher le rubber band effect sur iOS */
@supports (-webkit-touch-callout: none) {
    html,
    body {
        overscroll-behavior-y: none;
    }
    
    /* Fix pour Safari iOS */
    .adm-instagram-feed,
    .adm-page-content {
        position: relative;
        overflow: hidden;
    }
}

/* ========================================
   ACCESSIBILITY & PERFORMANCE
   ======================================== */

/* Smooth scrolling pour les zones autorisées */
.adm-stories-wrapper,
.adm-feed-tabs {
    scroll-behavior: smooth;
}

/* GPU acceleration pour les animations */
.adm-feed-post,
.adm-product-card,
.adm-ar-card {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ========================================
   SAFE AREA (iPhone X+)
   ======================================== */

@supports (padding: env(safe-area-inset-bottom)) {
    /* Padding pour les zones sûres */
    .adm-load-more,
    .adm-track-actions {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    
    /* Fix pour les boutons fixes en bas */
    .adm-sticky-bottom {
        bottom: env(safe-area-inset-bottom);
    }
}

/* ========================================
   DEBUG MODE (décommenter si besoin)
   ======================================== */

/* Voir les éléments qui débordent */
/*
* {
    outline: 1px solid red !important;
}
*/
