:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --ink: #1b2129;
  --muted: #56606c;
  --line: #d7dce2;
  --accent: #1d5fbf;
  --ok: #1d7a3c;
  --ok-bg: #e5f3ea;
  --bad: #b42318;
  --bad-bg: #fbeae8;
  --warn: #9a5b06;
  --warn-bg: #fdf3e2;
  --idle: #8a939e;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.4 var(--sans); }
button, select { font: inherit; }

.bar { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.title h1 { font-size: 17px; margin: 0; font-weight: 600; }
.title .sub { color: var(--muted); font-size: 13px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.controls label { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
button { min-height: 32px; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px; background: #f7f8fa; color: var(--ink); cursor: pointer; }
button:hover:not(:disabled) { background: #eceff3; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #174f9f; }
button:disabled { opacity: .5; cursor: not-allowed; }
select { min-height: 32px; border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 0 6px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 470px; height: calc(100% - 62px); min-height: 520px; }
.viewport { position: relative; min-height: 420px; }
#scene { position: absolute; inset: 0; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); background: var(--bg); }
.overlay[hidden] { display: none; }
.views { position: absolute; top: 10px; left: 12px; display: flex; gap: 6px; }
.views button { background: rgba(255,255,255,.94); }
.legend { position: absolute; left: 12px; bottom: 34px; display: flex; gap: 12px; padding: 6px 10px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.legend span { display: flex; gap: 5px; align-items: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.idle { background: var(--idle); } .dot.run { background: var(--accent); } .dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }
.hint { position: absolute; left: 12px; bottom: 6px; margin: 0; font-size: 12px; color: var(--muted); }
.lbl { font: 600 11px var(--sans); color: var(--ink); background: rgba(255,255,255,.9); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; pointer-events: none; white-space: nowrap; }
.lbl.ok { border-color: var(--ok); color: var(--ok); } .lbl.bad { border-color: var(--bad); color: var(--bad); }

.panel { overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); }
.panel section { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel h2 { font-size: 14px; margin: 0 0 8px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.tag { font-size: 11px; font-weight: 500; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 5px; }
.note { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.note.warn { color: var(--warn); } .note.bad { color: var(--bad); }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.steps li small { text-align: right; }
.steps li { display: grid; grid-template-columns: 18px minmax(0, 1fr) minmax(0, auto); gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.steps li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--idle); justify-self: center; }
.steps li.run { color: var(--ink); font-weight: 600; } .steps li.run::before { border-color: var(--accent); background: var(--accent); }
.steps li.done { color: var(--ink); } .steps li.done::before { border-color: var(--ok); background: var(--ok); }
.steps li.fail { color: var(--bad); } .steps li.fail::before { border-color: var(--bad); background: var(--bad); }
.steps li small { color: var(--muted); font-weight: 400; }
.kpi { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 0; }
.kpi div { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.kpi dt { font-size: 11.5px; color: var(--muted); } .kpi dd { margin: 0; font: 600 15px var(--mono); }
.kpi dd.ok { color: var(--ok); } .kpi dd.bad { color: var(--bad); }

canvas { display: block; max-width: 100%; background: #0d0f12; border-radius: 4px; }
#camView { width: 100%; height: auto; }
.headviews { display: grid; grid-template-columns: 200px 1fr; gap: 10px; margin-top: 8px; }
.headviews figure { margin: 0; } .headviews canvas { width: 100%; height: auto; }
figcaption { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.program { margin: 0; padding: 6px 0; max-height: 230px; overflow: auto; background: #f7f8fa; border: 1px solid var(--line); border-radius: 6px;
  font: 12px/1.55 var(--mono); list-style: none; counter-reset: ln; }
.program li { counter-increment: ln; padding: 0 8px 0 40px; position: relative; white-space: pre; }
.program li::before { content: counter(ln); position: absolute; left: 0; width: 30px; text-align: right; color: #9aa2ad; }
.program li.cmt { color: #6b7480; }
.program li.cur { background: #dce8fa; }
.program li.empty { white-space: normal; font-family: var(--sans); color: var(--muted); padding-left: 8px; }
.program li.empty::before { content: none; }
.program li.sec { color: var(--accent); font-weight: 600; }

.joints { display: grid; gap: 4px; }
.joint { display: grid; grid-template-columns: 128px minmax(0, 1fr) 64px; gap: 8px; align-items: center; font-size: 12.5px; }
.joint input { width: 100%; min-height: 24px; }
.joint output { text-align: right; font-family: var(--mono); }
.tcprow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-top: 8px; font-size: 12.5px; }
.num { font-family: var(--mono); }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 11.5px; }
td.num { font-family: var(--mono); white-space: nowrap; }
tbody tr { cursor: pointer; } tbody tr:hover { background: #f4f6f9; }
tbody tr.sel { background: #e8f0fb; }
tr.empty td { color: var(--muted); cursor: default; }
.v-ok { color: var(--ok); font-weight: 600; } .v-bad { color: var(--bad); font-weight: 600; } .v-run { color: var(--accent); }
td.truth { color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: min(560px, calc(100% - 32px));
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 6px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .viewport { height: 62vh; }
  .panel { border-left: 0; overflow: visible; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* вкладки панели */
.tabbar { position: sticky; top: 0; z-index: 2; background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 12px 6px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { min-height: 30px; padding: 0 10px; border-radius: 6px; background: #f7f8fa; font-size: 13px; }
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.follow { display: flex; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.howto { margin: 0; padding-left: 20px; font-size: 13px; display: grid; gap: 4px; }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pair figure { margin: 0; } .pair canvas { width: 100%; height: auto; }
#camMask, #triView, #peakView, #mapView, #axialView, #tolView, #resMap { width: 100%; height: auto; }
.formula { margin: 0; font: 12.5px/1.6 var(--mono); background: #f7f8fa; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; white-space: pre-wrap; }
.pad { padding: 8px 16px 0; margin: 0; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 8px; vertical-align: -1px; }
.sw.back { background: #ff8a4c; } .sw.front { background: #4cc3ff; } .sw.both { background: #b9c0c8; } .sw.fit { background: #35d07f; }
.sw.bad { background: #ff5a4c; } .sw.extra { background: #5a8cff; } .sw.hatch { background: repeating-linear-gradient(45deg, #464a50 0 3px, #282b30 3px 6px); }
.scheme { width: 100%; height: auto; margin-bottom: 8px; background: #f7f8fa; border: 1px solid var(--line); border-radius: 6px; }
.sc-metal { fill: #c9ced4; stroke: #8a939e; }
.sc-tube { fill: #e6e9ed; stroke: #6b727b; } .sc-cam { fill: #ff8a4c; } .sc-cam2 { fill: #4cc3ff; }
.sc-mirror { fill: #6b727b; } .sc-laser { stroke: #e0301e; stroke-width: 2.5; }
.sc-ray { stroke: #ff8a4c; stroke-dasharray: 4 3; } .sc-ray2 { stroke: #4cc3ff; stroke-dasharray: 4 3; }
.sc-dim { stroke: #1b2129; } .sc-t { font: 11px var(--sans); fill: #1b2129; }
