:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #667085;
  --line: #dde2ea;
  --accent: #1f5fbf;
  --accent-soft: #e6eefb;
  --ok: #1e8e3e;
  --warn: #c77700;
  --bad: #c62828;
  --shelf: #8a94a6;
  --gondola: #eef1f5;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 1.25rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.loading { padding: 2rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* top bar */
#topbar { background: #16233b; color: #fff; display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; min-height: 48px; }
#topbar .brand { font-weight: 700; letter-spacing: .3px; display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; }
#topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
#topbar nav a { color: #c9d6ee; text-decoration: none; padding: .3rem .6rem; border-radius: 6px; }
#topbar nav a.active, #topbar nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
#topbar .who { margin-left: auto; display: flex; align-items: center; gap: .6rem; color: #c9d6ee; }

/* buttons & forms */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: .4rem .75rem; cursor: pointer; display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.btn:hover { border-color: #b8c2d3; background: #f8fafc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #194f9f; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: .2rem .5rem; font-size: .85em; }
.btn:disabled { opacity: .5; cursor: default; }
#topbar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }
label.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
label.field > span { font-weight: 600; font-size: .9em; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: .45rem .55rem; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 80px; }
.check { display: flex; align-items: center; gap: .4rem; margin-bottom: .5rem; }

.page { max-width: 1150px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.auth { max-width: 380px; margin: 4rem auto; }
.auth .card { padding: 1.5rem; }
.error { color: var(--bad); margin: .5rem 0; min-height: 1.2em; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.case-card h3 { margin-top: 0; }
.chip { display: inline-block; font-size: .78em; padding: .1rem .5rem; border-radius: 99px; background: #eef1f5; color: #445; white-space: nowrap; }
.chip.ok { background: #e3f4e8; color: var(--ok); }
.chip.warn { background: #fff2dc; color: var(--warn); }
.chip.bad { background: #fde7e7; color: var(--bad); }
.chip.info { background: var(--accent-soft); color: var(--accent); }

table.data { border-collapse: collapse; width: 100%; background: #fff; }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: .35rem .5rem; text-align: left; vertical-align: middle; }
table.data th { font-size: .82em; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); background: #fafbfc; position: sticky; top: 0; z-index: 1; }
table.data tr:hover td { background: #fafcff; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }

#toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: #1d2433; color: #fff; padding: .6rem 1rem; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: 90vw; }
#toast.show { opacity: .95; }
#toast.bad { background: var(--bad); }

/* ------------------------------------------------------------ editor */
.editor { display: grid; grid-template-columns: 290px 1fr 300px; height: calc(100vh - 48px); }
.editor > aside, .editor > section { min-height: 0; }
.ed-left, .ed-right { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.ed-right { border-right: 0; border-left: 1px solid var(--line); overflow-y: auto; padding: .75rem; }
.ed-left .head { padding: .75rem; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: .4rem; }
.ed-left .list { overflow-y: auto; flex: 1; padding: .25rem 0; }
.ed-left.drop-remove { outline: 3px dashed var(--bad); outline-offset: -3px; background: #fff6f6; }
.cat-group { font-size: .78em; text-transform: uppercase; color: var(--muted); padding: .6rem .75rem .2rem; letter-spacing: .4px; font-weight: 600; }
.cat-item { display: flex; gap: .5rem; align-items: center; padding: .35rem .75rem; cursor: grab; border-left: 3px solid transparent; user-select: none; }
.cat-item:hover { background: #f5f8fd; }
.cat-item.placed { opacity: .55; }
.cat-item.placed .nm::after { content: " ✓"; color: var(--ok); }
.cat-item.sel { border-left-color: var(--accent); background: var(--accent-soft); }
.cat-item .sw { width: 22px; height: 22px; border-radius: 4px; flex: none; border: 1px solid rgba(0,0,0,.15); }
.cat-item .nm { font-weight: 600; line-height: 1.15; }
.cat-item .meta { font-size: .8em; color: var(--muted); }

.ed-main { display: flex; flex-direction: column; overflow: hidden; }
.ed-toolbar { display: flex; gap: .5rem; align-items: center; padding: .5rem .75rem; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ed-toolbar .title { font-weight: 700; margin-right: .5rem; max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); background: var(--panel); padding: 0 .75rem; }
.tabs button { border: 0; background: none; padding: .55rem .9rem; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.ed-body { flex: 1; overflow: auto; padding: 1rem; }
.ed-body.pad { padding: 1rem 1.25rem; }

.gondola-wrap { display: flex; gap: 0; align-items: flex-start; padding: 10px 10px 30px 0; }
.zone-axis { position: relative; width: 70px; flex: none; }
.zone-axis .z { position: absolute; left: 0; right: 6px; border-right: 3px solid; font-size: 11px; color: var(--muted); display: flex; align-items: center; justify-content: flex-end; padding-right: 6px; text-align: right; line-height: 1.1; }
.gondola { position: relative; background: var(--gondola); border: 2px solid #9aa4b5; border-bottom-width: 6px; flex: none; }
.gondola .module-sep { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px dashed #b8c0cc; pointer-events: none; }
.gondola .module-lbl { position: absolute; top: -18px; font-size: 11px; color: var(--muted); }
.shelf { position: absolute; left: 0; right: 0; }
.shelf .board { position: absolute; left: -2px; right: -2px; bottom: 0; background: var(--shelf); border-radius: 1px; }
.shelf .items { position: absolute; left: 0; bottom: 0; display: flex; align-items: flex-end; height: 100%; }
.shelf.sel .board { background: var(--accent); }
.shelf.over .board { background: var(--bad); }
.shelf.dragover { background: rgba(31,95,191,.07); }
.shelf .over-mark { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, rgba(198,40,40,.18) 0 6px, transparent 6px 12px); border-left: 2px solid var(--bad); pointer-events: none; }
.shelf .shelf-lbl { position: absolute; right: 4px; top: 2px; font-size: 10px; color: #8b95a7; pointer-events: none; }
.shelf .ins { position: absolute; bottom: 0; width: 3px; background: var(--accent); border-radius: 2px; pointer-events: none; }
.prod { position: relative; flex: none; border: 1px solid rgba(0,0,0,.35); border-bottom: 0; cursor: grab; overflow: hidden; color: #fff; display: flex; align-items: flex-end; justify-content: center; }
.prod .fac { position: absolute; inset: 0; pointer-events: none; }
.prod .lbl { position: relative; font-size: 10px; line-height: 1.05; padding: 1px 2px; text-align: center; text-shadow: 0 0 2px rgba(0,0,0,.7); pointer-events: none; overflow: hidden; max-height: 100%; }
.prod.sel { outline: 3px solid #ffd60a; outline-offset: -1px; z-index: 3; }
.prod.alert-h::after { content: "⚠"; position: absolute; top: 0; right: 1px; font-size: 11px; color: #ffd60a; text-shadow: 0 0 2px #000; }
.prod.dim { opacity: .25; }

.legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .85em; margin: .5rem 0 0 70px; }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.2); }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .75rem; }
.kpi { background: #f7f9fc; border: 1px solid var(--line); border-radius: 6px; padding: .45rem .55rem; }
.kpi b { display: block; font-size: 1.15em; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .78em; color: var(--muted); }
.kpi.bad b { color: var(--bad); }
.kpi.warn b { color: var(--warn); }
.kpi.ok b { color: var(--ok); }
.kpis-wide { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.insp h3 { margin-top: .25rem; }
.insp dl { display: grid; grid-template-columns: auto 1fr; gap: .2rem .6rem; margin: .5rem 0; font-size: .9em; }
.insp dt { color: var(--muted); }
.insp dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.stepper { display: flex; align-items: center; gap: .3rem; margin: .3rem 0; }
.stepper > span:first-child { flex: 1; }
.stepper b { min-width: 2ch; text-align: center; }
.alerts { list-style: none; padding: 0; margin: .25rem 0; font-size: .88em; }
.alerts li { padding: .3rem .4rem; border-radius: 5px; margin-bottom: .25rem; cursor: pointer; }
.alerts li.bad { background: #fde7e7; }
.alerts li.warn { background: #fff2dc; }
.alerts li:hover { filter: brightness(.97); }
.sep { border: 0; border-top: 1px solid var(--line); margin: .75rem 0; }

.instructions { white-space: pre-wrap; line-height: 1.5; max-width: 820px; }
.review-box { background: #fffbea; border: 1px solid #f1df9c; border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 1rem; }
svg text { font-family: inherit; }
.bar-pos { color: var(--ok); }
.bar-neg { color: var(--bad); }

/* case editor */
.cat-table input, .cat-table select { padding: .2rem .3rem; border-radius: 4px; min-width: 0; }
.cat-table input[type=number] { width: 70px; }
.cat-table input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 4px; }
.cat-table td { padding: .2rem .25rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0 .75rem; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 240px 1fr; }
  .ed-right { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: 40vh; }
  .editor { height: auto; }
  .ed-left .list { max-height: 60vh; }
}
@media (max-width: 700px) {
  .editor { grid-template-columns: 1fr; }
  #topbar .who span { display: none; }
}

@media print {
  #topbar, .ed-left, .ed-right, .ed-toolbar .btn, .tabs, .no-print { display: none !important; }
  .editor { display: block; height: auto; }
  .ed-body { overflow: visible; }
  body { background: #fff; }
  .print-only { display: block !important; }
  .prod { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.print-only { display: none; }

/* photos produits */
img.sw.thumb { object-fit: contain; background: #fff; width: 30px; height: 30px; }
.insp-photo { display: block; max-width: 100%; max-height: 150px; margin: 0 auto .5rem; object-fit: contain; }
.prod.photo { border-color: rgba(0,0,0,.18); image-rendering: auto; }
.prod.photo.sel { outline-color: #1f5fbf; }
.cat-photo { width: 40px; height: 40px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 4px; display: block; }
.cat-photo.empty { display: flex; align-items: center; justify-content: center; color: #b0b8c6; font-size: 18px; }
.photo-cell { display: flex; align-items: center; gap: .2rem; }
dialog.off { width: min(980px, 95vw); max-height: 88vh; border: 1px solid var(--line); border-radius: 10px; padding: 0; }
dialog.off::backdrop { background: rgba(20,30,50,.45); }
dialog.off .dlg-head { padding: .8rem 1rem; border-bottom: 1px solid var(--line); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; position: sticky; top: 0; background: #fff; z-index: 2; }
dialog.off .dlg-body { padding: 1rem; overflow: auto; }
.off-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.off-card { border: 1px solid var(--line); border-radius: 8px; padding: .5rem; display: flex; flex-direction: column; gap: .3rem; font-size: .85em; }
.off-card img { width: 100%; height: 110px; object-fit: contain; background: #fafafa; }
.off-card.added { opacity: .5; }
