/* ========================================
   RESPONSIVE & ACCESSIBILITÉ - PHASE 4
   Breakpoints mobile-first avec accessibilité
   ======================================== */

/* ===== BREAKPOINTS ===== */
/* Mobile: < 576px (default) */
/* Tablet: 576px - 768px */
/* Desktop: 768px - 1200px */
/* Large: > 1200px */

/* ===== ACCESSIBILITÉ - PRÉFÉRENCES UTILISATEUR ===== */

/* Respect des préférences reduced-motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Amélioration du contraste en mode high-contrast */
@media (prefers-contrast: high) {
    :root {
        --box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    }

    input:focus,
    select:focus,
    textarea:focus,
    button:focus {
        outline: 3px solid var(--secondary-color);
        outline-offset: 2px;
    }
}

/* ===== FOCUS STATES - ACCESSIBILITÉ CLAVIER ===== */

/* Focus visible pour tous les éléments interactifs */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-tab:focus-visible,
.auth-tab:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.2);
}

/* Focus pour les boutons de fermeture */
.close:focus-visible {
    outline: 2px solid var(--danger-color);
    outline-offset: 2px;
}

/* Skip to main content link (pour lecteurs d'écran) */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--secondary-color);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    border-radius: 0 0 4px 0;
}

.skip-to-main:focus {
    top: 0;
}

/* ===== MOBILE FIRST - BASE (< 576px) ===== */

/* Ajustements pour très petits écrans */
@media (max-width: 375px) {
    body {
        font-size: 14px;
    }

    .auth-card {
        padding: 1.5rem;
        margin: 10px;
    }

    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .nav-tab {
        padding: 0.6rem 0.8rem;
        font-size: 0.85rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.1rem; }
}

/* Tables responsive sur mobile */
@media (max-width: 576px) {
    .table-container {
        border-radius: var(--border-radius);
        box-shadow: var(--box-shadow);
    }

    /* Transformation des tables en cartes sur mobile */
    table.mobile-card-view {
        border: 0;
    }

    table.mobile-card-view thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    table.mobile-card-view tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #ddd;
        border-radius: var(--border-radius);
        background: white;
    }

    [data-theme="dark"] table.mobile-card-view tr {
        background: var(--light-color);
        border-color: var(--border-color);
    }

    table.mobile-card-view td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem;
        border-bottom: 1px solid #eee;
        text-align: right;
    }

    [data-theme="dark"] table.mobile-card-view td {
        border-bottom-color: var(--border-color);
    }

    table.mobile-card-view td:last-child {
        border-bottom: 0;
    }

    table.mobile-card-view td::before {
        content: attr(data-label);
        font-weight: 600;
        text-align: left;
        margin-right: 1rem;
        flex: 1;
    }

    /* Actions buttons en colonne sur mobile */
    .invoice-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .invoice-actions .btn {
        width: 100%;
    }

    /* Modals en plein écran sur mobile */
    .modal-content {
        width: 95%;
        max-height: 95vh;
        margin: 10px;
    }

    /* Search filters en colonne */
    .search-row {
        flex-direction: column;
        gap: 1rem;
    }

    .search-group {
        width: 100%;
        min-width: 100%;
    }

    /* Date navigation vertical */
    .date-nav {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .date-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* ===== TABLET (576px - 768px) ===== */

@media (min-width: 576px) {
    .auth-card {
        max-width: 500px;
    }

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

    .modal-content {
        max-width: 540px;
    }

    /* Amélioration des colonnes */
    .col {
        min-width: 250px;
    }

    .col-2 {
        flex: 0 0 50%;
    }
}

@media (min-width: 768px) {
    /* Header reste en ligne */
    .header-content {
        flex-direction: row;
    }

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

    /* Tables normales sur desktop */
    table.mobile-card-view thead {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        overflow: visible;
        clip: auto;
        white-space: normal;
    }

    table.mobile-card-view tr {
        display: table-row;
        margin-bottom: 0;
        border: 0;
    }

    table.mobile-card-view td {
        display: table-cell;
        justify-content: flex-start;
        text-align: left;
        border-bottom: 1px solid #eee;
    }

    table.mobile-card-view td::before {
        content: none;
    }

    /* Date nav en ligne */
    .date-nav {
        flex-direction: row;
        justify-content: space-between;
    }

    /* Search filters en ligne */
    .search-row {
        flex-direction: row;
    }

    .search-group {
        width: auto;
        min-width: 200px;
    }

    /* Invoice actions en ligne */
    .invoice-actions {
        flex-direction: row;
    }

    .invoice-actions .btn {
        width: auto;
    }
}

/* ===== DESKTOP (768px - 1200px) ===== */

@media (min-width: 992px) {
    .container {
        max-width: 1140px;
    }

    .modal-content {
        max-width: 600px;
    }

    /* 3 colonnes pour settings sur grand écran */
    .settings-grid.three-col {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }

    /* Navigation tabs avec plus d'espace */
    .nav-tab {
        padding: 0.75rem 2rem;
    }
}

/* ===== LARGE DESKTOP (> 1200px) ===== */

@media (min-width: 1200px) {
    .container {
        max-width: 1200px;
    }

    .modal-content {
        max-width: 700px;
    }

    /* Stats avec plus de détails */
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 1.5rem;
    }

    /* Trois colonnes pour settings */
    .settings-grid.three-col {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1400px) {
    .container {
        max-width: 1320px;
        padding: 30px;
    }

    /* Plus d'espace pour les cartes */
    .card {
        padding: 2rem;
    }

    /* Stats plus grandes */
    .stat-value {
        font-size: 2.5rem;
    }
}

/* ===== ORIENTATION LANDSCAPE (Mobile) ===== */

@media (max-width: 768px) and (orientation: landscape) {
    .auth-container {
        padding: 1rem 0;
    }

    .auth-card {
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-content {
        max-height: 85vh;
    }
}

/* ===== PRINT STYLES ===== */

@media print {
    /* Masquer les éléments non nécessaires */
    header,
    footer,
    .nav-container,
    .btn,
    .modal,
    .export-buttons,
    .user-info {
        display: none !important;
    }

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

    .card,
    .stat-card,
    table {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }

    /* Tables sans overflow */
    .table-container {
        overflow: visible;
    }

    /* Couleurs pour impression */
    .stat-income { border-left-color: #000; }
    .stat-expense { border-left-color: #000; }
    .stat-balance { border-left-color: #000; }

    /* Conserve les liens */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* ===== ACCESSIBILITÉ - HIGH CONTRAST MODE ===== */

@media (forced-colors: active) {
    .btn,
    .nav-tab,
    .auth-tab {
        border: 2px solid currentColor;
    }

    input:focus,
    select:focus,
    textarea:focus {
        outline: 2px solid currentColor;
    }
}

/* ===== TOUCH TARGETS - Amélioration tactile ===== */

@media (pointer: coarse) {
    /* Augmenter la taille des zones tactiles sur mobile */
    .btn,
    .nav-tab,
    .auth-tab,
    button,
    a {
        min-height: 44px;
        min-width: 44px;
        padding: 0.75rem 1rem;
    }

    input,
    select,
    textarea {
        min-height: 44px;
        padding: 0.75rem;
    }

    .close {
        min-width: 44px;
        min-height: 44px;
    }

    /* Plus d'espace entre les boutons d'action */
    .invoice-actions {
        gap: 0.75rem;
    }
}

/* ===== DARK MODE - Améliorations responsive ===== */

@media (prefers-color-scheme: dark) {
    /* Auto dark mode si non défini par l'utilisateur */
    body:not([data-theme]) {
        --primary-color: #1a252f;
        --background-color: #1a1a1a;
        --text-color: #ecf0f1;
        background-color: var(--background-color);
        color: var(--text-color);
    }
}

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

/* Hide/Show selon breakpoints */
.hide-mobile {
    display: none;
}

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

    .hide-desktop {
        display: none;
    }
}

/* Text alignment responsive */
.text-center-mobile {
    text-align: center;
}

@media (min-width: 768px) {
    .text-center-mobile {
        text-align: left;
    }
}

/* Stack columns sur mobile */
.stack-mobile {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@media (min-width: 768px) {
    .stack-mobile {
        flex-direction: row;
    }
}
