/* Reset et base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Variables pour le thème clair */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #e9ecef;
    --shadow: rgba(0, 0, 0, 0.1);
    --accent-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
}

[data-theme="dark"] {
    /* Variables pour le thème sombre */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --border-color: #404040;
    --shadow: rgba(0, 0, 0, 0.3);
    --accent-color: #4caf50;
    --danger-color: #f44336;
    --warning-color: #ff9800;
    --info-color: #2196f3;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Page de connexion */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    background: var(--bg-secondary);
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 15px 35px var(--shadow);
    width: 100%;
    max-width: 400px;
    text-align: center;
    transition: background-color 0.3s ease;
}

.login-header h1 {
    color: var(--text-primary);
    margin-bottom: 10px;
    font-size: 1.8em;
}

.login-header p {
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.login-form h2 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 1.4em;
}

.login-form .form-group {
    margin-bottom: 20px;
    text-align: left;
}

.login-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #333;
}

.login-form select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e1e5e9;
    border-radius: 6px;
    font-size: 16px;
    transition: border-color 0.3s ease;
}

.login-form select:focus {
    outline: none;
    border-color: #28a745;
}

/* Conteneur pour le champ mot de passe avec bouton œil */
.password-input-container {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-container input {
    width: 100%;
    padding-right: 45px; /* Espace pour le bouton œil */
}

.password-toggle-btn {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 5px;
    color: #666;
    transition: color 0.3s ease;
    z-index: 10;
}

.password-toggle-btn:hover {
    color: #28a745;
}

.password-toggle-btn:focus {
    outline: none;
    color: var(--accent-color);
}

/* Bouton de thème */
.btn-theme {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    transition: all 0.3s ease;
}

.btn-theme:hover {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* Section Recherche et Filtres */
.search-section {
    margin-bottom: 30px;
}

.search-filters-container {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px var(--shadow);
    border: 1px solid var(--border-color);
}

.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    align-items: center;
}

.search-input {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.filters-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group label {
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.filter-select {
    padding: 8px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: border-color 0.3s ease;
}

.filter-select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.filter-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.results-count {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Indicateur de connexion */
.connection-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.connection-indicator {
    font-size: 0.7rem;
    transition: all 0.3s ease;
}

.connection-status.offline .connection-indicator {
    color: #dc3545;
}

.connection-status.online .connection-indicator {
    color: #28a745;
}

.connection-status.syncing .connection-indicator {
    color: #ffc107;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Dashboard */
.dashboard-section {
    margin-bottom: 30px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.dashboard-card {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px var(--shadow);
    border: 1px solid var(--border-color);
    transition: transform 0.3s ease;
}

.dashboard-card:hover {
    transform: translateY(-2px);
}

.dashboard-card h3 {
    color: var(--text-primary);
    margin-bottom: 15px;
    font-size: 1.1rem;
    font-weight: 600;
}

.metric-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent-color);
    margin-bottom: 5px;
}

.metric-change {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.chart-container {
    width: 100%;
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-container canvas {
    max-width: 100%;
    max-height: 100%;
}

/* Correction pour le texte des photos - toujours noir */
.photo-upload-container h3 {
    color: #333333 !important;
}

/* Bouton OCR */
.btn-ocr {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.3);
}

.btn-ocr:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-ocr:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-ocr.loading {
    background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
    animation: pulse 1.5s infinite;
}

.login-form .btn {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    margin-top: 10px;
}

/* En-tête avec informations utilisateur */
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-info span {
    font-weight: 500;
    color: #333;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 14px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* En-tête */
.header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: 1px;
}

/* Sections */
.form-section, .table-section {
    background: var(--bg-secondary);
    padding: 30px;
    margin-bottom: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px var(--shadow);
}

.form-section h2, .table-section h2 {
    color: var(--text-primary);
    margin-bottom: 25px;
    font-size: 1.5rem;
    font-weight: 500;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
}

/* Formulaire */
.facture-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 8px;
    font-weight: 500;
    color: #495057;
}

.form-group input,
.form-group select {
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #28a745;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.1);
}

.form-group input[type="file"] {
    padding: 8px;
    background-color: #f8f9fa;
}

/* Boutons */
.form-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background-color: #007bff;
    color: white;
}

.btn-primary:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.btn-success {
    background-color: #28a745;
    color: white;
}

.btn-success:hover {
    background-color: #1e7e34;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}

.btn-info {
    background-color: #17a2b8;
    color: white;
}

.btn-info:hover {
    background-color: #138496;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(23, 162, 184, 0.3);
}

.btn-warning {
    background-color: #ffc107;
    color: #212529;
}

.btn-warning:hover {
    background-color: #e0a800;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.3);
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #545b62;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.3);
}

.btn-dark {
    background-color: #343a40;
    color: white;
}

.btn-dark:hover {
    background-color: #23272b;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 58, 64, 0.3);
}

.btn-danger {
    background-color: #dc3545;
    color: white;
    padding: 6px 12px;
    font-size: 0.875rem;
}

.btn-danger:hover {
    background-color: #c82333;
}

/* Tableau */
.table-container {
    overflow-x: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.factures-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.factures-table th {
    background-color: #495057;
    color: #ffffff;
    padding: 15px 12px;
    text-align: left;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.875rem;
}

.factures-table td {
    padding: 15px 12px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.factures-table tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.04);
}

.factures-table tbody tr:hover {
    background-color: rgba(42, 115, 204, 0.15);
    transition: background-color 0.2s ease;
}

.factures-table td:first-child {
    font-weight: 500;
    color: #007bff;
}

/* Photo upload container */
.photo-upload-container {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.btn-photo {
    background-color: #17a2b8;
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    min-width: 150px;
}

.btn-photo:hover {
    background-color: #138496;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(23, 162, 184, 0.3);
}

/* Photo preview container */
.photo-preview-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    margin-top: 15px;
    padding: 15px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    border: 2px dashed var(--border-color);
    min-height: 60px;
}

.photo-preview-container:empty::before {
    content: "Aucune photo sélectionnée";
    color: #6c757d;
    font-style: italic;
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px;
}

/* Photo item */
.photo-item {
    position: relative;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--shadow);
    transition: transform 0.2s ease;
}

.photo-item:hover {
    transform: scale(1.05);
}

.photo-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

.photo-item-info {
    padding: 8px;
    font-size: 0.8rem;
    color: var(--text-primary);
    text-align: center;
    word-break: break-all;
}

.photo-item-actions {
    position: absolute;
    top: 5px;
    right: 5px;
    display: flex;
    gap: 5px;
}

.photo-item-btn {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.photo-item-btn.edit {
    background-color: #ffc107;
    color: #212529;
}

.photo-item-btn.delete {
    background-color: #dc3545;
    color: #ffffff;
}

.photo-item-btn:hover {
    transform: scale(1.1);
}

/* Badge Cloudinary */
.cloudinary-badge {
    display: inline-block;
    margin-left: 8px;
    font-size: 0.9rem;
    color: #28a745;
    font-weight: bold;
}

/* Image preview dans le tableau */
.photo-preview {
    max-width: 50px;
    max-height: 50px;
    border-radius: 4px;
    object-fit: cover;
}

.photos-count {
    background-color: #007bff;
    color: white;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
    margin-right: 5px;
}

/* Messages */
.message {
    padding: 15px;
    border-radius: 6px;
    margin: 20px 0;
    font-weight: 500;
}

/* Section d'aide */
.help-section {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
}

.help-content {
    background: white;
    padding: 15px;
    border-radius: 6px;
    border-left: 4px solid #007bff;
}

.help-content h3 {
    color: #dc3545;
    margin-top: 0;
    margin-bottom: 15px;
}

.help-content ol {
    margin: 10px 0;
    padding-left: 20px;
}

.help-content li {
    margin: 8px 0;
    line-height: 1.5;
}

.help-content strong {
    color: #007bff;
}

.help-content em {
    color: #6c757d;
    font-size: 0.9em;
}

.message.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.message.info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .form-section, .table-section {
        padding: 20px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .photo-upload-container {
        flex-direction: column;
    }
    
    .btn-photo {
        min-width: auto;
    }
    
    .photo-preview-container {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 10px;
    }
    
    .photo-item img {
        height: 100px;
    }
    
    .factures-table {
        font-size: 0.75rem;
    }
    
    .factures-table th,
    .factures-table td {
        padding: 8px 4px;
        white-space: nowrap;
    }
    
    /* Masquer certaines colonnes sur mobile pour économiser l'espace */
    .factures-table th:nth-child(4), /* Camion */
    .factures-table td:nth-child(4),
    .factures-table th:nth-child(9), /* Nb Litres */
    .factures-table td:nth-child(9),
    .factures-table th:nth-child(10), /* Autres */
    .factures-table td:nth-child(10) {
        display: none;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5rem;
    }
    
    .form-section h2, .table-section h2 {
        font-size: 1.25rem;
    }
    
    .factures-table th,
    .factures-table td {
        padding: 6px 3px;
        font-size: 0.7rem;
    }
    
    /* Masquer encore plus de colonnes sur très petit écran */
    .factures-table th:nth-child(5), /* Type Paiement */
    .factures-table td:nth-child(5),
    .factures-table th:nth-child(8), /* Frais Divers */
    .factures-table td:nth-child(8) {
        display: none;
    }
}

/* Animation de chargement */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* État vide du tableau */
.empty-table {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-style: italic;
}

[data-theme="dark"] .factures-table th {
    background-color: #343a40;
}

[data-theme="dark"] .factures-table tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .factures-table tbody tr:hover {
    background-color: rgba(76, 175, 80, 0.2);
}

[data-theme="dark"] .form-section h2,
[data-theme="dark"] .table-section h2 {
    border-bottom-color: var(--border-color);
}

[data-theme="dark"] .photo-upload-container h3 {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .factures-table td:first-child {
    color: #66b0ff;
}

/* Classes pour remplacer les styles inline */
.hidden {
    display: none;
}

.photo-input-hidden {
    display: none;
}

/* Boutons de synchronisation */
.sync-buttons {
    margin-top: 15px;
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    text-align: center;
}

.sync-buttons .btn {
    margin: 5px;
    min-width: 200px;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
}

.sync-buttons .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}