:root {
    --brand-rgb: 0, 102, 51;
    --gold-rgb: 212, 160, 23;
    --brand: rgb(var(--brand-rgb));
    --gold: rgb(var(--gold-rgb));
    --bg: #f4f6f5;
    --panel: #ffffff;
    --text: #1b2420;
    --muted: #6b7770;
    --border: #e2e7e4;
    --positive: #1e8e4e;
    --negative: #c0392b;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .07);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- LAYOUT ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    background: rgb(var(--brand-rgb));
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.brand { padding: 16px 16px; border-bottom: 1px solid rgba(255, 255, 255, .15); }
.brand-logo { background: #fff; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.brand-logo img { width: 100%; height: auto; display: block; }
.login-logo { width: 172px; margin: 4px auto 16px; }
.login-logo img { width: 100%; height: auto; display: block; }
.brand-name { font-size: 18px; font-weight: 700; }
.brand-tag { font-size: 12px; opacity: .8; margin-top: 2px; }
.sidebar nav { display: flex; flex-direction: column; padding: 12px 0; }
.sidebar nav a {
    color: rgba(255, 255, 255, .85);
    padding: 11px 18px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 11px;
}
.sidebar nav a svg { flex-shrink: 0; opacity: .9; width: 18px; height: 18px; }
.sidebar nav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .1); text-decoration: none; }
.sidebar nav a.actif {
    background: rgba(255, 255, 255, .16);
    border-left: 3px solid var(--gold);
    color: #fff;
}

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--panel); padding: 14px 26px; border-bottom: 1px solid var(--border);
    /* Barre du haut FIXE au scroll (titre + cloche + déconnexion toujours visibles). z-index sous
       le drawer mobile (50) et son overlay (40), au-dessus du contenu. */
    position: sticky; top: 0; z-index: 30; box-shadow: 0 1px 8px rgba(22, 28, 45, .05);
}
.topbar-title { font-size: 18px; font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.user-name { font-weight: 600; }
.user-role { color: var(--muted); }
.logout { color: var(--negative); }

.page { padding: 24px 26px; flex: 1; }
.footer { padding: 14px 26px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); }

/* ---------- PANELS / KPI ---------- */
.panel {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 14px; font-size: 15px; color: var(--brand); }
.panel.center { text-align: center; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.kpi-card {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow);
}
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 6px; color: var(--brand); }
.kpi-action { display: flex; align-items: center; justify-content: center; }

/* ---------- TABLES ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.table .right { text-align: right; }
.table .vide { color: var(--muted); text-align: center; padding: 22px; }
.ligne-total td { font-weight: 700; border-top: 2px solid var(--border); }
.ligne-ttc td { font-weight: 700; font-size: 16px; color: var(--brand); border-top: 2px solid var(--brand); }
.table-mensuel .bar-col { width: 42%; }
.bar-track { background: rgba(var(--brand-rgb), .10); border-radius: 6px; height: 12px; width: 100%; }
.bar-fill { background: rgb(var(--brand-rgb)); border-radius: 6px; height: 12px; min-width: 2px; transition: width .3s; }

/* ---------- FORMS ---------- */
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
input, select, textarea {
    width: 100%; padding: 8px 10px; font-size: 14px; font-family: inherit;
    border: 1px solid var(--border); border-radius: 7px; background: #fff; margin-top: 3px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(var(--brand-rgb), .35); border-color: var(--brand); }
input:disabled { background: #f1f3f2; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-2 .col-2 { grid-column: 1 / -1; }
fieldset.garanties { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-top: 14px; }
fieldset.garanties legend { font-size: 13px; color: var(--muted); padding: 0 6px; }
label.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 400; margin: 5px 18px 5px 0; }
label.check input { width: auto; margin: 0; }

/* ---------- BUTTONS ---------- */
.btn {
    display: inline-block; padding: 9px 16px; font-size: 14px; font-weight: 600;
    border: none; border-radius: 7px; cursor: pointer; text-align: center;
}
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-secondaire { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn-petit { padding: 5px 10px; font-size: 12px; background: var(--gold); color: #3a2c00; }
.btn-block { width: 100%; }
.btn-wa { background: #25D366; color: #fff; font-weight: 700; }
.btn-wa:hover { filter: brightness(.95); }
.btn-orass { width: 100%; background: var(--gold); color: #3a2c00; font-weight: 700; }
.btn-orass:hover { filter: brightness(.95); }

/* ---------- DEVIS LAYOUT ---------- */
.devis-layout { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.devis-recap .sticky { position: sticky; top: 20px; }
.tarif-detail { font-size: 13.5px; }
.t-ligne { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--border); }
.t-ligne.total { font-weight: 700; border-bottom: 2px solid var(--border); }
.tarif-ttc {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 12px; padding-top: 12px; border-top: 2px solid var(--brand);
}
.tarif-ttc strong { font-size: 22px; color: var(--brand); }
.actions { display: flex; gap: 10px; margin-top: 14px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 10px; }
.avert { color: #9a6b00; font-size: 12px; margin-top: 8px; }
.erreur { color: var(--negative); }
/* Étiquette de source du tarif : officiel ORASS (exact) vs estimation locale (hors-ligne). */
.tarif-src { font-size: 12px; font-weight: 600; margin-top: 8px; padding: 4px 8px; border-radius: 6px; }
.tarif-src.ok { color: #137333; background: rgba(46,170,58,0.12); }
.tarif-src.est { color: #9a6b00; background: rgba(237,233,63,0.18); }

/* ---------- OCR CARTE GRISE ---------- */
.ocr-panel { border-left: 4px solid var(--gold); background: rgba(var(--gold-rgb), .06); }
.ocr-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.ocr-row input[type="file"] { width: auto; flex: 1; min-width: 220px; }
.ocr-status { font-size: 13px; color: var(--muted); }
.champ-ocr { background: rgba(var(--gold-rgb), .22) !important; transition: background 1.5s ease; }

/* ---------- TARIF ORASS ---------- */
.orass-tarif { margin: 12px 0; }
.tarif-orass-res { margin-top: 8px; font-size: 13px; }
.orass-badge { display: inline-block; background: var(--brand); color: #fff; font-size: 11px;
    font-weight: 700; padding: 2px 8px; border-radius: 12px; margin-bottom: 6px; }

/* ---------- FICHE / DL ---------- */
dl.fiche { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0 0 16px; font-size: 13.5px; }
dl.fiche dt { color: var(--muted); }
dl.fiche dd { margin: 0; font-weight: 500; }

/* ---------- BADGES / CHIPS ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-devis { background: #eef2f7; color: #4a5568; }
.badge-souscrit, .badge-valide { background: rgba(30, 142, 78, .15); color: var(--positive); }
.badge-en_attente { background: rgba(212, 160, 23, .18); color: #9a6b00; }
.badge-resilie, .badge-expire { background: rgba(192, 57, 43, .12); color: var(--negative); }
.badge-ok { background: rgba(30, 142, 78, .15); color: var(--positive); }
.badge-erreur { background: rgba(192, 57, 43, .14); color: var(--negative); }
.info { display: inline-block; font-size: 11px; color: #9aa5b1; cursor: help; vertical-align: middle; }
.filtres { margin-bottom: 14px; display: flex; gap: 8px; }
.chip { padding: 5px 12px; border-radius: 18px; background: #eef2f0; font-size: 13px; }
.chip.actif { background: var(--brand); color: #fff; }

/* ---------- ALERTS ---------- */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px; }
.alert-info { background: rgba(var(--gold-rgb), .14); color: #7a5800; }
.alert-ok { background: rgba(30, 142, 78, .12); color: var(--positive); }
.alert-erreur { background: rgba(192, 57, 43, .1); color: var(--negative); }

/* ---------- CONTRAT ---------- */
.contrat-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.contrat-actions { display: flex; gap: 10px; flex-shrink: 0; }
.bareme-edit { font-family: "Cascadia Code", "Consolas", monospace; font-size: 12.5px; }

/* ---------- LOGIN ---------- */
.login-body {
    display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px;
    background:
        radial-gradient(900px 520px at 50% -8%, rgba(var(--gold-rgb), .20), transparent 62%),
        linear-gradient(155deg, rgb(var(--brand-rgb)) 0%, rgba(var(--brand-rgb), .80) 52%, rgba(0, 0, 0, .42) 145%);
}
.login-card {
    position: relative; background: #fff; padding: 40px 34px 26px; border-radius: 18px;
    width: 384px; max-width: 92vw; text-align: center; overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .28);
}
.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 { font-size: 27px; font-weight: 800; color: var(--brand); letter-spacing: -.3px; line-height: 1.1; }
.login-company { font-size: 13.5px; font-weight: 600; color: #2b2b2b; margin-top: 5px; }
.login-tag { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.login-sep { display: flex; align-items: center; gap: 12px; margin: 24px 0 16px; }
.login-sep::before, .login-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.login-sep span { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.login-form { text-align: left; }
.login-card .field { margin-top: 14px; }
.login-card .field > span { display: block; font-size: 11px; font-weight: 700; letter-spacing: .5px;
    text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.login-card .field input { padding: 12px 14px; border-radius: 10px; }
.login-card .btn { width: 100%; margin-top: 22px; padding: 13px; font-size: 15px; border-radius: 10px; }
.login-foot { margin-top: 22px; font-size: 11.5px; color: var(--muted); }

/* ---------- DASHBOARD (production / CA / évolution) ---------- */
.dash-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.dash-bureau { font-size: 18px; font-weight: 700; color: var(--brand); }
.bureau-select select { min-width: 240px; }
.dash-section { font-size: 14px; color: var(--muted); margin: 14px 0 8px; font-weight: 600; }
.kpi-grid-4 { grid-template-columns: repeat(4, 1fr); }
.kpi-warn { color: var(--negative); }
.evo { font-size: 12.5px; font-weight: 700; }
.evo-up { color: var(--positive); }
.evo-down { color: var(--negative); }
.evo-n1 { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; font-weight: 400; }
.periode-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin: 10px 0 14px; }
.periode-form label { margin: 0; font-size: 13px; }
.periode-form input[type="date"] { width: auto; }
.periode-res { margin-top: 6px; }

/* ---------- NAV MOBILE (burger + overlay) ---------- */
.burger { display: none; background: none; border: none; font-size: 24px; line-height: 1;
    color: var(--brand); cursor: pointer; margin-right: 6px; padding: 2px 6px; }
.sidebar-overlay { display: none; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1100px) {
    .kpi-grid, .kpi-grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 980px) {
    .devis-layout, .two-col, .grid-2 { grid-template-columns: 1fr; }
    .devis-recap .sticky { position: static; }
}
@media (max-width: 820px) {
    /* Sidebar hors-écran, ouverte via le burger */
    .burger { display: inline-block; }
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; width: 250px; z-index: 50;
        transform: translateX(-100%); transition: transform .25s ease; overflow-y: auto;
    }
    .app.nav-open .sidebar { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.3); }
    .app.nav-open .sidebar-overlay {
        display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4);
    }
    .content { width: 100%; }
    .page { padding: 16px 14px; }
    .topbar { padding: 12px 14px; }
    .topbar-title { font-size: 16px; }
    .kpi-value { font-size: 20px; }
    /* tables scrollables horizontalement */
    .panel { overflow-x: auto; }
    .contrat-head { flex-direction: column; }
    .contrat-actions { width: 100%; }
}
@media (max-width: 560px) {
    .kpi-grid, .kpi-grid-4 { grid-template-columns: 1fr; }
    .userbox .user-role { display: none; }
    .login-card { width: 92vw; }
    .actions { flex-direction: column; }
    .actions .btn { width: 100%; }
}

/* Descriptif vulgarisé du pack d'assistance choisi (aide à la décision du client). */
.assist-detail { margin-top: .4rem; }
.assist-detail .assist-pack {
    background: rgba(var(--brand-rgb), 0.06);
    border-left: 3px solid rgba(var(--brand-rgb), 0.55);
    border-radius: 6px; padding: .55rem .75rem; font-size: .88em;
}
.assist-detail .assist-fait { margin: 0 0 .35rem; font-weight: 600; }
.assist-detail .assist-age { color: #b06a00; font-weight: 600; }
.assist-detail ul { margin: 0; padding-left: 1.1rem; }
.assist-detail li { margin: .12rem 0; }

/* ===== Fluidité : transitions douces, spinners, états de chargement ===== */
/* Respecte les préférences d'accessibilité (pas d'animation si l'utilisateur l'a désactivée). */
@media (prefers-reduced-motion: no-preference) {
    .btn, .panel, .badge, .t-input, select, input, .check, a { transition:
        background-color .15s ease, color .15s ease, border-color .15s ease,
        box-shadow .15s ease, opacity .15s ease, transform .08s ease; }
    .btn:active { transform: translateY(1px); }
    .panel { transition: box-shadow .2s ease; }
    .assist-detail .assist-pack { animation: fade-in .2s ease; }
}
@keyframes fade-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Spinner réutilisable. */
.spinner {
    display: inline-block; width: 1em; height: 1em; vertical-align: -0.15em;
    border: 2px solid rgba(var(--brand-rgb), 0.25);
    border-top-color: rgb(var(--brand-rgb));
    border-radius: 50%; animation: spin .7s linear infinite;
}

/* Bouton occupé : texte estompé + spinner, clics bloqués. */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; opacity: .85; }
.btn.is-loading::after {
    content: ""; position: absolute; top: 50%; left: 50%; width: 1.05em; height: 1.05em;
    margin: -0.52em 0 0 -0.52em; border: 2px solid rgba(255,255,255,0.5);
    border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
.btn-secondaire.is-loading::after, .btn.btn-petit.is-loading::after {
    border-color: rgba(var(--brand-rgb),0.35); border-top-color: rgb(var(--brand-rgb));
}

/* ===== Loader de MARQUE (logo de la compagnie + anneau) — white-label ===== */
/* Logo au centre (pulse doux, ne tourne pas → reste lisible) + anneau qui tourne autour. */
.brand-loader { position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: 84px; height: 84px; }
.brand-loader::before { content: ""; position: absolute; inset: 0; border-radius: 50%;
    border: 3px solid rgba(var(--brand-rgb), .15); border-top-color: rgb(var(--brand-rgb));
    animation: spin .85s linear infinite; }
.brand-loader img { width: 46px; height: 46px; object-fit: contain; animation: bl-pulse 1.3s ease-in-out infinite; }
@keyframes bl-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .55; transform: scale(.9); } }
/* Overlay plein écran pendant la navigation (apparaît après un court délai → pas de flash sur charge rapide). */
.page-loader { position: fixed; inset: 0; z-index: 9999; display: none; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .72); }
@supports (backdrop-filter: blur(2px)) { .page-loader { backdrop-filter: blur(2px); } }
.page-loader.on { display: flex; }
@media (prefers-reduced-motion: reduce) { .brand-loader::before, .brand-loader img { animation: none; } }

/* Cotation en cours de recalcul : léger estompage anti-clignotement. */
#tarif-detail.calcul, .devis-recap .calcul { opacity: .45; transition: opacity .15s ease; }
.ttc.calcul, #ttc.calcul { opacity: .5; }

/* Surbrillance d'un champ pré-rempli par l'OCR (transition douce). */
.champ-ocr { background: rgba(var(--gold-rgb), 0.25); transition: background-color 1.5s ease; }
