/* Corrections de responsivité globales pour tous les écrans */

/* Base guardrails: prevent horizontal overflow and preserve media ratio */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: clip;
}

img,
video,
canvas,
svg,
iframe {
    max-width: 100%;
    height: auto;
}

/* Corrections pour les très petits écrans (320px - 400px) */
@media (max-width: 400px) {

    /* Corrections générales */
    body {
        font-size: 14px;
        line-height: 1.4;
    }

    .container {
        padding: 0 8px;
        max-width: 100%;
    }

    /* Corrections pour les titres */
    h1 {
        font-size: 1.8rem !important;
        line-height: 1.2;
        margin-bottom: 0.8rem;
    }

    h2 {
        font-size: 1.5rem !important;
        line-height: 1.3;
        margin-bottom: 0.7rem;
    }

    h3 {
        font-size: 1.2rem !important;
        line-height: 1.3;
        margin-bottom: 0.6rem;
    }

    /* Corrections pour les boutons */
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
        min-height: 40px;
    }

    /* Corrections pour les grilles */
    .services-grid,
    .features-grid,
    .payment-grid,
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Corrections pour les cartes */
    .service-card,
    .feature-card,
    .payment-card {
        padding: 1rem !important;
        margin: 0 !important;
    }

    /* Corrections pour les formulaires */
    input,
    select,
    textarea {
        font-size: 16px;
        /* Évite le zoom sur iOS */
        padding: 0.8rem;
    }

    /* Corrections pour les images */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Corrections pour les tableaux */
    table {
        font-size: 0.8rem;
        overflow-x: auto;
        display: block;
        white-space: nowrap;
    }
}

/* Corrections pour les écrans moyens (401px - 768px) */
@media (min-width: 401px) and (max-width: 768px) {
    .container {
        padding: 0 15px;
    }

    /* Grilles à 2 colonnes pour les écrans moyens */
    .services-grid,
    .features-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.5rem !important;
    }

    /* Cartes avec padding adapté */
    .service-card,
    .feature-card {
        padding: 1.5rem !important;
    }
}

/* Corrections pour les grands écrans (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 0 20px;
    }

    /* Grilles à 3 colonnes pour les tablettes */
    .services-grid,
    .features-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 2rem !important;
    }
}

/* Corrections spécifiques pour l'orientation paysage sur mobile */
@media (max-height: 500px) and (orientation: landscape) {

    .hero,
    .services-hero,
    .payment-hero {
        min-height: auto !important;
        height: auto !important;
        padding: 2rem 0 !important;
    }

    .hero h1,
    .services-hero h1,
    .payment-hero h1 {
        font-size: 2rem !important;
        margin-bottom: 0.5rem !important;
    }

    .hero-stats,
    .hero-features-inline {
        display: none !important;
    }
}

/* Corrections pour les écrans haute résolution */
@media (min-width: 1920px) {
    .container {
        max-width: 1800px;
        margin: 0 auto;
    }

    .services-grid,
    .features-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* Corrections pour l'accessibilité */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Corrections pour le mode sombre sur mobile */
@media (max-width: 768px) {
    [data-theme="dark"] {
        --shadow-color: rgba(0, 0, 0, 0.4);
    }

    [data-theme="dark"] .service-card,
    [data-theme="dark"] .feature-card,
    [data-theme="dark"] .payment-card {
        border: 1px solid var(--border-color);
    }
}

/* Corrections pour l'impression */
@media print {

    .nav-actions,
    .mobile-menu-btn,
    .back-to-top,
    .promo-banner {
        display: none !important;
    }

    .container {
        max-width: 100% !important;
        padding: 0 !important;
    }

    .service-card,
    .feature-card {
        break-inside: avoid;
        page-break-inside: avoid;
        border: 1px solid #ccc !important;
        box-shadow: none !important;
    }
}

/* Corrections pour les écrans tactiles */
@media (hover: none) and (pointer: coarse) {

    .btn:hover,
    .service-card:hover,
    .feature-card:hover {
        transform: none !important;
    }

    /* Augmenter la taille des zones tactiles pour l'ergonomie (Mobile First) */
    .btn,
    .cart-button,
    .theme-toggle,
    .chatbot-button {
        min-height: 48px;
        /* Standard ergonomics + extra comfort */
        min-width: 48px;
    }

    .nav-menu a {
        padding: 1rem !important;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* Corrections pour les écrans pliables */
@media (max-width: 280px) {
    .logo {
        font-size: 0.8rem !important;
    }

    .nav-actions {
        gap: 0.2rem !important;
    }

    .cart-button,
    .theme-toggle,
    .chatbot-button {
        width: 28px !important;
        height: 28px !important;
        font-size: 0.7rem !important;
    }

    .container {
        padding: 0 4px !important;
    }
}

/* Corrections pour les écrans ultra-larges */
@media (min-width: 2560px) {
    .container {
        max-width: 2400px;
    }

    .services-grid,
    .features-grid {
        grid-template-columns: repeat(5, 1fr) !important;
    }

    body {
        font-size: 18px;
    }
}

/* ===== GLOBAL RESPONSIVE POLISH ===== */

/* More fluid spacing/typography across the site */
:root {
    --section-space-y: clamp(2rem, 4vw, 4.5rem);
    --content-space-y: clamp(1rem, 2.2vw, 2rem);
}

section {
    scroll-margin-top: 110px;
}

main section {
    padding-top: var(--content-space-y);
    padding-bottom: var(--content-space-y);
}

/* Common wrappers used across pages */
.hero,
.services-hero,
.payment-hero,
.blog-hero,
.article-hero {
    padding-top: var(--section-space-y) !important;
    padding-bottom: var(--section-space-y) !important;
}

/* Common grids across pages */
.blog-grid,
.screenshots-grid,
.showcase-grid,
.cart-layout,
.trust-grid,
.security-grid,
.footer-content {
    gap: clamp(0.8rem, 2vw, 1.5rem) !important;
}

/* Make sticky bars safer on very small screens */
@media (max-width: 768px) {
    .global-search-bar {
        top: auto !important;
        position: relative !important;
    }

    .promo-banner .container {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .promo-content {
        width: 100%;
        justify-content: center;
    }

    .promo-banner {
        overflow-x: clip !important;
    }

    .promo-banner .container {
        max-width: calc(100vw - 20px) !important;
        margin-left: auto !important;
        margin-right: auto !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
    }
}

/* Prevent fixed width blocks from breaking layout */
[style*="width: 350px"],
[style*="width:350px"] {
    width: min(100%, 350px) !important;
}

@media (max-width: 900px) {
    .cart-layout {
        grid-template-columns: 1fr !important;
    }
}

/* Touch ergonomics */
@media (max-width: 768px) {
    button,
    .btn,
    a.btn,
    .nav-menu a {
        min-height: 44px;
    }

    input,
    select,
    textarea {
        min-height: 44px;
    }

    .nav-menu:not(.active) {
        right: min(-100%, -320px) !important;
    }

    .nav-menu.active {
        right: 0 !important;
    }
}
