/* --- 1. Variables & Reset --- */
:root {
    --primary: #4f46e5;
    --bg-body: #f3f4f6;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e2e8f0;
    --sidebar-width: 260px;
    --success: #059669;
    --danger: #dc2626;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { 
    font-family: 'Inter', system-ui, sans-serif; 
    background-color: var(--bg-body); 
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* --- 2. Sidebar (Aside) --- */
aside {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 2.5rem;
}

nav { display: flex; flex-direction: column; gap: 0.5rem; }

.nav-link {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    transition: 0.2s;
    text-decoration: none;
}

.nav-link:hover { background: #f9fafb; color: var(--text-main); }
.nav-link.active { background: #eef2ff; color: var(--primary); font-weight: 600; }

.user-profile {
    margin-top: auto;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar { 
    width: 40px; height: 40px; background: var(--primary); 
    color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center;
}

/* --- 3. Main Area --- */
main { flex: 1; display: flex; flex-direction: column; }

header { 
    padding: 2rem; background: white; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}

.content-area { padding: 2rem; }

/* --- 4. Composants & Affichage --- */
.tab-content { display: none; }
.tab-content.active { display: block; }

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

/* Cartes (Styles unifiés) */
.card { 
    background: #ffffff; 
    padding: 1.5rem; 
    border-radius: 12px; 
    border: 1px solid var(--border); 
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); 
}

.card-title { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.card-value { font-size: 1.5rem; font-weight: 700; color: #1e293b; }

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

/* --- 5. Tableaux & Données --- */
.data-container {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

th {
    text-align: left;
    padding: 1rem;
    background-color: #f8fafc;
    color: #64748b;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid #e2e8f0;
}

td {
    padding: 1rem;
    border-bottom: 1px solid #f1f5f9;
    color: #1e293b;
    font-size: 0.95rem;
}

tr:hover { background-color: #f9fafb; }

/* --- 6. Utilitaires --- */
.positive { color: var(--success); }
.negative { color: var(--danger); }

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}
.badge-success { background: #dcfce7; color: #166534; }

.btn-primary {
    background-color: var(--primary);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: none;
    font-weight: 500;
    cursor: pointer;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-action {
    padding: 6px 12px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s;
    margin-right: 5px;
}

.btn-action:hover { opacity: 0.8; transform: translateY(-1px); }

/* Le fond sombre derrière le popup */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    align-items: center; justify-content: center;
}

/* La fenêtre blanche au centre */
.modal-content {
    background-color: #fff;
    padding: 2rem;
    border-radius: 12px;
    width: 500px;
    position: relative;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.close-modal {
    position: absolute; top: 10px; right: 20px;
    font-size: 24px; cursor: pointer; color: #666;
}

/* Style du Modal */
.modal-content {
    background: #fff;
    padding: 2.5rem;
    border-radius: 16px;
    width: 900px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    max-height: 90vh;
    overflow-y: auto;
}

/* Grille des lignes de facture */
.ligne-row {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr 1fr 0.5fr; /* Colonnes proportionnelles */
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

/* Style des inputs */
.ligne-row input, .form-control {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 100%;
}

.totals-section {
    display: flex;
    justify-content: flex-end;
    gap: 20px;
    margin-top: 20px;
    font-weight: bold;
}

.invoice-grid {
    display: grid;
    grid-template-columns: 3fr 1fr 1.5fr 1.5fr 0.5fr;
    gap: 15px;
    align-items: center;
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #4a5568;
}

.input-field {
    padding: 10px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    width: 100%;
    transition: border-color 0.2s;
}

.input-field:focus { border-color: #5a67d8; outline: none; }

.totals-footer {
    display: flex;
    justify-content: flex-end;
    gap: 30px;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 2px solid #edf2f7;
    font-size: 1.2rem;
    font-weight: bold;
}

.btn-action {
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}
.btn-voir { background: #e2e8f0; }
.btn-payer { background: #48bb78; color: white; }
.btn-ok { background: #cbd5e0; color: #718096; cursor: default; }

/* Overlay de chargement */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.9); /* Un peu plus opaque pour masquer le changement */
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 99999; /* Très haut pour être au-dessus du reste */
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

