:root {
  --bg: #000;
  --panel: #0d0d0f;
  --panel-2: #151518;
  --line: #24242a;
  --line-2: #33333b;
  --text: #f2f2f4;
  --muted: #9a9aa5;
  --faint: #6b6b75;
  --red: #d0202a;
  --red-2: #ff3b45;
  --red-bg: rgba(208, 32, 42, .14);
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, .13);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, .13);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, .14);
  --gray-bg: rgba(154, 154, 165, .13);
  --radius: 10px;
  --side: 232px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.red { color: var(--red-2); }
.green { color: var(--green); }
.amber { color: var(--amber); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.boot img { width: 220px; opacity: .9; }

/* ---------- Mise en page ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; padding: 14px 10px; }
.side .brand { padding: 4px 8px 14px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.side .brand img { width: 150px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.on { background: var(--red-bg); color: #fff; }
.nav a.on svg { color: var(--red-2); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.side .me { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 8px 0; font-size: 13px; }
.side .me button { margin-top: 6px; }
.main { min-width: 0; padding: 22px 28px 60px; }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head .grow { flex: 1; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.sous-onglets { display: flex; gap: 4px; overflow-x: auto; margin: -6px 0 18px; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.sous-onglets::-webkit-scrollbar { display: none; }
.sous-onglets a { padding: 9px 12px; color: var(--muted); font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.sous-onglets a:hover { color: var(--text); }
.sous-onglets a.on { color: #fff; border-bottom-color: var(--red); }
.crumb a:hover { color: var(--text); }
.mobilebar, .tabbar { display: none; }

/* ---------- Composants ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: var(--panel-2); padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #4a4a55; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #e2252f; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red-2); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.iconbtn { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; }
.iconbtn:hover { color: var(--text); background: var(--panel-2); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; align-items: start; }

.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12.5px; color: var(--faint); margin-top: 2px; }
.kpi.alert .value { color: var(--red-2); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--gray-bg); color: var(--muted); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.red { background: var(--red-bg); color: var(--red-2); }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.blue { background: var(--blue-bg); color: #7aa7ff; }

table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-weight: 500; color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr.link { cursor: pointer; }
.t tbody tr.link:hover td { background: var(--panel-2); }
.tablewrap { overflow-x: auto; margin: -4px -16px; padding: 0 6px; }
.thumb { width: 44px; height: 34px; border-radius: 6px; object-fit: cover; background: #1b1b20; }
.empty { color: var(--faint); padding: 18px 4px; text-align: center; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .search { flex: 1; min-width: 200px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); }

input.in, select.in, textarea.in { width: 100%; background: #08080a; border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; outline: none; }
input.in:focus, select.in:focus, textarea.in:focus { border-color: var(--red); }
textarea.in { min-height: 76px; resize: vertical; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

.dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Catalogue ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.eq { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.eq:hover { border-color: var(--line-2); }
.eq .img { aspect-ratio: 4/3; background: #fff; display: grid; place-items: center; }
.eq .img img { width: 100%; height: 100%; object-fit: contain; }
.eq .img.none { background: #141418; color: var(--faint); font-size: 12px; }
.eq .body { padding: 11px 12px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.eq .name { font-weight: 600; }
.eq .meta { font-size: 12.5px; color: var(--muted); }
.eq .price { margin-top: auto; padding-top: 8px; display: flex; justify-content: space-between; align-items: end; font-size: 13px; }
.eq .price b { font-size: 16px; }
.gallery { display: grid; grid-template-columns: 1fr; gap: 8px; }
.gallery .big { background: #fff; border-radius: var(--radius); height: min(420px, 62vw); display: grid; place-items: center; overflow: hidden; }
.gallery .big img { width: 100%; height: 100%; object-fit: contain; }
.gallery .strip { display: flex; gap: 8px; overflow-x: auto; }
.gallery .strip img { width: 74px; height: 56px; object-fit: contain; background: #fff; border-radius: 6px; cursor: pointer; border: 2px solid transparent; }
.gallery .strip img.on { border-color: var(--red); }
.prose { white-space: pre-line; color: #d6d6dc; font-size: 13.5px; }

/* ---------- Pipeline ---------- */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 140px; }
.col h3 { display: flex; justify-content: space-between; margin-bottom: 10px; }
.col .sum { font-size: 12px; color: var(--faint); margin: -6px 0 10px; }
.deal { display: block; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.deal:hover { border-color: var(--line-2); }
.deal .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.deal .what { font-size: 12.5px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal .bottom { display: flex; justify-content: space-between; font-size: 12px; color: var(--faint); margin-top: 6px; }
.deal.late { border-left: 3px solid var(--red); }

/* ---------- Commande ---------- */
.lines .t td { padding: 8px 6px; }
.lines input.in, .lines select.in { padding: 6px 8px; }
.lines .w-qty { width: 70px; }
.lines .w-money { width: 110px; }
.lines .w-date { width: 190px; }
.units { font-size: 12px; margin-top: 4px; }
.totals { margin-left: auto; max-width: 320px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { border-top: 1px solid var(--line-2); margin-top: 6px; padding-top: 8px; font-size: 18px; font-weight: 700; }
.totals .ren-note { display: block; font-size: 12px; color: var(--faint); padding-top: 6px; }
.ren-check { align-items: flex-start; }
.ren-check input { margin-top: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.timeline .item { border-left: 2px solid var(--line-2); padding: 0 0 12px 12px; margin-left: 4px; position: relative; }
.timeline .item::before { content: ""; position: absolute; left: -5px; top: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); }
.timeline .item.appel::before, .timeline .item.courriel::before, .timeline .item.texto::before { background: var(--blue); }
.timeline .item.tache::before { background: var(--amber); }
.timeline .item.note::before { background: var(--text); }
.timeline .meta { font-size: 12px; color: var(--faint); }
.timeline .body { white-space: pre-line; }

/* ---------- Calendrier ---------- */
.gantt { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.gantt table { border-collapse: collapse; min-width: 100%; }
.gantt th, .gantt td { border-bottom: 1px solid var(--line); padding: 0; height: 34px; }
.gantt th.unit, .gantt td.unit { position: sticky; left: 0; background: var(--panel); z-index: 2; min-width: 210px; max-width: 210px; padding: 0 10px; text-align: left; border-right: 1px solid var(--line); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt th.day { min-width: 34px; font-size: 11px; color: var(--faint); font-weight: 500; text-align: center; border-left: 1px solid #18181c; }
.gantt th.day.we, .gantt td.we { background: #0a0a0c; }
.gantt th.day.today { color: var(--red-2); }
.gantt td.cell { border-left: 1px solid #18181c; position: relative; }
.gantt .bar { position: absolute; top: 6px; height: 22px; border-radius: 5px; background: var(--red); color: #fff; font-size: 11.5px; padding: 0 6px; line-height: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; z-index: 1; cursor: pointer; }
.gantt .bar.prov { background: transparent; border: 1px dashed var(--amber); color: var(--amber); }
.gantt .bar.out { background: var(--blue); }
.gantt .bar.done { background: #2a2a31; color: var(--muted); }
.gantt .grp td { background: var(--panel-2); font-weight: 600; font-size: 12px; color: var(--muted); height: 28px; padding: 0 10px; }

/* ---------- Fenêtres ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .7); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 20px; }
.modal.wide { max-width: 760px; }
.modal .mhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal .mfoot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; }
#toast div { background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 10px; margin-top: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }
#toast div.err { border-color: var(--red); }

/* ---------- Connexion ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .box { width: 100%; max-width: 380px; }
.auth img { width: 240px; margin: 0 auto 22px; }
.auth .card { padding: 22px; }
.auth .err { color: var(--red-2); font-size: 13px; margin-bottom: 10px; }

/* ---------- Document imprimable (soumission / facture) ---------- */
.doc { background: #fff; color: #111; border-radius: 6px; padding: 36px 40px; max-width: 860px; margin: 0 auto; font-size: 13px; }
.doc .dhead { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; border-bottom: 3px solid var(--red); padding-bottom: 16px; margin-bottom: 18px; }
.doc .dhead img { width: 300px; }
.doc h1 { color: #111; font-size: 24px; }
.doc .t th { color: #555; border-color: #ddd; }
.doc .t td { border-color: #eee; }
.doc .totals .grand { border-color: #111; }
.doc .muted { color: #666; }
.doc .foot { margin-top: 28px; padding-top: 12px; border-top: 1px solid #ddd; font-size: 11.5px; color: #666; white-space: pre-line; }
/* Conditions de REP au bas du document : repliées à l'écran, complètes à l'impression */
.doc .conds { margin-top: 28px; padding-top: 12px; border-top: 2px solid #111; }
.doc .conds .chead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.doc .conds .chead .grow { flex: 1; }
.doc .conds h2 { color: #111; font-size: 15px; margin: 0; }
.doc .conds h3 { color: #111; font-size: 11.5px; margin: 12px 0 4px; text-transform: uppercase; letter-spacing: .02em; }
.doc .conds .ctxt { font-size: 9.5px; line-height: 1.4; color: #222; white-space: pre-line; text-align: justify; }
.doc .conds.replie .cbody { max-height: 90px; overflow: hidden; -webkit-mask-image: linear-gradient(#000 40%, transparent); mask-image: linear-gradient(#000 40%, transparent); }
.doc .csign { margin-top: 22px; break-inside: avoid; page-break-inside: avoid; }
.doc .csign .slines { display: grid; grid-template-columns: 2fr 2fr 1fr; gap: 18px; margin-top: 30px; }
.doc .csign .slines div { font-size: 10.5px; color: #555; }
.doc .csign .slines span { display: block; border-bottom: 1px solid #111; height: 28px; margin-bottom: 4px; }

@media print {
  body { background: #fff; }
  .side, .mobilebar, .tabbar, .head .actions, .noprint, #toast { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .doc { padding: 0; max-width: none; border-radius: 0; }
  .doc .conds { break-before: page; page-break-before: always; border-top: 0; margin-top: 0; padding-top: 0; }
  .doc .conds.replie .cbody { max-height: none; overflow: visible; -webkit-mask-image: none; mask-image: none; }
  .doc .conds section { break-inside: auto; }
  .doc .conds h3 { break-after: avoid; page-break-after: avoid; }
}

/* ---------- Téléphone ---------- */
@media (max-width: 980px) {
  .split { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { display: block; }
  .side { display: none; }
  .mobilebar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 20; background: rgba(0, 0, 0, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
  .mobilebar img { height: 30px; width: auto; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: rgba(13, 13, 15, .96); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 10.5px; color: var(--muted); }
  .tabbar a.on { color: var(--red-2); }
  .tabbar svg { width: 21px; height: 21px; }
  .main { padding: 16px 16px 96px; }
  h1 { font-size: 19px; }
  .g2 { grid-template-columns: 1fr; }
  .kpi .value { font-size: 22px; }
  .row { flex-direction: column; gap: 0; }
  input.in, select.in, textarea.in { font-size: 16px; }
  .dl { grid-template-columns: 110px 1fr; }
  .board { grid-template-columns: repeat(5, 82vw); scroll-snap-type: x mandatory; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .eq .body { padding: 9px 10px 10px; }
  .col { scroll-snap-align: start; }
  .modal-bg { padding: 0; align-items: end; }
  .modal { max-height: 94vh; border-radius: 14px 14px 0 0; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .t.cards-sm thead { display: none; }
  .t.cards-sm tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .t.cards-sm td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 3px 4px; }
  .t.cards-sm td[data-l]::before { content: attr(data-l); color: var(--faint); font-size: 12px; }
  .t.cards-sm td.hide-sm { display: none; }
  .lines .w-date { width: auto; }
  .doc { padding: 20px 16px; }
  .doc .dhead { flex-direction: column; }
  .doc .dhead img { width: 220px; }
}

.nav-outils { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line, rgba(255,255,255,.1)); }
.nav-titre { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 10px 6px; }
