:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1c2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2f5bea; --accent-ink: #fff; --danger: #c62f2f; --ok: #1f8a4c; --warn: #b7791f;
  --s-draft: #9aa3b2; --s-confirmed: #2f5bea; --s-out: #d97706; --s-returned: #1f8a4c; --s-cancelled: #c7cbd3;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); display: flex; min-height: 100vh; font-size: 14px; }
.sidebar { width: 200px; background: #151b27; color: #cfd6e4; padding: 18px 12px; flex-shrink: 0; }
.brand { font-weight: 700; font-size: 20px; color: #fff; padding: 0 10px 18px; letter-spacing: .3px; }
.sidebar nav a { display: block; color: inherit; text-decoration: none; padding: 9px 10px; border-radius: 6px; margin-bottom: 2px; }
.sidebar nav a:hover { background: #222a3a; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
main { flex: 1; padding: 24px 28px; min-width: 0; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head .spacer { flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 18px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { border-color: #b8bfcb; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--danger); }
button.small { padding: 3px 8px; font-size: 12px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; width: 100%; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
input.qty { width: 70px; text-align: right; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; }
.grid .wide { grid-column: 1 / -1; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: #f3f5fa; }
tr.cat td { background: #f3f4f6; font-weight: 600; font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); }
.neg { color: var(--danger); font-weight: 600; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; color: #fff; }
.badge.draft { background: var(--s-draft); } .badge.confirmed { background: var(--s-confirmed); }
.badge.out { background: var(--s-out); } .badge.returned { background: var(--s-returned); }
.badge.cancelled { background: var(--s-cancelled); color: var(--ink); }
.alert { border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; background: #fdecec; color: #7d1f1f; border: 1px solid #f3c3c3; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* Planning */
.timeline { overflow-x: auto; }
.tl { display: grid; min-width: 900px; position: relative; }
.tl-day { font-size: 11px; color: var(--muted); text-align: center; padding: 4px 0; border-left: 1px solid var(--line); }
.tl-day.we { background: #f3f4f6; } .tl-day.today { color: var(--accent); font-weight: 700; }
.tl-label { grid-column: 1; align-self: center; padding: 0 10px 0 0; font-size: 13px; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.15; }
.tl-label small { display: block; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.tl-label:hover { color: var(--accent); }
.tl-row { height: 40px; border-top: 1px solid var(--line); grid-column: 1 / -1; }
.tl-bar { height: 26px; margin: 4px 1px; border-radius: 5px; color: #fff; font-size: 12px; padding: 4px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.tl-bar.conflict { box-shadow: inset 0 0 0 2px var(--danger); }
.tl-bar.conflict::before { content: "⚠ "; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; background: var(--c); }

.totals td { border: none; padding: 3px 10px; }
.totals tr.grand td { font-weight: 700; border-top: 1px solid var(--ink); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

dialog { border: none; border-radius: 12px; padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 20, 30, .45); }
dialog form { padding: 20px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 420px; }
#toast.show { opacity: 1; } #toast.error { background: var(--danger); }

/* Comptes, rôles */
.sidebar { display: flex; flex-direction: column; }
.userbox { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid #2a3244; font-size: 12px; color: #9aa6bb; }
.userbox .who { color: #fff; font-size: 13px; margin-bottom: 6px; }
.userbox .who small { display: block; color: #9aa6bb; font-size: 11px; }
.linklike { background: none; border: none; padding: 0; color: #cfd6e4; font-size: 12px; cursor: pointer; text-decoration: underline; }
body.ro .w { display: none !important; }
body:not(.admin) .admin-only { display: none !important; }
body.auth .sidebar { display: none; }
body.auth main { display: grid; place-items: center; min-height: 100vh; }
.auth-card { width: min(380px, 100%); padding: 28px; }
.brand-lg { font-size: 26px; font-weight: 800; margin-bottom: 14px; color: var(--accent); }
.auth-card button { margin-top: 8px; }

/* Unités, codes */
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: #e8edfb; color: #2a47b8; vertical-align: middle; }
.ustate { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; }
.ustate.ok { background: #e3f4ea; color: #1f6b3f; } .ustate.broken { background: #fdecec; color: #9b2222; }
.ustate.missing { background: #fff2dc; color: #8a5a10; } .ustate.retired { background: #eceef1; color: #5b6270; }
.state-actions { margin-top: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.nowrap { white-space: nowrap; }
table.compact td, table.compact th { padding: 5px 8px; font-size: 13px; }

/* Scanner */
.scan-zone { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; align-items: start; }
.scan-form { display: flex; gap: 8px; }
.scan-input { font-size: 16px; padding: 10px 12px; }
.cam-btn { white-space: nowrap; }
.cam-wrap { position: relative; margin-top: 10px; border-radius: 10px; overflow: hidden; background: #000; max-width: 420px; }
.cam-wrap video { display: block; width: 100%; }
.cam-frame { position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.85); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); }
.feed { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.feed li { padding: 7px 10px; border-radius: 6px; margin-bottom: 4px; border-left: 4px solid; }
.feed li.ok { background: #e9f7ef; border-color: var(--ok); }
.feed li.info { background: #eef2fb; border-color: var(--accent); }
.feed li.error { background: #fdecec; border-color: var(--danger); color: #7d1f1f; font-weight: 600; }
.feed li:first-child { font-size: 14px; }
.prog { height: 6px; background: #e7e9ee; border-radius: 3px; margin-top: 5px; width: 110px; overflow: hidden; }
.prog span { display: block; height: 100%; background: var(--warn); }
.prog.done span { background: var(--ok); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.uchip { display: inline-flex; align-items: center; gap: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; padding: 3px 4px 3px 8px; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.uchip.on { background: #e9f7ef; border-color: #b7e0c7; }
.uchip.pending { background: #f4f5f7; color: var(--muted); border-style: dashed; }
.uchip.broken { background: #fdecec; border-color: #f0b9b9; }
.uchip .x { border: none; background: none; padding: 0 5px; font-size: 15px; line-height: 1; color: var(--muted); }
.uchip .brk { display: inline-flex; align-items: center; gap: 3px; margin: 0; font-family: system-ui, sans-serif; font-size: 11px; color: var(--danger); }
.uchip .brk input { width: auto; margin: 0; }
table.inv td { vertical-align: top; }

@media (max-width: 760px) {
  .scan-zone { grid-template-columns: 1fr; }
  .userbox { margin-top: 4px; padding: 6px 10px 0; border-top: none; }
  .userbox .who { display: inline; margin-right: 8px; } .userbox .who small { display: inline; margin-left: 4px; }
  body.auth main { min-height: auto; padding-top: 40px; }
  body { flex-direction: column; }
  .sidebar { width: auto; padding: 10px; }
  .sidebar nav { display: flex; overflow-x: auto; gap: 4px; }
  .sidebar nav a { white-space: nowrap; }
  .panel { overflow-x: auto; }
  .tabs { overflow-x: auto; }
  .tabs button { flex-shrink: 0; }
  .brand { padding: 4px 10px 8px; }
  main { padding: 16px; }
}
@media print { .sidebar, .head button, .no-print { display: none !important; } main { padding: 0; } }

/* Stock à date */
.stock-controls { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; }
.seg button.active { background: var(--ink); color: #fff; }
.when { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.when input { width: auto; }
label.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; font-size: 14px; color: var(--ink); }
.stock-filters { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-top: 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.tile span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tile b { font-size: 24px; font-variant-numeric: tabular-nums; }
.tile b.when-txt { font-size: 14px; line-height: 1.3; display: block; }
.tile.bad { border-color: #f3c3c3; background: #fdf3f3; } .tile.bad b { color: var(--danger); }
.stock-note { margin-top: 0; }
.av { display: inline-block; min-width: 34px; text-align: center; padding: 2px 8px; border-radius: 6px; font-weight: 700; }
.av-pos { background: #e3f4ea; color: #1f6b3f; } .av-zero { background: #fff2dc; color: #8a5a10; } .av-neg { background: #fdecec; color: #9b2222; }
.caret { display: inline-block; color: var(--muted); transition: transform .15s; }
tr.open .caret { transform: rotate(90deg); }
tr.sdetail > td { background: #fafbfc; }
.sdetail-inner { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; padding: 4px 0 8px; }
.sdetail-inner h3 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 0 0 6px; }
a.uchip { text-decoration: none; color: inherit; padding-right: 8px; }
.uchip small { font-family: system-ui, sans-serif; color: var(--muted); font-size: 11px; }
@media (max-width: 760px) {
  .stock-filters, .sdetail-inner { grid-template-columns: 1fr; }
  table.stock tr.srow td:nth-child(2), table.stock th:nth-child(2),
  table.stock tr.srow td:nth-child(5):not(:last-child), table.stock th:nth-child(5):not(:last-child),
  table.stock tr.srow td:last-child, table.stock th:last-child { display: none; }
}
@media print { .tiles { grid-template-columns: repeat(5, 1fr); } tr.sdetail[hidden] { display: none; } }
.when[hidden] { display: none; }

/* Entités */
.entity-box { padding: 0 10px 14px; }
.entity-box label { color: #9aa6bb; font-size: 11px; margin-bottom: 4px; }
.entity-box select { background: #222a3a; color: #fff; border-color: #2f384b; font-size: 13px; padding: 6px 8px; }
.entity-name { color: #cfd6e4; font-size: 13px; font-weight: 600; }
.logo-row { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.logo-row button { margin-right: 6px; }
.logo-box { width: 220px; height: 100px; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; background: #fafbfc; }
.logo-box img { max-width: 200px; max-height: 84px; }
input[type=color] { height: 38px; padding: 3px; width: 90px; }

/* Photo et documents du matériel */
.thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 5px; vertical-align: middle; margin-right: 8px; background: #eef0f3; }
.thumb.empty { display: inline-block; }
.with-thumb { display: inline-flex; align-items: center; }
.mat-top { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; align-items: start; }
.mat-photo img { width: 220px; height: 165px; object-fit: cover; border-radius: 8px; display: block; background: #eef0f3; }
.no-photo { width: 220px; height: 165px; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.photo-actions { display: flex; gap: 6px; margin-top: 8px; }
.doc-icon { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .03em; padding: 3px 5px; border-radius: 4px; background: #e8edfb; color: #2a47b8; }
@media (max-width: 760px) {
  .mat-top { grid-template-columns: 1fr; }
  .mat-photo img, .no-photo { width: 100%; height: auto; aspect-ratio: 4 / 3; }
  .entity-box { padding: 0 10px 6px; }
}
.with-thumb .muted { margin-left: 6px; }

/* Lieux de stockage */
.small-txt { font-size: 12px; }
.depots { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.depots .panel { margin-bottom: 0; }
.depot.clickable:hover { border-color: #b8bfcb; }
body.ro .depot.clickable { cursor: default; }
.stock-filters { grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)); }
.stock-filters select[hidden] { display: none; }
@media (max-width: 760px) { .stock-filters { grid-template-columns: 1fr; } }
