:root {
    --bg-page: #f3f4f8;
    --bg-card: #ffffff;
    --bg-card-soft: #fbfbfd;

    --topbar-bg: #232c3d;
    --topbar-text: #ffffff;

    --primary: #2f477a;
    --primary-soft: #aeb3e7;
    --primary-light: #dbe8f7;

    --accent: #f59b68;
    --accent-soft: #ffd8c2;

    --text-main: #1f2430;
    --text-muted: #7d8698;
    --border: #e3e7ef;
    --shadow: 0 10px 30px rgba(28, 39, 60, 0.06);

    --radius-lg: 18px;
    --radius-md: 14px;

    --topbar-height: 70px;
}

body {
    background-color: var(--bg-page);
    color: var(--text-main);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

/* TOPBAR */
.topbar {
    height: var(--topbar-height);
    background: var(--topbar-bg);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    z-index: 1030;
}

.topbar-inner {
    min-height: var(--topbar-height);
}

.brand-logo {
    display: inline-flex;
    align-items: baseline;
}

.brand-logo img {
    height:2rem;
    padding-right: 2rem;
}


.topbar-user {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.95rem;
}

.logout-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    background: var(--accent);
    color: #fff;
    transform: translateY(-1px);
}

.sousTitre {
    color: var(--primary-soft);
}

a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
}

/* Hover */
a:hover {
    color: var(--accent);
    text-decoration: none;
}

.aEnCours {
    color: var(--accent);
}

/* Focus (accessibilité clavier) */
a:focus {
    outline: none;
    text-decoration: none;
    color: var(--accent);
}


/* Liens dans textes secondaires */
.text-muted a {
    color: var(--text-muted);
}

.text-muted a:hover {
    color: var(--primary);
}

/* PAGE */
.stats-page {
    padding-top: calc(var(--topbar-height) + 24px);
    padding-bottom: 32px;
}

/* MODULES */
.stat-card {
    background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-card-soft) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
    height: 100%;
}

.module-header {
    margin-bottom: 20px;
}

.module-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
}

/* KPI */
.kpi-card {
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 120px;
}

.kpi-icon {
    width: 62px;
    height: 62px;
    border-radius: 16px;
    background: rgba(174, 179, 231, 0.18);
    color: var(--primary-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.9rem;
    flex-shrink: 0;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--text-main);
    margin-bottom: 6px;
}

.kpi-label {
    color: var(--primary);
    font-weight: 600;
    font-size: 1rem;
}

/* METRIC */
.metric-card {
    min-height: 180px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.metric-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 18px;
}

.metric-main {
    font-size: 2rem;
    font-weight: 800;
    color: #3a3f4b;
    margin-bottom: 8px;
}

.metric-sub {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ============================== */
/* ============================== */
/*      CHART.JS                    */
/* ============================== */
/* ============================== */

.chart-card {
    background: #fbfbfd;
    border: 1px solid #e3e7ef;
    border-radius: 24px;
    padding: 24px 24px 18px 24px;
    min-height: 540px;
}

.chartjs-donut-wrapper {
    position: relative;
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1 / 1;
    margin: 10px auto 24px auto;
}

.chartjs-donut-wrapper canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.chart-center-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.chart-center-label span {
    font-size: 3rem;
    font-weight: 800;
    color: #1f2b3d;
}

.custom-legend {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;     /* autorise retour si trop étroit */
    gap: 16px 24px;
}

.legend-dot {
    width: 12px !important;
    height: 12px !important;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;       /* empêche coupure du texte */
}

/* ============================== */
/* ============================== */
/*      TABLES                    */
/* ============================== */
/* ============================== */
.table-card {
    overflow: hidden;
}

.stats-table {
    --bs-table-bg: transparent;
    --bs-table-striped-bg: rgba(243, 244, 248, 0.45);
    --bs-table-hover-bg: rgba(174, 179, 231, 0.08);
    color: var(--text-main);
}

.stats-table thead th {
    border-bottom: 1px solid var(--border);
    color: var(--primary);
    font-size: 0.95rem;
    font-weight: 700;
    padding: 16px 14px;
    white-space: nowrap;
    background: transparent;
}

.stats-table tbody td {
    padding: 16px 14px;
    border-color: var(--border);
    vertical-align: middle;
}

.stats-table tbody tr:last-child td {
    border-bottom: 0;
}

.row-title {
    font-weight: 600;
    color: var(--text-main);
}

.row-title.strong {
    font-weight: 800;
}

.row-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.cell-main {
    font-weight: 700;
    color: var(--text-main);
}

.cell-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.accent {
    color: var(--accent);
}

/* ============================== */
/* ============================== */
/*      RESPONSIVE                */
/* ============================== */
/* ============================== */
@media (max-width: 991.98px) {
    .kpi-value,
    .metric-main {
        font-size: 1.8rem;
    }
}

@media (max-width: 575.98px) {
    .stats-page {
        padding-top: calc(var(--topbar-height) + 18px);
    }

    .stat-card {
        padding: 18px;
        border-radius: 16px;
    }

    .kpi-card {
        min-height: auto;
    }

    .kpi-icon {
        width: 52px;
        height: 52px;
        font-size: 1.5rem;
    }

    .kpi-value {
        font-size: 1.6rem;
    }

    .module-title {
        font-size: 1.05rem;
    }
}


/* ============================== */
/* ============================== */
/*      PRINT                      */
/* ============================== */
/* ============================== */
@media print {

    html,
    body {
        width: 100%;
        background: #ffffff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body {
        font-size: 10pt;
    }

    /* Masquer la barre fixe pour éviter la superposition */
    .topbar, .logout-btn {
        display: none !important;
    }

    .stats-page {
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }

    .container,
    .container-fluid {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Cartes */
    .stat-card,
    .chart-card,
    .table-card {
        background: #ffffff !important;
        box-shadow: none !important;
        border: 1px solid #d8deea !important;
        border-radius: 14px !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        position: relative !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .stat-card {
        padding: 8mm !important;
    }

    .chart-card {
        min-height: auto !important;
    }

    .chartjs-donut-wrapper {
        max-width: 180px !important;
        margin: 0 auto 14px auto !important;
    }

    .chart-center-label span {
        font-size: 2rem !important;
    }

    .custom-legend {
        justify-content: center !important;
        gap: 10px 14px !important;
        font-size: 0.95rem !important;
    }

    .lienListing {
        display:none;
    }

    .chart-soldes-print {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    .chart-soldes-print .stat-card,
    .chart-soldes-print .chart-card,
    .chart-soldes-print .chartjs-soldes-wrapper,
    .chart-soldes-print > div,
    .chart-soldes-print canvas {
        width: 100% !important;
        max-width: 100% !important;
    }
}