/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f6fa;
    --sidebar-bg: #1e272e;
    --sidebar-text: #d2dae2;
    --sidebar-active: #0be881;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-light: #636e72;
    --accent: #0984e3;
    --accent-red: #d63031;
    --accent-dark: #2d3436;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0,0,0,.08);
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-header {
    padding: 24px 20px;
    font-size: 1.3rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-header i { color: var(--sidebar-active); font-size: 1.4rem; }

.sidebar ul { list-style: none; padding: 12px 0; flex: 1; }
.sidebar li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .95rem;
    transition: background .2s, color .2s;
    border-left: 3px solid transparent;
}
.sidebar li a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar li a.active {
    background: rgba(11,232,129,.1);
    color: var(--sidebar-active);
    border-left-color: var(--sidebar-active);
    font-weight: 600;
}
.sidebar li a i { width: 20px; text-align: center; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.1);
    color: rgba(255,255,255,.4);
    font-size: .75rem;
}

.sidebar-footer a {
    color: rgba(255,255,255,.4);
    text-decoration: none;
    transition: color .2s;
}

/* ── Content ─────────────────────────────────────────────────────────────── */
.content {
    margin-left: 240px;
    flex: 1;
    padding: 0;
    max-width: 1200px;
}

/* ── Period Banner ───────────────────────────────────────────────────────── */
.period-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 13px 40px;
    background: linear-gradient(100deg, rgba(9,132,227,.06) 0%, rgba(108,92,231,.04) 100%);
    border-bottom: 2px solid rgba(9,132,227,.18);
    transition: background .4s, border-color .4s;
}
.period-bar.has-period {
    background: linear-gradient(100deg, rgba(9,132,227,.13) 0%, rgba(108,92,231,.08) 100%);
    border-bottom-color: var(--accent);
}
.period-bar-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: .9rem;
    color: var(--text-light);
    flex-wrap: wrap;
}
.period-bar-label > i { font-size: 1rem; color: var(--accent); }
.period-bar-label > span { font-weight: 500; color: var(--text); white-space: nowrap; }
.period-bar-badge {
    display: inline-flex;
    align-items: center;
    background: var(--accent);
    color: #fff;
    font-size: .88rem;
    font-weight: 700;
    padding: 4px 14px;
    border-radius: 999px;
    box-shadow: 0 2px 6px rgba(9,132,227,.25);
    transition: background .3s;
    white-space: nowrap;
}
.period-bar.has-period .period-bar-badge {
    background: #6c5ce7;
    box-shadow: 0 2px 8px rgba(108,92,231,.3);
}
.period-bar-control {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
/* ── Custom Period Picker ────────────────────────────────────────────────── */
.period-picker { position: relative; flex-shrink: 0; }

.period-picker-btn {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 16px 9px 18px;
    border: 2px solid rgba(9,132,227,.35);
    border-radius: 999px;
    background: #fff;
    color: var(--text);
    font-size: .88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    min-width: 200px;
    justify-content: space-between;
    transition: border-color .2s, box-shadow .2s;
    box-shadow: 0 1px 6px rgba(0,0,0,.07);
    outline: none;
}
.period-picker-btn:hover,
.period-picker-btn.open {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(9,132,227,.13);
}
.period-picker-btn .fa-calendar-alt { color: var(--accent); font-size: .9rem; }
.period-btn-label { flex: 1; text-align: left; }
.period-picker-btn .chevron { color: var(--accent); font-size: .7rem; transition: transform .22s; }
.period-picker-btn.open .chevron { transform: rotate(180deg); }

.period-picker-panel {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 250px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 36px rgba(0,0,0,.13), 0 2px 8px rgba(0,0,0,.06);
    overflow: hidden;
    z-index: 1000;
    max-height: 380px;
    overflow-y: auto;
    border: 1px solid rgba(9,132,227,.12);
    scrollbar-width: thin;
}
.period-picker-panel.open { display: block; }

.period-picker-item {
    display: block;
    width: 100%;
    padding: 9px 20px;
    font-size: .87rem;
    font-family: inherit;
    color: var(--text);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: background .13s, color .13s;
}
.period-picker-item:hover { background: rgba(9,132,227,.08); color: var(--accent); }
.period-picker-item.selected { background: rgba(9,132,227,.11); color: var(--accent); font-weight: 700; }

.period-picker-item.year-item {
    font-weight: 700;
    color: var(--accent);
    background: rgba(9,132,227,.04);
    border-top: 1px solid rgba(9,132,227,.1);
    padding-left: 20px;
}
.period-picker-item.year-item:hover { background: rgba(9,132,227,.13); }
.period-picker-item.year-item.selected { background: rgba(9,132,227,.18); }

.period-picker-group-label {
    padding: 7px 20px 4px;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-light);
    font-weight: 700;
    background: #f7f8fb;
    border-top: 1px solid #ececf0;
}

.period-picker-item.month-item { padding-left: 30px; font-size: .85rem; }

/* ── Inline Period Picker (dans la page, avant les graphes) ──────────────── */
.period-inline {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}
.period-inline-label {
    font-size: .88rem;
    font-weight: 600;
    color: var(--text-light);
    white-space: nowrap;
}
.period-inline-label i { color: var(--accent); margin-right: 4px; }

/* ── Report Badge (encart en haut à gauche de l'intro-text) ──────────────── */
.intro-text {
    position: relative;
    overflow: visible;
}
.report-badge {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--accent);
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .5px;
    padding: 6px 16px 6px 12px;
    border-radius: 12px 0 12px 0;
    box-shadow: 0 2px 8px rgba(9,132,227,.25);
    z-index: 2;
    text-transform: uppercase;
    white-space: nowrap;
    line-height: 1;
}

/* ── Content inner ────────────────────────────────────────────────────────── */
.content-inner {
    padding: 32px 52px 32px 40px;
    position: relative
}

/* ── Charts zone — right accent rail ─────────────────────────────────────── */
.charts-zone {
    position: relative;
    background-color: rgba(9,132,227,.05);
    padding: 12px;
    border-radius: 12px;
}
.charts-zone::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 6px;
    background: linear-gradient(to bottom, rgba(9,132,227,.18), rgba(9,132,227,.06));
    border-radius: 4px;
    transition: background .4s;
}
.content.has-period .charts-zone::after {
    background: linear-gradient(160deg, var(--accent) 0%, #6c5ce7 60%, rgba(108,92,231,.3) 100%);
    opacity: .6;
}

.page-header {
    margin-bottom: 28px;
}
.page-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-header h1 i { color: var(--accent); }
.subtitle { color: var(--text-light); margin-top: 6px; font-size: .95rem; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}
.card h3 {
    font-size: 1.05rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent-dark);
}
.card h3 i { color: var(--accent); font-size: .9rem; }

.intro-text h2 {
    font-size: 1.15rem;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.intro-text h2 i { color: var(--accent); }
.intro-text p { color: var(--text-light); line-height: 1.7; margin-bottom: 8px; }

/* ── Stats Grid ──────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    text-align: center;
}
.stat-card i { font-size: 1.6rem; color: var(--accent); margin-bottom: 8px; }
.stat-value { font-size: 1.7rem; font-weight: 700; color: var(--accent-dark); }
.stat-label { font-size: .8rem; color: var(--text-light); margin-top: 4px; }

/* ── Charts ──────────────────────────────────────────────────────────────── */
.charts-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}
.chart-wide { grid-column: 1 / -1; }

/* Chart.js requires a positioned container with explicit height to prevent
   the infinite-resize feedback loop when maintainAspectRatio is false. */
.chart-container {
    position: relative;
    height: 320px;
    width: 100%;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}
.data-table th {
    background: var(--sidebar-bg);
    color: #fff;
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid #eee; }
.data-table tbody tr:hover { background: #f0f7ff; }
.data-table td:nth-child(n+2) { text-align: right; }
.data-table th:nth-child(n+2) { text-align: right; }

/* Group badge inside tables */
.group-badge {
    display: inline-block;
    background: rgba(108, 92, 231, .12);
    color: #6c5ce7;
    border: 1px solid rgba(108, 92, 231, .25);
    font-size: .75rem;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
    .sidebar { width: 60px; }
    .sidebar-header span, .sidebar li a span, .sidebar-footer { display: none; }
    .sidebar li a { justify-content: center; padding: 14px; }
    .content { margin-left: 60px; }
    .content-inner { padding: 20px 28px 20px 16px; }
    .period-bar { flex-direction: column; align-items: flex-start; padding: 12px 16px; gap: 10px; }
    .period-picker-btn { min-width: 0; width: 100%; }
    .charts-row { grid-template-columns: 1fr; }
}

/* ── Export toolbar (inside card headings) ────────────────────────────────── */
.export-toolbar {
    display: inline-flex;
    gap: 4px;
    margin-left: auto;
    flex-shrink: 0;
}
.export-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid rgba(9,132,227,.2);
    border-radius: 8px;
    background: rgba(9,132,227,.06);
    color: var(--accent);
    font-size: .78rem;
    cursor: pointer;
    transition: background .2s, border-color .2s, color .2s, transform .15s;
}
.export-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    transform: scale(1.08);
}

/* "Voir tout / Réduire" button below paginated tables */
.table-more-btn {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 8px 14px;
    background: none;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: .85rem;
    cursor: pointer;
    transition: background .2s, color .2s;
}
.table-more-btn:hover { background: var(--accent); color: #fff; }
.table-more-btn i { margin-right: 6px; }

/* ── Export modal ─────────────────────────────────────────────────────────── */
.export-modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(3px);
    align-items: center;
    justify-content: center;
}
.export-modal-backdrop.open { display: flex; }

.export-modal {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    width: 420px;
    max-width: 92vw;
    overflow: hidden;
    animation: modalIn .2s ease-out;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(16px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.export-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid #eee;
}
.export-modal-header h3 {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent-dark);
    margin: 0;
}
.export-modal-header h3 i { color: var(--accent); }
.export-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-light);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: color .15s;
}
.export-modal-close:hover { color: var(--accent-red); }

.export-modal-body { padding: 20px 24px; }

.export-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 14px;
}
.export-field > span {
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: .4px;
}
.export-field input,
.export-field select {
    padding: 9px 12px;
    border: 1.5px solid #dfe6e9;
    border-radius: 8px;
    font-size: .9rem;
    font-family: inherit;
    color: var(--text);
    background: #fafbfc;
    transition: border-color .2s, box-shadow .2s;
    outline: none;
}
.export-field input:focus,
.export-field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(9,132,227,.12);
}

.export-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 24px 18px;
    border-top: 1px solid #eee;
}
.export-modal-btn {
    padding: 9px 20px;
    border-radius: 8px;
    font-size: .88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: background .2s, transform .1s;
}
.export-modal-btn.cancel {
    background: #f1f2f6;
    color: var(--text-light);
}
.export-modal-btn.cancel:hover { background: #dfe4ea; }
.export-modal-btn.confirm {
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 6px;
}
.export-modal-btn.confirm:hover { background: #0773c5; }
.export-modal-btn:active { transform: scale(.97); }

.section-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    margin: 2rem 0 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
