: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);
}
.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); }

/* ---------- 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); }
/* Statuts GED/GEC AssurDoc */
.badge-brouillon { background: #eef2f7; color: #4a5568; }
.badge-approuve, .badge-traite, .badge-expedie { background: rgba(30, 142, 78, .15); color: var(--positive); }
.badge-rejete, .badge-depassee { background: rgba(192, 57, 43, .12); color: var(--negative); }
.badge-archive { background: #e8eaed; color: #5a6472; }
.badge-recu, .badge-transmis, .badge-en_cours { background: rgba(33, 102, 196, .12); color: #1b56a8; }
.badge-normale { background: #eef2f7; color: #4a5568; }
.badge-urgente, .badge-imminente { background: rgba(212, 160, 23, .18); color: #9a6b00; }
.badge-critique { background: rgba(192, 57, 43, .14); color: var(--negative); }
.badge-confid { background: rgba(124, 58, 237, .14); color: #6b21a8; }
.tag { display: inline-block; padding: 1px 8px; margin: 1px; border-radius: 12px; background: #eef2f0; font-size: 11.5px; color: #475; }
/* Séparateur de section dans la navigation latérale */
.nav-sep { padding: 14px 14px 5px; font-size: 10.5px; font-weight: 700; letter-spacing: .08em;
           text-transform: uppercase; color: rgba(255,255,255,.55); }
/* Cloche de notifications (barre du haut) */
.notif-bell { position: relative; font-size: 19px; text-decoration: none; line-height: 1;
              padding: 4px 6px; border-radius: 8px; }
.notif-bell:hover, .notif-bell.actif { background: rgba(var(--brand-rgb), .10); }
.notif-badge { position: absolute; top: -3px; right: -4px; min-width: 17px; height: 17px;
               padding: 0 4px; border-radius: 9px; background: #c0392b; color: #fff;
               font-size: 11px; font-weight: 700; line-height: 17px; text-align: center; }
.notif-item { display: flex; gap: 10px; align-items: flex-start; padding: 11px 12px;
              border: 1px solid var(--border); border-radius: 9px; margin-bottom: 8px; background: #fff; }
.notif-item.non-lue { border-left: 3px solid var(--brand); background: rgba(var(--brand-rgb), .04); }
.notif-item .n-body { flex: 1; min-width: 0; }
.notif-item .n-titre { font-weight: 600; }
.notif-item .n-msg { font-size: 13px; color: var(--muted); margin-top: 2px; }
.notif-item .n-date { font-size: 11px; color: var(--muted); white-space: nowrap; }
.filtres { margin-bottom: 14px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filtres select, .filtres input { padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px; }
.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%; }
}
