:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e2e5eb;
  --accent: #1f5fbf; --accent-soft: #e8f0fc; --ok: #1e7a46; --warn: #b26a00; --bad: #b3261e;
  --ok-soft: #e6f4ec; --warn-soft: #fff3df; --bad-soft: #fdecea; --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
#app { display: flex; min-height: 100vh; }
aside { width: 220px; background: #17203a; color: #cfd6e6; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
aside .brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; font-weight: 600; color: #fff; }
.logo { background: var(--accent); color: #fff; border-radius: 6px; padding: 4px 7px; font-size: 12px; }
aside nav { display: flex; flex-direction: column; flex: 1; }
aside nav a { color: #cfd6e6; padding: 9px 18px; border-left: 3px solid transparent; }
aside nav a:hover { background: #1f2a4a; text-decoration: none; }
aside nav a.active { background: #1f2a4a; border-left-color: #6ea0ff; color: #fff; }
aside .me { padding: 14px 18px; border-top: 1px solid #2a3557; font-size: 13px; }
aside .me a { color: #9fb6e8; }
main { flex: 1; padding: 24px 28px; max-width: 1400px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 18px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h1 .btn, h1 button { font-size: 14px; font-weight: 400; }
.g4 { margin-bottom: 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 600; margin-top: 4px; }
.kpi.warn .v { color: var(--warn); } .kpi.bad .v { color: var(--bad); }
.bars .row { display: grid; grid-template-columns: 160px 1fr 50px; gap: 8px; align-items: center; margin: 5px 0; }
.bars .track { background: var(--accent-soft); border-radius: 4px; height: 12px; overflow: hidden; }
.bars .fill { background: var(--accent); height: 100%; }
.bars .n { text-align: right; font-variant-numeric: tabular-nums; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
th.sort { cursor: pointer; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f7f9fd; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #cdd2dc; border-radius: 6px; background: #fff; color: var(--ink); }
textarea { width: 100%; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
button, .btn { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid #cdd2dc; background: #fff; cursor: pointer; color: var(--ink); display: inline-block; }
button:hover, .btn:hover { background: #f1f3f7; text-decoration: none; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: #194f9f; }
button.danger { color: var(--bad); border-color: #e7b4b0; }
button:disabled { opacity: .5; cursor: default; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px 16px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.form label.full { grid-column: 1 / -1; }
.form input, .form select { width: 100%; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #eef0f4; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 14px; }
.tabs button.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; word-break: break-word; }
.photos { display: flex; flex-wrap: wrap; gap: 10px; }
.photos figure { margin: 0; width: 160px; }
.photos img { width: 160px; height: 120px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; }
.photos figcaption { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.list-compact { margin: 0; padding: 0; list-style: none; }
.list-compact li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.list-compact li:last-child { border-bottom: 0; }
#toast { position: fixed; bottom: 20px; right: 20px; background: #17203a; color: #fff; padding: 10px 16px; border-radius: 6px; max-width: 420px; z-index: 10; }
#toast.err { background: var(--bad); }
.login { max-width: 360px; margin: 10vh auto; }
.login input { width: 100%; margin-bottom: 10px; }
.login button { width: 100%; }
.diff { font-size: 12px; color: var(--muted); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: flex; align-items: center; justify-content: center; z-index: 20; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 92vh; }
/* Planche d'étiquettes (format A4, 3 x 8) */
.labels { display: grid; grid-template-columns: repeat(3, 63.5mm); gap: 0 2.5mm; }
.label { height: 33.9mm; display: flex; align-items: center; gap: 2mm; padding: 2mm; border: 1px dashed #ccc; overflow: hidden; background: #fff; }
.label svg { width: 26mm; height: 26mm; flex: none; }
.label .code { font-weight: 700; font-size: 13px; }
.label .l2 { font-size: 10px; color: #444; }
@media print {
  aside, .no-print, #toast { display: none !important; }
  main { padding: 0; }
  body { background: #fff; }
  .label { border-color: transparent; }
  @page { size: A4; margin: 13mm 7mm; }
}
@media (max-width: 800px) {
  #app { flex-direction: column; }
  aside { width: 100%; height: auto; position: static; }
  aside nav { flex-direction: row; flex-wrap: wrap; }
  main { padding: 14px; }
  .g2 { grid-template-columns: 1fr; }
}
