/* ==================== Variables ==================== */
:root {
    --primary-color: #0d1b2a;
    --secondary-color: #1b263b;
    --accent-color: #415a77;
    --success-color: #27ae60;
    --warning-color: #e67e22;
    --danger-color: #c0392b;
    --light-bg: #ecf0f1;
    --dark-bg: #34495e;
    --text-color: #2c3e50;
    --border-color: #bdc3c7;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ==================== Reset & Base ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-bg);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ==================== Header ==================== */
.header {
    background: linear-gradient(135deg, #0d1b2a, #1b263b);
    color: white;
    padding: 15px 0;
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 1.5rem;
    margin-bottom: 3px;
    font-weight: 600;
}

.header .subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* ==================== Loading ==================== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    padding: 40px;
}

.spinner {
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--secondary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

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

/* ==================== Controls Panel ==================== */
.controls-panel {
    background: white;
    padding: 25px;
    margin: 30px 0;
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
    align-items: center;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-group label {
    font-weight: 600;
    color: var(--primary-color);
}

.radio-group {
    display: flex;
    gap: 15px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    padding: 5px 15px;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    transition: all 0.3s;
}

.radio-label:hover {
    border-color: var(--secondary-color);
    background-color: rgba(52, 152, 219, 0.1);
}

.radio-label input[type="radio"]:checked + span {
    color: var(--secondary-color);
    font-weight: 600;
}

.filter-select {
    padding: 8px 15px;
    border: 2px solid var(--border-color);
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.3s;
    min-width: 200px;
}

.filter-select:focus {
    outline: none;
    border-color: var(--secondary-color);
}

/* ==================== Statistics Cards ==================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 20px;
    margin: 30px 0;
}

@media (max-width: 1400px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    transition: transform 0.3s, box-shadow 0.3s;
}

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

.stat-icon {
    display: none; /* Cacher les icônes */
}

.stat-content {
    flex: 1;
    text-align: center;
}

.stat-label {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-attendu .stat-value { color: #2980b9; }
.stat-recouvre .stat-value { color: var(--success-color); }
.stat-impaye .stat-value { color: var(--danger-color); }
.stat-taux .stat-value { color: #8e44ad; }
.stat-usagers .stat-value { color: var(--warning-color); }

/* Couleur dynamique pour Recouv. % */
.stat-taux .stat-value.taux-bon { color: var(--success-color); }
.stat-taux .stat-value.taux-moyen { color: var(--warning-color); }
.stat-taux .stat-value.taux-faible { color: var(--danger-color); }

/* ==================== Info Message ==================== */
.info-message {
    background: #e3f2fd;
    border-left: 4px solid #2196f3;
    padding: 15px 20px;
    margin: 20px 0;
    border-radius: 5px;
    color: #1565c0;
    font-size: 0.95rem;
}

.info-message strong {
    color: #0d47a1;
}

/* ==================== Export Section ==================== */
.export-section {
    background: white;
    padding: 25px;
    margin-top: 30px;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.export-section h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.3rem;
}

.export-description {
    color: #7f8c8d;
    margin-bottom: 20px;
    font-size: 0.95rem;
}

.export-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.btn-export {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

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

.btn-export-mgmt:hover {
    border-color: #2980b9;
    background: #f0f8ff;
}

.btn-export-detail:hover {
    border-color: #27ae60;
    background: #f0fff4;
}

.btn-export-brut:hover {
    border-color: #e67e22;
    background: #fff8f0;
}

.btn-icon {
    font-size: 2.5rem;
    flex-shrink: 0;
}

.btn-text {
    flex: 1;
}

.btn-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary-color);
    margin-bottom: 3px;
}

.btn-subtitle {
    font-size: 0.75rem;
    color: #7f8c8d;
}

.export-status {
    margin-top: 15px;
    padding: 12px;
    border-radius: 5px;
    text-align: center;
    font-weight: 600;
}

.export-status.success {
    background: #d4edda;
    color: #155724;
}

.export-status.processing {
    background: #fff3cd;
    color: #856404;
}

@media (max-width: 768px) {
    .export-buttons {
        grid-template-columns: 1fr;
    }
}

/* ==================== Analytics Section ==================== */
.analytics-section {
    background: white;
    padding: 30px;
    margin: 30px 0;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.analytics-section h3 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.4rem;
}

.analytics-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    border-bottom: 2px solid #e0e0e0;
}

.tab-button {
    padding: 12px 30px;
    border: none;
    background: transparent;
    color: #7f8c8d;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.tab-button:hover {
    color: var(--primary-color);
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 25px;
    margin-bottom: 25px;
}

.chart-container {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    min-height: 350px;
}

.chart-container h4 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.1rem;
    text-align: center;
}

.chart-subtitle {
    text-align: center;
    color: #7f8c8d;
    font-size: 0.85rem;
    margin: -10px 0 10px 0;
}

.chart-full-width {
    grid-column: 1 / -1;
}

canvas {
    max-height: 300px;
}

@media (max-width: 992px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .chart-full-width {
        grid-column: 1;
    }
}

/* ==================== Tables ==================== */
.table-container {
    background: white;
    padding: 25px;
    margin: 30px 0;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.table-container h2 {
    margin-bottom: 20px;
    color: var(--primary-color);
}

table.dataTable {
    border-collapse: collapse !important;
}

table.dataTable thead th {
    background-color: var(--primary-color);
    color: white;
    padding: 15px 10px;
    font-weight: 600;
}

table.dataTable tbody tr {
    transition: background-color 0.2s;
}

table.dataTable tbody tr:hover {
    background-color: rgba(52, 152, 219, 0.1);
    cursor: pointer;
}

table.dataTable tbody tr.selected-row {
    background-color: rgba(52, 152, 219, 0.2);
}

table.dataTable tbody td {
    padding: 12px 10px;
}

/* Badges de criticité */
.badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85rem;
    display: inline-block;
}

.badge-risque-a {
    background-color: rgba(231, 76, 60, 0.2);
    color: var(--danger-color);
}

.badge-risque-b {
    background-color: rgba(243, 156, 18, 0.2);
    color: var(--warning-color);
}

.badge-risque-c {
    background-color: rgba(39, 174, 96, 0.2);
    color: var(--success-color);
}

.badge-paye {
    background-color: rgba(39, 174, 96, 0.2);
    color: var(--success-color);
}

.badge-impaye {
    background-color: rgba(231, 76, 60, 0.2);
    color: var(--danger-color);
}

/* ==================== Details Panel (RIGHT STICKY) ==================== */
.sticky-panel {
    position: sticky;
    top: 20px;
    height: calc(100vh - 150px);
}

.details-panel-right {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.details-panel-right h2 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
}

.details-panel-right .text-primary {
    color: var(--secondary-color) !important;
}

.details-summary-inline {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.details-summary-inline .summary-box {
    background: var(--light-bg);
    padding: 12px;
    border-radius: 5px;
    text-align: center;
}

.details-summary-inline .summary-label {
    font-size: 0.75rem;
    color: #7f8c8d;
    display: block;
    margin-bottom: 5px;
    text-transform: uppercase;
    font-weight: 600;
}

.details-summary-inline .summary-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary-color);
}

.details-table-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.details-table-container table {
    margin: 0 !important;
}

/* Chart Container */
.table-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Responsive Grid */
.row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -15px;
}

.col-md-8 {
    flex: 0 0 66.666667%;
    max-width: 66.666667%;
    padding: 0 15px;
}

.col-md-4 {
    flex: 0 0 33.333333%;
    max-width: 33.333333%;
    padding: 0 15px;
}

/* ==================== OLD Details Panel (REMOVE/HIDE) ==================== */
.details-panel {
    position: fixed;
    top: 0;
    right: -600px;
    width: 600px;
    height: 100vh;
    background: white;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.2);
    transition: right 0.3s ease-in-out;
    z-index: 1000;
    overflow-y: auto;
}

.details-panel.active {
    right: 0;
}

.details-header {
    background: var(--primary-color);
    color: white;
    padding: 25px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.details-header h2 {
    color: white;
    margin-bottom: 15px;
}

.details-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-top: 15px;
}

.summary-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px;
    border-radius: 5px;
}

.summary-item strong {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 5px;
    opacity: 0.9;
}

.summary-item span {
    font-size: 1.1rem;
    font-weight: 600;
}

.btn-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.details-panel .table-container {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
}

/* ==================== Footer ==================== */
.footer {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
    font-size: 0.9rem;
    margin-top: 40px;
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
    .header h1 {
        font-size: 1.8rem;
    }
    
    .controls-panel {
        flex-direction: column;
        align-items: stretch;
    }
    
    .control-group {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .details-panel {
        width: 100%;
        right: -100%;
    }
}

/* ==================== DataTables Customization ==================== */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    margin-bottom: 15px;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    margin-top: 15px;
}

div.dataTables_scrollBody {
    border: 1px solid var(--border-color);
    border-radius: 5px;
}
