/**
 * =========================================================================================
 * JK AUDIT LAB — FEUILLE DE STYLE PRINCIPALE (CSS RESPONSIVE PARFAIT)
 * Cabinet J.K. Audit SARLU — RDC (Ordre National des Experts-Comptables)
 * Conçu et développé par : Josué KASILEMBO BUJINGA
 * =========================================================================================
 */

/* --- 1. PALETTE DE COULEURS INSTITUTIONNELLES & VARIABLES CSS --- */
:root {
    --navy: #12263f;              /* Bleu Nuit institutionnel */
    --navy2: #1f3d63;             /* Bleu secondaire */
    --blue: #256abf;              /* Bleu d'action principal */
    --blue-s: #eaf1fb;            /* Bleu clair de sélection */
    --gold: #b8934a;              /* Or institutionnel */
    --gold-s: #f4ecda;            /* Or clair survol */
    --ink: #1b232e;               /* Texte sombre */
    --mut: #5c6775;               /* Texte secondaire / gris */
    --line: #e5e9f0;              /* Lignes et bordures */
    --bg: #f4f6f9;                /* Arrière-plan général */
    --panel: #fff;                /* Fond des cartes */
    --ok: #0ca30c;                 /* Vert succès */
    --warn: #ec835a;               /* Orange avertissement */
    --crit: #d03b3b;               /* Rouge critique */
    --amber: #fab219;              /* Jaune modéré */
    --green-btn: #1b5e39;          /* Vert bouton de connexion */
    --green-btn-hover: #14472b;    /* Vert bouton survol */
    --sh: 0 1px 2px rgba(18,38,63,.05), 0 6px 18px rgba(18,38,63,.05); /* Ombre portée */
}

/* --- 2. NORMALISATION ET BASE --- */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; width: 100%; overflow-x: hidden; }
body { font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); font-size: 14.5px; line-height: 1.5; }
button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }

/* Overlay de fond pour le menu mobile */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(18, 38, 63, 0.5);
    z-index: 998;
    display: none;
    opacity: 0;
    transition: opacity .3s ease;
}
.sidebar-backdrop.open {
    display: block;
    opacity: 1;
}

/* --- 3. DISPOSITION EN GRILLE (CSS GRID LAYOUT DESKTOP) --- */
.app { display: grid; grid-template-columns: 230px 1fr; grid-template-rows: auto 1fr; grid-template-areas: "top top" "side main"; height: 100vh; }

/* --- 4. BANDEAU SUPÉRIEUR (TOPBAR) --- */
.topbar {
    grid-area: top;
    background: #fff;
    color: var(--navy);
    padding: 8px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
    z-index: 6;
    min-height: 56px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex-shrink: 1;
}
.brand .mark {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--navy);
    color: #fff;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    letter-spacing: -.5px;
    border: 2px solid var(--gold);
    flex-shrink: 0;
    overflow: hidden;
}
.brand .mark img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.brand-titles {
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.brand h1 {
    font-size: 15px;
    margin: 0;
    font-weight: 800;
    letter-spacing: .3px;
    color: var(--navy);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 340px;
}
.brand .tag {
    font-size: 11px;
    color: var(--mut);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 380px;
}

/* Zone de contexte & actions du Topbar */
.top-ctx {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 12px;
    color: var(--mut);
    flex-shrink: 0;
}
.top-ctx-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.top-ctx-main {
    display: flex;
    align-items: center;
    gap: 8px;
}
.top-user-row, .top-selects-row, .top-actions-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.top-ctx select {
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 5px 8px;
    font-size: 12px;
    max-width: 165px;
    transition: border-color .2s;
}
.top-ctx select:focus {
    border-color: var(--blue);
    outline: none;
}
.select-lbl {
    font-size: 12px;
    white-space: nowrap;
    color: var(--mut);
}
.savedot {
    font-size: 11px;
    color: var(--blue);
    margin-left: 2px;
}

/* Bouton Menu Mobile (Hamburger) */
.menu-toggle {
    display: none;
    background: var(--navy);
    color: #fff;
    border: 1px solid var(--gold);
    border-radius: 8px;
    padding: 6px 11px;
    font-size: 18px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

/* --- 5. NAVIGATION LATÉRALE (SIDEBAR) --- */
.sidebar { grid-area: side; background: #fff; border-right: 1px solid var(--line); overflow-y: auto; padding: 8px 0; }
.nav-i { display: flex; align-items: center; gap: 10px; color: #3a4658; padding: 9px 16px; font-size: 13.5px; cursor: pointer; border-left: 3px solid transparent; }
.nav-i:hover { background: var(--blue-s); color: var(--navy); }
.nav-i.active { background: var(--blue-s); color: var(--navy); border-left-color: var(--blue); font-weight: 600; }
.nav-i .ic { width: 18px; text-align: center; color: var(--blue); }
.nav-sec { color: #8593a8; font-size: 10.5px; text-transform: uppercase; letter-spacing: .7px; padding: 12px 16px 4px; }

/* --- 6. ZONE PRINCIPALE D'AFFICHAGE (MAIN CONTENT) --- */
.page-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 16px; flex-wrap: wrap; }
.page-h-titles { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.page-h h2 { font-size: 20px; margin: 0; color: var(--navy); white-space: nowrap; }
.page-h .sub { color: var(--mut); font-size: 13px; }


/* --- 7. COMPOSANTS UI : CARTES, BOUTONS, BADGES ET TABLES --- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--sh); padding: 18px; margin-bottom: 16px; max-width: 100%; overflow-x: auto; }
.card h3 { margin: 0 0 12px; color: var(--navy); font-size: 15.5px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.fld label { display: block; font-size: 11.5px; color: var(--mut); margin-bottom: 3px; }
.fld input, .fld select, .fld textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13.5px; }
.fld textarea { min-height: 80px; resize: vertical; }

.btn { background: var(--blue); color: #fff; border: none; padding: 9px 15px; border-radius: 8px; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #1c5cab; }
.btn.gold { background: var(--gold); color: #20150a; }
.btn.green { background: var(--green-btn); color: #fff; }
.btn.green:hover { background: var(--green-btn-hover); }
.btn.ghost { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--gold-s); }
.btn.sm { padding: 6px 11px; font-size: 12px; }
.btn.danger { background: #fff; color: #b23b3b; border: 1px solid #edc9c9; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { background: #f5f7fa; text-align: left; padding: 8px 10px; color: var(--navy); border-bottom: 2px solid var(--line); font-weight: 600; }
table.tbl td { border-bottom: 1px solid var(--line); padding: 7px 10px; vertical-align: top; }
table.tbl tr:hover td { background: #fafbfd; }

.chip { display: inline-flex; align-items: center; gap: 5px; background: var(--gold-s); color: #7a5a1c; border: 1px solid #e6d3a8; border-radius: 20px; padding: 2px 10px; font-size: 11.5px; margin: 2px 4px 2px 0; }
.badge { border-radius: 20px; padding: 2px 10px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: #e2f3ea; color: var(--ok); }
.badge.wc { background: #fdeee5; color: var(--warn); }

.kpi { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.kpi .k { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: var(--sh); }
.kpi .k .v { font-size: 26px; font-weight: 700; color: var(--navy); }
.kpi .k .l { font-size: 11.5px; color: var(--mut); text-transform: uppercase; letter-spacing: .5px; }
.prog { height: 8px; background: #eef1f6; border-radius: 5px; overflow: hidden; }
.prog>i { display: block; height: 100%; background: var(--blue); }

.subtabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.subtab { padding: 8px 14px; font-size: 13px; color: var(--mut); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 600; }
.subtab.active { color: var(--navy); border-bottom-color: var(--blue); }
.subtab:hover { color: var(--navy); }
textarea.imp { width: 100%; min-height: 120px; border: 1px solid var(--line); border-radius: 8px; padding: 9px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- 8. CARTOGRAPHIE DES RISQUES & HEATMAP --- */
.hm { border-collapse: separate; border-spacing: 3px; }
.hm td { width: 64px; height: 44px; text-align: center; border-radius: 6px; color: #0b0b0b; font-weight: 700; font-size: 13px; position: relative; }
.hm .axl { background: none; color: var(--mut); font-weight: 600; font-size: 11px; width: auto; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--mut); margin-top: 8px; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* --- 9. ACCORDÉON DES PHASES ET DILIGENCES --- */
.phase { border: 1px solid var(--line); border-radius: 11px; margin-bottom: 12px; overflow: hidden; }
.phase>.ph-h { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: #f7f9fc; cursor: pointer; }
.phase>.ph-h .code { background: var(--navy); color: #fff; border-radius: 7px; padding: 3px 9px; font-size: 12px; font-weight: 700; }
.phase>.ph-h .t { font-weight: 600; color: var(--navy); }
.phase>.ph-h .pc { margin-left: auto; font-size: 12px; color: var(--mut); min-width: 170px; display: flex; align-items: center; gap: 8px; }
.phase>.ph-b { padding: 14px; display: none; }
.phase.open>.ph-b { display: block; }
.norm-line { font-size: 12px; color: var(--mut); margin: 2px 0; }
.norm-line b { color: var(--navy); }
.dil { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dotted var(--line); }
.dil .txt { flex: 1; }
.dil .ck { display: flex; gap: 12px; align-items: center; font-size: 12px; color: var(--mut); white-space: nowrap; }
.dil .wp { font-size: 11px; color: var(--gold); font-weight: 600; }
.dil input[type=text] { width: 100%; margin-top: 4px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.att { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 4px 0; }
.mut { color: var(--mut); }

/* --- 10. EXPLORATEUR DES 190 MODÈLES (RESPONSIVE & FLUIDE) --- */
.split {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
    width: 100%;
}
.split > div:first-child {
    min-width: 0;
    transition: opacity .2s ease, width .2s ease;
}
.split.collapsed {
    grid-template-columns: 0px minmax(0, 1fr) !important;
    gap: 0 !important;
}
.split.collapsed > div:first-child {
    display: none !important;
}

.tpl-list {
    max-height: calc(100vh - 210px);
    min-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    box-shadow: var(--sh);
}
.tpl-sec {
    font-size: 12px;
    font-weight: 700;
    color: var(--navy);
    background: #f5f7fa;
    padding: 8px 12px;
    position: sticky;
    top: 0;
    z-index: 2;
    border-bottom: 1px solid var(--line);
}
.tpl-i {
    padding: 8px 12px;
    font-size: 12.5px;
    cursor: pointer;
    display: flex;
    gap: 8px;
    border-bottom: 1px solid #f0f2f6;
    transition: background .15s ease;
}
.tpl-i:hover { background: var(--gold-s); }
.tpl-i.active { background: var(--navy); color: #fff; }
.tpl-i .n { color: var(--gold); font-weight: 700; flex-shrink: 0; }
.tpl-i.active .n { color: #ffd98a; }
.search {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 10px;
    font-size: 13px;
    box-sizing: border-box;
    background: #fff;
}
.search:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37,106,191,.15);
}

/* Volet de prévisualisation et édition du document */
#docPane {
    min-width: 0;
    max-width: 100%;
    width: 100%;
}
#docPane .card {
    margin-bottom: 12px;
}
#docPane .row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
#docPane .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 10px;
}
#docPane .fld input {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}
.toggle-tpl-btn {
    white-space: nowrap;
    cursor: pointer;
    font-size: 12px;
}

/* --- 11. RENDU PAPIER DES DOCUMENTS GÉNÉRÉS (RESPONSIVE A4) --- */
.doc {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(18,38,63,.08);
    width: 100%;
    max-width: 21cm;
    margin: 0 auto;
    padding: clamp(16px, 3.5vw, 1.8cm) clamp(16px, 4vw, 2cm);
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--ink);
    box-sizing: border-box;
    overflow-x: auto;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.doc table {
    max-width: 100%;
}

.lh { display: flex; align-items: center; gap: 16px; border-bottom: 3px solid var(--gold); padding-bottom: 10px; margin-bottom: 6px; }
.lh .lh-nom { font-size: 18px; font-weight: 800; color: var(--navy); letter-spacing: .3px; }
.lh .lh-sub { font-size: 10.5px; color: var(--mut); }
.lh-band { font-size: 10.5px; color: var(--mut); border-top: 1px solid #e2e8f0; border-bottom: 2px solid var(--gold); margin-top: 4px; padding-top: 5px; padding-bottom: 5px; margin-bottom: 18px; }
.lh-img { text-align: center; margin-bottom: 16px; }
.lh-foot { margin-top: 26px; }
.lh-foot img { width: 100%; display: block; }
.doc h2.title { font-size: 18px; font-weight: 800; color: var(--navy); margin: 8px 0 4px; border-bottom: 2px solid var(--gold); padding-bottom: 8px; text-transform: uppercase; letter-spacing: .3px; }
.doc .obj { font-size: 12px; color: var(--mut); margin: 0 0 16px; font-style: italic; }
.doc-h { font-weight: 700; color: var(--navy); border-left: 4px solid var(--gold); padding: 4px 10px; margin: 18px 0 8px; background: #f8fafd; border-radius: 0 4px 4px 0; font-size: 14px; }
.doc p { margin: 8px 0; }
.doc ul, .doc ol { margin: 8px 0 8px 4px; padding-left: 22px; }
.qr { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dotted var(--line); }
.qr .o { color: var(--mut); font-size: 12.5px; white-space: nowrap; }
.qobs { font-size: 11.5px; color: #9aa4b1; padding: 1px 0 5px; }
.fl { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; }
.fl b { white-space: nowrap; }
.fl .d { flex: 1; border-bottom: 1px dotted #aab3c0; height: 13px; }
table.dt { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 12.5px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
table.dt th { background: var(--navy); color: #fff; text-align: left; padding: 8px 10px; font-weight: 700; border: 1px solid #1a365d; }
table.dt td { border: 1px solid #cbd5e1; padding: 7px 10px; vertical-align: top; }
table.dt tr:nth-child(even) td { background: #f8fafc; }
.cellfill { display: inline-block; min-width: 70px; border-bottom: 1px dotted #aab3c0; height: 12px; }
.sign-block { margin-top: 26px; text-align: right; page-break-inside: avoid; }
.sign-block .sig-name { font-weight: 700; color: var(--navy); font-size: 13.5px; }
.sign-block .sig-tit { font-size: 11px; color: var(--mut); }
.ph-open { background: #fff4d6; border-bottom: 1px dashed var(--gold); padding: 0 2px; }
.ph-empty { background: #ffe1e1; border-bottom: 1px dashed #d98b8b; color: #a23b3b; }
.datebox { display: inline-block; min-width: 130px; border-bottom: 1px solid #8895a6; height: 14px; }

/* --- 12. TOAST NOTIFICATIONS & MODALES --- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 11px 20px; border-radius: 9px; box-shadow: 0 8px 26px rgba(0,0,0,.25); z-index: 99; opacity: 0; transition: .3s; font-size: 13.5px; }
.modal-bg { position: fixed; inset: 0; background: rgba(15,25,40,.55); display: none; align-items: flex-start; justify-content: center; z-index: 50; overflow: auto; padding: 30px; }
.modal-bg.on { display: flex; }
.modal { background: #fff; border-radius: 12px; max-width: 900px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-h { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-h h3 { margin: 0; color: var(--navy); }
.modal-h .x { margin-left: auto; background: none; border: none; font-size: 20px; color: var(--mut); }
.modal-b { padding: 18px; max-height: 70vh; overflow: auto; }
.hint { font-size: 12px; color: var(--mut); }
#printArea { display: none; }

/* --- 13. BOÎTE DE DIALOGUE DE CONNEXION SÉCURISÉE (OVERLAY) --- */
.login-overlay { position: fixed; inset: 0; background: #162740; display: flex; align-items: center; justify-content: center; z-index: 999; padding: 20px; }
.login-box { background: #fff; border-radius: 14px; width: 100%; max-width: 440px; padding: 32px; box-shadow: 0 25px 60px rgba(0,0,0,.4); text-align: center; }
.login-header img { max-height: 85px; margin-bottom: 12px; }
.login-title { font-size: 20px; font-weight: 800; color: #1b5e39; margin: 8px 0 4px; letter-spacing: .4px; }
.login-subtitle { font-size: 12px; color: #6b7c93; margin-bottom: 4px; }
.login-author { font-size: 11px; color: #8a9bb2; margin-bottom: 24px; }
.login-form .fld { text-align: left; margin-bottom: 16px; }
.login-form label { font-size: 12px; font-weight: 600; color: #334155; margin-bottom: 6px; display: block; }
.login-form input { width: 100%; padding: 11px 14px; border: 1px solid #d1d5db; border-radius: 9px; font-size: 14px; background: #f8fafc; outline: none; }
.login-form input:focus { border-color: #1b5e39; background: #fff; box-shadow: 0 0 0 3px rgba(27,94,57,.15); }
.btn-login { width: 100%; padding: 12px; background: #1b5e39; color: #fff; border: none; border-radius: 9px; font-size: 14.5px; font-weight: 700; margin-top: 10px; cursor: pointer; transition: .2s; }
.btn-login:hover { background: #14472b; }
.login-error { background: #fee2e2; color: #b91c1c; padding: 10px; border-radius: 8px; font-size: 12px; margin-bottom: 14px; display: none; }

/* --- 14. BOUTON DE SYNCHRONISATION & DROITS --- */
.sync-btn { display: inline-flex; align-items: center; gap: 6px; background: #e8f5e9; color: #1b5e39; border: 1px solid #a5d6a7; border-radius: 20px; padding: 5px 12px; font-size: 12px; font-weight: 600; cursor: pointer; transition: .2s; white-space: nowrap; }
.sync-btn:hover { background: #c8e6c9; }
.sync-btn.syncing { background: #fff3e0; color: #e65100; border-color: #ffe0b2; }
.user-badge { display: inline-flex; align-items: center; gap: 6px; background: #f1f5f9; color: #334155; border-radius: 20px; padding: 4px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }

/* =========================================================================================
 * 15. RÈGLES RESPONSIVE DESIGN (PARFAITE ADAPTATION MOBILE / TABLETTE / PC)
 * ========================================================================================= */

/* --- Écrans PC Portables et fenêtres larges (max 1440px) --- */
@media (max-width: 1440px) {
    .brand h1 { max-width: 270px; }
    .brand .tag { max-width: 270px; }
    .top-ctx {
        flex-direction: column;
        align-items: flex-end;
        gap: 5px;
    }
    .top-ctx-group {
        justify-content: flex-end;
    }
    .top-ctx-main {
        gap: 8px;
    }
    .top-actions-row {
        gap: 5px;
    }
    .top-ctx select {
        max-width: 140px;
        padding: 4px 7px;
        font-size: 12px;
    }
    .btn.sm {
        padding: 5px 9px;
        font-size: 11.5px;
    }
}

/* --- Écrans Laptops et formats intermédiaires (max 1120px) --- */
@media (max-width: 1120px) {
    .app { grid-template-columns: 200px minmax(0, 1fr); }
    .main { padding: 14px 16px; }
    .split { grid-template-columns: 220px minmax(0, 1fr); gap: 12px; }
    .tpl-list { max-height: calc(100vh - 180px); }
    .tpl-i { padding: 6px 8px; font-size: 12px; }
    .topbar { padding: 7px 12px; }
    .brand h1 { max-width: 210px; font-size: 14px; }
    .brand .tag { display: none; } /* Masqué pour éviter tout encombrement */
    .top-ctx select { max-width: 125px; font-size: 11.5px; }
    .select-lbl { display: none; }
    #docPane .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
    .doc { padding: 1cm 1.2cm; font-size: 12.5px; }
}

/* --- Écrans Tablettes en paysage & fenêtres étroites (max 960px) --- */
@media (max-width: 960px) {
    .split { grid-template-columns: 1fr !important; gap: 14px; }
    .tpl-list { max-height: 260px !important; min-height: auto !important; }
    .doc { padding: 18px 14px; font-size: 12.5px; }
    .brand h1 { max-width: 180px; }
    .user-badge { padding: 3px 8px; font-size: 11.5px; }
    .sync-btn { padding: 4px 9px; font-size: 11.5px; }
    .btn.sm { padding: 4px 8px; font-size: 11px; }
}

/* --- Écrans Tablettes & Smartphones (max 768px) --- */
@media (max-width: 768px) {
    .app {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto 1fr !important;
        grid-template-areas: "top" "main" !important;
    }
    
    .menu-toggle {
        display: inline-flex !important;
        padding: 6px 10px !important;
        font-size: 18px !important;
    }

    /* Navigation latérale coulissante moderne sur Mobile */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -290px !important;
        bottom: 0 !important;
        width: 280px !important;
        height: 100vh !important;
        z-index: 999 !important;
        box-shadow: 6px 0 25px rgba(0,0,0,.3) !important;
        transition: left .3s cubic-bezier(.4, 0, .2, 1) !important;
    }

    .sidebar.open {
        left: 0 !important;
    }

    /* En-tête supérieur compact & responsive pour smartphone */
    .topbar {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 8px 12px !important;
        gap: 8px !important;
        height: auto !important;
        min-height: auto !important;
    }

    .brand {
        width: 100% !important;
        justify-content: flex-start !important;
        gap: 8px !important;
    }
    .brand-titles { flex: 1 1 auto !important; min-width: 0 !important; }
    .brand h1 {
        font-size: 14.5px !important;
        max-width: 100% !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    .brand .tag { display: none !important; }

    .top-ctx {
        width: 100% !important;
        margin-left: 0 !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 7px !important;
        padding-top: 7px !important;
        border-top: 1px solid var(--line) !important;
    }

    .top-ctx-main {
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
    }

    .top-user-row {
        width: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }

    .top-selects-row {
        width: 100% !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
    }

    .select-lbl { display: none !important; }

    #selSoc {
        flex: 1 1 auto !important;
        max-width: none !important;
        min-width: 0 !important;
        font-size: 12px !important;
        padding: 5px 7px !important;
    }
    #selEx {
        width: 74px !important;
        flex-shrink: 0 !important;
        font-size: 12px !important;
        padding: 5px 6px !important;
    }
    #selDev {
        width: 64px !important;
        flex-shrink: 0 !important;
        font-size: 12px !important;
        padding: 5px 6px !important;
    }

    .top-actions-row {
        width: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 6px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding-bottom: 3px !important;
        scrollbar-width: none !important;
    }
    .top-actions-row::-webkit-scrollbar {
        display: none !important;
    }
    .top-actions-row .btn {
        flex-shrink: 0 !important;
        padding: 6px 10px !important;
        font-size: 12px !important;
    }

    .main { padding: 14px 10px !important; }
    .page-h { flex-direction: column !important; align-items: flex-start !important; gap: 4px !important; }
    .page-h h2 { font-size: 18px !important; }
    .grid { grid-template-columns: 1fr !important; }
    .kpi { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important; gap: 8px !important; }
    .kpi .k { padding: 10px !important; }
    .kpi .k .v { font-size: 20px !important; }
    table.tbl, table.dt { display: block !important; overflow-x: auto !important; max-width: 100% !important; }
    .split { grid-template-columns: 1fr !important; gap: 12px !important; }
    .tpl-list { max-height: 240px !important; min-height: auto !important; }
    #docPane .grid { grid-template-columns: 1fr !important; }
    .doc { width: 100% !important; padding: 14px 10px !important; font-size: 11.5px !important; }
    .lh { flex-direction: column !important; align-items: flex-start !important; gap: 6px !important; }
    .modal-bg { padding: 8px !important; }
    .modal { max-width: 100vw !important; margin: 0 !important; }
    .modal-b { max-height: 80vh !important; padding: 10px !important; }
    .login-box { max-width: 95vw !important; padding: 22px 14px !important; }
    .login-title { font-size: 18px !important; }
}

/* --- Petits Smartphones (max 480px) --- */
@media (max-width: 480px) {
    .brand .mark { width: 30px !important; height: 30px !important; font-size: 12px !important; }
    .brand h1 { font-size: 13.5px !important; }
    .topbar { padding: 6px 8px !important; }
    .user-badge { font-size: 10.5px !important; padding: 3px 6px !important; }
    .sync-btn { font-size: 10.5px !important; padding: 3px 7px !important; }
    .top-actions-row .btn { font-size: 11px !important; padding: 5px 8px !important; }
    .btn { padding: 6px 9px !important; font-size: 11px !important; }
}

/* --- 16. STYLES D'IMPRESSION A4 PROPRES (SANS BANDE NI SCROLLBAR FANTÔME) --- */
@media print {
    /* 1. Masquer TOTALEMENT l'application et tous les panneaux pour supprimer les scrollbars résiduels */
    .app,
    .topbar,
    .sidebar,
    .main,
    .login-overlay,
    .sidebar-backdrop,
    .modal-bg,
    #modalBg,
    .toast,
    #toast,
    #presenceBar,
    #updBanner,
    #lockBanner,
    #lockScreen,
    .toggle-tpl-btn,
    .row-actions,
    .card:not(#printArea *) {
        display: none !important;
        visibility: hidden !important;
        width: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
    }

    /* 2. Éliminer tous les ascenseurs Chromium/Webkit/Firefox lors de l'impression */
    ::-webkit-scrollbar {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
    }
    * {
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
    }

    /* 3. Réinitialiser html et body pour une page A4 immaculée */
    html, body {
        background: #ffffff !important;
        color: #1b232e !important;
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important;
        min-height: 100% !important;
        width: 100% !important;
        overflow: visible !important;
        font-family: "Segoe UI", Calibri, Arial, sans-serif !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* 4. Afficher exclusivement la zone de document #printArea */
    #printArea {
        display: block !important;
        visibility: visible !important;
        position: static !important;
        inset: auto !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }

    #printArea, #printArea * {
        visibility: visible !important;
    }

    .doc, #printArea .doc, .doc-print-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
        font-size: 11pt !important;
        line-height: 1.5 !important;
        overflow: visible !important;
    }

    .lh-band { margin-bottom: 14px; }
    .sign-block { page-break-inside: avoid !important; margin-top: 24px; text-align: right; }
    table, tr { page-break-inside: avoid !important; }
    thead { display: table-header-group; }
    tfoot { display: table-footer-group; }

    @page {
        size: A4 portrait;
        margin: 1.5cm;
    }
}

/* Règle d'isolation stricte lors de l'impression PDF */
body.is-printing-pdf .app,
body.is-printing-pdf .sidebar-backdrop,
body.is-printing-pdf .login-overlay,
body.is-printing-pdf #modalBg {
    display: none !important;
}
body.is-printing-pdf #printArea {
    display: block !important;
    position: static !important;
    width: 100% !important;
}
/* --- 17. STYLES SPÉCIFIQUES CAC & DILIGENCES --- */
.dil-tbl td { vertical-align: top; padding: 10px 12px; font-size: 15.5px; line-height: 1.55; }
.dil-tbl th { white-space: nowrap; }
.dil-tbl details { margin: 2px 0; }
.dil-tbl input[type=checkbox] { transform: scale(1.15); }
.dil-doc > td { background: #f7faff; border-top: none; padding-top: 0; }
.qtab td { vertical-align: top; }
.qtab th { background: #f0f4fa; }

/* --- Styles En-tête & Pied de page Cabinet --- */
.lh-onf { text-align: center; border-bottom: 3px double var(--navy, #12263f); padding-bottom: 8px; margin-bottom: 16px; font-family: Cambria, Georgia, 'Times New Roman', serif; }
.lh-onf-logo { max-height: 66px; display: block; margin: 0 auto 6px; }
.lh-onf-nom { font-size: 18px; font-weight: 700; color: var(--navy, #12263f); letter-spacing: .4px; text-transform: uppercase; line-height: 1.2; }
.lh-onf-mention { font-size: 11px; font-weight: 600; color: var(--gold, #b8934a); text-transform: uppercase; margin-top: 3px; line-height: 1.3; }
.lh-onf-aff { font-size: 11px; font-weight: 600; color: var(--gold, #b8934a); text-transform: uppercase; margin-top: 2px; }
.lh-onf-foot { margin-top: 26px; border-top: 2px solid #808080; padding-top: 6px; text-align: center; font-size: 10px; color: #444; line-height: 1.55; font-family: Cambria, 'Times New Roman', Georgia, serif; }
.lh-onf-foot-ids { font-weight: 600; color: #333; letter-spacing: .2px; }
