:root {
  --bg: #0f1720; --bg2: #16212c; --bg3: #1e2b38; --line: #2a3a4a; --fg: #e8eef3; --muted: #8a9bab;
  --accent: #00ae42; --accent2: #00c94d; --danger: #e5484d; --warn: #f5a524; --radius: 12px;
  --top: calc(52px + env(safe-area-inset-top)); --nav: calc(60px + env(safe-area-inset-bottom));
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-size: 15px; overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--bg3); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent2); }
button.danger { color: var(--danger); }
button.small { padding: 4px 10px; font-size: 13px; }
button.big { width: 100%; padding: 14px; font-size: 16px; }
button.icon { width: 40px; height: 40px; padding: 0; display: inline-grid; place-items: center; font-size: 18px; }
button.icon.active { background: var(--accent); border-color: var(--accent); color: #fff; }
select, input, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; min-height: 120px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 6px 0; }
label > select, label > input, label > textarea { margin-top: 4px; color: var(--fg); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--fg); font-size: 14px; }
label.check.inline { display: inline-flex; margin: 0 8px; }
h2 { margin: 0; font-size: 18px; } h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
a { color: var(--accent2); }
.muted { color: var(--muted); } .small { font-size: 12px; } .hidden { display: none !important; } .grow { flex: 1; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* barre du haut */
.topbar { position: fixed; inset: 0 0 auto 0; height: var(--top); padding: env(safe-area-inset-top) 12px 0; display: flex; align-items: center; justify-content: space-between; background: var(--bg2); border-bottom: 1px solid var(--line); z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; } .brand img { width: 28px; height: 28px; }
.printer-pill { display: flex; align-items: center; gap: 8px; border-radius: 999px; padding: 6px 12px; font-size: 13px; max-width: 60vw; }
.printer-pill .txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--accent); } .dot.busy { background: #3b9eff; } .dot.err { background: var(--danger); } .dot.warn { background: var(--warn); }

/* navigation */
.tabs { position: fixed; inset: auto 0 0 0; height: var(--nav); padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--bg2); border-top: 1px solid var(--line); z-index: 20; }
.tabs button { flex: 1; border: 0; border-radius: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--muted); padding: 6px 0; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tabs button.active { color: var(--accent2); }
main { position: fixed; top: var(--top); bottom: var(--nav); left: 0; right: 0; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
.view.scroll { overflow-y: auto; padding: 12px; }

@media (min-width: 900px) {
  :root { --nav: 0px; }
  .tabs { inset: var(--top) auto 0 0; width: 84px; height: auto; flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--line); padding-top: 8px; }
  .tabs button { flex: none; height: 70px; }
  main { left: 84px; }
}

/* scène + panneau */
.stage { position: absolute; inset: 0; }
.canvas3d { position: absolute; inset: 0; touch-action: none; }
.canvas3d canvas { display: block; }
.floating { position: absolute; z-index: 5; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.toolbar.floating { top: 10px; left: 10px; right: 10px; }
.toolbar.top-left select { width: auto; }
.toolbar button.icon { background: rgba(30, 43, 56, .9); backdrop-filter: blur(6px); }
.drop-hint { position: absolute; inset: 20px; border: 2px dashed var(--accent); border-radius: 20px; display: none; place-items: center; font-size: 18px; background: rgba(0, 174, 66, .08); z-index: 6; pointer-events: none; }
.drop-hint.show { display: grid; }
.empty-state { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); pointer-events: none; padding: 40px; }

.panel { position: absolute; z-index: 10; background: var(--bg2); border-top: 1px solid var(--line); display: flex; flex-direction: column;
  left: 0; right: 0; bottom: 0; height: 46%; border-radius: 16px 16px 0 0; transition: height .2s; }
.panel.collapsed { height: 120px; } .panel.expanded { height: calc(100% - 20px); }
.panel-handle { padding: 8px; display: grid; place-items: center; cursor: grab; touch-action: none; }
.panel-handle span { width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
.panel-body { flex: 1; overflow-y: auto; padding: 0 12px 12px; overscroll-behavior: contain; }
.panel-foot { padding: 10px 12px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.panel-foot.two > button { flex: 1; padding: 12px; }
@media (min-width: 900px) {
  .stage { right: 400px; }
  .panel { left: auto; top: 0; width: 400px; height: auto !important; border-radius: 0; border-top: 0; border-left: 1px solid var(--line); }
  .panel-handle { display: none; } .panel-body { padding-top: 12px; }
}

.card { background: var(--bg3); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; } .card-head h3 { margin: 0; }

/* filaments */
.slots { display: flex; flex-direction: column; gap: 6px; }
.slot { display: grid; grid-template-columns: 18px 34px minmax(0, 1fr) auto; gap: 6px; align-items: center; }
.slot .tray { width: 78px; padding: 6px 4px; }
.slot button.small { padding: 4px 7px; }
.slot .num { font-weight: 700; text-align: center; color: var(--muted); }
.slot input[type=color] { width: 34px; height: 34px; padding: 0; border-radius: 8px; border: 1px solid var(--line); background: none; }
.slot select { padding: 6px 8px; }
.slot .tray { font-size: 11px; color: var(--muted); white-space: nowrap; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(255,255,255,.25); vertical-align: middle; }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.quick label { margin: 4px 0; }
.dirty { font-size: 12px; color: var(--warn); margin-top: 6px; }

.objects { display: flex; flex-direction: column; gap: 4px; }
.obj { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.obj.sel { border-color: var(--accent); background: rgba(0,174,66,.08); }
.obj .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.obj select { width: auto; padding: 4px 6px; }
.obj-props { margin-top: 8px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 6px; }
.obj-props label { margin: 2px 0; font-size: 11px; } .obj-props input { padding: 5px 6px; }
.obj-props .full { grid-column: 1 / -1; }

/* aperçu */
.layer-slider { position: absolute; right: 8px; top: 60px; bottom: 20px; width: 44px; display: flex; flex-direction: column; align-items: center; z-index: 5; }
.layer-slider input { writing-mode: vertical-lr; direction: rtl; flex: 1; width: 30px; accent-color: var(--accent); }
.layer-label { font-size: 11px; background: var(--bg3); padding: 3px 6px; border-radius: 6px; margin-top: 4px; white-space: nowrap; }
.legend { left: 10px; bottom: 10px; background: rgba(22,33,44,.9); border-radius: 10px; padding: 8px 10px; font-size: 12px; max-height: 40%; overflow: auto; }
.legend div { display: flex; gap: 6px; align-items: center; margin: 2px 0; }
.legend .t { margin-left: auto; color: var(--muted); padding-left: 10px; }
@media (max-width: 899px) { .legend { bottom: calc(46% + 10px); } .layer-slider { bottom: calc(46% + 10px); } }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--bg); border-radius: 8px; padding: 8px; } .stat b { display: block; font-size: 18px; }
.joblist { display: flex; flex-direction: column; gap: 6px; }
.job { display: grid; grid-template-columns: 48px 1fr auto; gap: 8px; align-items: center; padding: 6px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; }
.job.sel { border-color: var(--accent); }
.job img { width: 48px; height: 48px; object-fit: contain; background: var(--bg); border-radius: 6px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { color: var(--accent2); border-color: var(--accent); } .badge.err { color: var(--danger); border-color: var(--danger); } .badge.run { color: #3b9eff; border-color: #3b9eff; }
pre.log { background: var(--bg); border-radius: 8px; padding: 8px; font-size: 11px; max-height: 200px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* imprimante */
.device-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); max-width: 1200px; margin: 0 auto; }
.device-grid .card { margin: 0; }
.progress { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); transition: width .5s; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; } .kv span:nth-child(odd) { color: var(--muted); }
.temps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.temp { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.temp b { font-size: 22px; display: block; } .temp small { color: var(--muted); }
.ams { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tray { background: var(--bg); border-radius: 10px; padding: 8px 4px; text-align: center; font-size: 12px; position: relative; }
.tray .spool { width: 36px; height: 36px; border-radius: 50%; margin: 0 auto 4px; border: 3px solid rgba(255,255,255,.15); }
.tray.active { outline: 2px solid var(--accent); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; }
.form button { margin-top: 10px; width: 100%; }

/* fichiers / profils */
.lib-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.lib-head input[type=search] { flex: 1; min-width: 160px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--bg3); }
.seg button.active { background: var(--accent); color: #fff; }
.crumbs { flex: 1; font-size: 13px; color: var(--muted); min-width: 120px; } .crumbs a { cursor: pointer; }
.filelist { display: flex; flex-direction: column; gap: 4px; }
.file { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 10px; background: var(--bg3); border-radius: 10px; border: 1px solid var(--line); }
.file .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .file .acts { display: flex; gap: 6px; }
.file .meta { font-size: 12px; color: var(--muted); }
.file.clickable { cursor: pointer; }

/* modales */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: none; align-items: center; justify-content: center; padding: 12px; }
.modal.open { display: flex; }
.modal-box { background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; width: 100%; max-width: 520px; max-height: 100%; display: flex; flex-direction: column; }
.modal-box.wide { max-width: 1000px; height: 100%; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal-content { padding: 14px 16px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.editor-tools { display: flex; gap: 8px; padding: 10px 16px 0; align-items: center; flex-wrap: wrap; } .editor-tools input[type=search] { flex: 1; min-width: 200px; }
.editor-tabs { display: flex; gap: 4px; padding: 10px 16px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.editor-tabs button { white-space: nowrap; } .editor-tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.editor-body { flex: 1; overflow-y: auto; padding: 8px 16px 16px; }
.opt-group h4 { margin: 16px 0 6px; font-size: 13px; color: var(--accent2); text-transform: uppercase; letter-spacing: .04em; }
.opt { display: grid; grid-template-columns: minmax(140px, 1fr) minmax(140px, 1.2fr) 28px; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px solid rgba(42,58,74,.5); }
.opt .lbl { font-size: 14px; } .opt .lbl small { display: block; color: var(--muted); font-size: 11px; font-family: ui-monospace, monospace; }
.opt.modified .lbl { color: var(--warn); }
.opt .val { display: flex; gap: 6px; align-items: center; } .opt .val .unit { color: var(--muted); font-size: 12px; white-space: nowrap; }
.opt .reset { border: 0; background: none; padding: 0; color: var(--warn); visibility: hidden; } .opt.modified .reset { visibility: visible; }
.opt.multiline { grid-template-columns: 1fr 28px; } .opt.multiline .lbl { grid-column: 1 / -1; }
@media (max-width: 600px) { .opt { grid-template-columns: 1fr 28px; } .opt .lbl { grid-column: 1 / -1; } }
.ams-map { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center; margin-bottom: 10px; }

#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav) + 16px); z-index: 100; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--bg3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: 90vw; }
.toast.err { border-color: var(--danger); } .toast.ok { border-color: var(--accent); }

/* ---- V2 ---- */
.toolbar .sep { width: 1px; height: 28px; background: var(--line); margin: 0 2px; }
.paint-btn { font-weight: 700; }
.paint-btn.active { background: #ffb020; border-color: #ffb020; color: #111; }
.paintbar { left: 10px; right: 10px; bottom: 10px; background: rgba(22,33,44,.95); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; z-index: 6; }
.paintbar label { margin: 0; display: flex; align-items: center; gap: 6px; color: var(--fg); }
.paintbar input[type=range] { width: 110px; }
.paintbar .chip { padding: 5px 10px; border-radius: 999px; }
.paintbar .chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.paintbar .swatch { width: 18px; height: 18px; }
@media (max-width: 899px) { .paintbar { bottom: calc(46% + 10px); } }
.panel-tabs { margin: 0 12px 8px; display: flex; }
.panel-tabs button { flex: 1; padding: 8px 4px; font-size: 13px; }
@media (min-width: 900px) { .panel-tabs { margin-top: 12px; } }
.tab-pane { display: none; } .tab-pane.active { display: block; }
.plates { display: flex; flex-direction: column; gap: 6px; }
.plate-item { border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; }
.plate-item.active { border-color: var(--accent); background: rgba(0,174,66,.06); }
.plate-item .head { display: flex; align-items: center; gap: 6px; }
.plate-item .head b { flex: 1; }
.plate-item .opts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
.plate-item .opts select { padding: 5px 6px; font-size: 13px; }
.row-actions { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.editor-inline { padding: 0; overflow: hidden; }
.editor-inline .editor-tools { padding: 10px 10px 0; }
.editor-inline .editor-tabs { padding: 8px 10px; }
.editor-inline .editor-body { padding: 0 10px 10px; overflow: visible; }
.editor-inline .opt { grid-template-columns: 1fr 1fr 22px; gap: 6px; }
.editor-inline .opt .lbl { font-size: 13px; }
.editor-mount { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editor-mount .editor-body { flex: 1; }
.ams-units { display: flex; flex-direction: column; gap: 8px; }
.flush-grid { display: grid; gap: 4px; }
.flush-grid input { padding: 4px; text-align: center; font-size: 12px; }
.flush-grid .hd { display: grid; place-items: center; font-size: 11px; }
.obj .plate-tag { font-size: 11px; color: var(--muted); margin-right: 4px; }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.plate-results { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.plate-results button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- V2 : panneau préparation ---- */
.obj { display: flex; flex-wrap: nowrap; }
.obj .name { flex: 1; min-width: 0; }
.obj .badge { font-size: 10px; padding: 1px 5px; }
.plate-item .head b { flex: none; }
.plate-item .head .small.muted { white-space: nowrap; }
.slot-acts { display: flex; gap: 4px; align-items: center; }
.slot .num.used { color: var(--accent); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 6px; margin-top: 8px; }
.grid3 label { margin: 2px 0; font-size: 11px; } .grid3 input { padding: 5px 6px; }
.swatch.big { width: 26px; height: 26px; display: inline-grid; place-items: center; font-size: 11px; color: #fff; text-shadow: 0 0 2px #000; }
.flush-grid { margin-top: 8px; align-items: center; justify-items: center; overflow-x: auto; }
.paintbar { flex-direction: column; align-items: stretch; }
.paint-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.paint-row .seg button { padding: 5px 10px; min-width: 32px; }
.ams .tray.clickable { cursor: pointer; }
.ams .tray .badge { position: absolute; top: 4px; right: 4px; font-size: 10px; padding: 1px 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 899px) {
  #view-prepare.painting .panel { height: 120px; }
  #view-prepare.painting .paintbar { bottom: 130px; max-height: 45%; overflow-y: auto; }
}
