:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --ink: #101828;
  --ink-2: #344054;
  --ink-3: #667085;
  --ink-4: #98a2b3;
  --accent: #1d4ed8;
  --accent-soft: #eff4ff;
  --ok: #067647;  --ok-soft: #ecfdf3;
  --warn: #b54708; --warn-soft: #fffaeb;
  --bad: #b42318;  --bad-soft: #fef3f2;
  --info: #175cd3; --info-soft: #eff8ff;
  --muted-soft: #f2f4f7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* ── Boutons & champs ─────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink-2); font-weight: 600; cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .input:focus, .select:focus, textarea:focus { outline: 2px solid #84adff; outline-offset: 1px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #1d2939; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #05603a; }
.btn-warn { background: var(--warn-soft); border-color: #fedf89; color: var(--warn); }
.btn-bad { background: var(--bad-soft); border-color: #fecdca; color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--muted-soft); }
.btn-wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn-wa:hover { background: #1fb457; }
.input, .select, textarea {
  height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); min-width: 0;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; width: 100%; }
label.field { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }

/* ── Connexion ───────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card form { display: grid; gap: 14px; margin-top: 20px; }
.login-brands { display: flex; gap: 8px; margin-top: 18px; }
.error { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ── Structure ───────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.logo-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--ink); display: grid; place-items: center; color: #fff; font-size: 15px; }
.nav { display: flex; gap: 2px; margin-left: 12px; }
.nav button { height: 34px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-3); font-weight: 600; cursor: pointer; }
.nav button:hover { background: var(--muted-soft); color: var(--ink); }
.nav button.active { background: var(--muted-soft); color: var(--ink); }
.topbar .spacer { flex: 1; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-4); display: inline-block; flex: none; }
.dot.on { background: #12b76a; box-shadow: 0 0 0 3px #d1fadf; }
.dot.off { background: #f04438; }
.dot.idle { background: #f79009; }
.toggle-dispo { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); font-weight: 600; cursor: pointer; }
.toggle-dispo.on { background: var(--ok-soft); border-color: #abefc6; color: var(--ok); }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
main { padding: 20px; max-width: 1480px; margin: 0 auto; }

/* ── Marques ─────────────────────────────────────── */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
.brand-logo { width: 26px; height: 26px; border-radius: 6px; object-fit: contain; background: #fff; border: 1px solid var(--border); flex: none; }
.brand-logo.fallback { display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700; border: 0; }
.brand-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 3px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; font-weight: 600; }
.brand-chip .brand-logo { width: 20px; height: 20px; border-radius: 50%; }

/* ── Barre d'outils ──────────────────────────────── */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.seg { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--muted-soft); border: 1px solid var(--border); }
.seg button { height: 30px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-3); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.seg .brand-logo { width: 18px; height: 18px; border-radius: 4px; }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.search { flex: 1; min-width: 200px; max-width: 360px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; color: var(--ink-2); }
.chip .count { min-width: 22px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--muted-soft); display: inline-grid; place-items: center; font-size: 12px; }
.chip.active { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }

/* ── Statuts ─────────────────────────────────────── */
.status { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-a_confirmer { background: var(--info-soft); color: var(--info); }
.s-en_cours { background: #f4f3ff; color: #5925dc; }
.s-confirmee { background: var(--ok-soft); color: var(--ok); }
.s-injoignable { background: var(--warn-soft); color: var(--warn); }
.s-annulee { background: var(--bad-soft); color: var(--bad); }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 6px; font-size: 11px; font-weight: 700; background: var(--muted-soft); color: var(--ink-3); }
.tag-bad { background: var(--bad-soft); color: var(--bad); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-lock { background: #f4f3ff; color: #5925dc; }

/* ── Tableau des commandes ───────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.row { cursor: pointer; transition: background .1s; }
tbody tr.row:hover { background: var(--surface-2); }
tbody tr.row.selected { background: var(--accent-soft); }
tbody tr.row.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { from { background: #fef7c3; } to { background: transparent; } }
.cell-main { font-weight: 600; }
.cell-main.mono { white-space: nowrap; }
.cell-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.products { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.amount { font-weight: 700; white-space: nowrap; text-align: right; }
th.right { text-align: right; }
.empty { padding: 48px 20px; text-align: center; color: var(--ink-3); }
.pager { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); }

/* ── Fiche commande ──────────────────────────────── */
/* Fiche commande : fenêtre modale centrée */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 30; animation: fade .15s ease-out; }
.drawer {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(1120px, calc(100% - 32px)); max-height: calc(100vh - 32px);
  background: var(--surface); z-index: 31; border-radius: 14px; overflow: hidden;
  box-shadow: 0 24px 64px rgba(16, 24, 40, .28); display: flex; flex-direction: column;
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translate(-50%, -48%) scale(.98); opacity: 0; } to { transform: translate(-50%, -50%); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
body.modal-open { overflow: hidden; }
@keyframes slide { from { transform: translateY(8px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--border); border-top: 4px solid var(--brand, var(--ink)); }
.drawer-head .row1 { display: flex; align-items: center; gap: 12px; }
.drawer-head .brand-logo { width: 40px; height: 40px; border-radius: 10px; }
.drawer-title { font-size: 17px; font-weight: 700; }
.drawer-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 20px 20px; display: grid; gap: 16px; align-content: start; }
.col-main, .col-side { display: grid; gap: 16px; align-content: start; min-width: 0; }
/* Ordinateur : deux colonnes, la fenêtre tient dans l'écran ; seul l'historique défile s'il est long */
@media (min-width: 1000px) {
  .drawer-body { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 24px; overflow: hidden; }
  .col-main, .col-side { overflow-y: auto; min-height: 0; padding-right: 4px; }
  .col-side { border-left: 1px solid var(--border); padding-left: 24px; }
}
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); display: grid; gap: 10px; }
.brand-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12px; color: var(--ink-3); }
.brand-meta strong { color: var(--ink-2); }
.section h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; color: var(--ink); word-break: break-word; }
.contact-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; display: flex; gap: 8px; align-items: flex-start; }
.alert-warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #fedf89; }
.alert-bad { background: var(--bad-soft); color: var(--bad); border: 1px solid #fecdca; }
.alert-info { background: var(--info-soft); color: var(--info); border: 1px solid #b2ddff; }
.lines { width: 100%; font-size: 13px; }
.lines td { padding: 7px 0; border-bottom: 1px dashed var(--border); }
.lines tr:last-child td { border-bottom: 0; }
.totals { display: grid; gap: 4px; margin-top: 8px; font-size: 13px; }
.totals div { display: flex; justify-content: space-between; }
.totals .grand { font-size: 16px; font-weight: 700; padding-top: 6px; border-top: 1px solid var(--border); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: grid; grid-template-columns: 12px 1fr; gap: 10px; font-size: 13px; }
.timeline .tl-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); margin-top: 5px; }
.timeline .tl-dot.assign { background: var(--accent); }
.timeline .tl-time { font-size: 11px; color: var(--ink-4); }
.inline-form { display: flex; gap: 8px; }
.inline-form .select, .inline-form .input { flex: 1; }

/* ── Tableau de bord ─────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 16px; }
.kpi .label { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; font-size: 15px; }
.rate { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.bar { flex: 1; height: 6px; border-radius: 999px; background: var(--muted-soft); overflow: hidden; min-width: 50px; }
.bar > span { display: block; height: 100%; background: var(--ok); border-radius: 999px; }
.brand-card { padding: 16px; display: grid; gap: 12px; border-top: 4px solid var(--brand); }
.brand-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.brand-stats div { background: var(--surface-2); border-radius: 8px; padding: 10px; }
.brand-stats .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.brand-stats .l { font-size: 11px; color: var(--ink-3); font-weight: 600; }

/* ── Agents ──────────────────────────────────────── */
.switch { position: relative; width: 36px; height: 20px; border-radius: 999px; background: var(--border-strong); border: 0; cursor: pointer; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); transition: transform .15s; }
.switch.on { background: #12b76a; }
.switch.on::after { transform: translateX(16px); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; padding: 16px; align-items: end; }

/* ── Notifications ───────────────────────────────── */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 50; display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; animation: slide .16s ease-out; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

@media (max-width: 640px) {
  .drawer { top: 0; left: 0; transform: none; width: 100%; max-height: none; height: 100%; border-radius: 0; animation: none; }
}
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .nav { margin-left: 0; order: 3; width: 100%; overflow-x: auto; }
  .conn-label, .user-name { display: none; }
  main { padding: 14px 16px; }
  .hide-sm { display: none; }
  .search { max-width: none; }
}

/* ── Tableau de bord : pilotage ──────────────────── */
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 12px; }
.hero-tile { padding: 16px 18px; border-top: 3px solid var(--border-strong); }
.hero-tile .label { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.hero-value { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -.01em; }
.hero-tile.tone-accent { border-top-color: var(--accent); }
.hero-tile.tone-ok { border-top-color: #12b76a; }
.hero-tile.tone-bad { border-top-color: #f04438; }
.kpi.tone-warn { box-shadow: inset 0 0 0 1px #fedf89, var(--shadow); }
.kpi-rows { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin: 10px 0 0; font-size: 12px; }
.kpi-rows dt { color: var(--ink-3); }
.kpi-rows dd { margin: 0; text-align: right; color: var(--ink-2); font-weight: 600; }
.grid-chart { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 16px; margin-bottom: 16px; }
.chart-wrap { padding: 8px 16px 12px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 11px; }
.chart .hit { fill: transparent; }
.chart .day:hover .hit { fill: var(--muted-soft); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.motifs { padding: 12px 16px 16px; display: grid; gap: 12px; }
.motif-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.bar.bar-neutral > span { background: var(--ink-4); }
.section-title { font-size: 15px; margin: 20px 0 10px; }
.brand-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.brand-flags { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.brand-stats .small-v { font-size: 16px; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
@media (max-width: 900px) { .grid-chart { grid-template-columns: 1fr; } }

/* ── Livraison ───────────────────────────────────── */
.ltag { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 6px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.l-wait { background: var(--muted-soft); color: var(--ink-2); }
.l-prep { background: #f4f3ff; color: #5925dc; }
.l-ship { background: var(--info-soft); color: var(--info); }
.l-done { background: var(--ok-soft); color: var(--ok); }
.l-back { background: var(--bad-soft); color: var(--bad); }
.livraison-box { display: grid; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.livraison-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── Catalogue & nouvelle commande ───────────────── */
.spacer-flex { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.tag-wa { background: #dcfce7; color: #166534; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.cat-card { overflow: hidden; display: flex; flex-direction: column; }
.prod-img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: #fff; border-bottom: 1px solid var(--border); display: block; }
.prod-img.fallback, .prod-thumb.fallback { display: grid; place-items: center; background: var(--muted-soft); color: var(--ink-4); font-weight: 700; font-size: 22px; }
.cat-body { padding: 12px 14px 14px; display: grid; gap: 6px; flex: 1; align-content: start; }
.cat-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.cat-name { font-weight: 600; line-height: 1.3; }
.cat-price { font-size: 15px; }
.cat-actions { display: flex; gap: 8px; margin-top: 4px; }
.cat-actions .btn { flex: 1; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; font-size: 13px; }
.cr-results { display: grid; gap: 6px; margin-top: 10px; }
.cr-prod { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto auto; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.prod-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: contain; background: #fff; border: 1px solid var(--border); }
.prod-thumb.fallback { font-size: 12px; }
.cr-prod-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.drawer-head .seg .brand-logo { width: 18px; height: 18px; border-radius: 4px; }
