/* ================= ORASS IA – ULTRA INSTITUTIONNEL ================= */

:root {
    --bg-primary: #0f1c2e;
    --bg-secondary: #14253d;
    --bg-card: #1c304f;

    /* Couleurs de marque en triplets "R,G,B" -> pilotables par le logo
       (extraction automatique, super-admin). Les surfaces utilisent
       rgb()/rgba(var(--brand-rgb)) afin de suivre la marque en direct. */
    --brand-rgb: 46,125,50;
    --gold-rgb: 200,169,76;
    --accent-primary: rgb(var(--brand-rgb));
    --accent-gold: rgb(var(--gold-rgb));

    --text-main: #f4f6fa;
    --text-soft: #9fb2c9;

    --positive: #2e7d32;
    --negative: #c62828;
}

/* ================= GLOBAL ================= */

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-main);
    letter-spacing: 0.3px;
}

.layout {
    display: flex;
    height: 100vh;
}

/* ================= SIDEBAR ================= */

.sidebar {
    width: 248px;
    background: linear-gradient(180deg, #14253d, #0f1c2e);
    padding: 16px 16px 12px;
    border-right: 1px solid rgba(255,255,255,0.06);
    /* Colonne : logo epingle en haut, menu defilant au milieu, footer en bas */
    display: flex;
    flex-direction: column;
    height: 100vh;
    box-sizing: border-box;
    overflow: hidden;
}

.logo-container {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
    flex: 0 0 auto;
}

.logo-img {
    width: 82px;
    height: auto;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--text-soft);
    text-decoration: none;
    padding: 14px 16px;
    border-radius: 8px;
    margin-bottom: 10px;
    transition: 0.25s ease;
    font-weight: 500;
}

.sidebar nav a:hover {
    background: rgba(var(--brand-rgb),0.12);
    color: var(--text-main);
}

/* ----- Menu lateral (ul.sidebar-menu) ----- */
.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    /* Seule zone defilante : le logo et le footer restent visibles */
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.18) transparent;
}

.sidebar-menu::-webkit-scrollbar {
    width: 6px;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.18);
    border-radius: 3px;
}

.sidebar-menu li {
    list-style: none;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--text-soft);
    text-decoration: none;
    padding: 5px 11px;
    border-radius: 7px;
    margin-bottom: 1px;
    font-weight: 500;
    font-size: 12.5px;
    transition: 0.2s ease;
}

.sidebar-menu a:hover {
    background: rgba(var(--brand-rgb),0.12);
    color: var(--text-main);
}

.sidebar-menu a.active {
    background: rgba(var(--brand-rgb),0.20);
    color: #ffffff;
    box-shadow: inset 3px 0 0 var(--accent-gold);
}

.sidebar-menu .menu-section {
    color: var(--accent-gold);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    opacity: 0.75;
    margin: 7px 0 2px;
    padding-left: 11px;
}

.sidebar-menu .menu-section:first-child {
    margin-top: 0;
}

.sidebar-footer {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.06);
    color: var(--text-soft);
    font-size: 11px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 0 0 auto;
}

/* ================= MAIN ================= */

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;            /* CLE : laisse .main retrecir -> evite l'etirement horizontal */
}

/* ================= HEADER ================= */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 40px;
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.topbar-left h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--accent-primary);
}

.topbar-subtitle {
    font-size: 13px;
    color: var(--text-soft);
}

/* ----- Cluster haut-droite : statut live + theme + utilisateur ----- */

.topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.live-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 13px;
    border-radius: 20px;
    background: rgba(var(--brand-rgb),0.12);
    border: 1px solid rgba(var(--brand-rgb),0.25);
    color: #81c784;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.6px;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #43d675;
    box-shadow: 0 0 0 0 rgba(67,214,117,0.6);
    animation: live-pulse 1.8s infinite;
}

@keyframes live-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(67,214,117,0.6); }
    70%  { box-shadow: 0 0 0 7px rgba(67,214,117,0); }
    100% { box-shadow: 0 0 0 0 rgba(67,214,117,0); }
}

.theme-toggle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.04);
    color: var(--text-main);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s ease;
}

.theme-toggle:hover {
    background: rgba(255,255,255,0.10);
    border-color: rgba(255,255,255,0.22);
}

.badge-live {
    background: rgba(var(--brand-rgb),0.15);
    color: var(--accent-primary);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

/* ================= CONTENT ================= */

.content {
    padding: 50px;
    overflow-x: hidden;      /* filet : pas de scroll horizontal au niveau page */
    overflow-y: auto;
    min-width: 0;
}

/* ================= KPI ================= */

.kpi-container {
    display: flex;
    flex-wrap: wrap;            /* les cartes passent a la ligne si trop nombreuses */
    gap: 20px;
    margin-bottom: 40px;
}

.kpi-card {
    flex: 1 1 210px;           /* base 210px, partage l'espace, jamais ecrase */
    min-width: 0;
    padding: 22px 20px;
    border-radius: 14px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.05);
    position: relative;
    overflow: hidden;
    transition: 0.2s ease;
}

.kpi-card:hover {
    background: #22395a;
}

.kpi-card h4 {
    margin: 0;
    font-size: 12px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-soft);
}

.kpi-card h2 {
    margin-top: 10px;
    font-size: clamp(15px, 1.3vw, 22px);   /* s'adapte : ne deborde plus de la carte */
    font-weight: 600;
    line-height: 1.15;
    /* Montant affiché EN ENTIER : les séparateurs de milliers fr-FR sont
       insécables, donc le nombre ne se coupe jamais ; seul « FCFA » peut
       passer à la ligne si la place manque. Plus de troncature « … ». */
    white-space: normal;
    overflow-wrap: normal;
    word-break: keep-all;
}

/* Ligne intelligente animée */

.kpi-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    height: 2px;
    width: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        var(--accent-gold),
        transparent
    );
    animation: smartSlide 4s ease-in-out infinite;
    opacity: 0.8;
}

.kpi-card.positive::before {
    background: linear-gradient(
        90deg,
        transparent,
        var(--positive),
        transparent
    );
}

.kpi-card.negative::before {
    background: linear-gradient(
        90deg,
        transparent,
        var(--negative),
        transparent
    );
}

.kpi-card.positive h2 {
    color: var(--positive);
}

.kpi-card.negative h2 {
    color: var(--negative);
}

/* ===== Pilotage stratégique : sections + cartes à statut (feu tricolore) ===== */

.pilot-section {
    margin-bottom: 28px;
}

.pilot-section-title {
    margin: 0 0 14px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: 0.3px;
}

/* Couleur d'alerte (ambre franc, plus lisible que le doré --accent-gold). */
:root { --warn-amber: #e08c00; }

/* Pas de filet doré animé sur le cockpit : il parasitait le code couleur. */
.pilot-card::before { display: none; animation: none; }

.pilot-card .kpi-hint {
    margin: 8px 0 0;
    font-size: 11px;
    color: var(--text-soft);
    white-space: normal;
}

.pilot-dot {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-soft);
}

/* Contour coloré selon le statut (1px tout autour + barre gauche 4px).
   !important : doit gagner sur l'override de bordure du thème clair/sombre,
   plus spécifique (html[data-theme] .kpi-card). Les cartes NEUTRES gardent
   la bordure discrète du thème. */
.pilot-ok   { border: 1px solid rgba(46, 125, 50, 0.45) !important;  border-left: 4px solid var(--positive) !important; }
.pilot-warn { border: 1px solid rgba(224, 140, 0, 0.55) !important;  border-left: 4px solid var(--warn-amber) !important; }
.pilot-bad  { border: 1px solid rgba(198, 40, 40, 0.45) !important;  border-left: 4px solid var(--negative) !important; }

.pilot-ok   .pilot-dot { background: var(--positive); }
.pilot-warn .pilot-dot { background: var(--warn-amber); }
.pilot-bad  .pilot-dot { background: var(--negative); }

.pilot-ok   h2 { color: var(--positive); }
.pilot-warn h2 { color: var(--warn-amber); }
.pilot-bad  h2 { color: var(--negative); }

/* ===== Zoom au survol + lumière défilante autour du cadre ===== */

/* Angle animable (necessaire pour faire tourner le degrade conique). */
@property --pilot-angle {
    syntax: "<angle>";
    initial-value: 0deg;
    inherits: false;
}

.pilot-card {
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

/* Zoom : la carte grossit et passe au-dessus de ses voisines. */
.pilot-card:hover {
    transform: scale(1.045);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
    z-index: 3;
}

/* Couleur de la lumiere : teintee selon le statut (neutre = bleu clair). */
.pilot-card    { --pilot-glow: rgba(120, 170, 255, 0.95); }
.pilot-ok      { --pilot-glow: rgba(56, 200, 90, 0.95); }
.pilot-warn    { --pilot-glow: rgba(245, 170, 30, 0.98); }
.pilot-bad     { --pilot-glow: rgba(240, 70, 70, 0.98); }

/* Lumiere defilante : degrade conique tournant, masque sur le seul pourtour. */
.pilot-card::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 14px;
    padding: 2px;                 /* epaisseur du filet lumineux */
    background: conic-gradient(
        from var(--pilot-angle),
        transparent 0deg,
        transparent 295deg,
        var(--pilot-glow) 340deg,
        transparent 360deg
    );
    -webkit-mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    mask-composite: exclude;
    animation: pilotSweep 3.5s linear infinite;
    pointer-events: none;
    z-index: 1;
}

/* Au survol : la lumiere accelere. */
.pilot-card:hover::after { animation-duration: 1.6s; }

@keyframes pilotSweep {
    to { --pilot-angle: 360deg; }
}

/* Respect des preferences d'accessibilite : pas d'animation si demande. */
@media (prefers-reduced-motion: reduce) {
    .pilot-card::after { animation: none; }
    .pilot-card:hover { transform: none; }
}

/* Panneau de saisie solvabilité, repliable, intégré au cockpit */

.solv-panel {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 14px;
    margin-bottom: 28px;
    overflow: hidden;
}

.solv-panel > summary {
    cursor: pointer;
    padding: 16px 20px;
    font-weight: 600;
    color: var(--text-main);
    list-style: none;
}

.solv-panel > summary::-webkit-details-marker { display: none; }
.solv-panel > summary::before { content: "▸ "; color: var(--accent-gold); }
.solv-panel[open] > summary::before { content: "▾ "; }

.solv-body { padding: 0 20px 20px; }

.solv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin: 14px 0 18px;
}

.solv-grid label {
    display: block;
    font-size: 12px;
    color: var(--text-soft);
    margin-bottom: 4px;
}

.solv-grid input { width: 100%; }

.solv-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

@keyframes smartSlide {
    0% { left: -100%; }
    50% { left: 100%; }
    100% { left: 100%; }
}

/* ================= FILTRE ================= */

.glass-card {
    background: rgba(28, 48, 79, 0.85);
    border-radius: 16px;
    padding: 30px;
    border: 1px solid rgba(255,255,255,0.06);
}

.card-filter {
    background: transparent;
    padding: 0;
}

.card-filter select,
.card-filter input {
    background: #203552;
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 6px;
}

/* ================= SYNTHÈSE IA ================= */

.card-section {
    margin-top: 40px;
    position: relative;
    padding-left: 35px;
}

.card-section::before {
    content: "";
    position: absolute;
    left: 15px;
    top: 30px;
    bottom: 30px;
    width: 3px;
    background: var(--accent-gold);
    border-radius: 2px;
    opacity: 0.7;
}

.commentaire {
    font-size: 15px;
    line-height: 1.7;
}

/* ================= CHARTS ================= */

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-top: 50px;
}

.chart-card {
    background: var(--bg-card);
    padding: 35px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.05);
    transition: 0.2s ease;
    display: flex;
    flex-direction: column;
    height: 440px;            /* hauteur fixe -> Chart.js remplit, sans s'etirer */
}

.chart-card:hover {
    background: #22395a;
}

.chart-card h3 {
    margin-bottom: 20px;
    font-size: 15px;
    color: var(--accent-gold);
}

.chart-card canvas {
    flex: 1 1 auto;
    min-height: 0;            /* indispensable pour que le flex contraigne la hauteur */
}

/* Conteneur graphique generique (pages CA / rentabilite)
   IMPORTANT : hauteur FIXE sur le conteneur, aucune taille sur le <canvas>.
   C'est la regle Chart.js pour le responsive : sinon le graphe s'etire a l'infini. */
.chart-container {
    position: relative;
    width: 100%;
    height: 400px;
    overflow: hidden;          /* filet de securite : le conteneur ne s'agrandit jamais */
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 14px;
    padding: 16px;
    margin-top: 18px;
}

/* ================= BUTTONS ================= */

button {
    background: var(--accent-primary);
    border: none;
    padding: 12px 26px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    color: white;
    cursor: pointer;
    transition: 0.2s ease;
}

button:hover {
    background: #256728;
}

/* ================= LOADER ================= */

.loader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    visibility: hidden;
    opacity: 0;
    transition: 0.3s ease;
}

.loader-overlay.active {
    visibility: visible;
    opacity: 1;
}

.loader-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

/* Loader de MARQUE (white-label) : logo de la compagnie centré (pulse doux,
   ne tourne pas → reste lisible) + anneau à la couleur de marque qui tourne
   autour. Aligné sur le loader d'ORIZON Connect (souscription). */
.brand-loader {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 92px;
    height: 92px;
}
.brand-loader::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid rgba(var(--brand-rgb), .18);
    border-top-color: rgb(var(--brand-rgb));
    animation: spin .85s linear infinite;
}
.brand-loader img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    /* Pastille blanche : le logo reste lisible sur le voile sombre. */
    background: #fff;
    border-radius: 50%;
    padding: 8px;
    box-shadow: 0 4px 14px rgba(0,0,0,.18);
    animation: bl-pulse 1.3s ease-in-out infinite;
}
@keyframes bl-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: .6; transform: scale(.92); }
}

/* Ancien spinner simple (conservé pour les boutons occupés, etc.). */
.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(255,255,255,0.1);
    border-top: 5px solid var(--accent-gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .brand-loader::before, .brand-loader img, .spinner { animation: none; }
}

/* ================= TITRE DE PAGE ================= */

.page-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 24px;
    color: var(--text-main);
}

/* ================= FILTRE (grille responsive) ================= */

.filter-grid {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    padding: 18px 20px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.06);
}

.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-soft);
    font-size: 14px;
}

/* ================= BANDEAU INFO / APERCU ================= */

.commentaire-box {
    background: rgba(var(--brand-rgb),0.10);
    border: 1px solid rgba(var(--brand-rgb),0.25);
    color: var(--text-main);
    padding: 12px 16px;
    border-radius: 10px;
    margin: 18px 0;
    font-size: 14px;
    line-height: 1.5;
}

/* ================= TABLEAUX DE DONNEES ================= */

.table-container {
    margin-top: 18px;
    max-height: 70vh;
    overflow: auto;                       /* scroll horizontal + vertical */
    -webkit-overflow-scrolling: touch;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    background: var(--bg-card);
}

/* Conteneur scrollable : si le tableau est plus large que le card, il défile
   à l'intérieur (la colonne ACTIONS reste atteignable) sans casser la page. */
.table-scroll {
    overflow-x: auto;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13.5px;
}

.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-secondary);
    color: var(--accent-gold);
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    padding: 12px 13px;
    white-space: nowrap;
    border-bottom: 2px solid rgba(var(--gold-rgb),0.35);
}

.data-table tbody td {
    padding: 10px 13px;
    white-space: nowrap;                  /* une ligne par cellule -> scroll horizontal propre */
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: var(--text-main);
}

.data-table tbody tr:nth-child(even) {
    background: rgba(255,255,255,0.025);
}

.data-table tbody tr:hover {
    background: rgba(var(--brand-rgb),0.12);
}

.data-table tbody td:first-child {
    font-weight: 500;
}

.data-table td.number,
.data-table th.number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Ligne Total : figee en bas du conteneur */
.data-table tr.total-row td {
    position: sticky;
    bottom: 0;
    z-index: 1;
    background: #20406a;
    color: #ffffff;
    font-weight: 700;
    white-space: nowrap;
    border-top: 2px solid rgba(var(--gold-rgb),0.5);
}

/* ----- Pagination (liste des comptes, et tables paginées) ----- */
.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    margin-top: 14px;
}
.pager-info {
    font-size: 12.5px;
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
}
.pager-btn {
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    padding: 8px 14px;
    border-radius: 9px;
    cursor: pointer;
    color: var(--c-accent);
    background: rgba(var(--brand-rgb), 0.10);
    border: 1px solid rgba(var(--brand-rgb), 0.30);
    transition: 0.15s ease;
}
.pager-btn:hover:not(:disabled) { background: rgba(var(--brand-rgb), 0.18); }
.pager-btn:disabled { opacity: 0.45; cursor: not-allowed; }
html[data-theme="dark"] .pager-btn {
    color: color-mix(in srgb, rgb(var(--brand-rgb)) 55%, white);
}

.empty-state {
    padding: 30px;
    text-align: center;
    color: var(--text-soft);
}

/* ================= RESPONSIVE ================= */

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

    .kpi-container {
        flex-wrap: wrap;
    }

    .kpi-card {
        flex: 1 1 45%;
    }
}

@media (max-width: 992px) {
    .layout {
        flex-direction: column;
        height: auto;
    }

    .sidebar {
        width: auto;
        padding: 16px 20px;
        border-right: none;
        border-bottom: 1px solid rgba(255,255,255,0.08);
        /* Sur mobile la sidebar s'empile au-dessus du contenu : pas de hauteur fixe */
        height: auto;
        overflow: visible;
    }

    .logo-container {
        margin-bottom: 16px;
    }

    .sidebar-menu {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        overflow: visible;
    }

    .sidebar-menu a {
        margin-bottom: 0;
    }

    .sidebar-menu .menu-section {
        width: 100%;
        margin: 10px 0 2px;
    }

    .sidebar-footer {
        display: none;
    }

    .content {
        padding: 25px;
        overflow: visible;
    }

    .filter-grid {
        gap: 8px;
        padding: 14px;
    }

    .filter-grid input,
    .filter-grid select,
    .filter-grid button {
        flex: 1 1 auto;
    }

    .data-table {
        font-size: 12.5px;
    }

    .data-table thead th,
    .data-table tbody td {
        padding: 9px 10px;
    }

    .table-container {
        max-height: 65vh;
    }

    .chart-container {
        height: 300px;
    }

    .chart-card {
        height: 360px;
    }
}


/* ================================================================= */
/* ================= AUTH / COMPTES / PARAMETRES =================== */
/* ================================================================= */

/* ---------- Page de connexion ---------- */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background:
        radial-gradient(720px 380px at 50% -6%, rgba(var(--gold-rgb), .16), transparent 60%),
        radial-gradient(circle at 30% 20%, #1c304f, #0f1c2e 70%);
}

.login-card {
    position: relative;
    overflow: hidden;
    width: 384px;
    max-width: 92vw;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 18px;
    padding: 42px 36px 28px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.45);
}

.login-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 5px;
    background: linear-gradient(90deg, rgb(var(--brand-rgb)), rgb(var(--gold-rgb)));
}

.login-brand {
    text-align: center;
    margin-bottom: 6px;
}

.login-logo {
    box-sizing: border-box;
    display: block;
    width: 162px;
    height: auto;
    margin: 2px auto 16px;
    background: #fff;
    padding: 10px 16px;
    border-radius: 14px;
    box-shadow: 0 8px 22px rgba(0,0,0,0.28);
}

.login-sep {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 22px 0 18px;
}
.login-sep::before, .login-sep::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgba(255,255,255,0.12);
}
.login-sep span {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-soft);
}

.login-brand h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-primary);
}

.login-brand p {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--text-soft);
}

.login-form label {
    display: block;
    margin-bottom: 16px;
}

.login-form label span {
    display: block;
    font-size: 12px;
    color: var(--text-soft);
    margin-bottom: 6px;
}

.login-form input {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.12);
    background: var(--bg-secondary);
    color: var(--text-main);
    font-size: 14px;
}

.login-form input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.login-btn {
    width: 100%;
    margin-top: 8px;
    padding: 13px;
    border: none;
    border-radius: 8px;
    background: var(--accent-primary);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s ease;
}

.login-btn:hover {
    filter: brightness(1.1);
}

.login-error {
    background: rgba(198,40,40,0.15);
    border: 1px solid rgba(198,40,40,0.4);
    color: #ff8a80;
    padding: 11px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 20px;
    text-align: center;
}

.login-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 11px;
    color: var(--text-soft);
}

/* ---------- Badge utilisateur (topbar) ---------- */

.user-menu {
    position: relative;
}

/* Le badge est un <button> : on neutralise le style bouton global. */
.user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 10px;
    transition: 0.2s ease;
    background: transparent;
    border: none;
    color: inherit;
    font-family: inherit;
    cursor: pointer;
}

.user-badge:hover {
    background: rgba(255,255,255,0.06);
}

.user-caret {
    color: var(--text-soft);
    font-size: 12px;
    margin-left: 2px;
    transition: transform 0.2s ease;
}

.user-badge[aria-expanded="true"] .user-caret {
    transform: rotate(180deg);
}

/* ----- Menu déroulant ----- */
.user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 210px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.35);
    padding: 6px;
    z-index: 1000;
    display: none;
}

.user-dropdown.open {
    display: block;
}

.user-dropdown a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 13px;
    border-radius: 8px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 14px;
    transition: 0.15s ease;
}

.user-dropdown a:hover {
    background: rgba(var(--brand-rgb),0.14);
}

.user-dropdown a.danger {
    color: #ff8a80;
    margin-top: 4px;
    border-top: 1px solid rgba(255,255,255,0.08);
    border-radius: 0 0 8px 8px;
}

.user-dropdown a.danger:hover {
    background: rgba(198,40,40,0.15);
}

html[data-theme="light"] .user-badge:hover {
    background: rgba(0,0,0,0.05);
}
html[data-theme="light"] .user-dropdown {
    border-color: rgba(0,0,0,0.1);
    box-shadow: 0 12px 32px rgba(0,0,0,0.15);
}
html[data-theme="light"] .user-dropdown a.danger {
    border-top-color: rgba(0,0,0,0.08);
}

.user-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
}

.user-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;   /* nom / rôle / puce parfaitement alignés à gauche */
    gap: 3px;                  /* rythme vertical régulier */
    line-height: 1.2;
}

.user-name {
    color: var(--text-main);
    font-size: 13px;
    font-weight: 600;
}

.user-role {
    color: var(--text-soft);
    font-size: 11px;
}

/* Puce « localité » du bureau (responsable de bureau) — via tokens de marque. */
.user-bureau {
    margin-top: 1px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10.5px;
    font-weight: 650;
    letter-spacing: 0.2px;
    padding: 2px 9px;
    border-radius: 20px;
    color: var(--c-accent);
    background: rgba(var(--brand-rgb), 0.12);
    border: 1px solid rgba(var(--brand-rgb), 0.28);
}
/* Sombre : le vert de marque brut est trop foncé sur fond sombre -> on
   l'ÉCLAIRCIT (color-mix garde le white-label : ça éclaircit N'IMPORTE quelle marque). */
html[data-theme="dark"] .user-bureau {
    color: color-mix(in srgb, rgb(var(--brand-rgb)) 55%, white);
    background: rgba(var(--brand-rgb), 0.20);
    border-color: rgba(var(--brand-rgb), 0.42);
}

/* ---------- En-tete de page ---------- */

.page-header {
    margin-bottom: 28px;
}

.page-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-main);
}

.page-subtitle {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--text-soft);
}

/* ---------- Cartes generiques ---------- */

.card {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 14px;
    padding: 26px 28px;
    margin-bottom: 26px;
}

.card h3 {
    margin: 0 0 20px;
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-gold);
}

/* ---------- Formulaires ---------- */

.form-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 460px;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px 24px;
    max-width: 760px;
}

.form-grid label {
    display: flex;
    flex-direction: column;
}

.form-grid label span {
    font-size: 12px;
    color: var(--text-soft);
    margin-bottom: 6px;
}

.form-grid input,
.form-grid select {
    padding: 11px 13px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.12);
    background: var(--bg-secondary);
    color: var(--text-main);
    font-size: 14px;
}

.form-grid input:focus,
.form-grid select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* ----- Champ mot de passe avec oeil (afficher / masquer) ----- */
.pwd-wrap { position: relative; display: block; }
.pwd-wrap input { width: 100%; box-sizing: border-box; padding-right: 42px; }
.pwd-eye {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: none; border: 0; cursor: pointer; font-size: 17px; line-height: 1;
    padding: 4px 6px; opacity: 0.6; border-radius: 6px; color: inherit;
}
.pwd-eye:hover { opacity: 1; }
.pwd-eye:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 1px; }

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    align-items: flex-end;
}

.btn-primary {
    padding: 12px 22px;
    border: none;
    border-radius: 8px;
    background: var(--accent-primary);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s ease;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.form-msg {
    margin-top: 14px;
    font-size: 13px;
    min-height: 18px;
}

.form-msg.success {
    color: #81c784;
}

.form-msg.error {
    color: #ff8a80;
}

/* ---------- Profil ---------- */

.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 22px;
}

.profile-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.profile-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-soft);
}

.profile-value {
    font-size: 15px;
    color: var(--text-main);
    font-weight: 500;
}

/* ---------- Badges profil / statut ---------- */

.badge-role,
.badge-status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    width: fit-content;
}

.badge-admin              { background: rgba(var(--gold-rgb),0.18);  color: var(--accent-gold); }
.badge-direction_generale { background: rgba(var(--gold-rgb),0.14);  color: #e0c878; }
.badge-production         { background: rgba(var(--brand-rgb),0.18);   color: #81c784; }
.badge-sinistres          { background: rgba(33,150,243,0.16);  color: #64b5f6; }
.badge-finance            { background: rgba(156,39,176,0.16);  color: #ce93d8; }
.badge-commercial         { background: rgba(255,152,0,0.16);   color: #ffb74d; }
.badge-consultation       { background: rgba(159,178,201,0.15); color: var(--text-soft); }

.badge-status.active   { background: rgba(var(--brand-rgb),0.18);  color: #81c784; }
.badge-status.inactive { background: rgba(198,40,40,0.18);  color: #ff8a80; }

/* ---------- Actions dans le tableau des comptes ---------- */

.row-actions {
    display: flex;
    justify-content: flex-end;
}
.act-wrap { position: relative; }

/* Menu déroulant d'actions (positionné en fixed par le JS -> jamais clippé). */
.act-menu {
    position: fixed;
    display: none;
    flex-direction: column;
    gap: 2px;
    min-width: 170px;
    padding: 6px;
    background: var(--bg-card);
    border: 1px solid rgba(128,128,128,0.25);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.28);
    z-index: 9999;
}
.act-menu.open { display: flex; }
.act-item {
    text-align: left;
    padding: 8px 12px;
    border: 0;
    background: transparent;
    color: var(--text-main);
    font: inherit;
    font-size: 13px;
    border-radius: 7px;
    cursor: pointer;
    white-space: nowrap;
}
.act-item:hover { background: rgba(var(--brand-rgb), 0.12); }
.act-item.danger { color: var(--negative); }
.act-item.danger:hover { background: rgba(216,0,0,0.12); }

.btn-mini {
    padding: 6px 10px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-main);
    font-size: 12px;
    white-space: nowrap;        /* pas de retour à la ligne dans le bouton */
    cursor: pointer;
    transition: 0.2s ease;
}

.btn-mini:hover {
    border-color: var(--accent-primary);
}

.btn-mini.danger:hover {
    border-color: var(--negative);
    color: #ff8a80;
}

.role-select {
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.12);
    background: var(--bg-secondary);
    color: var(--text-main);
    font-size: 13px;
}

.table-empty {
    text-align: center;
    color: var(--text-soft);
    padding: 22px;
}

/* ---------- Page 403 (acces refuse) ---------- */

.access-denied {
    text-align: center;
    max-width: 520px;
    margin: 40px auto;
    padding: 44px 40px;
}

.access-denied-icon {
    font-size: 52px;
    margin-bottom: 8px;
}

.access-denied h2 {
    margin: 0 0 14px;
    color: var(--text-main);
}

.access-denied p {
    color: var(--text-soft);
    line-height: 1.6;
}

.access-denied .btn-primary {
    display: inline-block;
    margin-top: 22px;
    text-decoration: none;
}

@media (max-width: 720px) {
    .form-grid-2 {
        grid-template-columns: 1fr;
    }
}


/* ================================================================= */
/* ========================== COPILOT ============================== */
/* ================================================================= */

.copilot-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 900px;
    height: calc(100vh - 230px);
    min-height: 420px;
}

.copilot-chat {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 4px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.msg {
    display: flex;
    gap: 12px;
    max-width: 85%;
}

.msg-bot { align-self: flex-start; }
.msg-user { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.08);
}

.msg-user .msg-avatar {
    background: var(--accent-primary);
    color: #fff;
    border: none;
    font-weight: 700;
}

.msg-bubble {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    padding: 13px 16px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text-main);
}

.msg-user .msg-bubble {
    background: rgba(var(--brand-rgb),0.18);
    border-color: rgba(var(--brand-rgb),0.3);
}

.msg-bubble.bubble-warn {
    background: rgba(200,80,40,0.12);
    border-color: rgba(200,80,40,0.3);
    color: #ffb59a;
}

.msg-meta {
    margin-top: 8px;
    padding-top: 7px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 11px;
    color: var(--text-soft);
}

/* Indicateur de saisie (points animés) */
.typing { display: inline-flex; gap: 4px; }
.typing i {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--text-soft);
    animation: typing-blink 1.2s infinite both;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-blink {
    0%, 80%, 100% { opacity: 0.25; }
    40% { opacity: 1; }
}

.copilot-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0 12px;
}

.suggestion {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text-soft);
    padding: 7px 13px;
    border-radius: 20px;
    font-size: 12.5px;
    cursor: pointer;
    transition: 0.2s ease;
}
.suggestion:hover {
    border-color: var(--accent-primary);
    color: var(--text-main);
}

.copilot-input {
    display: flex;
    gap: 10px;
    padding-top: 6px;
}

.copilot-input input {
    flex: 1 1 auto;
    padding: 13px 16px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.12);
    background: var(--bg-secondary);
    color: var(--text-main);
    font-size: 14px;
}
.copilot-input input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.copilot-input button {
    padding: 0 24px;
    border: none;
    border-radius: 10px;
    background: var(--accent-primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}
.copilot-input button:disabled { opacity: 0.6; cursor: default; }

/* Graphique dans une bulle de réponse */
.msg-chart {
    margin-top: 12px;
    width: min(520px, 68vw);
    height: 240px;
    background: var(--bg-secondary);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 10px;
    padding: 10px 12px;
    position: relative;
}
html[data-theme="light"] .msg-chart {
    border-color: rgba(0,0,0,0.1);
}

/* Surfaces claires pour le copilot */
html[data-theme="light"] .msg-avatar,
html[data-theme="light"] .msg-bubble {
    border-color: rgba(0,0,0,0.1);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
html[data-theme="light"] .suggestion {
    background: rgba(0,0,0,0.03);
    border-color: rgba(0,0,0,0.15);
}
html[data-theme="light"] .copilot-input input {
    border-color: rgba(0,0,0,0.15);
}
html[data-theme="light"] .msg-meta {
    border-top-color: rgba(0,0,0,0.1);
}


/* ================================================================= */
/* ======================= THEME CLAIR ============================= */
/* ================================================================= */
/* Active via <html data-theme="light"> (bouton 🌙 / ☀️, memorise).  */
/* La majorite des composants utilisent les variables CSS : on       */
/* surcharge la palette + les rares surfaces codees "en dur".         */

html[data-theme="light"] {
    --bg-primary: #eef1f6;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --accent-primary: rgb(var(--brand-rgb));
    --gold-rgb: 154,125,46;   /* dore plus fonce -> lisible sur fond clair */
    --text-main: #1b2737;
    --text-soft: #5d6b7e;
    --positive: #2e7d32;
    --negative: #c62828;

    color-scheme: light;
}

/* ----- Surfaces structurelles ----- */

html[data-theme="light"] .sidebar {
    background: linear-gradient(180deg, #ffffff, #eef1f6);
    border-right: 1px solid rgba(0,0,0,0.08);
}

html[data-theme="light"] .sidebar-footer {
    border-top: 1px solid rgba(0,0,0,0.08);
}

html[data-theme="light"] .topbar {
    border-bottom: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

html[data-theme="light"] .theme-toggle {
    border: 1px solid rgba(0,0,0,0.12);
    background: rgba(0,0,0,0.04);
}
html[data-theme="light"] .theme-toggle:hover {
    background: rgba(0,0,0,0.08);
    border-color: rgba(0,0,0,0.2);
}

html[data-theme="light"] .user-badge:hover {
    background: rgba(0,0,0,0.05);
}

/* ----- Cartes / conteneurs (bordures + ombres) ----- */

html[data-theme="light"] .card,
html[data-theme="light"] .kpi-card,
html[data-theme="light"] .chart-card,
html[data-theme="light"] .chart-container,
html[data-theme="light"] .filter-grid,
html[data-theme="light"] .table-container {
    border: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

html[data-theme="light"] .glass-card {
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.08);
}

html[data-theme="light"] .kpi-card:hover,
html[data-theme="light"] .chart-card:hover {
    background: #f6f8fb;
}

/* ----- Champs de saisie ----- */

html[data-theme="light"] .card-filter select,
html[data-theme="light"] .card-filter input {
    background: #f6f8fb;
    border: 1px solid rgba(0,0,0,0.15);
    color: var(--text-main);
}

/* ----- Tableaux ----- */

html[data-theme="light"] .data-table tbody td {
    border-bottom: 1px solid rgba(0,0,0,0.06);
}

html[data-theme="light"] .data-table tbody tr:nth-child(even) {
    background: rgba(0,0,0,0.025);
}

html[data-theme="light"] .data-table tbody tr:hover {
    background: rgba(var(--brand-rgb),0.10);
}

html[data-theme="light"] .data-table tr.total-row td {
    background: #e4ecf5;
    color: var(--text-main);
}

/* ----- Page de connexion ----- */

html[data-theme="light"] .login-body {
    background: radial-gradient(circle at 30% 20%, #ffffff, #e7edf4 70%);
}

html[data-theme="light"] .login-card {
    border: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 25px 60px rgba(0,0,0,0.12);
}

/* Champs de saisie bien VISIBLES en thème clair (bordure grise nette) */
html[data-theme="light"] .login-form input,
html[data-theme="light"] .form-grid input,
html[data-theme="light"] .form-grid select {
    border-color: var(--input-border);   /* token (= #c3cede en clair) */
    background: var(--input-bg);
    color: #16324c;
}
html[data-theme="light"] .login-form input:focus,
html[data-theme="light"] .form-grid input:focus,
html[data-theme="light"] .form-grid select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.15);
}
html[data-theme="light"] .login-form input::placeholder,
html[data-theme="light"] .form-grid input::placeholder {
    color: #9aa7b8;
}

/* ----- Scrollbar du menu ----- */

html[data-theme="light"] .sidebar-menu {
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}
html[data-theme="light"] .sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
}

/* ================= ALERTE GRANDS SINISTRES (> 10 victimes) ================= */
/* Rouge sémantique (alerte), volontairement indépendant de la marque. */

.gs-alert {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 0 0 18px;
    padding: 16px 20px;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(198,40,40,0.18), rgba(198,40,40,0.06));
    border: 1px solid rgba(198,40,40,0.55);
    border-left: 6px solid #c62828;
    color: var(--text-main);
    cursor: pointer;
    transition: 0.2s ease;
    animation: gsPulse 2.2s ease-in-out infinite;
}
.gs-alert:hover { transform: translateY(-1px); background: linear-gradient(135deg, rgba(198,40,40,0.28), rgba(198,40,40,0.10)); }
.gs-alert-ico { font-size: 26px; line-height: 1; }
.gs-alert-txt { display: flex; flex-direction: column; flex: 1 1 auto; }
.gs-alert-txt strong { font-size: 15px; color: #ff6b6b; }
.gs-alert-txt small { color: var(--text-soft); margin-top: 2px; }
.gs-alert-cta { font-weight: 600; color: #ff6b6b; white-space: nowrap; }

@keyframes gsPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(198,40,40,0.0); }
    50%      { box-shadow: 0 0 0 4px rgba(198,40,40,0.18); }
}

html[data-theme="light"] .gs-alert-txt strong,
html[data-theme="light"] .gs-alert-cta { color: #c62828; }

/* ----- Modal de détail ----- */
.gs-modal-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(8,15,26,0.62);
    align-items: center; justify-content: center;
    padding: 30px;
}
.gs-modal {
    background: var(--bg-secondary);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 14px;
    width: min(1200px, 96vw);
    max-height: 88vh;
    display: flex; flex-direction: column;
    box-shadow: 0 30px 80px rgba(0,0,0,0.45);
}
.gs-modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 22px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.gs-modal-head h3 { margin: 0; font-size: 16px; color: #ff6b6b; }
html[data-theme="light"] .gs-modal-head h3 { color: #c62828; }
.gs-modal-head-actions { display: flex; align-items: center; gap: 14px; }
.gs-modal-export {
    display: inline-flex; align-items: center; gap: 6px;
    background: #1D6F42; color: #fff;
    font-size: 12.5px; font-weight: 600; text-decoration: none;
    padding: 8px 14px; border-radius: 8px;
    transition: background .15s ease, transform .05s ease;
}
.gs-modal-export:hover { background: #185c37; }
.gs-modal-export:active { transform: translateY(1px); }
/* Export des victimes (période) : bleu, pour le distinguer de l'export des dossiers */
.gs-modal-export-vic { background: #1b6f8f; }
.gs-modal-export-vic:hover { background: #155b76; }
.gs-modal-close {
    background: transparent; border: none; color: var(--text-soft);
    font-size: 20px; cursor: pointer; line-height: 1;
}
.gs-modal-close:hover { color: var(--text-main); }
.gs-modal-body { padding: 14px 18px; overflow: auto; }
.gs-modal-body .data-table { font-size: 12px; }

/* Sous-modal « Victimes » : au-dessus du modal des grands sinistres */
.gs-vic-overlay { z-index: 1001; }
.gs-vic-btn {
    display: inline-flex; align-items: center; gap: 4px;
    background: rgba(var(--brand-rgb), 0.14); color: var(--text-main);
    border: 1px solid rgba(var(--brand-rgb), 0.35);
    font-size: 11.5px; font-weight: 600; cursor: pointer;
    padding: 4px 10px; border-radius: 6px; white-space: nowrap;
}
.gs-vic-btn:hover { background: rgba(var(--brand-rgb), 0.26); }

/* ===== Drill-down universel (double-clic) ===== */
.dd-modal-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 10000;
    background: rgba(8,15,26,0.62);
    align-items: center; justify-content: center;
    padding: 30px;
}
.dd-modal {
    background: var(--bg-secondary);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 14px;
    width: min(1200px, 96vw);
    max-height: 88vh;
    display: flex; flex-direction: column;
    box-shadow: 0 30px 80px rgba(0,0,0,0.45);
}
.dd-modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 22px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.dd-modal-head h3 { margin: 0; font-size: 16px; color: var(--text-main); }
.dd-modal-actions { display: flex; align-items: center; gap: 14px; }
.dd-export {
    display: inline-flex; align-items: center; gap: 6px;
    background: #1D6F42; color: #fff; border: none;
    font-size: 12.5px; font-weight: 600; cursor: pointer;
    padding: 8px 14px; border-radius: 8px;
    transition: background .15s ease, transform .05s ease;
}
.dd-export:hover { background: #185c37; }
.dd-export:active { transform: translateY(1px); }
.dd-close {
    background: transparent; border: none; color: var(--text-soft);
    font-size: 20px; cursor: pointer; line-height: 1;
}
.dd-close:hover { color: var(--text-main); }
.dd-modal-body { padding: 14px 18px; overflow: auto; }
.dd-modal-body .data-table { font-size: 12px; }
.dd-empty { color: var(--text-soft); padding: 20px; text-align: center; }

/* Indice visuel : cadres/tableaux « double-cliquables » */
.data-table, .kpi-card, .chart-card { cursor: zoom-in; }

/* Sélecteur d'intermédiaire (filtre de l'alerte) */
.gs-inter-filter { display: inline-flex; align-items: center; gap: 8px; }
.gs-inter-filter label { color: var(--text-soft); font-size: 12.5px; }


/* ================================================================= */
/* ====== RESPONSIVE MOBILE / TABLETTE — refonte (2026-07) ========= */
/* ------------------------------------------------------------------
   Principe : sur poste de travail rien ne change. En dessous de
   992 px la barre latérale devient un TIROIR hors-écran (ouvert par
   le bouton ☰), le contenu occupe toute la largeur, et plus aucun
   défilement horizontal de page n'est possible.
   ------------------------------------------------------------------ */

/* Garde-fou global : la page ne défile jamais latéralement.
   `overflow-x` doit être posé sur HTML aussi : un élément `position:fixed`
   (le voile) se dimensionne sur le bloc conteneur initial, qui suit la
   largeur du DOCUMENT — sans ce clamp, le moindre débordement s'auto-entretient. */
html, body { max-width: 100%; overflow-x: hidden; }

/* Bouton ☰ et voile : invisibles sur grand écran. */
.nav-toggle { display: none; }
.nav-overlay { display: none; }

@media (max-width: 992px) {

    /* --- 1) Mise en page : le contenu prend toute la largeur --------- */
    .layout { display: block; height: auto; }
    .main   { display: block; width: 100%; min-width: 0; }
    .content { padding: 16px 14px; overflow: visible; }

    /* --- 2) La barre latérale devient un tiroir hors-écran ----------- */
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0;
        width: 82vw; max-width: 310px; height: 100vh;
        display: block; overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px 14px;
        border-right: 1px solid rgba(255,255,255,0.10);
        border-bottom: none;
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 1200;
    }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.45); }
    .sidebar-menu { display: block; overflow: visible; }
    .sidebar-footer { display: block; }

    /* Voile sombre derrière le tiroir ouvert. */
    .nav-overlay {
        display: block; position: fixed; inset: 0;
        background: rgba(0,0,0,.55);
        opacity: 0; pointer-events: none;
        transition: opacity .25s ease; z-index: 1100;
    }
    .nav-overlay.show { opacity: 1; pointer-events: auto; }
    body.nav-open { overflow: hidden; }

    /* --- 3) Barre du haut : compacte, jamais débordante -------------- */
    .nav-toggle {
        display: inline-flex; align-items: center; justify-content: center;
        width: 44px; height: 44px; flex: 0 0 auto;
        background: rgba(var(--brand-rgb), .14);
        color: var(--text-main);
        border: 1px solid rgba(var(--brand-rgb), .40);
        border-radius: 10px; font-size: 20px; line-height: 1; cursor: pointer;
    }
    .nav-toggle:active { transform: scale(.96); }

    .topbar {
        flex-wrap: wrap; gap: 10px; padding: 10px 14px;
    }
    .topbar-left {
        display: flex; align-items: center; gap: 10px;
        flex: 1 1 auto; min-width: 0;
    }
    .topbar-left h1 {
        font-size: 17px; min-width: 0;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .topbar-subtitle { display: none; }
    .topbar-right { gap: 8px; flex: 0 0 auto; min-width: 0; }

    /* --- 4) Cibles tactiles (44 px minimum) ------------------------- */
    .sidebar-menu a { min-height: 44px; display: flex; align-items: center; }
    .filter-grid input,
    .filter-grid select,
    .filter-grid button,
    .theme-toggle, .user-badge { min-height: 44px; }

    /* --- 5) Filtres empilés en pleine largeur ------------------------ */
    .filter-grid { flex-direction: column; align-items: stretch; }
    .filter-grid input,
    .filter-grid select,
    .filter-grid button { width: 100%; flex: 1 1 auto; }
    .gs-inter-filter { width: 100%; flex-wrap: wrap; }
    .gs-inter-filter select { width: 100%; }

    /* --- 6) Tableaux : le défilement reste DANS le cadre ------------- */
    .table-container {
        overflow-x: auto; -webkit-overflow-scrolling: touch;
        max-height: none;
    }
    .data-table { min-width: 640px; }   /* lisible ; scroll horizontal contenu */

    /* --- 7) Graphiques ---------------------------------------------- */
    .charts-grid { grid-template-columns: 1fr; }
    .chart-container { height: 260px; }
    .chart-card { height: 320px; }

    /* Un enfant de grille/flex ne rétrécit pas sous son contenu par défaut
       (min-width:auto) : c'est la cause classique des quelques pixels de
       débordement. On l'autorise explicitement. */
    .charts-section, .charts-grid, .charts-grid > *,
    .chart-card, .chart-container, .card-section, .kpi-card {
        min-width: 0; max-width: 100%;
    }
    canvas { max-width: 100% !important; }

    /* Libellés de menu longs : on les laisse passer à la ligne dans le tiroir. */
    .sidebar-menu a { white-space: normal; }

    /* Largeur 100 % + padding + bordure => débordement si le modèle de boîte
       n'inclut pas les marges internes. On le force sur les éléments étirés. */
    .filter-grid, .filter-grid > *,
    .filter-grid input, .filter-grid select, .filter-grid button,
    .sidebar-menu, .sidebar-menu li, .sidebar-menu a,
    .card-section, .card-filter, .chart-card, .chart-container {
        box-sizing: border-box; max-width: 100%; min-width: 0;
    }
    .sidebar-menu a { overflow-wrap: anywhere; }

    /* --- 8) Formulaires hors filtres (comptes, solvabilité, objectifs…) --
       Mêmes exigences tactiles que les filtres : 44 px de hauteur utile. */
    .content input:not([type="checkbox"]):not([type="radio"]),
    .content select,
    .content button { min-height: 44px; }
    .pwd-eye { min-width: 44px; min-height: 44px; }

    /* Tableaux de gestion (comptes) : défilement contenu, comme les autres. */
    .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Bouton flottant d'export : ne masque pas le contenu */
    #excelExportBtn { right: 14px !important; bottom: 14px !important; }
}

/* ---------------- Téléphone (≤ 600 px) : densité minimale --------- */
@media (max-width: 600px) {
    .kpi-card { flex: 1 1 100%; }        /* une carte par ligne : chiffres lisibles */
    .kpi-container { gap: 10px; }
    .live-status { display: none; }      /* décoratif : on libère la largeur */
    .user-meta { display: none; }        /* avatar seul */
    .page-title { font-size: 19px; }
    .content { padding: 14px 12px; }
    .card-filter, .card-section { padding: 14px 12px; }
    .data-table { font-size: 12px; }
}
