:root {
  --bg: #0f1216;
  --panel: #161b22;
  --panel-2: #1d232c;
  --line: #2a323d;
  --text: #dfe5ec;
  --muted: #8b96a3;
  --accent: #3fa7ff;
  --accent-2: #2b7fd1;
  --ok: #38c172;
  --bad: #ff5a5f;
  --x: #ff6b6b;
  --y: #51cf66;
  --z: #4dabf7;
  --radius: 6px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 10px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent); }
button.wide { width: 100%; margin-top: 8px; }
input[type=number], input[type=search], input:not([type]), input[type=password], select {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 7px; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
input[type=range] { accent-color: var(--accent); flex: 1; min-width: 0; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }
.brand { font-weight: 700; letter-spacing: .05em; display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 400; color: var(--muted); letter-spacing: 0; }
.logo { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--accent); border-radius: 2px;
  background: linear-gradient(var(--accent), var(--accent)) center / 2px 100% no-repeat,
              linear-gradient(var(--accent), var(--accent)) center / 100% 2px no-repeat; }

/* ---------- login ---------- */
.login { height: 100%; display: grid; place-items: center; }
.login-card {
  width: 320px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.login-card input { color: var(--text); }

/* ---------- layout ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; }
.tab { background: transparent; border-color: transparent; }
.tab.active { background: var(--panel-2); border-color: var(--line); color: var(--accent); }
.toolbar { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-badge { color: var(--muted); padding: 0 6px; }
.user-badge em { font-style: normal; font-size: 11px; border: 1px solid var(--line); border-radius: 10px; padding: 1px 6px; margin-left: 4px; }

.slicer { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 360px; flex-shrink: 0; overflow-y: auto; background: var(--panel);
  border-right: 1px solid var(--line); padding: 4px 14px 20px;
}
.panel section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }
.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.row label { display: flex; align-items: center; gap: 8px; }
.row input[type=number] { width: 90px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.grid3 label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 12px; min-width: 0; }
.grid3 input { width: 100%; }
.panel { overflow-x: hidden; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.file-drop {
  display: block; border: 1px dashed var(--line); border-radius: var(--radius); padding: 14px;
  text-align: center; cursor: pointer; color: var(--muted);
}
.file-drop:hover, .file-drop.drag { border-color: var(--accent); color: var(--text); }
.file-drop input { display: none; }
#model-info { margin-top: 6px; }

/* ---------- cuts panel ---------- */
.axis-block { margin-bottom: 14px; }
.axis-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.axis-head strong { width: 18px; }
.axis-head .count { color: var(--muted); font-size: 12px; flex: 1; }
.axis-head button { padding: 2px 8px; font-size: 12px; }
.axis-x strong { color: var(--x); } .axis-y strong { color: var(--y); } .axis-z strong { color: var(--z); }
.shift-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.shift-row output { width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.cut-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.cut-row .idx { width: 20px; color: var(--muted); font-size: 11px; }
.cut-row input[type=number] { width: 84px; padding: 2px 5px; font-size: 12px; }
.cut-row button { padding: 0 7px; font-size: 12px; line-height: 20px; }
.segments { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.seg-chip { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.seg-chip.bad { border-color: var(--bad); color: var(--bad); }

.summary { background: var(--panel-2); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 8px; line-height: 1.6; }
.summary .bad { color: var(--bad); } .summary .ok { color: var(--ok); }

.progress { position: relative; height: 18px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 8px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--accent-2); transition: width .2s; }
.progress.indeterminate .bar { width: 30% !important; animation: slide 1.2s infinite ease-in-out; }
.progress .label { position: absolute; inset: 0; font-size: 11px; display: grid; place-items: center; }
@keyframes slide { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }

/* ---------- viewport ---------- */
.viewport { flex: 1; position: relative; min-width: 0; }
#canvas-host, #canvas-host canvas { width: 100%; height: 100%; display: block; }
.overlay { position: absolute; background: rgba(15, 18, 22, .82); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.dims { top: 12px; left: 12px; font-variant-numeric: tabular-nums; line-height: 1.6; pointer-events: none; }
.dims b { display: inline-block; width: 16px; }
.dims .x { color: var(--x); } .dims .y { color: var(--y); } .dims .z { color: var(--z); }
.view-toggles { top: 12px; right: 12px; display: flex; gap: 12px; align-items: center; }
.view-toggles button { padding: 2px 8px; }
.legend { bottom: 12px; left: 12px; display: flex; align-items: center; gap: 6px; color: var(--muted); }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-left: 6px; }
.sw.x { background: var(--x); } .sw.y { background: var(--y); } .sw.z { background: var(--z); }
.sw.ok { border: 2px solid var(--ok); } .sw.bad { border: 2px solid var(--bad); }

/* ---------- admin ---------- */
.admin { flex: 1; display: flex; flex-direction: column; padding: 14px; min-height: 0; gap: 10px; }
.admin-bar { display: flex; gap: 8px; align-items: center; }
.admin-bar input[type=search] { flex: 1; max-width: 420px; }
.seg { display: flex; }
.seg-btn { border-radius: 0; }
.seg-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.seg-btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.seg-btn.active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.table-wrap { flex: 1; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel-2); color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .05em; }
td.wrap { white-space: normal; max-width: 360px; word-break: break-word; }
tr:hover td { background: var(--panel); }
.st-SUCCESS { color: var(--ok); } .st-FAILURE, .st-LOCKED { color: var(--bad); } .st-LOGOUT { color: var(--muted); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; }

@media (max-width: 860px) {
  .slicer { flex-direction: column; }
  .panel { width: 100%; max-height: 50%; border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar { flex-wrap: wrap; gap: 8px; }
}

/* ---------- v2: plan / results ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.grid2 label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 12px; min-width: 0; }
.grid2 input, .grid2 select { width: 100%; }
#usable-info { margin-top: 6px; }
.block-list { max-height: 260px; overflow-y: auto; margin-top: 6px; border: 1px solid var(--line); border-radius: var(--radius); }
.block-list:empty { display: none; }
.blk { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; padding: 4px 8px;
       font-size: 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-variant-numeric: tabular-nums; }
.blk:last-child { border-bottom: 0; }
.blk:hover { background: var(--panel-2); }
.blk.sel { background: #3a3413; }
.blk .name { font-weight: 600; }
.blk .dims { color: var(--muted); }
.blk .flag { font-size: 11px; color: var(--bad); }
.blk .flag.warn { color: #f0b429; }
.blk a { padding: 1px 8px; }
a.button { display: inline-block; text-decoration: none; color: inherit; background: var(--panel-2);
           border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; font-size: 13px; }
a.button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
a.button:hover { border-color: var(--accent); }
.summary .warn { color: #f0b429; }
.summary.stale { opacity: .55; }
.sw.plate { background: #f08c2e; }
.sw.sel { border: 2px solid #ffd43b; }
#results .row { gap: 6px; }
