/* Styles de base — mobile first, thème clair/sombre via variables CSS */
/* Charte Le9hiwa : brun café #2d261e, orange cuivré #d05c27, sable chaud ; accents « zellige » (bleu, vert, or) */
:root {
  --bg: #f7f1e8; --surface: #fffdf9; --text: #2d261e; --muted: #6b5f53; --border: #e3d8c9;
  --primary: #b5481a; --primary-text: #ffffff; --accent: #d05c27; --brown: #2d261e; --danger: #b3261e;
  --ok: #2f7d4f; --ok-bg: #e9f3e4; --err-bg: #fdecea; --warn: #b7791f; --warn-bg: #fff3d6; --warn-text: #4a3200;
  --shadow: 0 1px 2px rgba(45, 38, 30, .06), 0 4px 14px rgba(45, 38, 30, .06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1510; --surface: #241d16; --text: #f4ece2; --muted: #b3a595; --border: #3a3026;
    --primary: #e07a3f; --primary-text: #1a1510; --accent: #e07a3f; --brown: #120e0a; --danger: #ff8a80;
    --ok: #5fbf86; --ok-bg: #1d3326; --err-bg: #3a1f1d; --warn: #d9a441; --warn-bg: #3d3114; --warn-text: #f6e3b0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  --bg: #1a1510; --surface: #241d16; --text: #f4ece2; --muted: #b3a595; --border: #3a3026;
  --primary: #e07a3f; --primary-text: #1a1510; --accent: #e07a3f; --brown: #120e0a; --danger: #ff8a80;
  --ok: #5fbf86; --ok-bg: #1d3326; --err-bg: #3a1f1d; --warn: #d9a441; --warn-bg: #3d3114; --warn-text: #f6e3b0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .brand { font-weight: 700; text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.who { color: var(--muted); font-size: .9rem; }

.page { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; }
.card .code { font-size: 2.5rem; font-weight: 700; margin: 0; color: var(--muted); }

form label { display: block; margin: .9rem 0 .25rem; font-weight: 600; font-size: .95rem; }
input, select { width: 100%; padding: .65rem .75rem; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
input:focus-visible, select:focus-visible, .btn:focus-visible, .btn-ghost:focus-visible, a:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
form.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }
form.inline select { width: auto; }
.cf-turnstile { margin-top: 1rem; }

.btn, .btn-ghost { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid transparent; }
.btn { width: 100%; margin-top: 1.1rem; padding: .7rem 1rem; background: var(--primary); color: var(--primary-text); font-weight: 600; }
.btn-sm { width: auto; margin: 0; padding: .35rem .7rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); padding: .35rem .6rem; border-color: var(--border); }
.links { margin-top: 1.1rem; font-size: .95rem; text-align: center; }

.alert { padding: .6rem .9rem; border-radius: 8px; margin: .75rem 0; }
.alert p { margin: .15rem 0; }
.alert-error { background: var(--err-bg); border: 1px solid var(--danger); }
.alert-ok { background: var(--ok-bg); border: 1px solid var(--primary); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .85rem; color: var(--muted); }
td.actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- Phase 2 : collaborateurs, rôles ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .5rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.count { font-size: 1rem; font-weight: 400; }
.small { font-size: .85rem; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pre { white-space: pre-wrap; }
.breadcrumb { margin: 0 0 .5rem; font-size: .9rem; }
a.btn, .btn-sm { text-decoration: none; display: inline-block; text-align: center; }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.alert-warn { background: #fff4d6; border: 1px solid #b7791f; color: #4a3200; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .alert-warn { background: #3d3114; border-color: #d9a441; color: #f6e3b0; } }
:root[data-theme="dark"] .alert-warn { background: #3d3114; border-color: #d9a441; color: #f6e3b0; }
.text-error { color: var(--danger); }

.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 9rem; flex: 1 1 9rem; }
.toolbar .btn-sm { flex: 0 0 auto; }
.empty { padding: 1.5rem 0; }
.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid var(--border); vertical-align: middle; }
.badge-active { background: var(--ok-bg); border-color: var(--primary); }
.badge-pending { background: #fff4d6; border-color: #b7791f; color: #4a3200; }
.badge-disabled, .badge-rejected { background: var(--err-bg); border-color: var(--danger); }

.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; max-width: 760px; }
.form-card textarea { width: 100%; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .65rem .75rem; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.form-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.form-actions .btn-sm { margin: 0; }
input:disabled { opacity: .7; }

.profile { display: grid; grid-template-columns: 1fr; gap: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; }
@media (min-width: 720px) { .profile { grid-template-columns: 160px 1fr; } }
.avatar-box { display: flex; flex-direction: column; align-items: flex-start; gap: .5rem; }
.avatar { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }
.avatar-initials { display: grid; place-items: center; font-size: 2.2rem; font-weight: 700; background: var(--ok-bg); color: var(--text); }
.photo-btn { cursor: pointer; margin: 0; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: .75rem 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.action-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.action-row .btn-sm { margin: 0; }
.block { margin-top: 1.5rem; }
.form-inline { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .75rem; }

.tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin: .75rem 0 1rem; }
.tab { padding: .4rem .8rem; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; background: var(--surface); color: var(--text); }
.tab-active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
table.matrix th[scope="row"] { font-weight: 600; white-space: nowrap; }
table.matrix input[type="checkbox"] { width: 1.15rem; height: 1.15rem; }

/* ---------- Phase 3A : catalogue ---------- */
.form-card.wide { max-width: 900px; }
.form-card h2 { margin-top: 1.25rem; padding-bottom: .25rem; border-bottom: 1px solid var(--border); }
.form-card h2:first-child { margin-top: 0; }
label.check { display: inline-flex; align-items: center; gap: .45rem; margin: .6rem .75rem .2rem 0; font-weight: 500; }
label.check input[type="checkbox"], .toolbar label.check input { width: 1.1rem; height: 1.1rem; min-width: 0; flex: 0 0 auto; }
.indent { padding-left: 2rem; }
code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: .05rem .35rem; font-size: .85em; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .75rem 1rem; display: flex; flex-direction: column; gap: .15rem; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.product-head { grid-template-columns: 1fr; }
@media (min-width: 720px) { .product-head { grid-template-columns: 220px 1fr; } }
.product-photo { width: 200px; height: 200px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); }
.product-photo-empty { display: grid; place-items: center; color: var(--muted); font-size: .9rem; }
.thumbs { list-style: none; margin: 0 0 .75rem; padding: 0; display: flex; flex-wrap: wrap; gap: .75rem; }
.thumbs li { display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; }
.thumbs img { width: 110px; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.variant-form { margin: .5rem 0; padding: .75rem; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; min-width: 260px; }
.variant-form label { display: block; margin: .4rem 0 0; font-size: .85rem; font-weight: 600; }
.add-variant { margin-top: .75rem; }
td.actions details { flex: 1 1 100%; }

/* ---------- Phase 3B : stock, grilles, import, étiquettes ---------- */
.badge-stock-ok { background: var(--ok-bg); border-color: var(--primary); }
.badge-stock-alert { background: #fff4d6; border-color: #b7791f; color: #4a3200; }
.badge-stock-out { background: var(--err-bg); border-color: var(--danger); }
.badge-stock-untracked { background: var(--bg); color: var(--muted); }
.badge-mv-in { background: var(--ok-bg); border-color: var(--primary); }
.badge-mv-out { background: var(--err-bg); border-color: var(--danger); }
.badge-mv-adjust, .badge-mv-inventory { background: #fff4d6; border-color: #b7791f; color: #4a3200; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge-stock-alert, :root:not([data-theme="light"]) .badge-mv-adjust, :root:not([data-theme="light"]) .badge-mv-inventory { background: #3d3114; border-color: #d9a441; color: #f6e3b0; }
}
:root[data-theme="dark"] .badge-stock-alert, :root[data-theme="dark"] .badge-mv-adjust, :root[data-theme="dark"] .badge-mv-inventory { background: #3d3114; border-color: #d9a441; color: #f6e3b0; }
.neg { color: var(--danger); font-weight: 600; }
.pos { color: var(--primary); font-weight: 600; }
.stock-lines { margin: .25rem 0 1rem; padding-left: 1.2rem; }
.count-input { width: 8rem; text-align: right; }
.stat-link { text-decoration: none; color: inherit; }
.stat-warn { border-color: #b7791f; }
.stat-bad { border-color: var(--danger); }
.import-result { margin-top: 1rem; }
.import-result .btn { margin: .5rem 0; width: auto; }

/* Étiquettes : grille de 3 colonnes, impression A4 */
.labels { display: grid; grid-template-columns: repeat(3, 63mm); gap: 2mm; margin-top: 1rem; }
.label { width: 63mm; height: 38mm; box-sizing: border-box; padding: 2mm 3mm; border: 1px dashed var(--border); background: #fff; color: #000; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; break-inside: avoid; }
.label-name { font-size: 9pt; font-weight: 700; line-height: 1.15; }
.label-variant { font-size: 7.5pt; }
.label-code { text-align: center; flex: 1; display: grid; place-items: center; min-height: 0; font-size: 8pt; }
.label-code svg { max-width: 100%; max-height: 17mm; height: auto; }
.label-foot { display: flex; justify-content: space-between; align-items: baseline; font-size: 7.5pt; }
.label-foot strong { font-size: 10pt; }
@media print {
  .topbar, .no-print, .tabs, .alert { display: none !important; }
  body { background: #fff; }
  .page { max-width: none; padding: 0; }
  .labels { margin: 0; gap: 0; }
  .label { border: 0; outline: 0.1mm dotted #bbb; }
  @page { size: A4; margin: 8mm 6mm; }
}

/* ---------- Phase 4 : clients ---------- */
.badge-cust-active { background: var(--ok-bg); border-color: var(--primary); }
.badge-cust-inactive { background: var(--bg); color: var(--muted); }
.badge-cust-blocked { background: var(--err-bg); border-color: var(--danger); }
.action-row select, .action-row input[type="text"] { width: auto; min-width: 10rem; }
.alert ul { margin: .25rem 0 .5rem 1.2rem; padding: 0; }
.alert label.check { margin-top: .5rem; }

/* ---------- Phase 5 : ventes ---------- */
.badge-doc-draft, .badge-doc-expired { background: var(--bg); color: var(--muted); }
.badge-doc-sent, .badge-doc-confirmed, .badge-doc-partially_delivered, .badge-doc-issued, .badge-doc-partial { background: #fff4d6; border-color: #b7791f; color: #4a3200; }
.badge-doc-accepted, .badge-doc-converted, .badge-doc-delivered, .badge-doc-paid, .badge-doc-validated { background: var(--ok-bg); border-color: var(--primary); }
.badge-doc-refused, .badge-doc-cancelled { background: var(--err-bg); border-color: var(--danger); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge-doc-sent, :root:not([data-theme="light"]) .badge-doc-confirmed, :root:not([data-theme="light"]) .badge-doc-partially_delivered,
  :root:not([data-theme="light"]) .badge-doc-issued, :root:not([data-theme="light"]) .badge-doc-partial { background: #3d3114; border-color: #d9a441; color: #f6e3b0; }
}
:root[data-theme="dark"] .badge-doc-sent, :root[data-theme="dark"] .badge-doc-confirmed, :root[data-theme="dark"] .badge-doc-partially_delivered,
:root[data-theme="dark"] .badge-doc-issued, :root[data-theme="dark"] .badge-doc-partial { background: #3d3114; border-color: #d9a441; color: #f6e3b0; }

.totals-box { margin: 1rem 0 0 auto; max-width: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .6rem 1rem; }
.totals-box div { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem 0; font-variant-numeric: tabular-nums; }
.totals-box .grand { border-top: 1px solid var(--border); margin-top: .3rem; padding-top: .45rem; font-size: 1.1rem; }

.chip { display: inline-flex; align-items: center; gap: .6rem; padding: .35rem .75rem; border: 1px solid var(--primary); background: var(--ok-bg); border-radius: 999px; margin: .25rem 0 .5rem; }
.chip[hidden], [hidden] { display: none !important; }
.results { list-style: none; margin: .25rem 0 .5rem; padding: 0; max-width: 640px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.results:empty { display: none; }
.results li { border-bottom: 1px solid var(--border); padding: .35rem .6rem; }
.results li:last-child { border-bottom: 0; }
.result-btn { width: 100%; text-align: left; background: none; border: 0; padding: .3rem 0; font: inherit; color: var(--text); cursor: pointer; }
.result-btn:hover, .result-btn:focus-visible { color: var(--primary); text-decoration: underline; outline: none; }
.editor-table td { vertical-align: top; }
.editor-table select { width: auto; max-width: 11rem; padding: .35rem .4rem; }
.cell-input { width: 5.5rem; text-align: right; padding: .35rem .4rem; }
.company-logo { max-width: 200px; max-height: 90px; object-fit: contain; border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: .4rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }

/* ---------- Phase 5B : livraisons, factures ---------- */
.badge-doc-invoiced { background: var(--ok-bg); border-color: var(--primary); }
.email-box { margin-top: .75rem; }
.email-box > summary { display: inline-block; }

/* ---------- Phase 5C : paiements, avoirs ---------- */
.badge-pay-cleared { background: var(--ok-bg); border-color: var(--primary); }
.badge-pay-received { background: #fff4d6; border-color: #b7791f; color: #4a3200; }
.badge-pay-bounced, .badge-pay-cancelled { background: var(--err-bg); border-color: var(--danger); }
.badge-doc-applied { background: var(--ok-bg); border-color: var(--primary); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge-pay-received { background: #3d3114; border-color: #d9a441; color: #f6e3b0; } }
:root[data-theme="dark"] .badge-pay-received { background: #3d3114; border-color: #d9a441; color: #f6e3b0; }

/* ---------- Phase 6 : rapports ---------- */
:root { --c1: #d05c27; --c2: #1e4fa0; --c3: #2f7d4f; --c4: #e0a526; --c5: #5a4636; --c6: #7a4fa3; --c7: #16a2b8; --c8: #a8473a; --c9: #8a7f73; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --c1: #e8854a; --c2: #6f9be6; --c3: #5fbf86; --c4: #f0c04a; --c5: #c9ad94; --c6: #b68ae0; --c7: #52c7d9; --c8: #e58a7c; --c9: #aaa095; } }
:root[data-theme="dark"] { --c1: #e8854a; --c2: #6f9be6; --c3: #5fbf86; --c4: #f0c04a; --c5: #c9ad94; --c6: #b68ae0; --c7: #52c7d9; --c8: #e58a7c; --c9: #aaa095; }

.filters { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .75rem 1rem; margin: .5rem 0 1rem; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 .75rem; }
.filters label { display: block; margin: .5rem 0 .2rem; font-size: .8rem; font-weight: 600; color: var(--muted); }
.filters .form-actions { margin-top: .75rem; }
.filters .form-actions .btn-sm { margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .75rem; margin: 1rem 0; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .8rem 1rem; display: flex; flex-direction: column; gap: .2rem; }
.kpi-value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-bad { border-color: var(--danger); }
.delta { font-size: .8rem; color: var(--muted); }
.delta-up strong { color: var(--primary); }
.delta-down strong { color: var(--danger); }
.charts-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 900px) { .charts-grid { grid-template-columns: 1fr 1fr; } }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .75rem 1rem; margin-top: 1rem; }
.chart-card h2 { margin-top: .25rem; }
.chart-box { position: relative; height: 320px; }
.chart-msg { padding: 2rem 0; text-align: center; }
tfoot th { background: var(--bg); border-top: 2px solid var(--border); }
.badge-abc-A { background: var(--ok-bg); border-color: var(--primary); }
.badge-abc-B { background: #fff4d6; border-color: #b7791f; color: #4a3200; }
.badge-abc-C { background: var(--bg); color: var(--muted); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge-abc-B { background: #3d3114; border-color: #d9a441; color: #f6e3b0; } }
:root[data-theme="dark"] .badge-abc-B { background: #3d3114; border-color: #d9a441; color: #f6e3b0; }
@media print { .filters, .tabs, .page-actions, .topbar { display: none !important; } .chart-box { height: 240px; } }

/* Phase 7 : journal d'audit, activité, alertes, tâches, synthèse */
.grid-2 .full { grid-column: 1 / -1; }
.audit-lines { margin: .4rem 0 0; padding-left: 1.1rem; font-size: .88rem; }
.audit-before { color: var(--danger); text-decoration: line-through; }
.audit-after { color: var(--primary); font-weight: 600; }
details > summary { cursor: pointer; }
.task-overdue td:first-child { border-left: 3px solid var(--danger); }
.input-sm { padding: .25rem .5rem; font-size: .85rem; max-width: 12rem; }
.synthese { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.25rem; max-width: 820px; }
.synthese h3 { margin: 1.1rem 0 .4rem; }
.synthese table { width: 100%; }
.synthese th[scope="row"] { text-align: left; font-weight: 500; }
@media print { .synthese { border: 0; padding: 0; max-width: none; } .toolbar { display: none !important; } }

/* Phase 8 : double authentification */
.recovery-codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; max-width: 22rem; }
.recovery-codes code { font-size: 1.1rem; letter-spacing: .05em; }

/* ============================================================
   Charte Le9hiwa : habillage moderne (café, terre cuite, zellige)
   ============================================================ */
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; -webkit-font-smoothing: antialiased; line-height: 1.55; }
body { background-image: radial-gradient(1200px 500px at 85% -10%, rgba(208, 92, 39, .09), transparent 60%), radial-gradient(900px 420px at -10% 0%, rgba(30, 79, 160, .05), transparent 55%); background-attachment: fixed; }
h1, h2, h3 { letter-spacing: -.01em; }
h1 { font-weight: 800; font-size: 1.65rem; }
h2 { font-weight: 700; }
a { color: var(--primary); text-underline-offset: 2px; }
::selection { background: var(--accent); color: #fff; }
a, .btn, .btn-ghost, .tab, input, select, textarea { transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .1s ease; }

/* Logo : version claire / sombre */
.brand-logo { display: block; height: auto; max-width: 100%; }
.logo-on-dark { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo-on-light { display: none; } :root:not([data-theme="light"]) .logo-on-dark { display: block; } }
:root[data-theme="dark"] .logo-on-light { display: none; }
:root[data-theme="dark"] .logo-on-dark { display: block; }

/* Barre de navigation : brun café, logo clair, liens en pastilles */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--brown); color: #f4ece2; border-bottom: 3px solid var(--accent); gap: .5rem 1rem; padding: .5rem 1rem; box-shadow: 0 2px 10px rgba(0, 0, 0, .18); }
.topbar .brand { display: flex; align-items: center; flex: 0 0 auto; }
.topbar .brand .logo-on-light { display: none !important; }
.topbar .brand .logo-on-dark { display: block !important; width: 108px; height: auto; }
.topbar nav { gap: .15rem; flex-wrap: wrap; align-items: center; }
.topbar nav a { color: #f4ece2; text-decoration: none; padding: .32rem .7rem; border-radius: 999px; font-size: .9rem; font-weight: 500; }
.topbar nav a:hover { background: rgba(255, 255, 255, .12); }
.topbar nav a[aria-current="page"] { background: var(--accent); color: #fff; font-weight: 600; }
.topbar .who { color: #e7dccd; text-decoration: none; padding: .25rem .6rem; border-radius: 999px; }
.topbar .who:hover { background: rgba(255, 255, 255, .12); }
.topbar .btn-ghost { color: #f4ece2; border-color: rgba(244, 236, 226, .35); }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, .12); }
.topbar a:focus-visible, .topbar .btn-ghost:focus-visible { outline-color: #fff; }
@media (max-width: 900px) {
  .topbar nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: thin; }
  .topbar nav a { white-space: nowrap; }
}

/* Cartes, tableaux, formulaires */
.card, .form-card, .table-wrap, .profile, .stat, .kpi, .form-inline, .synthese, .chart-card { border-radius: var(--radius); box-shadow: var(--shadow); border-color: var(--border); }
th { text-transform: uppercase; letter-spacing: .04em; font-size: .72rem; font-weight: 700; background: color-mix(in srgb, var(--bg) 70%, var(--surface)); color: var(--muted); }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
input, select, textarea { border-radius: 10px; background: var(--surface); }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent); }
.btn:focus-visible, .btn-ghost:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
.page { padding: 1.25rem 1rem 3rem; }

/* Boutons */
.btn, .btn-ghost { border-radius: 10px; }
.btn { background: var(--primary); box-shadow: 0 1px 0 rgba(255, 255, 255, .18) inset, 0 2px 6px rgba(181, 72, 26, .25); }
.btn:hover { background: color-mix(in srgb, var(--primary) 88%, #000); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn-outline:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); border-color: var(--accent); }
.btn-danger { box-shadow: none; }
.btn-ghost:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* Onglets en pastilles */
.tab { border-radius: 999px; font-size: .92rem; background: var(--surface); }
.tab:hover { border-color: var(--accent); }
.tab-active, .tab-active:hover { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

/* États : vert « zellige » pour le succès, ambre pour l'attention */
.alert { border-radius: 12px; }
.alert-ok { border-color: var(--ok); background: var(--ok-bg); }
.alert-warn, .badge-pending, .badge-stock-alert, .badge-mv-adjust, .badge-mv-inventory, .badge-pay-received, .badge-abc-B,
.badge-doc-sent, .badge-doc-confirmed, .badge-doc-partially_delivered, .badge-doc-issued, .badge-doc-partial { background: var(--warn-bg); border-color: var(--warn); color: var(--warn-text); }
.badge-active, .badge-stock-ok { background: var(--ok-bg); border-color: var(--ok); }
.stat-warn { border-color: var(--warn); }
.avatar-initials { background: var(--ok-bg); }

/* Indicateurs : liseré terre cuite */
.kpi, .stat { position: relative; overflow: hidden; }
.kpi::before, .stat::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: linear-gradient(90deg, var(--accent), #e0a526); }
.kpi-bad::before { background: var(--danger); }
.kpi-value { letter-spacing: -.02em; }

/* Pages d'authentification : fond sable, motif discret, grande carte */
.auth-page { background: radial-gradient(700px 380px at 15% 10%, rgba(208, 92, 39, .14), transparent 65%), radial-gradient(700px 420px at 90% 95%, rgba(30, 79, 160, .10), transparent 65%), var(--bg); position: relative; }
.auth-page::before { content: ""; position: absolute; inset: 0; opacity: .5; pointer-events: none;
  background-image: radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--accent) 22%, transparent) 1.5px, transparent 2px); background-size: 28px 28px;
  -webkit-mask-image: radial-gradient(ellipse at center, transparent 35%, #000 100%); mask-image: radial-gradient(ellipse at center, transparent 35%, #000 100%); }
.auth-page .card { position: relative; max-width: 440px; padding: 2rem 1.75rem; border-top: 4px solid var(--accent); }
.brand-title { margin: 0 0 .5rem; text-align: center; font-size: 1rem; }
.brand-title .brand-logo { width: min(260px, 80%); margin: 0 auto; }
.auth-page .card h2 { text-align: center; margin-top: .25rem; }
.auth-page .card .muted { text-align: center; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } .btn:hover { transform: none; } }
@media print { body { background: #fff !important; } .topbar { display: none !important; } }

/* ============================================================
   Menu latéral (écrans larges) : la barre du haut devient une colonne à gauche.
   Sur téléphone et tablette étroite, le menu reste une barre horizontale défilante.
   ============================================================ */
@media (min-width: 901px) {
  body.with-sidebar { padding-left: 252px; }
  .topbar { position: fixed; top: 0; left: 0; bottom: 0; width: 252px; z-index: 30; flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: .75rem;
    padding: 1.1rem .85rem 1rem; border-bottom: 0; border-right: 3px solid var(--accent); box-shadow: 2px 0 14px rgba(0, 0, 0, .18); overflow-y: auto; scrollbar-width: thin; }
  .topbar .brand { justify-content: center; padding: .2rem .4rem .9rem; border-bottom: 1px solid rgba(244, 236, 226, .15); }
  .topbar .brand .logo-on-dark { width: 160px; }
  .topbar nav { order: 0; flex: 1 1 auto; flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: .15rem; overflow: visible; padding: 0; }
  .topbar nav a { display: block; padding: .5rem .8rem; border-radius: 10px; font-size: .93rem; border-left: 3px solid transparent; }
  .topbar nav a[aria-current="page"] { background: rgba(208, 92, 39, .22); border-left-color: var(--accent); color: #fff; }
  .topbar-right { position: sticky; bottom: -1rem; margin-top: auto; background: var(--brown); padding-bottom: .5rem; flex-direction: column; align-items: stretch; gap: .5rem; padding-top: .9rem; border-top: 1px solid rgba(244, 236, 226, .15); }
  .topbar-right .who { text-align: center; }
  .topbar-right form.inline { display: block; }
  .topbar-right .btn-ghost { width: 100%; }
  .page { max-width: 1240px; padding: 1.5rem 1.75rem 3rem; }
}
@media print { body.with-sidebar { padding-left: 0; } }

.kpi-value small { font-size: .8rem; font-weight: 600; color: var(--muted); }
.vues { gap: .35rem; }
.vues .tab { font-weight: 600; }
details.block > summary { cursor: pointer; font-weight: 600; margin-bottom: .5rem; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }

/* Catalogue de l'espace client */
.catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; margin-top: 1rem; }
.catalog-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; display: flex; flex-direction: column; gap: .35rem; }
.catalog-card h2 { font-size: 1rem; margin: .25rem 0 0; }
.catalog-card p { margin: 0; }
.catalog-photo { display: grid; place-items: center; height: 160px; background: var(--bg); border-radius: 10px; overflow: hidden; }
.catalog-photo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.catalog-prices { list-style: none; margin: .4rem 0 0; padding: 0; display: grid; gap: .25rem; }
.catalog-prices li { display: flex; justify-content: space-between; gap: .5rem; border-top: 1px dashed var(--border); padding-top: .25rem; }

.pwd-admin { margin-top: .75rem; }
.pwd-admin-body { margin-top: .5rem; padding: .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; display: grid; gap: .75rem; max-width: 520px; }
.big-code { font-size: 1.25rem; letter-spacing: .04em; user-select: all; }

/* Cartes (Leaflet) : liste des clients et petite carte de la fiche */
.map-layout { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-top: .75rem; }
@media (min-width: 900px) { .map-layout { grid-template-columns: 280px 1fr; align-items: start; } }
.map-filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.map-filters fieldset { border: 0; margin: 0 0 .5rem; padding: 0; }
.map-filters legend { font-weight: 700; margin-bottom: .35rem; padding: 0; }
.owner-list { display: grid; gap: .25rem; max-height: 280px; overflow-y: auto; margin-top: .35rem; }
.owner-list label.owner { margin: 0; display: flex; align-items: center; gap: .4rem; font-weight: 500; }
.owner-dot { width: .85rem; height: .85rem; border-radius: 50%; display: inline-block; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); flex: 0 0 auto; }
.map-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: var(--surface); }
.map-big { height: 560px; width: 100%; }
.map-small { height: 240px; width: 100%; max-width: 640px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin: .5rem 0; }
.map-popup .small { margin-top: .1rem; }
.leaflet-container { font: inherit; }
@media print { .map-filters { display: none; } .map-big { height: 480px; } }


/* ============================================================
   Application mobile (PWA) : rendu « application » sur Android / iOS, zones sûres (encoche, barre de geste), cibles tactiles
   ============================================================ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
@supports (padding: env(safe-area-inset-top)) {
  .topbar { padding-top: calc(.5rem + env(safe-area-inset-top)); padding-left: calc(1rem + env(safe-area-inset-left)); padding-right: calc(1rem + env(safe-area-inset-right)); }
  .page { padding-left: calc(1rem + env(safe-area-inset-left)); padding-right: calc(1rem + env(safe-area-inset-right)); padding-bottom: calc(3rem + env(safe-area-inset-bottom)); }
  .auth-page { padding-top: calc(1rem + env(safe-area-inset-top)); padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
}
@media (max-width: 900px) {
  /* 16 px minimum dans les champs : iOS ne zoome pas à la saisie */
  input, select, textarea { font-size: 16px; }
  .btn, .btn-sm, .btn-ghost, .tab { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn-sm { padding-left: .9rem; padding-right: .9rem; }
  .topbar nav a { min-height: 40px; display: inline-flex; align-items: center; }
  .page-actions, .toolbar { gap: .6rem; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .map-big { height: 62vh; }
  h1 { font-size: 1.4rem; }
}
/* Une fois installée (plein écran), pas de survol ni de soulignement parasites */
@media (display-mode: standalone) {
  a { -webkit-touch-callout: none; }
  body { user-select: none; -webkit-user-select: none; }
  input, textarea, select, .pre, code, td, dd { user-select: text; -webkit-user-select: text; }
}
@media (hover: none) { .btn:hover { transform: none; } tbody tr:hover { background: transparent; } }


/* Créances et commissions */
.text-bad { color: var(--danger); font-weight: 600; }
details.creance { padding: .75rem 1rem; }
details.creance > summary { font-weight: 400; }
details.creance .table-wrap { margin-top: .75rem; }
details.creance-sub { margin: .5rem 0 .5rem 1rem; padding-left: .75rem; border-left: 3px solid var(--border); }

/* État du règlement des commandes */
.badge-paiement-paid { background: var(--ok-bg); border-color: var(--primary); }
.badge-paiement-pending, .badge-paiement-partial { background: #fff4d6; border-color: #b7791f; color: #4a3200; }
.badge-paiement-unpaid { background: var(--bg); color: var(--muted); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge-paiement-pending, :root:not([data-theme="light"]) .badge-paiement-partial { background: #3d3114; border-color: #d9a441; color: #f6e3b0; } }
:root[data-theme="dark"] .badge-paiement-pending, :root[data-theme="dark"] .badge-paiement-partial { background: #3d3114; border-color: #d9a441; color: #f6e3b0; }
tr.row-current td { background: var(--ok-bg); font-weight: 600; }

/* Catégories : liste déroulante des modèles, avec défilement */
.cat-models { margin-top: .35rem; }
.cat-models summary { cursor: pointer; color: var(--accent, #b4441c); font-size: .9rem; }
.cat-models-list { list-style: none; margin: .4rem 0 0; padding: 0 .5rem 0 0; max-height: 16rem; overflow-y: auto; border: 1px solid var(--border, #e4ddd0); border-radius: 8px; background: var(--surface, #fffdf9); }
.cat-models-list li { padding: .4rem .75rem; border-bottom: 1px solid var(--border, #eee6d9); }
.cat-models-list li:last-child { border-bottom: 0; }

.cat-thumb img, .cat-preview img { object-fit: contain; background: #fff; border: 1px solid var(--border, #e4ddd0); border-radius: 8px; }
.cat-preview { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; margin-top: .5rem; padding: .75rem; border: 1px dashed var(--border, #d9cfbd); border-radius: 10px; }
.model-rename { margin-top: .25rem; }
.model-rename summary { cursor: pointer; font-size: .8rem; color: var(--muted, #7a6f62); }
.model-rename form { display: flex; gap: .4rem; margin-top: .3rem; }
.model-rename input { min-width: 16rem; }

/* Stock : disponibilité par catégorie */
.avail-summary { display: flex; flex-wrap: wrap; gap: .6rem; margin: .75rem 0; }
.avail-chip { display: inline-flex; gap: .4rem; align-items: baseline; padding: .5rem .9rem; border: 1px solid var(--border, #e4ddd0); border-radius: 999px; background: var(--surface, #fffdf9); text-decoration: none; color: inherit; }
.avail-chip strong { font-size: 1.15rem; }
.avail-chip.is-active { outline: 2px solid var(--primary, #b4441c); }
.avail-ok { border-color: #2f8a58; } .avail-alert { border-color: #b7791f; } .avail-out { border-color: #c0392b; }
.avail-group { margin: .6rem 0; border: 1px solid var(--border, #e4ddd0); border-radius: 12px; background: var(--surface, #fffdf9); }
.avail-group > summary { cursor: pointer; padding: .8rem 1rem; display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; }
.avail-counts { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.avail-mini { padding: .1rem .6rem; border-radius: 999px; border: 1px solid; font-size: .85rem; }
.avail-sub { margin: .8rem 1rem .2rem; font-size: 1rem; }
.avail-list { list-style: none; margin: 0 0 .5rem; padding: 0 1rem .5rem; }
.avail-row { display: grid; grid-template-columns: 1fr auto auto; gap: .75rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--border, #eee6d9); }
.avail-row:last-child { border-bottom: 0; }
.avail-qty { text-align: right; min-width: 7rem; }
@media (max-width: 600px) { .avail-row { grid-template-columns: 1fr auto; } .avail-qty { grid-column: 1; text-align: left; } }

/* Étiquettes : QR code + code-barres, catégorie, grande taille de boîte */
.label-meta { display: flex; justify-content: space-between; gap: 2mm; font-size: 7.5pt; align-items: baseline; }
.label-sku { font-size: 9pt; font-family: ui-monospace, monospace; }
.label-codes { display: flex; align-items: center; justify-content: center; gap: 3mm; flex: 1; min-height: 0; }
.label-qr svg { height: 17mm; width: 17mm; }
.labels-large .label { width: 100mm; height: 70mm; padding: 4mm; }
.labels-large .label-name { font-size: 14pt; }
.labels-large .label-meta { font-size: 10pt; }
.labels-large .label-sku { font-size: 13pt; }
.labels-large .label-qr svg { height: 30mm; width: 30mm; }
.labels-large .label-code svg { max-height: 30mm; }

/* Parcours d'un collaborateur sur la carte */
.trail-legend { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; margin: .4rem 0; padding: 0; font-size: .9rem; }
.trail-dot { display: inline-block; width: .8rem; height: .8rem; border-radius: 50%; vertical-align: -1px; }
.trail-num { background: transparent; border: 0; box-shadow: none; color: #fff; font-weight: 700; font-size: .75rem; padding: 0; }
.trail-num::before { display: none; }

/* Bouton « Installer l'application » toujours visible, et fenêtre d'aide à l'installation */
.install-btn { white-space: nowrap; }
.install-bar { display: flex; justify-content: flex-end; padding: .5rem max(1rem, env(safe-area-inset-right, 0px)) 0 1rem; }
.install-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, .5); display: grid; place-items: center; padding: 1rem; }
.install-box { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; max-width: 28rem; width: 100%; padding: 1.25rem; display: grid; gap: .75rem; box-shadow: var(--shadow); }
.install-box h2 { margin: 0; }
.install-box ol { margin: 0; padding-left: 1.2rem; display: grid; gap: .4rem; }
@media (max-width: 700px) { .install-btn .install-label { display: none; } }
