/* SPDX-License-Identifier: Apache-2.0 */
/* quboforge web lab: instrument-panel look, no external assets. */

:root {
  --sans: "Segoe UI Variable Text", "Segoe UI", "Inter", "Helvetica Neue", Arial, system-ui, sans-serif;
  --mono: "Cascadia Mono", "JetBrains Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
  --radius: 4px;
  --gap: 16px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c100e;
  --panel: #121816;
  --panel-2: #18201d;
  --line: #25302b;
  --line-strong: #3a4a42;
  --text: #e2ebe5;
  --muted: #94a59b;
  --accent: #52e3a4;
  --accent-ink: #04140c;
  --amber: #f0b451;
  --danger: #ff8a7a;
  --focus: #9ad7ff;
  --waste: #1b2420;
  --c0: #3f9d7a; --c1: #c98f3a; --c2: #5b8fc7; --c3: #b7657d; --c4: #8f85cf;
  --c5: #6aa7a8; --c6: #a8a24b; --c7: #c4764a; --c8: #7d9a5a; --c9: #9b7bb0;
  --part-ink: #06100b;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f1ea;
  --panel: #fbfaf5;
  --panel-2: #efede4;
  --line: #d8d4c6;
  --line-strong: #b4ae9c;
  --text: #17201b;
  --muted: #56615a;
  --accent: #0a744a;
  --accent-ink: #ffffff;
  --amber: #955800;
  --danger: #b3261e;
  --focus: #0b57d0;
  --waste: #e6e3d8;
  --c0: #58b392; --c1: #dba653; --c2: #7aa8d8; --c3: #cf8499; --c4: #a59fdd;
  --c5: #84bdbe; --c6: #c0ba66; --c7: #d98f66; --c8: #98b377; --c9: #b397c6;
  --part-ink: #10160f;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
  min-width: 320px;
}

h1, h2, p, figure, fieldset { margin: 0; }
fieldset { border: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
button, input, select { font: inherit; color: inherit; }

svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.skip {
  position: absolute; left: 8px; top: -48px; z-index: 10;
  background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: var(--radius);
}
.skip:focus { top: 8px; }

.num, output, td.num, .metric b, pre, code { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.r { text-align: right; }

/* ------------------------------------------------------------------ header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; flex: none; color: var(--accent); stroke-width: 2; }
.brand-mark circle { fill: currentColor; stroke: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-name { font: 600 18px/1.2 var(--mono); letter-spacing: -0.01em; }
.brand-by { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg.wide { display: flex; width: 100%; }
.seg.wide .seg-btn { flex: 1 1 0; }
.seg-btn {
  min-height: 36px; padding: 6px 12px; background: transparent; border: 0; border-right: 1px solid var(--line-strong);
  font: 500 13px/1.2 var(--mono); cursor: pointer; color: var(--muted);
}
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover { color: var(--text); background: var(--panel-2); }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.seg.stack .seg-btn { font-family: var(--sans); padding: 6px 4px; }

.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer;
  background: transparent; border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--muted);
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn svg { width: 18px; height: 18px; }

/* -------------------------------------------------------------------- tabs */
.tabs {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.tab {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0;
  min-height: 48px; padding: 8px 10px; background: transparent; border: 0; border-right: 1px solid var(--line);
  border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; font-weight: 500;
}
.tab:last-child { border-right: 0; }
.tab svg { width: 20px; height: 20px; flex: none; }
.tab span { min-width: 0; overflow-wrap: anywhere; text-align: center; line-height: 1.2; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); background: var(--bg); }
.tab[aria-selected="true"] svg { color: var(--accent); }

/* ------------------------------------------------------------------ layout */
main { padding: 24px; max-width: 1680px; margin: 0 auto; }
.panel[hidden] { display: none; }
.head { margin-bottom: 20px; max-width: 86ch; }
.head h1 { font: 600 22px/1.25 var(--sans); letter-spacing: -0.01em; margin-bottom: 6px; }
.head p { color: var(--muted); }
h2.sub { font: 600 16px/1.3 var(--sans); margin: 32px 0 12px; }

.split { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 24px; align-items: start; }
.controls {
  display: grid; gap: 14px; padding: 16px; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.stage { display: grid; gap: var(--gap); min-width: 0; }

.field { display: grid; gap: 6px; min-width: 0; font-size: 13px; color: var(--muted); }
.field > legend { margin-bottom: 6px; }
.field-row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.field-row output, .field-row .num { color: var(--text); }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; align-items: end; }

input[type="number"], input[type="text"], select {
  width: 100%; min-width: 0; min-height: 36px; padding: 6px 8px;
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-family: var(--mono); font-size: 13px; color: var(--text);
}
select { font-family: var(--sans); }
input:hover, select:hover { border-color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 24px; margin: 0; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 14px;
  background: transparent; border: 1px solid var(--line-strong); border-radius: var(--radius);
  color: var(--text); cursor: pointer; font-weight: 500;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary svg { fill: currentColor; stroke: none; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; justify-self: start; }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.hint, .note { font-size: 12.5px; color: var(--muted); }
.error { font-size: 13px; color: var(--danger); }

/* ----------------------------------------------------------------- metrics */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.metrics:empty { display: none; }
.metric { background: var(--panel); padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.metric span { font-size: 12px; color: var(--muted); }
.metric b { font-size: 19px; font-weight: 600; overflow-wrap: anywhere; line-height: 1.25; }
.metric small { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.metric.good b { color: var(--accent); }
.metric.warn b { color: var(--amber); }

/* ------------------------------------------------------------------ charts */
.chart { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.chart figcaption {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px;
  padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 500;
}
.legend { display: inline-flex; flex-wrap: wrap; gap: 4px 14px; font-weight: 400; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid currentColor; vertical-align: middle; margin-right: 5px; }
.legend .k-accent { color: var(--accent); }
.legend .k-amber { color: var(--amber); }
.legend .k-muted { color: var(--muted); }
.legend span span { color: var(--muted); }
canvas { display: block; width: 100%; }
#labTraj { height: 300px; }
#labEnergy { height: 200px; }

.code { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.code-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 500;
}
.code-actions { display: inline-flex; gap: 8px; flex-wrap: wrap; }
pre {
  margin: 0; padding: 12px; max-height: 320px; overflow: auto; font-size: 12.5px; line-height: 1.55;
  white-space: pre; tab-size: 2;
}

/* ----------------------------------------------------------------- compare */
.compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.side > header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 12px; border-bottom: 1px solid var(--line);
}
.side h2 { font: 500 13px/1.3 var(--sans); flex: 1 1 160px; min-width: 0; }
.side header .num { font-size: 12.5px; color: var(--muted); }
.tag { font: 600 11.5px/1 var(--mono); padding: 4px 6px; border-radius: 3px; border: 1px solid currentColor; }
.tag.classic { color: var(--amber); }
.tag.forge { color: var(--accent); }

.sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 12px; }
.sheet { display: grid; gap: 4px; min-width: 0; }
.sheet svg { width: 100%; height: auto; display: block; stroke: none; }
.sheet .sheet-bg { fill: var(--waste); stroke: var(--line-strong); }
.sheet .part { stroke: var(--panel); }
.sheet text { fill: var(--part-ink); font-family: var(--mono); font-weight: 600; stroke: none; }
.sheet figcaption { font: 11.5px/1.3 var(--mono); color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.empty { padding: 28px 12px; color: var(--muted); font-size: 13px; text-align: center; }

.legend-row { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }
.legend-row:empty { display: none; }
.legend-row span { display: inline-flex; align-items: center; gap: 6px; }
.legend-row i { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }

.map { padding: 8px; }
.map svg { width: 100%; height: auto; display: block; }
.map .grid-line { stroke: var(--line); stroke-width: 1; }
.map .stop { fill: var(--panel); stroke-width: 2; }
.map .stop-label { fill: var(--muted); stroke: none; font-family: var(--mono); }
.map .depot { fill: var(--text); stroke: var(--panel); }
.map .route { stroke-width: 2.2; fill: none; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-weight: 500; color: var(--muted); font-size: 12px; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { border-top: 1px solid var(--line-strong); border-bottom: 0; font-weight: 600; }
table.data td.num, table.data th.r { white-space: nowrap; }
table.data tr.best td { color: var(--accent); }
table.data caption { caption-side: top; text-align: left; padding: 8px 10px; font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--line); }

/* order parts: two-row cards, so four-digit sizes are never clipped in the narrow side panel */
.part-list { display: grid; gap: 8px; max-height: 520px; overflow-y: auto; padding-right: 2px; }
.part-card { display: grid; gap: 6px; padding: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.part-top { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 6px; min-width: 0; }
.part-id { font: 600 12px/1 var(--mono); color: var(--text); min-width: 22px; padding: 4px 5px; border: 1px solid var(--line-strong); border-radius: 3px; text-align: center; }
.part-dims { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 6px; align-items: end; min-width: 0; }
.part-dims label { display: grid; gap: 2px; min-width: 0; font-size: 11.5px; color: var(--muted); }
.part-dims input[type="number"], .part-top input[type="text"] { min-height: 32px; padding: 4px 6px; font-size: 13px; }
.part-dims .part-rot { display: flex; align-items: center; gap: 4px; min-height: 32px; white-space: nowrap; }
.row-del { width: 28px; height: 30px; display: grid; place-items: center; background: transparent; border: 0; color: var(--muted); cursor: pointer; border-radius: 3px; padding: 0; }
.row-del:hover { color: var(--danger); background: var(--panel-2); }
.row-del svg { width: 14px; height: 14px; }
abbr { text-decoration: none; }

/* ------------------------------------------------------------------- bench */
.bench { display: grid; gap: var(--gap); }
.bench .cmd { font-family: var(--mono); font-size: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; overflow-wrap: anywhere; }
.bench-meta { font: 12px/1.5 var(--mono); color: var(--muted); overflow-wrap: anywhere; }

.arch { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow-x: auto; }
.arch svg { width: 100%; min-width: 640px; height: auto; display: block; }
.arch-box rect { fill: var(--bg); stroke: var(--line-strong); stroke-width: 1.2; rx: 4px; }
.arch-box.core rect { stroke: var(--accent); }
.arch-box.out rect { stroke: var(--amber); }
.arch-box text { fill: var(--text); stroke: none; text-anchor: middle; font: 600 15px var(--mono); }
.arch-box text.arch-sub { fill: var(--muted); font: 400 13px var(--mono); }
.arch-line path { stroke: var(--muted); stroke-width: 1.4; }

.foot {
  display: flex; flex-wrap: wrap; gap: 6px 20px; padding: 16px 24px 28px; border-top: 1px solid var(--line);
  font: 12px/1.4 var(--mono); color: var(--muted);
}

/* -------------------------------------------------------- industry packs */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: end; }
.ind-seg { margin-bottom: 16px; }
.ind-seg .seg-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-family: var(--sans); }
.ind-seg .seg-btn svg { width: 18px; height: 18px; flex: none; }
.demand-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) repeat(3, minmax(0, 1fr)); gap: 6px; align-items: center; }
.demand-grid .dg-h { font-size: 11.5px; text-align: center; }
.demand-grid .dg-r { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.box-list { display: grid; gap: 6px; }
.box-row { display: grid; grid-template-columns: minmax(0, 1fr) 72px; gap: 8px; align-items: center; padding: 6px 8px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); }
.box-name { display: grid; gap: 2px; font-size: 12.5px; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.box-name b { font-family: var(--mono); margin-right: 4px; }
.box-name small { color: var(--muted); font-size: 11px; }
.roster-wrap { padding: 8px; }
table.roster th, table.roster td { padding: 4px 5px; }
table.roster .c { text-align: center; font-family: var(--mono); }
table.roster td.sh0 { background: color-mix(in srgb, var(--c0) 30%, transparent); }
table.roster td.sh1 { background: color-mix(in srgb, var(--c1) 30%, transparent); }
table.roster td.sh2 { background: color-mix(in srgb, var(--c2) 34%, transparent); }
table.roster td.off { color: var(--muted); }
.crates { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; padding: 12px; }
.crate { display: grid; gap: 4px; min-width: 0; }
.crate svg { width: 100%; height: auto; display: block; }
.crate .floor { fill: var(--waste); stroke: var(--line-strong); stroke-width: 12; }
.crate .wall { fill: var(--panel-2); stroke: var(--line-strong); stroke-width: 12; fill-opacity: 0.6; }
.crate .box polygon { stroke: var(--panel); stroke-width: 8; }
.crate .face-x { fill-opacity: 0.78; }
.crate .face-y { fill-opacity: 0.62; }
.crate .face-z { fill-opacity: 1; }
.crate .edge { fill: none; stroke: var(--muted); stroke-width: 10; stroke-dasharray: 60 50; }
.crate figcaption { font: 11.5px/1.3 var(--mono); color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.svg-chart { padding: 8px; }
.svg-chart svg { width: 100%; height: auto; display: block; }
.svg-chart .band0 { fill: var(--c2); fill-opacity: 0.1; }
.svg-chart .band1 { fill: var(--c6); fill-opacity: 0.1; }
.svg-chart .band2 { fill: var(--c3); fill-opacity: 0.16; }
.svg-chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.svg-chart .pv-area { fill: var(--c6); fill-opacity: 0.35; stroke: none; }
.svg-chart .grid-base { fill: none; stroke: var(--amber); stroke-width: 2; stroke-dasharray: 6 4; }
.svg-chart .grid-opt { fill: none; stroke: var(--accent); stroke-width: 2.4; }
.svg-chart .soc-line { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-dasharray: 2 3; }
.svg-chart .tick { fill: var(--muted); stroke: none; font: 11px var(--mono); }
.svg-chart .ideal-line { stroke: var(--text); stroke-width: 1.2; stroke-dasharray: 5 4; }
.svg-chart .zne-fit { fill: none; stroke: var(--accent); stroke-width: 2; }
.svg-chart .zne-lin { stroke: var(--muted); stroke-width: 1.4; stroke-dasharray: 6 4; }
.svg-chart .zne-point { fill: var(--amber); stroke: var(--panel); stroke-width: 2; }
.svg-chart .zne-est { fill: var(--accent); stroke: var(--panel); stroke-width: 1.5; }
.legend .k-pv { color: var(--c6); }
.legend .k-ideal { color: var(--text); }

/* -------------------------------------------------------------- responsive */
@media (max-width: 1020px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tab { border-bottom: 1px solid var(--line); }
  .ind-seg .seg-btn { flex-direction: column; gap: 2px; font-size: 12px; }
  .crates { grid-template-columns: minmax(0, 1fr); }
  .top { padding: 10px 14px; }
  main { padding: 16px 14px; }
  .foot { padding: 14px 14px 24px; }
  .compare { grid-template-columns: minmax(0, 1fr); }
  .tab { flex-direction: column; gap: 4px; padding: 8px 4px; font-size: 11.5px; min-height: 56px; }
  .head h1 { font-size: 19px; }
  .brand-name { font-size: 16px; }
  .brand-by span { display: none; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric b { font-size: 16px; }
  .sheets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #labTraj { height: 240px; }
  #labEnergy { height: 170px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* part-type fills and route strokes (CSS variables cannot be used in SVG presentation attributes) */
.t0 { fill: var(--c0); } .t1 { fill: var(--c1); } .t2 { fill: var(--c2); } .t3 { fill: var(--c3); } .t4 { fill: var(--c4); }
.t5 { fill: var(--c5); } .t6 { fill: var(--c6); } .t7 { fill: var(--c7); } .t8 { fill: var(--c8); } .t9 { fill: var(--c9); }
.b0 { background: var(--c0); } .b1 { background: var(--c1); } .b2 { background: var(--c2); } .b3 { background: var(--c3); } .b4 { background: var(--c4); }
.b5 { background: var(--c5); } .b6 { background: var(--c6); } .b7 { background: var(--c7); } .b8 { background: var(--c8); } .b9 { background: var(--c9); }
.s0 { stroke: var(--c0); } .s1 { stroke: var(--c1); } .s2 { stroke: var(--c2); } .s3 { stroke: var(--c3); } .s4 { stroke: var(--c4); }
.s5 { stroke: var(--c5); } .s6 { stroke: var(--c6); } .s7 { stroke: var(--c7); } .s8 { stroke: var(--c8); } .s9 { stroke: var(--c9); }

/* author display rules must not defeat the hidden attribute */
[hidden] { display: none !important; }
/* map strokes stay crisp regardless of the viewBox scale */
.map svg * { vector-effect: non-scaling-stroke; }
