/* ========================================
   RESPONSIVE CSS - Mobile Compatibility
   ======================================== */

/* Général - Base responsive */
* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Tables scrollables */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    min-width: 600px;
    width: 100%;
}

/* Toggle Menu Mobile */
.menu-toggle {
    display: none;
    position: fixed;
    top: 10px;
    right: 15px;
    z-index: 1001;
    background: #007bff;
    border: none;
    color: white;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
}

.menu-toggle:active {
    background: #0056b3;
}

.navbar {
    transition: all 0.3s ease;
}

.navbar.mobile-hidden {
    display: none !important;
}

/* ========================================
   TABLETS - Max 1024px
   ======================================== */
@media (max-width: 1024px) {
    .container {
        flex-direction: column;
        gap: 20px;
        padding: 15px;
    }
    
    .left-column {
        flex: 1;
    }
    
    .right-column {
        flex: 1;
    }
    
    .stat-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========================================
   MOBILE - Max 768px
   ======================================== */
@media (max-width: 768px) {
    /* Header et conteneurs */
    .menu-toggle {
        display: block !important;
    }
    
    .container {
        flex-direction: column;
        gap: 0;
        padding: 10px;
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
    
    .left-column,
    .right-column {
        flex: 1;
        width: 100%;
    }
    
    .right-column {
        margin-top: 20px;
    }
    
    /* Welcome box adaptée */
    .welcome-box {
        flex-direction: column;
        padding: 15px;
        gap: 15px;
    }
    
    .logo img {
        max-width: 150px;
    }
    
    /* Navbar */
    .navbar {
        margin-top: 50px; /* Espace pour le bouton fixed */
    }
    
    .navbar ul {
        flex-direction: column;
    }
    
    .navbar li {
        width: 100%;
    }
    
    .navbar a {
        display: block;
        padding: 12px 15px !important;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    
    /* Grids en colonne unique */
    .stats-grid,
    .stat-container,
    .info-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }
    
    /* Boxes de classement - 2 colonnes sur mobile */
    .boxes-container {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }
    
    .boxes-container > div,
    .winner-box {
        flex: none !important;
        display: block !important;
    }
    
    /* Stat boxes */
    .stat-box,
    .stat-card {
        margin-bottom: 10px;
        padding: 12px !important;
    }
    
    /* Boutons pleine largeur */
    button,
    .button,
    input[type="submit"],
    input[type="button"] {
        width: 100%;
        padding: 12px 15px !important;
        font-size: 1em;
        margin-bottom: 10px;
        min-height: 44px;
        border-radius: 4px;
    }
    
    button + button,
    .button + .button {
        margin-left: 0 !important;
        margin-top: 10px;
    }
    
    /* Formulaires */
    input,
    select,
    textarea {
        font-size: 16px !important; /* Évite le zoom auto sur iOS */
        width: 100%;
        padding: 10px 12px !important;
        min-height: 44px;
        border-radius: 4px;
        margin: 8px 0 !important;
    }
    
    form > div,
    .form-group {
        margin-bottom: 15px;
    }
    
    form label {
        display: block;
        margin-bottom: 5px;
        font-weight: bold;
    }
    
    /* Tableaux */
    table {
        font-size: 0.85em;
        min-width: 100%;
    }
    
    table th,
    table td {
        padding: 10px 5px;
    }
    
    /* Responsive table - stack on mobile */
    table.responsive-table {
        display: block;
    }
    
    table.responsive-table thead {
        display: none;
    }
    
    table.responsive-table tbody,
    table.responsive-table tr,
    table.responsive-table td {
        display: block;
        width: 100%;
    }
    
    table.responsive-table tr {
        margin-bottom: 15px;
        border: 1px solid #ddd;
        border-radius: 4px;
        overflow: hidden;
    }
    
    table.responsive-table td {
        padding: 10px;
        border-bottom: 1px solid #eee;
    }
    
    table.responsive-table td:before {
        content: attr(data-label);
        display: block;
        font-weight: bold;
        color: #007bff;
    }
    
    /* Cacher colonnes moins importantes sur mobile */
    .hide-mobile {
        display: none !important;
    }
    
    /* Navigation */
    nav {
        flex-direction: column;
    }
    
    nav a {
        display: block;
        padding: 12px 15px;
        text-align: center;
        border-bottom: 1px solid #ddd;
    }
    
    /* Sidebar */
    .sidebar,
    .right-column {
        width: 100%;
        position: relative;
        margin-top: 20px;
    }
    
    /* Titres */
    h1 {
        font-size: 1.8em;
        margin: 15px 0 10px 0;
    }
    
    h2 {
        font-size: 1.5em;
        margin: 12px 0 8px 0;
    }
    
    h3 {
        font-size: 1.3em;
        margin: 10px 0 6px 0;
    }
    
    h4 {
        font-size: 1.1em;
    }
    
    /* Espacements */
    section,
    .section {
        margin-bottom: 20px;
        padding: 0;
    }
    
    /* Flex containers */
    .flex-container,
    .flex {
        flex-direction: column;
        gap: 10px;
    }
    
    /* Info sections */
    .info-section {
        padding: 15px;
    }
    
    /* Badges et tags */
    .badge,
    .tag {
        font-size: 0.9em;
        padding: 5px 10px;
        display: inline-block;
        margin: 2px;
    }
    
    /* Modal sur mobile */
    .modal-content {
        width: 95%;
        margin: 20% auto;
        padding: 15px;
        border-radius: 8px;
    }
    
    .modal {
        overflow-y: auto;
    }
    
    /* Admin sections */
    .table-container h2 {
        font-size: 1.3em;
    }
    
    .admin-panel {
        margin: 10px 0;
    }
    
    /* Grids spécifiques */
    div[style*="grid-template-columns"] {
        display: block !important;
    }
    
    div[style*="display: grid"] > div {
        margin-bottom: 10px;
    }
    
    /* Tournois cards */
    .tournoi-card,
    .tournoi-item {
        padding: 12px;
        margin-bottom: 10px;
    }
    
    /* Stats display */
    .value {
        font-size: 1.8em;
    }
    
    /* Box styling */
    .auth-box,
    .inscription-box,
    .tournois-box,
    .box {
        padding: 15px !important;
        margin-bottom: 15px;
        border-radius: 4px;
    }
    
    /* Links */
    a {
        word-break: break-word;
    }
    
    /* Padding and margins adjustment */
    body {
        padding: 10px;
    }
}

/* ========================================
   SMALL MOBILE - Max 480px
   ======================================== */
@media (max-width: 480px) {
    body {
        font-size: 14px;
        padding: 5px;
    }
    
    .container {
        padding: 5px;
        gap: 0;
    }
    
    .menu-toggle {
        padding: 8px 12px;
        font-size: 16px;
    }
    
    h1 {
        font-size: 1.5em;
        margin: 10px 0 8px 0;
    }
    
    h2 {
        font-size: 1.3em;
        margin: 10px 0 6px 0;
    }
    
    h3 {
        font-size: 1.1em;
    }
    
    /* Maintenir les boxes en 2 colonnes sur petit mobile */
    .boxes-container {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    
    .boxes-container > div,
    .winner-box {
        flex: none !important;
        display: block !important;
    }
    
    .winner-box h2 {
        font-size: 0.95em;
        padding-bottom: 8px;
    }
    
    table {
        font-size: 0.75em;
    }
    
    table th,
    table td {
        padding: 6px 3px;
    }
    
    button,
    .button,
    input[type="submit"],
    input[type="button"] {
        padding: 10px 12px !important;
        font-size: 0.95em;
    }
    
    input,
    select,
    textarea {
        font-size: 16px !important;
        padding: 8px 10px !important;
        min-height: 40px;
    }
    
    .stat-box,
    .stat-card {
        padding: 8px !important;
    }
    
    /* Réduire les marges */
    section,
    .section {
        margin-bottom: 15px;
    }
    
    .auth-box,
    .inscription-box,
    .tournois-box,
    .box {
        padding: 12px !important;
        margin-bottom: 12px;
    }
    
    /* Logo smaller */
    .welcome-box .logo img {
        max-width: 120px;
    }
    
    /* Modal smaller on tiny screens */
    .modal-content {
        margin: 30% auto;
        padding: 12px;
    }
    
    /* Tighter nav */
    .navbar a {
        padding: 10px 12px !important;
        font-size: 0.9em;
    }
    
    /* Reduced gap for touch buttons */
    button + button {
        margin-top: 8px;
    }
    
    .value {
        font-size: 1.5em;
    }
}

/* ========================================
   EXTRA SMALL MOBILE - Max 360px
   ======================================== */
@media (max-width: 360px) {
    body {
        font-size: 13px;
        padding: 3px;
    }
    
    h1 {
        font-size: 1.3em;
    }
    
    h2 {
        font-size: 1.1em;
    }
    
    h3 {
        font-size: 1em;
    }
    
    button,
    .button,
    input[type="submit"] {
        padding: 8px 10px !important;
        font-size: 0.9em;
    }
}

/* ========================================
   TOUCH DEVICES - Amélioration tactile
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* Taille minimale pour les éléments cliquables */
    button,
    a,
    input[type="submit"],
    input[type="button"],
    select,
    .btn,
    .button {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Espacement entre éléments cliquables */
    button + button,
    a + a,
    .button + .button {
        margin-left: 8px;
    }
    
    /* Feedback tactile */
    button:active,
    a:active,
    .button:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
    
    /* Meilleur contraste au toucher */
    input:focus,
    select:focus,
    textarea:focus {
        outline: 2px solid #007bff;
        outline-offset: 2px;
    }
    
    /* Prévenir selection de texte sur toucher prolongé */
    button,
    a,
    .button {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ========================================
   LANDSCAPE MODE - Mode paysage mobile
   ======================================== */
@media (max-width: 768px) and (orientation: landscape) {
    .stat-container {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* ========================================
   PRINT - Mode impression
   ======================================== */
@media print {
    .sidebar,
    button,
    nav,
    .no-print {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
    }
    
    table {
        page-break-inside: avoid;
    }
}
