/* Variables CSS */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --light-color: #ecf0f1;
    --dark-color: #34495e;
    --border-radius: 8px;
    --box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    --transition: all 0.3s ease;
}

/* Dark mode variables */
[data-theme="dark"] {
    --primary-color: #1a252f;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --light-color: #2c3e50; /* Fond des cartes et modules */
    --dark-color: #ecf0f1;
    --background-color: #1a1a1a; /* Fond général de la page */
    --text-color: #ecf0f1;
    --border-color: #34495e;
}

/* Reset et base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-color, #f8f9fa);
    color: var(--dark-color, #333);
    line-height: 1.6;
    transition: var(--transition);
}

[data-theme="dark"] body {
    background-color: var(--background-color);
    color: var(--text-color);
}

/* Container principal */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    background: var(--primary-color);
    color: white;
    padding: 1rem 0;
    margin-bottom: 2rem;
    box-shadow: var(--box-shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Footer */
footer {
    background: var(--primary-color);
    color: white;
    text-align: center;
    padding: 1rem 0;
    margin-top: 3rem;
    box-shadow: var(--box-shadow);
}

[data-theme="dark"] footer {
    background: var(--light-color);
}

/* Écran de connexion */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
}

.auth-card {
    background: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    width: 100%;
    max-width: 400px;
}

[data-theme="dark"] .auth-card {
    background: var(--light-color);
    color: var(--text-color);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-tabs {
    display: flex;
    margin-bottom: 2rem;
    border-radius: var(--border-radius);
    overflow: hidden;
}

.auth-tab {
    flex: 1;
    padding: 0.75rem;
    background: var(--light-color);
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.auth-tab.active {
    background: var(--secondary-color);
    color: white;
}

.forgot-password {
    text-align: center;
    margin-top: 1rem;
}

.forgot-password a {
    color: var(--secondary-color);
    text-decoration: none;
    font-size: 0.875rem;
}

.forgot-password a:hover {
    text-decoration: underline;
}

/* Formulaires */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

input, select, textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: var(--primary-color);
    color: var(--text-color);
    border-color: var(--border-color);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* Boutons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    text-decoration: none;
    font-size: 1rem;
    transition: var(--transition);
    text-align: center;
}

.btn:hover {
    background: #2980b9;
    transform: translateY(-1px);
}

.btn-primary { background: var(--secondary-color); }
.btn-success { background: var(--success-color); }
.btn-danger { background: var(--danger-color); }
.btn-warning { background: var(--warning-color); }

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-block {
    width: 100%;
}

/* Navigation */
.nav-container {
    background: white;
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 2rem;
    box-shadow: var(--box-shadow);
}

[data-theme="dark"] .nav-container {
    background: var(--light-color);
}

.nav-tabs {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.nav-tab {
    padding: 0.75rem 1.5rem;
    background: var(--light-color);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

[data-theme="dark"] .nav-tab {
    background-color: #34495e; /* Couleur plus claire pour les onglets inactifs */
    color: var(--text-color);
}

.nav-tab.active {
    background: var(--secondary-color);
    color: white;
}

.nav-tab:hover:not(.active) {
    background: #d5dbdb;
}

[data-theme="dark"] .nav-tab:hover:not(.active) {
    background: #4a637a;
}

/* Date Navigation */
.date-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1rem;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

[data-theme="dark"] .date-nav {
    background: var(--light-color);
}

.date-nav.hidden {
    display: none;
}

.date-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Cards */
.card {
    background: white;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--box-shadow);
    transition: var(--transition);
}

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

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #eee;
}

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

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
}

[data-theme="dark"] .card-title {
    color: var(--text-color);
}

/* Grid */
.row {
    display: flex;
    flex-wrap: wrap;
    margin: -0.75rem;
}

.col {
    flex: 1;
    padding: 0.75rem;
    min-width: 300px;
}

.col-1 { flex: 0 0 100%; }
.col-2 { flex: 0 0 50%; }
.col-3 { flex: 0 0 33.333%; }
.col-4 { flex: 0 0 25%; }

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    text-align: center;
    transition: var(--transition);
}

[data-theme="dark"] .stat-card {
    background: var(--light-color);
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.stat-label {
    color: #666;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

[data-theme="dark"] .stat-label {
    color: #bbb;
}

.stat-income { border-left: 4px solid var(--success-color); }
.stat-expense { border-left: 4px solid var(--danger-color); }
.stat-balance { border-left: 4px solid var(--secondary-color); }
.stat-tax { border-left: 4px solid var(--warning-color); }

/* Tables */
.table-container {
    overflow-x: auto;
    margin-bottom: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--box-shadow);
}

[data-theme="dark"] table {
    background: var(--light-color);
}

th, td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

[data-theme="dark"] th,
[data-theme="dark"] td {
    border-bottom-color: var(--border-color);
}

th {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.875rem;
    letter-spacing: 0.5px;
}

tr:hover {
    background: rgba(52, 152, 219, 0.05);
}

[data-theme="dark"] tr:hover {
    background: rgba(52, 152, 219, 0.1);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: modalSlideIn 0.3s ease;
}

[data-theme="dark"] .modal-content {
    background: var(--light-color);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

[data-theme="dark"] .modal-header {
    border-bottom-color: var(--border-color);
}

.close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition);
}

.close:hover {
    background: #f0f0f0;
    color: var(--danger-color);
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    border-left: 4px solid;
    animation: alertSlideIn 0.3s ease;
}

@keyframes alertSlideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border-color: var(--success-color);
}

.alert-danger {
    background: #f8d7da;
    color: #721c24;
    border-color: var(--danger-color);
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border-color: var(--warning-color);
}

.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border-color: var(--secondary-color);
}

/* Loading */
.loading {
    display: none;
    text-align: center;
    padding: 2rem;
}

.loading.show {
    display: block;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--secondary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Search and Filters */
.search-filters {
    background: white;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    margin-bottom: 1.5rem;
    box-shadow: var(--box-shadow);
}

[data-theme="dark"] .search-filters {
    background: var(--light-color);
}

.search-row {
    display: flex;
    gap: 1rem;
    align-items: end;
    flex-wrap: wrap;
}

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

/* Export buttons */
.export-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

/* Settings */
.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.settings-section {
    background: white;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

[data-theme="dark"] .settings-section {
    background: var(--light-color);
}

.settings-section h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 0.5rem;
}

[data-theme="dark"] .settings-section h3 {
    color: var(--text-color);
}

/* Theme Toggle */
.theme-toggle {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.theme-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.4s;
    border-radius: 34px;
}

.theme-slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked + .theme-slider {
    background-color: var(--secondary-color);
}

input:checked + .theme-slider:before {
    transform: translateX(26px);
}

/* Styles for invoices and clients */
.invoice-item {
    background: #f8f9fa;
    padding: 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--border-radius);
    position: relative;
}

[data-theme="dark"] .invoice-item {
    background: var(--primary-color);
}

.invoice-item .remove-item {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 12px;
    cursor: pointer;
}

.status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: var(--border-radius);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-draft { background: #e9ecef; color: #495057; }
.status-sent { background: #d1ecf1; color: #0c5460; }
.status-pending { background: #fff3cd; color: #856404; }
.status-paid { background: #d4edda; color: #155724; }
.status-overdue { background: #f8d7da; color: #721c24; }
.status-cancelled { background: #f8d7da; color: #721c24; }

.client-inactive {
    opacity: 0.6;
}

/* Invoice actions */
.invoice-actions {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.invoice-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Client suggestions */
.client-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: var(--box-shadow);
}

[data-theme="dark"] .client-suggestions {
    background: var(--light-color);
    border-color: var(--border-color);
}

.client-suggestion-item {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}

[data-theme="dark"] .client-suggestion-item {
    border-bottom-color: var(--border-color);
}

.client-suggestion-item:hover {
    background: var(--secondary-color);
    color: white;
}

.client-suggestion-item:last-child {
    border-bottom: none;
}

/* Validation errors */
.validation-error {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
}

/* Styles pour les badges de catégorie */
.category-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 1px solid #dee2e6;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #495057;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

[data-theme="dark"] .category-badge {
    background: linear-gradient(135deg, var(--primary-color), var(--border-color));
    border-color: var(--border-color);
    color: var(--text-color);
}

/* Améliorations pour le select de catégories */
#expenseCategory optgroup {
    font-weight: bold;
    font-size: 0.9rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e9ecef;
}

[data-theme="dark"] #expenseCategory optgroup {
    border-bottom-color: var(--border-color);
}

#expenseCategory option {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

#expenseCategory option:hover {
    background-color: var(--secondary-color);
    color: white;
}

/* NOUVEAUX STYLES POUR LES CALCULATEURS INTÉGRÉS */
.integrated-calculator {
    background: #f8f9fa;
    margin-top: 1rem;
    margin-bottom: 1rem;
    padding: 1rem;
    border: 1px solid #e9ecef;
    border-radius: var(--border-radius);
}

[data-theme="dark"] .integrated-calculator {
    background: var(--primary-color);
    border-color: var(--border-color);
}

.calculator-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 0.5rem;
}

[data-theme="dark"] .calculator-title {
    border-bottom-color: var(--border-color);
}

#inverseTaxResult, #mileageResult {
    background: white;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin-top: 1rem;
}

[data-theme="dark"] #inverseTaxResult, 
[data-theme="dark"] #mileageResult {
    background: #1a252f;
}

#inverseTaxResult p, #mileageResult p {
    margin: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .container { padding: 10px; }
    .header-content { flex-direction: column; gap: 1rem; text-align: center; }
    .nav-tabs { justify-content: center; }
    .nav-tab { flex: 1; text-align: center; }
    .date-nav { flex-direction: column; gap: 1rem; }
    .col { min-width: 100%; }
    .stats-grid { grid-template-columns: 1fr; }
    .search-row { flex-direction: column; }
    .search-group { min-width: 100%; }
    .export-buttons { justify-content: center; }
    .settings-grid { grid-template-columns: 1fr; }
    table { font-size: 0.875rem; }
    th, td { padding: 0.5rem; }
}

/* Utility classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.p-0 { padding: 0; }
.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.hidden { display: none; }
.visible { display: block; }
.flex { display: flex; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.w-100 { width: 100%; }
.text-success { color: var(--success-color); }
.text-danger { color: var(--danger-color); }
.text-warning { color: var(--warning-color); }
.text-info { color: var(--secondary-color); }
.fw-bold { font-weight: bold; }
.fw-normal { font-weight: normal; }
.fs-small { font-size: 0.875rem; }
.fs-large { font-size: 1.25rem; }

// STYLES CSS POUR LE TABLEAU DE BORD FISCAL
const taxDashboardStyles = `
<style>
.tax-dashboard {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
    margin-top: 20px;
}

.tax-dashboard h3 {
    color: #495057;
    margin-bottom: 15px;
    border-bottom: 2px solid #007bff;
    padding-bottom: 5px;
}

.tax-summary {
    display: grid;
    gap: 10px;
}

.tax-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #e9ecef;
}

.tax-item.total {
    background: #e3f2fd;
    padding: 12px;
    border-radius: 4px;
    font-size: 1.1em;
    border-bottom: none;
    margin-top: 10px;
}

.tax-note {
    margin-top: 15px;
    color: #6c757d;
    font-style: italic;
}

.currency-section {
    margin: 15px 0;
    padding: 15px;
    background: #ffffff;
    border-radius: 6px;
    border-left: 4px solid #007bff;
}

.currency-section h3 {
    margin-bottom: 10px;
    color: #343a40;
}
</style>
`;

// Injecter les styles dans le document
if (!document.getElementById('tax-dashboard-styles')) {
    const styleElement = document.createElement('div');
    styleElement.id = 'tax-dashboard-styles';
    styleElement.innerHTML = taxDashboardStyles;
    document.head.appendChild(styleElement);
}
