/**
 * MOBILE & RESPONSIVE DESIGN
 * Optimisé pour tous les appareils (smartphone, tablette, desktop)
 */

/* ===== VARIABLES MOBILE ===== */
:root {
    --mobile-padding: 12px;
    --mobile-header-height: 60px;
    --touch-target-size: 44px; /* Taille recommandée pour touch */
}

/* ===== BREAKPOINTS ===== */
/* Mobile S (< 375px) */
/* Mobile M (375px - 425px) */
/* Mobile L (425px - 768px) */
/* Tablet (768px - 1024px) */
/* Desktop (> 1024px) */

/* ===== BASE MOBILE (< 768px) ===== */
@media (max-width: 767px) {
    /* --- HTML & BODY --- */
    html {
        font-size: 14px; /* Réduit la base */
    }
    
    body {
        padding: 0;
        overflow-x: hidden;
    }
    
    /* --- HEADER MOBILE --- */
    header {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        height: var(--mobile-header-height);
        padding: 0 var(--mobile-padding);
        box-shadow: 0 2px 8px rgba(0,0,0,0.3);
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    header .container.nav {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 0;
    }
    
    header .logo {
        max-width: 120px;
        height: auto;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    header .logo-img {
        max-height: 40px;
    }
    
    header .logo-text {
        font-size: 14px;
    }
    
    /* --- NAVIGATION MOBILE (HAMBURGER) --- */
    /* Définition gérée par responsive-menu.css pour éviter les doublons */
    /*
    .header-menu {
        position: fixed;
        top: var(--mobile-header-height);
        right: -100%;
        width: 90%;
        max-width: 320px;
        height: calc(100vh - var(--mobile-header-height));
        background: var(--bg-dark, #1a1a2e);
        transition: right 0.3s ease;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        z-index: 999;
        box-shadow: -2px 0 12px rgba(0,0,0,0.5);
        display: flex !important;
        flex-direction: column;
        padding: 5px 0 80px 0;
        gap: 0;
    }
    */
    
    .header-menu.mobile-open {
        right: 0;
    }
    
    .header-menu > * {
        width: 100%;
        padding: 14px 20px;
        margin: 0 !important;
        border-bottom: 1px solid rgba(255,255,255,0.08);
        justify-content: flex-start !important;
        flex-shrink: 0;
    }
    
    /* Cacher les éléments non-essentiels dans le menu */
    .header-menu > span:first-child {
        display: none; /* Masque "Bienvenue, username" */
    }
    
    .header-menu .btn {
        width: 100%;
        text-align: left;
        border-radius: 0;
        background: transparent;
        margin: 0;
        padding: 14px 20px;
        transition: background 0.2s ease;
    }
    
    .header-menu .btn:hover,
    .header-menu .btn:active {
        background: rgba(139, 92, 246, 0.1);
    }
    
    .header-menu .nav-dropdown {
        width: 100%;
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
    }
    
    .header-menu .nav-dropdown-trigger {
        width: 100%;
        padding: 14px 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
        transition: background 0.2s ease;
    }
    
    /* --- DROPDOWNS MOBILES --- */
    /* Géré par responsive-menu.css pour éviter les doublons */
    
    .header-menu .avatar-btn {
        padding: 12px 20px;
        display: flex;
        align-items: center;
        gap: 12px;
    }
    
    .header-menu .avatar-btn img {
        display: none; /* Masquer l'image avatar sur mobile */
    }
    
    .header-menu .avatar-btn::before {
        content: 'Mon profil';
        color: white;
    }
    
    /* Bouton hamburger */
    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: var(--touch-target-size);
        height: var(--touch-target-size);
        background: none;
        border: none;
        color: var(--text-light, #fff);
        cursor: pointer;
        padding: 0;
        position: relative;
        z-index: 1001;
        flex-shrink: 0;
    }
    
    .mobile-menu-toggle span {
        display: block;
        width: 24px;
        height: 2px;
        background: currentColor;
        position: relative;
        transition: all 0.3s ease;
    }
    
    .mobile-menu-toggle.active span {
        background: transparent;
    }
    
    /* Overlay menu */
    .mobile-menu-overlay {
        position: fixed;
        top: var(--mobile-header-height);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.7);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        z-index: 998;
    }
    
    .mobile-menu-overlay.active {
        opacity: 1;
        pointer-events: all;
    }
    
    /* --- MAIN CONTENT --- */
    main {
        margin-top: var(--mobile-header-height);
        padding: var(--mobile-padding);
        width: 100%;
    }
    
    .container {
        padding: 0;
        max-width: 100%;
    }
    
    /* --- CARDS & GRIDS --- */
    .card {
        margin-bottom: 16px;
        padding: 16px;
        border-radius: 8px;
    }
    
    .grid,
    .equipment-grid,
    .builds-grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }
    
    /* Grilles 2 colonnes pour petits items */
    .small-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }
    
    /* --- FORMS --- */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        width: 100%;
        min-height: var(--touch-target-size);
        font-size: 16px; /* Évite le zoom automatique sur iOS */
        padding: 12px;
        border-radius: 6px;
    }
    
    button,
    .btn {
        min-height: var(--touch-target-size);
        padding: 12px 20px;
        font-size: 16px;
        width: 100%;
        margin-bottom: 12px;
    }
    
    .btn-group {
        flex-direction: column;
        gap: 12px;
    }
    
    .btn-group button,
    .btn-group .btn {
        width: 100%;
    }
    
    /* --- TABLES --- */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    
    table thead {
        display: none; /* Masquer l'en-tête sur mobile */
    }
    
    table tr {
        display: flex;
        flex-direction: column;
        margin-bottom: 16px;
        border: 1px solid rgba(255,255,255,0.1);
        border-radius: 8px;
        padding: 12px;
    }
    
    table td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border: none;
    }
    
    table td::before {
        content: attr(data-label);
        font-weight: bold;
        margin-right: 12px;
    }
    
    /* --- MODALS --- */
    .modal-content,
    #fm-modal-content {
        width: 95vw;
        max-width: 95vw;
        max-height: 85vh;
        margin: 8vh auto;
        padding: 16px;
        overflow-y: auto;
    }
    
    .modal-header {
        padding: 12px;
        font-size: 18px;
    }
    
    .modal-close {
        width: var(--touch-target-size);
        height: var(--touch-target-size);
    }
    
    /* --- EQUIPMENT BUILDER --- */
    .equipment-preview {
        flex-direction: column;
    }
    
    .equipment-slots {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px;
    }
    
    .slot-item {
        width: 100%;
        aspect-ratio: 1;
    }
    
    .stats-panel {
        width: 100%;
        margin-top: 20px;
    }
    
    /* --- SEARCH & FILTERS --- */
    .search-bar {
        flex-direction: column;
        gap: 12px;
    }
    
    .search-bar input {
        width: 100%;
    }
    
    .filter-buttons {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    /* --- FORUM --- */
    .forum-topic,
    .forum-post {
        padding: 12px;
    }
    
    .forum-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .forum-reactions {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    /* --- NEWS & ARTICLES --- */
    .news-grid,
    .articles-grid {
        grid-template-columns: 1fr !important;
    }
    
    .news-card,
    .article-card {
        margin-bottom: 16px;
    }
    
    /* --- IMAGES --- */
    img {
        max-width: 100%;
        height: auto;
    }
    
    .avatar {
        max-width: 48px;
        max-height: 48px;
    }
    
    /* --- FOOTER --- */
    footer {
        padding: 24px var(--mobile-padding);
        text-align: center;
    }
    
    footer .footer-content {
        flex-direction: column;
        gap: 16px;
    }
    
    /* --- BADGES & LABELS --- */
    .badge,
    .label {
        font-size: 12px;
        padding: 4px 8px;
    }
    
    /* --- ALIGNEMENT --- */
    .alignment-badge {
        font-size: 14px;
        padding: 6px 12px;
    }
    
    /* --- DISCORD & LIVE --- */
    .stream-embed,
    .discord-widget {
        width: 100%;
        height: 300px;
    }
    
    /* --- ADMIN PANEL --- */
    .admin-nav {
        flex-direction: column;
    }
    
    .admin-stats {
        grid-template-columns: 1fr !important;
    }
}

/* ===== TABLET (768px - 1024px) ===== */
@media (min-width: 768px) and (max-width: 1024px) {
    .grid,
    .builds-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .equipment-slots {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .news-grid,
    .articles-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .admin-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===== SMALL MOBILE (< 375px) ===== */
@media (max-width: 374px) {
    html {
        font-size: 13px;
    }
    
    .equipment-slots {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .filter-buttons {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        width: 98vw;
        padding: 12px;
    }
}

/* ===== LANDSCAPE MODE (MOBILE) ===== */
@media (max-height: 500px) and (orientation: landscape) {
    .modal-content {
        max-height: 90vh;
        margin: 5vh auto;
    }
    
    nav {
        height: calc(100vh - 50px);
    }
}

/* ===== TOUCH IMPROVEMENTS ===== */
@media (hover: none) and (pointer: coarse) {
    /* Amélioration des zones de touch */
    a, button, .btn, .clickable {
        min-height: var(--touch-target-size);
        min-width: var(--touch-target-size);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Désactiver hover sur touch */
    *:hover {
        transition: none;
    }
    
    /* Feedback tactile */
    button:active,
    .btn:active,
    a:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
}

/* ===== ACCESSIBILITÉ ===== */
/* Préférence réduite de mouvement */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Mode sombre */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-dark: #0f0f1e;
        --bg-light: #1a1a2e;
        --text-light: #e0e0e0;
    }
}

/* ===== UTILITIES MOBILE ===== */
.hide-mobile {
    display: none !important;
}

.show-mobile {
    display: none !important;
}

@media (max-width: 767px) {
    .hide-mobile {
        display: none !important;
    }
    
    .show-mobile {
        display: block !important;
    }
    
    button.show-mobile,
    .mobile-menu-toggle.show-mobile {
        display: flex !important;
    }
}

@media (min-width: 768px) {
    .hide-mobile {
        display: block !important;
    }
    
    .show-mobile {
        display: none !important;
    }
}

/* Scroll amélioré */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Safe areas pour iPhone X+ */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
    
    header {
        padding-top: max(var(--mobile-padding), env(safe-area-inset-top));
    }
}
