/* ECOTRAF Facturation - Styles principaux */
:root {
    --primary: #1B5E20;
    --primary-light: #2E7D32;
    --primary-dark: #0D3B10;
    --accent: #4CAF50;
    --accent-light: #81C784;
    --bg: #F0F4F0;
    --bg-card: #FFFFFF;
    --text: #1A1A2E;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --danger: #DC2626;
    --warning: #F59E0B;
    --success: #16A34A;
    --info: #2563EB;
    --sidebar-width: 260px;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(27, 94, 32, 0.08);
    --shadow-lg: 0 8px 40px rgba(27, 94, 32, 0.12);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--accent) 100%);
    position: relative;
    overflow: hidden;
}

.login-card {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 3rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
    animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(40px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo .icon {
    width: 70px; height: 70px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
    margin-bottom: 1rem;
}

.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: white;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-brand .brand-icon {
    width: 42px; height: 42px;
    background: rgba(255,255,255,0.15);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.sidebar-nav { padding: 1rem 0.75rem; flex: 1; }

.nav-section {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    opacity: 0.5;
    padding: 1rem 0.75rem 0.5rem;
    font-weight: 600;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    border-radius: 10px;
    margin-bottom: 2px;
    transition: var(--transition);
    font-size: 0.9rem;
    font-weight: 500;
}

.nav-link:hover { background: rgba(255,255,255,0.12); color: white; transform: translateX(4px); }
.nav-link.active { background: rgba(255,255,255,0.18); color: white; }
.nav-link i { width: 20px; text-align: center; }

.main-content { margin-left: var(--sidebar-width); flex: 1; min-height: 100vh; }

.top-bar {
    background: var(--bg-card);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-bar h1 { font-size: 1.35rem; font-weight: 700; color: var(--primary); margin: 0; }
.top-bar-left { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; }
.top-bar-left h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-content { padding: 2rem; }

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 4px; height: 100%;
}

.stat-card.green::before { background: var(--accent); }
.stat-card.blue::before { background: var(--info); }
.stat-card.orange::before { background: var(--warning); }
.stat-card.red::before { background: var(--danger); }
.stat-card.purple::before { background: #7C3AED; }
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }

.stat-card .stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    margin-bottom: 1rem;
}

.stat-card.green .stat-icon { background: #E8F5E9; color: var(--primary); }
.stat-card.blue .stat-icon { background: #EFF6FF; color: var(--info); }
.stat-card.orange .stat-icon { background: #FFF7ED; color: var(--warning); }
.stat-card.red .stat-icon { background: #FEF2F2; color: var(--danger); }
.stat-card.purple .stat-icon { background: #F5F3FF; color: #7C3AED; }

.stat-card .stat-value { font-size: 1.75rem; font-weight: 800; line-height: 1; }
.stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.35rem; }

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 { font-size: 1rem; font-weight: 700; color: var(--primary); }
.card-body { padding: 1.5rem; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    box-shadow: 0 4px 12px rgba(27,94,32,0.3);
}

.btn-primary:hover { transform: translateY(-2px); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-info { background: var(--info); color: white; }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    background: linear-gradient(to right, var(--primary), var(--primary-light));
    color: white;
    padding: 0.85rem 1rem;
    text-align: left;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}
.data-table td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
.data-table tbody tr:hover { background: #F0FFF0; }

.badge {
    display: inline-flex;
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-success { background: #DCFCE7; color: #166534; }
.badge-danger { background: #FEE2E2; color: #991B1B; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-primary { background: #DBEAFE; color: #1E40AF; }
.badge-secondary { background: #F3F4F6; color: #374151; }
.badge-dark { background: #E5E7EB; color: #1F2937; }

.form-control, .form-select {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 0.9rem;
    transition: var(--transition);
}
.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(76,175,80,0.15);
}
.form-label { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.4rem; display: block; }
.form-group { margin-bottom: 1.25rem; }

.alert {
    padding: 1rem 1.25rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}
.alert-success { background: #DCFCE7; color: #166534; border-left: 4px solid var(--success); }
.alert-danger { background: #FEE2E2; color: #991B1B; border-left: 4px solid var(--danger); }
.alert-warning { background: #FEF3C7; color: #92400E; border-left: 4px solid var(--warning); }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; }

.ligne-facture-row {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr 1fr auto;
    gap: 0.75rem;
    align-items: end;
    padding: 0.75rem;
    background: #FAFFFA;
    border-radius: 10px;
    margin-bottom: 0.5rem;
}

.totaux-panel {
    background: linear-gradient(135deg, #F0FFF0, #E8F5E9);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 2px solid var(--accent-light);
}

.totaux-panel .total-row { display: flex; justify-content: space-between; padding: 0.5rem 0; }
.totaux-panel .total-row.grand {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    border-top: 2px solid var(--accent);
    padding-top: 0.75rem;
    margin-top: 0.5rem;
}

.chart-container { position: relative; height: 300px; padding: 1rem; }
.search-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    background: white;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    border: 2px solid var(--border);
}
.search-bar input { border: none; outline: none; flex: 1; font-size: 0.9rem; }
.empty-state { text-align: center; padding: 3rem; color: var(--text-muted); }
.action-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.ligne-libelle-row {
    display: grid;
    grid-template-columns: 1fr 120px 120px 100px;
    gap: 0.75rem;
    align-items: end;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.ligne-libelle-row:hover { background: #FAFFFA; }
.categorie-select-card:has(input:checked) {
    border-color: var(--accent) !important;
    background: #F0FFF0;
}

.categorie-section-fast {
    animation: categorieFadeIn 0.15s ease-out;
}

@keyframes categorieFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 200;
        box-shadow: none;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 8px 0 30px rgba(0,0,0,0.3);
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 150;
    }
    .sidebar-overlay.active { display: block; }
    .sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        border: none;
        border-radius: 10px;
        background: var(--primary);
        color: white;
        font-size: 1.1rem;
        cursor: pointer;
        margin-right: 0.75rem;
        flex-shrink: 0;
    }
    .top-bar { gap: 0.5rem; }
    .top-bar h1 { font-size: 1.1rem; }
    .main-content { margin-left: 0; }
    .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
    .ligne-facture-row, .ligne-libelle-row { grid-template-columns: 1fr; }
    .ligne-libelle-header { display: none; }
}

@media (min-width: 769px) {
    .sidebar-toggle { display: none; }
    .sidebar-overlay { display: none !important; }
}

.ligne-libelle-header {
    display: grid;
    grid-template-columns: 1fr 120px 120px 100px;
    gap: 0.75rem;
    padding: 0.5rem;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
