/* ===== RESPONSIVE.CSS ===== */
/* Styles responsive dédiés pour l'application de gestion financière */

/* ===== VARIABLES RESPONSIVE ===== */
:root {
    --mobile-padding: 12px;
    --tablet-padding: 20px;
    --desktop-padding: 30px;
    --mobile-font-size: 15px; /* Augmenté de 14px à 15px */
    --tablet-font-size: 15px;
    --desktop-font-size: 16px;
    --mobile-touch-target: 44px;
    --border-radius-mobile: 8px;
    --spacing-mobile: 16px;
    
    /* Nouvelles variables pour la lisibilité */
    --mobile-text-secondary: #475569; /* Plus sombre que la version desktop */
    --mobile-text-muted: #64748b;
    --mobile-line-height: 1.5;
}

/* ===== BREAKPOINTS ===== */
/* Petits mobiles (0-480px) */
@media (max-width: 480px) {
    .container {
        padding: 8px;
        margin: 0;
        min-width: 300px;
    }
    
    .app-header h1 {
        font-size: 18px; /* Augmenté de 16px */
        font-weight: 700;
        color: var(--primary-color);
        line-height: 1.2;
    }
    
    .btn {
        font-size: 14px; /* Augmenté de 13px */
        padding: 10px 14px; /* Padding amélioré */
        min-width: auto;
        min-height: var(--mobile-touch-target);
        font-weight: 600; /* Renforcement du texte */
    }
    
    .financial-table {
        min-width: 800px;
        font-size: 12px; /* Maintenu mais avec meilleur contraste */
    }
    
    .financial-table th,
    .financial-table td {
        color: var(--text-primary); /* Assure un bon contraste */
        line-height: var(--mobile-line-height);
    }
    
    .settings-header h2 {
        font-size: 18px; /* Augmenté de 16px */
        font-weight: 600;
    }
    
    .chart-item {
        height: 200px;
    }
    
    /* Amélioration des textes secondaires sur très petits écrans */
    .text-secondary,
    .help-text,
    .card-meta {
        color: var(--mobile-text-secondary);
        font-size: 13px; /* Minimum lisible */
        line-height: 1.4;
    }
}

/* Mobile standard (481px-768px) */
@media (min-width: 481px) and (max-width: 768px) {
    /* Layout principal */
    .container {
        padding: var(--mobile-padding);
        margin: 0;
        min-width: 320px;
    }
    
    /* En-tête responsive */
    .app-header h1 {
        font-size: 20px; /* Augmenté de 18px */
        text-align: center;
        margin-bottom: 15px;
        word-break: break-word;
        font-weight: 700;
        line-height: 1.2;
    }
    
    .header-controls {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }
    
    .year-controls, 
    .action-controls, 
    .export-controls {
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    /* Boutons responsive */
    .btn {
        font-size: var(--mobile-font-size); /* 15px */
        padding: 12px 16px; /* Padding amélioré */
        min-width: auto;
        min-height: 44px;
        white-space: nowrap;
        font-weight: 600;
        line-height: 1.2;
    }
    
    .btn-small {
        padding: 8px 12px; /* Amélioré */
        font-size: 13px; /* Plus lisible */
        min-height: 36px;
    }
    
    /* Table responsive */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -10px;
        padding: 0 10px;
    }
    
    .financial-table {
        min-width: 900px;
        font-size: 13px; /* Augmenté de 11px */
    }
    
    .financial-table th,
    .financial-table td {
        padding: 10px 8px; /* Padding amélioré */
        white-space: nowrap;
        color: var(--text-primary);
        line-height: 1.3;
    }
    
    .financial-table input {
        width: 80px; /* Augmenté de 70px */
        font-size: 13px; /* Augmenté de 12px */
        padding: 8px; /* Padding amélioré */
        min-height: 36px; /* Touch-friendly */
    }
    
    .action-btn {
        padding: 6px 8px; /* Amélioré */
        font-size: 12px; /* Augmenté de 10px */
        margin: 0 1px;
        min-height: 32px; /* Touch-friendly */
        min-width: 32px;
        font-weight: 500;
    }
    
    /* Graphiques responsive */
    .charts-container {
        display: flex;
        flex-direction: column;
        gap: 15px;
    }
    
    .chart-item {
        height: 250px;
        margin-bottom: 10px;
    }
    
    /* Modals responsive */
    .custom-modal .modal-content {
        width: 95% !important;
        height: 90vh !important;
        max-height: 90vh !important;
        margin: 5vh auto !important;
        overflow-y: auto;
    }
    
    .modal-header {
        padding: 12px 15px !important;
        flex-wrap: wrap;
    }
    
    .modal-header h2 {
        font-size: 16px !important;
        margin-right: auto;
    }
    
    .modal-body {
        padding: 15px !important;
        font-size: 14px;
        line-height: 1.4;
    }
    
    .modal-footer {
        padding: 10px 15px !important;
        flex-direction: column;
        gap: 8px;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
    
    /* Paramètres responsive */
    .settings-panel {
        padding: 10px;
    }
    
    .settings-content {
        width: 95%;
        max-height: 85vh;
        margin: 0 auto;
    }
    
    .settings-header h2 {
        font-size: 20px; /* Augmenté de 18px */
        font-weight: 600;
    }
    
    .setting-group {
        margin-bottom: 15px;
    }
    
    .setting-group label {
        font-size: 15px; /* Augmenté de 14px */
        display: block;
        margin-bottom: 8px;
        font-weight: 500;
        color: var(--text-primary); /* Contraste amélioré */
    }
    
    .setting-group input,
    .setting-group select {
        width: 100%;
        font-size: 16px; /* Évite le zoom iOS */
        padding: 12px;
        border-radius: 6px;
        border: 1px solid #d1d5db;
        min-height: 44px;
        color: var(--text-primary);
    }
    
    /* Notifications responsive */
    .notification {
        right: 10px !important;
        left: 10px !important;
        top: 10px !important;
        max-width: none !important;
        font-size: 15px; /* Augmenté de 14px */
        line-height: 1.4;
        padding: 12px 16px;
    }
    
    /* Raccourcis clavier responsive */
    .keyboard-shortcuts {
        bottom: 10px !important;
        right: 10px !important;
        left: 10px !important;
        font-size: 12px; /* Augmenté de 11px */
        padding: 10px; /* Amélioré */
        text-align: center;
        line-height: 1.4;
    }
    
    /* Alertes responsive */
    .alert {
        font-size: 14px; /* Augmenté de 13px */
        padding: 12px 14px; /* Padding amélioré */
        margin: 8px 0;
        border-radius: 6px;
        line-height: 1.4;
    }
    
    /* Footer responsive */
    footer {
        padding: 15px 10px !important;
        font-size: 12px !important; /* Augmenté de 11px */
        text-align: center;
        line-height: 1.4;
    }
    
    /* Formulaires responsive */
    .year-select {
        width: 100%;
        padding: 10px;
        font-size: 14px;
        min-height: 44px;
    }
    
    /* Grilles responsive */
    .stats-container,
    .comparison-grid,
    .forecast-grid,
    .budget-grid,
    .report-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    
    /* Cards responsive */
    .stats-card,
    .comparison-card,
    .forecast-card,
    .budget-card,
    .report-card {
        padding: 12px !important;
        margin-bottom: 10px;
    }
    
    /* Text responsive */
    .stats-value,
    .comparison-value,
    .forecast-value {
        font-size: 18px !important;
    }
    
    /* Navigation par onglets responsive */
    .stats-tabs,
    .forecast-tabs,
    .budget-tabs {
        flex-wrap: wrap;
        gap: 8px; /* Augmenté de 5px */
    }
    
    .tab-btn {
        padding: 10px 12px !important; /* Amélioré */
        font-size: 13px !important; /* Augmenté de 12px */
        flex: 1;
        min-width: 90px; /* Augmenté de 80px */
        text-align: center;
        font-weight: 500;
        line-height: 1.2;
        color: var(--text-secondary);
    }
    
    .tab-btn.active {
        font-weight: 600;
        color: var(--primary-color);
    }
    
    /* Amélioration des cartes sur mobile */
    .summary-card,
    .stats-card,
    .comparison-card {
        padding: 14px !important; /* Amélioré */
        margin-bottom: 12px;
    }
    
    .card-value,
    .stats-value,
    .comparison-value,
    .forecast-value {
        font-size: 1.3rem !important; /* Plus lisible */
        font-weight: 600;
        line-height: 1.2;
    }
    
    .card-content h3,
    .card-header h5 {
        font-size: 14px; /* Plus lisible */
        font-weight: 500;
        color: var(--text-secondary);
        line-height: 1.3;
    }
    
    .card-meta,
    .card-change {
        font-size: 12px;
        color: var(--mobile-text-muted);
        line-height: 1.3;
    }
}

/* ===== TABLETTE PORTRAIT (769px - 1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: var(--tablet-padding);
        max-width: 100%;
    }
    
    .app-header h1 {
        font-size: 22px;
    }
    
    .header-controls {
        gap: 15px;
        flex-wrap: wrap;
    }
    
    .action-controls {
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 10px;
    }
    
    .btn {
        font-size: var(--tablet-font-size);
        padding: 10px 16px;
        min-height: 42px;
        touch-action: manipulation;
    }
    
    .financial-table {
        font-size: 13px;
    }
    
    .financial-table input {
        width: 90px;
        font-size: 13px;
        min-height: 38px;
    }
    
    /* Amélioration de la disposition pour tablettes */
    .stats-container,
    .comparison-grid,
    .forecast-grid,
    .budget-grid,
    .report-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }
    
    .charts-container {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
    
    .chart-item {
        height: 300px;
    }
    
    .charts-container {
        display: grid;
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .chart-item {
        height: 300px;
    }
    
    .settings-content {
        width: 80%;
        max-width: 600px;
    }
    
    /* Grilles pour tablette */
    .stats-container,
    .comparison-grid,
    .forecast-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }
    
    .budget-grid,
    .report-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
    }
    
    /* Modals pour tablette */
    .custom-modal .modal-content.modal-large {
        width: 90% !important;
        max-width: 800px;
    }
    
    .trend-indicators,
    .budget-categories {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ===== TABLETTE PAYSAGE (1025px - 1280px) ===== */
@media (min-width: 1025px) and (max-width: 1280px) {
    .container {
        padding: calc(var(--tablet-padding) + 4px);
        max-width: 100%;
    }
    
    .btn {
        font-size: var(--tablet-font-size);
    }
    
    .financial-table {
        font-size: 14px;
    }
    
    .stats-container,
    .comparison-grid,
    .forecast-grid,
    .budget-grid,
    .report-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 20px !important;
    }
    
    .charts-container {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 25px;
    }
    
    .chart-item {
        height: 350px;
    }
}

/* ===== DESKTOP (1025px et plus) ===== */
@media (min-width: 1025px) {
    .container {
        max-width: 1400px;
        margin: 0 auto;
        padding: var(--desktop-padding);
    }
    
    .app-header h1 {
        font-size: 28px;
    }
    
    .btn {
        font-size: var(--desktop-font-size);
        padding: 12px 20px;
    }
    
    .financial-table {
        font-size: 15px;
    }
    
    .financial-table input {
        width: 120px;
        font-size: 14px;
    }
    
    .charts-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 30px;
    }
    
    .chart-item {
        height: 350px;
    }
    
    .settings-content {
        width: 60%;
        max-width: 700px;
    }
    
    /* Grilles pour desktop */
    .stats-container {
        grid-template-columns: repeat(4, 1fr) !important;
    }
    
    .comparison-grid,
    .forecast-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    
    .budget-categories,
    .report-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)) !important;
    }
}

/* ===== LARGE DESKTOP (1440px et plus) ===== */
@media (min-width: 1440px) {
    .container {
        max-width: 1600px;
    }
    
    .app-header h1 {
        font-size: 32px;
    }
    
    .financial-table {
        font-size: 16px;
    }
    
    .financial-table input {
        width: 140px;
        font-size: 15px;
    }
    
    .chart-item {
        height: 400px;
    }
    
    .charts-container {
        gap: 40px;
    }
}

/* ===== OPTIMISATIONS TACTILES ===== */
@media (pointer: coarse) {
    /* Optimisations pour les écrans tactiles */
    input, 
    select, 
    button,
    .btn,
    .tab-btn,
    .action-btn {
        touch-action: manipulation;
    }
    
    /* Augmenter la taille des zones tactiles */
    .btn,
    .action-btn,
    button, 
    input[type="button"],
    input[type="submit"],
    select {
        min-height: var(--mobile-touch-target);
        min-width: var(--mobile-touch-target);
        font-size: 15px; /* Plus lisible */
    }
    
    /* Amélioration des contrastes pour le tactile */
    .btn,
    .tab-btn {
        font-weight: 600;
        border: 1px solid transparent;
    }
    
    .btn:active,
    .tab-btn:active {
        transform: scale(0.98);
        filter: brightness(0.95);
    }
}

/* ===== STYLES POUR APPAREILS TACTILES ===== */
.touch-device button,
.touch-device .btn,
.touch-device .action-btn,
.touch-device .tab-btn,
.touch-device select,
.touch-device input[type="button"],
.touch-device input[type="submit"] {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
}

.touch-device input[type="text"],
.touch-device input[type="number"],
.touch-device input[type="email"],
.touch-device input[type="password"],
.touch-device select {
    font-size: 16px; /* Évite le zoom automatique sur iOS */
}

/* Amélioration de l'accessibilité des tableaux défilables */
.table-container {
    position: relative;
}

.scroll-indicator {
    transition: opacity 0.3s ease;
}

.table-container:focus-within .scroll-indicator {
    opacity: 0;
}

/* Visibilité du bouton retour en haut */
.back-to-top-btn {
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.back-to-top-btn:hover,
.back-to-top-btn:focus {
    opacity: 1;
}

/* État active (pressed) pour les éléments tactiles */
.touch-device .btn:active,
.touch-device .action-btn:active,
.touch-device .tab-btn:active {
    transform: translateY(1px);
    filter: brightness(0.95);
}

/* Styles pour l'installation PWA */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 10px 15px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    border-top: 1px solid #e2e8f0;
    animation: slide-up 0.3s ease;
}

.pwa-install-banner .btn-close {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
}

@keyframes slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* Amélioration du feedback visuel sur mobiles */
@media (hover: none) {
    .btn:active, 
    .action-btn:active {
        background-color: var(--primary-hover);
        transform: scale(0.98);
    }
    
    .tab-btn:active {
        background-color: rgba(37, 99, 235, 0.1);
        transform: scale(0.98);
    }
    
    td:active, 
    th:active {
        background-color: rgba(59, 130, 246, 0.05);
    }
    
    /* Amélioration des inputs sur mobile */
    input:focus,
    select:focus,
    textarea:focus {
        border-color: var(--primary-color);
        box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
        outline: none;
    }
}

/* ===== STYLES D'IMPRESSION ===== */
@media print {
    .no-print,
    .action-controls,
    .export-controls,
    .settings-panel,
    .btn:not(.print-only) {
        display: none !important;
    }
    
    .container {
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .financial-table {
        width: 100% !important;
        font-size: 10pt !important;
        border-collapse: collapse !important;
    }
    
    .financial-table th,
    .financial-table td {
        border: 1px solid #000 !important;
    }
    
    @page {
        margin: 1cm;
    }
}

/* ===== 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;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #f1f5f9; /* Plus clair */
        --card-bg: #2d2d2d;
        --border-color: #4b5563;
        --mobile-text-secondary: #cbd5e1; /* Plus clair en mode sombre */
        --mobile-text-muted: #94a3b8;
    }
}

/* ===== ÉCRANS HAUTE RÉSOLUTION ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .financial-table {
        font-weight: 500; /* Plus visible sur haute résolution */
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    .btn {
        font-weight: 600; /* Plus visible */
        -webkit-font-smoothing: antialiased;
    }
    
    .app-header h1 {
        font-weight: 700; /* Plus visible */
        -webkit-font-smoothing: antialiased;
    }
    
    /* Amélioration des textes fins sur haute résolution */
    .text-secondary,
    .help-text,
    .card-meta {
        font-weight: 500;
        -webkit-font-smoothing: antialiased;
    }
}

/* ===== MODES D'AFFICHAGE SPÉCIAUX ===== */
@media (orientation: landscape) and (max-height: 500px) {
    /* Mode paysage sur mobile */
    .modal-content {
        height: 95vh !important;
        max-height: 95vh !important;
    }
    
    .keyboard-shortcuts {
        display: none;
    }
}

@media (max-width: 480px) {
    /* Très petits écrans */
    .app-header h1 {
        font-size: 16px;
    }
    
    .btn {
        font-size: 11px;
        padding: 8px 10px;
    }
    
    .financial-table {
        font-size: 10px;
    }
    
    .chart-item {
        height: 200px;
    }
}

/* ===== FALLBACKS POUR ANCIENS NAVIGATEURS ===== */
@supports not (display: grid) {
    .stats-container,
    .comparison-grid,
    .forecast-grid,
    .budget-grid {
        display: flex;
        flex-wrap: wrap;
        gap: 15px;
    }
    
    .stats-card,
    .comparison-card,
    .forecast-card,
    .budget-card {
        flex: 1;
        min-width: 250px;
    }
}

@supports not (gap: 10px) {
    .header-controls > * {
        margin-right: 10px;
        margin-bottom: 10px;
    }
    
    .action-controls > * {
        margin-right: 8px;
    }
}

/* ===== RESPONSIVE IMAGES ET MEDIA ===== */
img, video, canvas {
    max-width: 100%;
    height: auto;
}

canvas {
    display: block;
}

/* ===== SCROLLBARS PERSONNALISÉES ===== */
@media (min-width: 1025px) {
    .table-container::-webkit-scrollbar {
        height: 8px;
    }
    
    .table-container::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 4px;
    }
    
    .table-container::-webkit-scrollbar-thumb {
        background: #c1c1c1;
        border-radius: 4px;
    }
    
    .table-container::-webkit-scrollbar-thumb:hover {
        background: #a8a8a8;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
.chart-item canvas {
    will-change: transform;
}

.modal-content {
    contain: layout style;
}

.financial-table {
    contain: layout;
}

/* ===== RESPONSIVE UTILITIES ===== */
.mobile-only {
    display: block;
}

.tablet-only,
.desktop-only {
    display: none;
}

@media (min-width: 769px) and (max-width: 1024px) {
    .mobile-only,
    .desktop-only {
        display: none;
    }
    
    .tablet-only {
        display: block;
    }
    
    /* Amélioration des textes sur tablette */
    .btn {
        font-size: 15px;
        padding: 10px 16px;
    }
    
    .financial-table {
        font-size: 14px;
    }
    
    .tab-btn {
        font-size: 14px !important;
        padding: 10px 14px !important;
    }
}

@media (min-width: 1025px) {
    .mobile-only,
    .tablet-only {
        display: none;
    }
    
    .desktop-only {
        display: block;
    }
}

/* Amélioration spécifique des contrastes pour l'accessibilité */
@media (prefers-contrast: high) {
    :root {
        --text-secondary: #374151; /* Plus sombre pour fort contraste */
        --text-muted: #4b5563;
        --mobile-text-secondary: #374151;
        --mobile-text-muted: #4b5563;
    }
    
    .btn {
        border: 2px solid currentColor;
        font-weight: 700;
    }
    
    .alert {
        border-width: 2px;
        font-weight: 500;
    }
}

/* Support des grandes tailles de police système */
@media (prefers-reduced-motion: no-preference) {
    html {
        font-size: 16px; /* Base pour les préférences utilisateur */
    }
    
    @media (max-width: 768px) {
        html {
            font-size: 17px; /* Légèrement plus grand sur mobile */
        }
    }
}