:root{--ink:#111;--gray:#6b6b6b;--line:#e3e3e3;--bg:#f6f6f4;--card:#fff;--green:#1d7a46;--red:#b3362f;--amber:#9a6b1f;--blue:#235c8f}
*{box-sizing:border-box;margin:0;padding:0}
body{font-family:Inter,'Segoe UI',system-ui,sans-serif;background:var(--bg);color:var(--ink);font-size:14px}
.hidden{display:none!important}
button{font-family:inherit;cursor:pointer}
a{cursor:pointer;text-decoration:none;color:inherit}

/* login */
.login{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:var(--ink)}
.login-card{background:#fff;padding:44px 40px;width:340px;text-align:center}
.login-brand{font-size:18px;font-weight:800;letter-spacing:.14em}
.login-sub{font-size:10px;letter-spacing:.26em;text-transform:uppercase;color:var(--gray);margin:6px 0 26px}
.login-card input{width:100%;padding:12px;border:1px solid var(--line);margin-bottom:12px;font-size:14px}
.err{color:var(--red);font-size:12px;margin-top:10px}

/* shell */
#shell{min-height:100vh}
.view{margin-left:0;padding:18px 16px 60px;max-width:1200px}
@media(min-width:992px){
  #shell{display:flex}
  .view{margin-left:220px;padding:30px 36px;flex:1}
}
.view-inner{width:100%}

/* sidebar bureau (fixe) */
.sidebar{width:220px;background:var(--ink);color:#fff;padding:26px 18px;flex-direction:column;position:fixed;inset:0 auto 0 0;z-index:20}
.side-brand{font-weight:800;letter-spacing:.16em;font-size:17px;line-height:1.1;padding:4px 8px 22px;border-bottom:1px solid #333;margin-bottom:18px}
.side-brand span{font-weight:400;letter-spacing:.32em;font-size:11px}
.side-nav{display:flex;flex-direction:column}
.side-nav a{display:block;padding:11px 8px;font-size:13.5px;color:#cfcfcf;border-left:2px solid transparent}
.side-nav a:hover{color:#fff}
.side-nav a.active{color:#fff;border-left-color:#fff;background:#222}
.side-foot{margin-top:auto;display:flex;flex-direction:column;gap:10px}
.side-foot .btn-dark{background:#fff;color:#111;border-color:#fff}
.side-foot .btn-dark:hover{background:#ddd;color:#111}
.side-foot .btn-ghost{background:transparent;color:#cfcfcf;border-color:#4a4a4a}
.side-foot .btn-ghost:hover{background:#2c2c2c;color:#fff}

/* tiroir mobile */
.side-mobile{background:var(--ink);color:#fff}
.side-mobile .offcanvas-header{color:#fff}
.side-mobile .side-brand{border-bottom-color:#333;padding-top:0}
.side-mobile .side-nav{padding:8px 18px}
.side-mobile .side-foot{padding:0 18px 20px}

/* barre mobile */
.topbar{display:flex;justify-content:space-between;align-items:center;padding:12px 16px;background:var(--ink);color:#fff;position:sticky;top:0;z-index:30}
.topbar-brand{font-weight:800;letter-spacing:.14em;font-size:14px}
.topbar .btn{border-color:#555}
.btn{display:inline-block;padding:10px 16px;border:1px solid var(--ink);font-size:12.5px;font-weight:600;letter-spacing:.05em;background:#fff;color:var(--ink);text-align:center}
.btn:hover{background:var(--ink);color:#fff}
.btn-dark{background:var(--ink);color:#fff;border-color:var(--ink)}
.btn-dark:hover{background:#333}
.btn-block{display:block;width:100%}
.btn-sm{padding:5px 10px;font-size:11.5px}
.btn-ghost{border-color:var(--line);color:var(--gray)}
.btn-ghost:hover{background:var(--line);color:var(--ink)}
.side-foot #btn-logout{color:#888;font-size:11.5px;text-align:center;letter-spacing:.05em}
.side-foot #btn-logout:hover{color:#fff}
.page-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:22px}
.page-head h2{font-size:21px;font-weight:800;letter-spacing:.02em;text-transform:uppercase}
.page-head .sub{font-size:11.5px;color:var(--gray);letter-spacing:.08em;text-transform:uppercase;margin-top:3px}

/* dashboard */
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:14px;margin-bottom:26px}
.kpi{background:var(--card);border:1px solid var(--line);padding:16px 18px}
.kpi .k-label{font-size:10px;letter-spacing:.18em;text-transform:uppercase;color:var(--gray)}
.kpi .k-val{font-size:23px;font-weight:800;margin-top:6px}
.kpi .k-sub{font-size:11px;color:var(--gray);margin-top:3px}
.kpi.small .k-val{font-size:18px}
.dash-grid{display:grid;grid-template-columns:1.5fr 1fr;gap:14px}
.panel{background:var(--card);border:1px solid var(--line);padding:18px 20px}
.panel h3{font-size:11px;letter-spacing:.18em;text-transform:uppercase;color:var(--gray);margin-bottom:14px;font-weight:700}
.chart{display:flex;align-items:flex-end;gap:8px;height:150px;padding-top:8px}
.bar-wrap{flex:1;display:flex;flex-direction:column;align-items:center;gap:6px;height:100%;justify-content:flex-end}
.bar{width:70%;background:var(--ink);min-height:2px}
.bar-wrap:hover .bar{background:var(--blue)}
.bar-l{font-size:9.5px;color:var(--gray)}
.statut-row{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:8px}
.badge{font-size:11px;padding:4px 10px;border:1px solid var(--line);background:#fafafa;letter-spacing:.04em}
.badge.brouillon{color:var(--gray)}
.badge.envoye{color:var(--blue);border-color:var(--blue)}
.badge.valide{color:var(--green);border-color:var(--green);background:#f2faf5}
.badge.refuse,.badge.annule{color:var(--red);border-color:var(--red);background:#fdf3f2}
.badge.payee{color:var(--green);border-color:var(--green);background:#f2faf5}
.badge.emise{color:var(--amber);border-color:var(--amber)}
.badge.nouveau{color:var(--gray);border-color:var(--gray)}
.badge.qualifie{color:var(--blue);border-color:var(--blue)}
.badge.devis_envoye{color:var(--amber);border-color:var(--amber)}
.badge.gagne{color:var(--green);border-color:var(--green);background:#f2faf5}
.badge.perdu{color:var(--red);border-color:var(--red);background:#fdf3f2}
.badge.paye{color:var(--green);border-color:var(--green);background:#f2faf5}
.echeance{display:flex;align-items:center;gap:6px;justify-content:flex-end;white-space:nowrap}
.echeance .badge{font-size:10px;padding:2px 7px}
.list-compact{display:flex;flex-direction:column}
.list-compact .row{display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--line);font-size:13px}
.list-compact .row:last-child{border-bottom:none}
.top5 li{list-style:none;display:flex;justify-content:space-between;padding:7px 0;border-bottom:1px solid var(--line);font-size:13px}
.muted{color:var(--gray)}

/* tables */
table.data{width:100%;border-collapse:collapse;background:var(--card);border:1px solid var(--line)}
table.data th{font-size:10px;letter-spacing:.16em;text-transform:uppercase;color:var(--gray);text-align:left;padding:11px 12px;border-bottom:1px solid var(--ink);font-weight:700}
table.data td{padding:11px 12px;border-bottom:1px solid var(--line);font-size:13px;vertical-align:middle}
table.data tr:hover td{background:#fafaf8}
.num{text-align:right;white-space:nowrap}
.row-actions{display:flex;gap:6px;justify-content:flex-end}

/* forms */
form.panel{max-width:560px}
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:14px}
.field{display:flex;flex-direction:column;gap:4px}
.field.wide{grid-column:1/-1}
.field label{font-size:10.5px;letter-spacing:.14em;text-transform:uppercase;color:var(--gray);font-weight:600}
.field input,.field select,.field textarea{padding:9px 10px;border:1px solid var(--line);font-size:13.5px;font-family:inherit;background:#fff}
.field textarea{resize:vertical;min-height:60px}
.form-actions{display:flex;gap:10px;justify-content:flex-end}

/* devis editor */
.editor{display:grid;grid-template-columns:1.4fr 1fr;gap:16px;align-items:start}
.lignes th{font-size:10px;letter-spacing:.14em;text-transform:uppercase;color:var(--gray);text-align:left;padding:8px;border-bottom:1px solid var(--ink)}
.lignes td{padding:6px}
.lignes input,.lignes select{padding:8px;border:1px solid var(--line);font-size:13px;width:100%;font-family:inherit}
.totaux{padding:16px 18px}
.totaux .t-row{display:flex;justify-content:space-between;padding:6px 0;font-size:13.5px}
.totaux .t-grand{font-weight:800;font-size:18px;border-top:2px solid var(--ink);margin-top:8px;padding-top:10px}
.totaux .t-rem{color:var(--green)}

/* modal */
#modal-root .overlay{position:fixed;inset:0;background:rgba(0,0,0,.45);display:flex;align-items:flex-start;justify-content:center;padding:6vh 16px;z-index:50}
#modal-root .smodal{background:#fff;max-width:640px;width:100%;padding:26px 28px;border:1px solid var(--line)}
#modal-root .smodal h3{font-size:14px;letter-spacing:.12em;text-transform:uppercase;margin-bottom:18px}
.smodal-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:20px}

.legend-dot{display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:6px}
.hint{font-size:12px;color:var(--gray);margin-top:8px}
.devis-note{font-size:12px;color:var(--gray);margin-top:6px}
.link-cell{font-size:11.5px;color:var(--blue);word-break:break-all;margin-top:4px}
#modal-root .smodal.smodal-preview{position:fixed;inset:0;width:100vw;height:100vh;height:100dvh;max-width:none!important;max-height:none;padding:0;border:0;background:var(--bg);display:flex;flex-direction:column}
.smodal-head{display:flex;justify-content:space-between;align-items:center;gap:10px;flex-wrap:wrap;padding:14px 22px;border-bottom:1px solid var(--line);background:var(--card)}
.smodal-head h3{font-size:12px;letter-spacing:.14em;text-transform:uppercase;margin:0;flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.smodal-head div{display:flex;gap:8px;flex-shrink:0}
.smodal-head .btn{white-space:nowrap}
.preview-frame{flex:1;width:100%;height:auto;min-height:0;border:none;background:#fff;display:block}
#toast{position:fixed;bottom:22px;right:22px;background:var(--ink);color:#fff;padding:12px 18px;font-size:13px;z-index:99;opacity:0;transition:opacity .25s;pointer-events:none}
#toast.show{opacity:1}

/* ---------- responsive (sous 992px) ---------- */
@media(max-width:991.98px){
  .login-card{width:min(340px,92vw);padding:36px 24px}
  .page-head{flex-direction:column;align-items:flex-start;gap:12px}
  .page-head h2{font-size:18px}
  .page-head > div:nth-child(2), .page-head > button{width:100%}
  .kpis{grid-template-columns:repeat(auto-fit,minmax(150px,1fr))}
  .dash-grid{grid-template-columns:1fr}
  .kpi .k-val{font-size:19px}
  /* tables → cartes empilées (pas de scroll horizontal) */
  table.data{display:block;overflow:visible;border:0;background:transparent}
  table.data tr:first-child{display:none} /* ligne d'en-tête */
  table.data tbody{display:block}
  table.data tr{display:block;border:1px solid var(--line);margin-bottom:10px;padding:4px 0;background:var(--card)}
  table.data tr:hover td{background:none}
  table.data td{display:flex;justify-content:space-between;align-items:center;gap:14px;padding:9px 12px;border-bottom:1px dashed var(--line);text-align:right}
  table.data td:last-child{border-bottom:0}
  table.data td::before{content:attr(data-label);flex:0 0 auto;max-width:48%;text-align:left;font-size:10px;letter-spacing:.14em;text-transform:uppercase;color:var(--gray);font-weight:700;white-space:normal}
  table.data td.num{white-space:normal}
  table.data .row-actions{justify-content:flex-end;flex-wrap:wrap}
  .editor{grid-template-columns:1fr}
  .editor .panel.totaux{position:static!important}
  /* éditeur de lignes → cartes */
  table.lignes{display:block;min-width:0}
  table.lignes tr:first-child{display:none}
  table.lignes tbody{display:block;min-width:0}
  table.lignes tr.ligne{display:block;border:1px solid var(--line);padding:10px 12px;margin-bottom:12px;background:var(--card)}
  table.lignes td{display:block;width:100%!important;padding:6px 0;text-align:left}
  table.lignes td .l-svc,table.lignes td .l-lib{width:100%}
  .l-tot{text-align:left!important}
  .form-grid{grid-template-columns:1fr}
  .row-actions{flex-wrap:wrap}
  .topbar + .view #view{padding-top:8px}
}

/* ---------- thème sombre ---------- */
body[data-theme="dark"]{background:#131519;color:#e6e8ec}
body[data-theme="dark"] .panel,body[data-theme="dark"] .kpi,body[data-theme="dark"] table.data,body[data-theme="dark"] .smodal,body[data-theme="dark"] .login-card{background:#1b1e24;border-color:#2c3038}
body[data-theme="dark"] table.data th{border-bottom-color:#e6e8ec}
body[data-theme="dark"] table.data td{border-bottom-color:#262a32}
body[data-theme="dark"] table.data tr:hover td{background:#21252c}
@media(max-width:991.98px){
  body[data-theme="dark"] table.data tr,body[data-theme="dark"] table.lignes tr.ligne{background:#1b1e24;border-color:#2c3038}
  body[data-theme="dark"] table.data td{border-bottom-color:#262a32}
}
body[data-theme="dark"] .k-label,body[data-theme="dark"] .k-sub,body[data-theme="dark"] .sub,body[data-theme="dark"] .muted,body[data-theme="dark"] .panel h3,body[data-theme="dark"] .field label,body[data-theme="dark"] table.data th,body[data-theme="dark"] .hint,body[data-theme="dark"] .devis-note,body[data-theme="dark"] .side-foot #btn-logout,body[data-theme="dark"] .bar-l,body[data-theme="dark"] .totaux .t-row,body[data-theme="dark"] .row-title,body[data-theme="dark"] .client-mail{color:#9aa1ab}
body[data-theme="dark"] .page-head h2,body[data-theme="dark"] .kpi .k-val,body[data-theme="dark"] .t-grand,body[data-theme="dark"] .totaux .t-grand{color:#e6e8ec}
body[data-theme="dark"] .btn{background:#1b1e24;border-color:#3a3f49;color:#e6e8ec}
body[data-theme="dark"] .btn:hover{background:#3a3f49;color:#fff}
body[data-theme="dark"] .btn-dark{background:#e6e8ec;color:#131519;border-color:#e6e8ec}
body[data-theme="dark"] .btn-dark:hover{background:#c9cdd4;color:#131519}
body[data-theme="dark"] .btn-ghost{border-color:#3a3f49;color:#9aa1ab}
body[data-theme="dark"] .btn-ghost:hover{background:#3a3f49;color:#fff}
body[data-theme="dark"] .field input,body[data-theme="dark"] .field select,body[data-theme="dark"] .field textarea,body[data-theme="dark"] .lignes input,body[data-theme="dark"] .lignes select,body[data-theme="dark"] .login-card input{background:#131519;border-color:#2c3038;color:#e6e8ec}
body[data-theme="dark"] select option{background:#1b1e24}
body[data-theme="dark"] .badge{background:#22262d;border-color:#3a3f49;color:#cfd3da}
body[data-theme="dark"] .badge.valide{color:#7fd6a4;border-color:#2e6b4a;background:rgba(29,122,70,.15)}
body[data-theme="dark"] .badge.payee{color:#7fd6a4;border-color:#2e6b4a;background:rgba(29,122,70,.15)}
body[data-theme="dark"] .badge.refuse,body[data-theme="dark"] .badge.annule{color:#ef8f89;border-color:#7a3b36;background:rgba(179,54,47,.15)}
body[data-theme="dark"] .badge.envoye{color:#8db8dd;border-color:#2e4d6e;background:rgba(35,92,143,.18)}
body[data-theme="dark"] .badge.emise{color:#d3ab63;border-color:#6e5527;background:rgba(154,107,31,.15)}
body[data-theme="dark"] .badge.brouillon{color:#9aa1ab;background:#22262d}
body[data-theme="dark"] .badge.nouveau{color:#9aa1ab;background:#22262d}
body[data-theme="dark"] .badge.qualifie{color:#8db8dd;border-color:#2e4d6e;background:rgba(35,92,143,.18)}
body[data-theme="dark"] .badge.devis_envoye{color:#d3ab63;border-color:#6e5527;background:rgba(154,107,31,.15)}
body[data-theme="dark"] .badge.gagne{color:#7fd6a4;border-color:#2e6b4a;background:rgba(29,122,70,.15)}
body[data-theme="dark"] .badge.perdu{color:#ef8f89;border-color:#7a3b36;background:rgba(179,54,47,.15)}
body[data-theme="dark"] .login{background:#131519}
body[data-theme="dark"] .login-card input::placeholder{color:#6b7280}
body[data-theme="dark"] .bar{background:#e6e8ec}
body[data-theme="dark"] .totaux .t-grand{border-top-color:#e6e8ec}
body[data-theme="dark"] .smodal-head{background:#1b1e24;border-color:#2c3038}
body[data-theme="dark"] .overlay{background:rgba(0,0,0,.62)}
body[data-theme="dark"] .top5 li,body[data-theme="dark"] .x5 li{border-bottom-color:#262a32}
body[data-theme="dark"] .chart .bar-wrap{background:#262a32}
body[data-theme="dark"] .link-cell{color:#8db8dd}