/**
 * Responsive CSS - Centre de Contrôle PWA
 * Optimisations pour mobile et tablettes
 */

/* ============================================================================
   VARIABLES RESPONSIVE
   ========================================================================= */
:root {
    --mobile-padding: 16px;
    --tablet-padding: 24px;
    --desktop-padding: 32px;

    --mobile-font-size: 14px;
    --tablet-font-size: 15px;
    --desktop-font-size: 16px;

    --touch-target-min: 44px; /* WCAG recommandation */
}

/* ============================================================================
   MOBILE FIRST (< 768px)
   ========================================================================= */

/* Améliorer les tap targets pour mobile */
@media (max-width: 768px) {
    /* Touch-friendly buttons */
    button, .btn, a.btn {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
        padding: 12px 20px;
        font-size: 15px;
    }

    /* Navigation responsive */
    .nav-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
    }

    .nav-container::-webkit-scrollbar {
        display: none; /* Chrome, Safari */
    }

    .nav-bar {
        flex-wrap: nowrap;
        gap: 8px;
        padding: 12px;
    }

    .nav-btn {
        white-space: nowrap;
        padding: 10px 16px;
        font-size: 14px;
        flex-shrink: 0;
    }

    /* Header responsive */
    .header {
        padding: 12px var(--mobile-padding);
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    /* Container padding */
    .container {
        padding: var(--mobile-padding);
    }

    /* Cards responsive */
    .card {
        padding: 16px;
        margin-bottom: 16px;
    }

    /* Grid responsive */
    .grid-auto,
    .grid-two,
    .grid-three {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* Stack spacing */
    .stack {
        gap: 16px;
    }

    /* Layout split devient vertical sur mobile */
    .layout-split {
        flex-direction: column;
        gap: 16px;
    }

    /* Typography responsive */
    h1 {
        font-size: 24px;
    }

    h2 {
        font-size: 20px;
    }

    h3 {
        font-size: 18px;
    }

    p, span, div {
        font-size: var(--mobile-font-size);
    }

    /* Stats cards responsive */
    .stat-card {
        padding: 16px;
    }

    .stat-value {
        font-size: 24px;
    }

    /* Charts responsive */
    .charts-grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    .chart-container {
        height: 250px;
    }

    /* Tables responsive */
    table {
        font-size: 13px;
    }

    th, td {
        padding: 8px;
    }

    /* Formulaires responsive */
    input, select, textarea {
        font-size: 16px; /* Évite le zoom automatique sur iOS */
        padding: 12px;
    }

    /* Modal responsive */
    .modal-content {
        width: 95%;
        max-width: 100%;
        margin: 10px;
        padding: 20px;
    }

    /* Dashboard actions responsive */
    .action-buttons {
        flex-direction: column;
        width: 100%;
    }

    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }

    /* Stats grid responsive */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* Page header responsive */
    .page-header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
        padding: 16px;
    }

    .page-title {
        font-size: 22px;
    }
}

/* ============================================================================
   TABLETTE (768px - 1024px)
   ========================================================================= */

@media (min-width: 768px) and (max-width: 1024px) {
    .container {
        padding: var(--tablet-padding);
    }

    /* Grid 2 colonnes sur tablette */
    .grid-three {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Typography tablette */
    body {
        font-size: var(--tablet-font-size);
    }

    h1 {
        font-size: 28px;
    }

    h2 {
        font-size: 22px;
    }
}

/* ============================================================================
   DESKTOP (> 1024px)
   ========================================================================= */

@media (min-width: 1024px) {
    .container {
        padding: var(--desktop-padding);
        max-width: 1400px;
        margin: 0 auto;
    }

    /* Grid complète sur desktop */
    .grid-three {
        grid-template-columns: repeat(3, 1fr);
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    body {
        font-size: var(--desktop-font-size);
    }
}

/* ============================================================================
   ORIENTATION LANDSCAPE MOBILE
   ========================================================================= */

@media (max-width: 768px) and (orientation: landscape) {
    .header {
        padding: 8px var(--mobile-padding);
    }

    .nav-bar {
        padding: 8px;
    }

    .chart-container {
        height: 200px;
    }

    /* Réduire les marges en mode paysage */
    .container {
        padding: 12px;
    }

    .card {
        padding: 12px;
        margin-bottom: 12px;
    }
}

/* ============================================================================
   DARK MODE (si supporté par le navigateur)
   ========================================================================= */

@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #1a1a1a;
        --text-color: #ffffff;
        --card-background: #2a2a2a;
    }

    body {
        background-color: var(--background-color);
        color: var(--text-color);
    }

    .card {
        background-color: var(--card-background);
    }

    .btn {
        background-color: #444;
        color: white;
    }
}

/* ============================================================================
   REDUCED MOTION (accessibilité)
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================================================
   PRINT (impression)
   ========================================================================= */

@media print {
    /* Masquer navigation et actions */
    .nav-container,
    .action-buttons,
    button,
    .btn {
        display: none !important;
    }

    /* Optimiser pour impression */
    body {
        font-size: 12pt;
        color: black;
        background: white;
    }

    .card {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    /* Afficher les URLs des liens */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        color: #666;
    }
}

/* ============================================================================
   HIGH CONTRAST (accessibilité)
   ========================================================================= */

@media (prefers-contrast: high) {
    button, .btn {
        border: 2px solid currentColor;
    }

    .card {
        border: 1px solid currentColor;
    }
}

/* ============================================================================
   OPTIMISATIONS PERFORMANCE MOBILE
   ========================================================================= */

/* Améliorer le scrolling sur iOS */
* {
    -webkit-overflow-scrolling: touch;
}

/* Désactiver le tap highlight sur iOS */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Améliorer le rendu des polices */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Améliorer les performances des animations */
.card,
.btn,
button {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ============================================================================
   SAFE AREAS (iPhone X+ avec notch)
   ========================================================================= */

@supports (padding: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .nav-container {
        padding-left: calc(env(safe-area-inset-left) + 12px);
        padding-right: calc(env(safe-area-inset-right) + 12px);
    }
}

/* ============================================================================
   PWA STANDALONE MODE
   ========================================================================= */

@media (display-mode: standalone) {
    /* Styles spécifiques quand l'app est installée */
    body {
        user-select: none; /* Éviter la sélection accidentelle */
    }

    /* Ajouter un indicateur visuel */
    body::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 2px;
        background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
        z-index: 9999;
    }
}

/* ============================================================================
   UTILITIES RESPONSIVE
   ========================================================================= */

/* Masquer sur mobile */
.hide-mobile {
    display: none !important;
}

@media (min-width: 768px) {
    .hide-mobile {
        display: block !important;
    }
}

/* Afficher uniquement sur mobile */
.show-mobile {
    display: block !important;
}

@media (min-width: 768px) {
    .show-mobile {
        display: none !important;
    }
}

/* Centrer sur mobile */
@media (max-width: 768px) {
    .center-mobile {
        text-align: center !important;
        justify-content: center !important;
    }
}

/* Full width sur mobile */
@media (max-width: 768px) {
    .full-width-mobile {
        width: 100% !important;
    }
}
