:root {
    --primary: #4A9B9E;
    --primary-dark: #3d8285;
    --primary-light: #80CBC9;
    --secondary: #C5DC64;
    --secondary-dark: #b5cc54;
    --text-dark: #2d3436;
    --text-muted: #636e72;
    --bg-body: #f8f9fa;
    --bg-card: #ffffff;
    --border-color: #edf2f7;
    --danger: #ff7675;
    --warning: #fab1a0;
    --success: #55efc4;
    --info: #74b9ff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-dark);
    line-height: 1.5;
    min-height: 100vh;
    padding: 2rem 1rem;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
header {
    background: var(--bg-card);
    padding: 1.5rem 2rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    height: 50px;
    width: auto;
}

h1 {
    color: var(--primary);
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.025em;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 155, 158, 0.2);
}

.btn-secondary {
    background-color: var(--secondary);
    color: var(--text-dark);
}

.btn-secondary:hover {
    background-color: var(--secondary-dark);
    transform: translateY(-1px);
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-danger:hover {
    filter: brightness(0.9);
}

.btn-small {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
}

.btn-icon {
    padding: 0.5rem;
    border-radius: 50%;
}

/* Stats */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border-bottom: 4px solid var(--primary);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.stat-card h3 {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-dark);
}

/* Filters */
.filters {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
}

.filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.filters-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-dark);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.filter-count-badge {
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.btn-reset {
    background: none;
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    transition: all 0.2s;
}

.btn-reset:hover {
    background: var(--danger);
    color: white;
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.25rem;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.filter-group select,
.filter-group input[type="text"] {
    padding: 0.625rem 0.875rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background-color: #fcfcfc;
    transition: all 0.2s;
}

.filter-group select:focus,
.filter-group input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    background-color: white;
    box-shadow: 0 0 0 3px rgba(74, 155, 158, 0.1);
}

/* Filtre actif : bordure colorée + fond léger */
.filter-group select.filter-active,
.filter-group input[type="text"].filter-active {
    border-color: var(--primary);
    background-color: rgba(74, 155, 158, 0.05);
    box-shadow: 0 0 0 1px rgba(74, 155, 158, 0.15);
}

.filter-group-checkbox {
    display: flex;
    align-items: flex-end;
    padding-bottom: 0.375rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    user-select: none;
}

.checkbox-label input {
    width: 1.125rem;
    height: 1.125rem;
    accent-color: var(--primary);
}

/* Section & Cards */
.section {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.section-title {
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.filiale-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: all 0.2s;
}

.filiale-card:hover {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 1px var(--primary-light);
}

.filiale-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.filiale-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--primary);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.dettes-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.dettes-table th {
    background: #f8fafc;
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
}

.dettes-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.dettes-table tr:last-child td {
    border-bottom: none;
}

.dettes-table tr:hover td {
    background-color: #fcfcfc;
}

/* Badges */
.badge {
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.badge-a-payer { background: #fff3cd; color: #856404; }
.badge-paye { background: #d4edda; color: #155724; }
.badge-echeancier { background: #cce5ff; color: #004085; }
.badge-relance { background: #f8d7da; color: #721c24; }
.badge-saisie { background: #e2e3e5; color: #383d41; }
.badge-en-cours { background: #e2e3e5; color: #383d41; }
.badge-finie { background: #d4edda; color: #155724; }
.badge-en-attente { background: #fff3cd; color: #856404; }

.amount {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 650px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.modal-header {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
}

.close-modal {
    background: #f1f5f9;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.close-modal:hover {
    background: var(--danger);
    color: white;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    transition: all 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 155, 158, 0.1);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2.5rem;
}

/* Echeances */
.echeance-item {
    background: #f8fafc;
    padding: 1.25rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.echeance-info {
    display: grid;
    grid-template-columns: auto 1fr 1fr auto;
    align-items: center;
    gap: 1rem;
}

@media (max-width: 768px) {
    header {
        padding: 1.5rem;
        flex-direction: column;
        align-items: stretch;
    }

    .header-actions {
        flex-direction: column;
    }

    .stats-container {
        grid-template-columns: 1fr;
    }

    .echeance-info {
        grid-template-columns: 1fr;
    }
}
