/* GIS Lab — white, clean engineering UI.
   Layout: header with mode tabs · full-bleed 3D viewport · floating left catalogue · right mode panel. */
:root {
  --bg: #ffffff;
  --surface: #f5f7f8;
  --surface-2: #eef1f3;
  --line: #e2e6e9;
  --line-2: #cfd5da;
  --ink: #15202b;
  --muted: #5b6874;
  --faint: #8a96a0;
  --accent: #1d5bbf;
  --accent-soft: #e8f0fc;
  --service: #d8342c;
  --ground: #1f9d4c;
  --free: #2a2f35;
  --test: #2f6fde;
  --sf6: #f2cf1d;
  --reduced: #a3abb2;
  --vented: #ffffff;
  --warn: #d98a00;
  --warn-soft: #fff4dc;
  --alarm: #c9302c;
  --alarm-soft: #fde9e8;
  --ok-soft: #e6f5ec;
  --shadow: 0 1px 2px rgba(21, 32, 43, .06), 0 8px 24px rgba(21, 32, 43, .08);
  --radius: 10px;
  --font-ui: "Barlow", "Segoe UI", system-ui, sans-serif;
  --font-cond: "Barlow Semi Condensed", "Barlow", "Arial Narrow", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Consolas", monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 var(--font-ui); -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 600; text-wrap: balance; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); height: 100%; }
.top {
  display: flex; align-items: center; gap: 16px;
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--line); background: var(--bg); z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand b { font: 700 18px/1 var(--font-cond); letter-spacing: .02em; }
.brand span { color: var(--muted); font: 500 13px/1 var(--font-cond); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 2px; margin-left: auto; min-width: 0; background: var(--surface); border-radius: 9px; padding: 3px; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; white-space: nowrap;
  font: 600 13px/1.2 var(--font-cond); letter-spacing: .03em; text-transform: uppercase; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.stage { position: relative; min-height: 0; }
#viewport { position: absolute; inset: 0; isolation: isolate; z-index: 0; }
#viewport canvas { display: block; touch-action: none; }
.label-layer { position: absolute; inset: 0; pointer-events: none; }
.tag3d {
  font: 600 12px/1 var(--font-cond); letter-spacing: .02em; color: var(--ink);
  background: rgba(255,255,255,.86); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 5px;
  white-space: nowrap; transform: translateY(-8px);
}
.hide-labels .tag3d { display: none; }

/* ---------- panels ---------- */
.panel {
  position: absolute; top: 12px; bottom: 12px; width: 372px; max-width: calc(100% - 24px);
  background: rgba(255,255,255,.97); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0; z-index: 3;
}
.panel.right { right: max(12px, env(safe-area-inset-right, 0px)); }
.panel.left { left: max(12px, env(safe-area-inset-left, 0px)); width: 300px; }
.panel header { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.panel header h2 { font: 600 15px/1.2 var(--font-cond); letter-spacing: .04em; text-transform: uppercase; }
.panel header .sub { color: var(--muted); font-size: 12px; margin-left: auto; }
.panel .body > * { min-width: 0; }
.panel .body { overflow-y: auto; padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.panel .collapse { margin-left: auto; border: 0; background: transparent; color: var(--muted); width: 28px; height: 28px; border-radius: 6px; display: none; }
section.block { display: flex; flex-direction: column; gap: 8px; }
.eyebrow { font: 600 11px/1 var(--font-cond); letter-spacing: .09em; text-transform: uppercase; color: var(--faint); }
.hint { color: var(--muted); font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { min-width: 0; }
.spread { justify-content: space-between; }

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--line-2); background: #fff; border-radius: 7px; padding: 6px 11px;
  font: 600 13px/1.2 var(--font-ui); display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #24313d; }
.btn.open { color: var(--ground); border-color: #b9dcc7; }
.btn.close { color: var(--service); border-color: #efc1be; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 5px 10px; font: 600 12px/1.2 var(--font-ui); color: var(--muted); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 13px; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 20px; background: var(--line-2); position: relative; transition: background .15s; flex: none; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.field { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; font-size: 13px; }
.field output { font: 500 12px/1 var(--font-mono); color: var(--muted); }

/* ---------- catalogue ---------- */
.cat-group { display: flex; flex-direction: column; gap: 2px; }
.cat-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: baseline; text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 6px; }
.cat-item:hover { background: var(--surface); }
.cat-item[aria-current="true"] { background: var(--accent-soft); }
.cat-item .des { font: 500 11px/1.2 var(--font-mono); color: var(--faint); }
.cat-item .nm { font-size: 13px; }

.info { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: #fff; }
.info h3 { font: 600 16px/1.25 var(--font-ui); }
.info .des { font: 600 12px/1 var(--font-mono); color: var(--accent); }
.info p { margin: 0; font-size: 13px; color: #2c3a46; max-width: 65ch; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 0; font-size: 12.5px; border-top: 1px solid var(--line); }
.kv > div { padding: 5px 0; border-bottom: 1px solid var(--line); }
.kv > div:nth-child(odd) { color: var(--muted); padding-right: 8px; }
.kv > div:nth-child(even) { font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { border: 1px solid var(--line-2); background: #fff; border-radius: 999px; padding: 2px 8px; font-size: 12px; }
button.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.subpart { font-size: 12.5px; color: var(--muted); }
.subpart b { color: var(--ink); font-weight: 600; }

/* ---------- operate ---------- */
.sld-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.sld { display: block; width: 100%; min-width: 420px; height: auto; }
.sld text { font-family: var(--font-cond); }
.sld .dev { cursor: pointer; }
.sld .dev:hover .hit { fill: rgba(29, 91, 191, .08); }
.sld .dev.sel .hit { fill: rgba(29, 91, 191, .14); stroke: var(--accent); stroke-width: 1; }
.devcard { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.devcard h3 { font-size: 15px; }
.state-pill { font: 600 11px/1 var(--font-cond); letter-spacing: .06em; text-transform: uppercase; padding: 4px 7px; border-radius: 4px; }
.state-pill.closed { background: var(--alarm-soft); color: var(--service); }
.state-pill.open { background: var(--ok-soft); color: var(--ground); }
.state-pill.moving, .state-pill.intermediate { background: var(--warn-soft); color: var(--warn); }
.cond { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; }
.cond li { display: flex; gap: 6px; }
.cond li::before { content: "✓"; color: var(--ground); font-weight: 700; }
.cond li.no::before { content: "✕"; color: var(--alarm); }
.annun { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.lamp { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: 500 12px/1.25 var(--font-cond); color: var(--faint); background: var(--surface); }
.lamp.on { background: var(--alarm-soft); border-color: #f0b7b4; color: var(--alarm); font-weight: 600; }
.lamp.on.warn { background: var(--warn-soft); border-color: #f1d38f; color: #9a6200; }
.log { font: 12px/1.4 var(--font-mono); max-height: 160px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column-reverse; gap: 2px; background: var(--surface); }
.log div { color: var(--muted); }
.log .alarm { color: var(--alarm); }
.log .warn { color: #9a6200; }
.log .ok { color: var(--ground); }
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tbl th { font: 600 11px/1.2 var(--font-cond); letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.tbl td.closed { color: var(--service); font-weight: 600; }
.tbl td.open { color: var(--ground); font-weight: 600; }

/* ---------- SF6 ---------- */
.comp { display: grid; grid-template-columns: 14px minmax(0,1fr) auto; gap: 4px 10px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 8px; text-align: left; background: #fff; width: 100%; }
.comp:hover { border-color: var(--line-2); }
.comp[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.comp .sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line-2); }
.sw.operating { background: var(--sf6); }
.sw.reduced { background: var(--reduced); }
.sw.vented { background: #fff; }
.sw.vacuum { background: repeating-linear-gradient(45deg, #fff 0 3px, #6b7680 3px 4.5px); }
.comp .nm { font-size: 13px; font-weight: 600; }
.comp .val { font: 500 12px/1.2 var(--font-mono); text-align: right; }
.comp .al { grid-column: 2 / 4; font-size: 12px; color: var(--alarm); }
.bar { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--alarm) 0 30%, var(--warn) 30% 45%, var(--ground) 45% 100%); position: relative; grid-column: 2 / 4; opacity: .85; }
.bar i { position: absolute; top: -3px; width: 2px; height: 12px; background: var(--ink); border-radius: 1px; }
.ptchart { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: 8px; }
.ptchart text { font: 10px var(--font-mono); fill: var(--muted); }

/* ---------- interrupter ---------- */
.stage-card { border-left: 3px solid var(--accent); padding: 6px 0 6px 12px; }
.stage-card b { font: 600 13px/1.2 var(--font-cond); letter-spacing: .04em; text-transform: uppercase; }
.stage-card p { margin: 4px 0 0; font-size: 13px; }
.tchart { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; display: block; }
.tchart text { font: 10px var(--font-mono); fill: var(--muted); }

/* ---------- procedures ---------- */
.proc-list { display: flex; flex-direction: column; gap: 4px; }
.proc-list button { text-align: left; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; display: flex; flex-direction: column; gap: 2px; }
.proc-list button[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
.proc-list .t { font-weight: 600; font-size: 13px; }
.proc-list .s { font-size: 12px; color: var(--muted); }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; counter-reset: st; }
.steps li { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 8px 36px; position: relative; counter-increment: st; }
.steps li::before { content: counter(st); position: absolute; left: 9px; top: 9px; width: 19px; height: 19px; border-radius: 50%; border: 1.5px solid var(--line-2); font: 600 11px/16px var(--font-mono); text-align: center; color: var(--muted); }
.steps li.done::before { content: "✓"; background: var(--ground); border-color: var(--ground); color: #fff; }
.steps li.current { border-color: var(--accent); }
.steps li.current::before { border-color: var(--accent); color: var(--accent); }
.steps li b { font-size: 13px; }
.steps li p { margin: 3px 0 6px; font-size: 12.5px; color: #33424e; }

/* ---------- overlays ---------- */
.toolbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 9px; padding: 4px; box-shadow: var(--shadow); z-index: 2; }
.toolbar button { border: 0; background: transparent; border-radius: 6px; padding: 5px 9px; font: 600 12px/1.2 var(--font-cond); letter-spacing: .04em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.toolbar button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.legend { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 12px; z-index: 2; max-width: calc(100% - 24px); }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { width: 18px; height: 4px; border-radius: 2px; display: inline-block; }
.legend i.box { width: 12px; height: 12px; border-radius: 2px; border: 1px solid var(--line-2); }
.toast { position: absolute; left: 50%; top: 60px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 6; box-shadow: var(--shadow); max-width: min(560px, calc(100% - 32px)); }
.toast.alarm { background: var(--alarm); }
.hover-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font: 500 12px/1.2 var(--font-ui); padding: 5px 8px; border-radius: 5px; z-index: 4; white-space: nowrap; transform: translate(12px, 12px); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .panel.left { width: 260px; }
  .panel.right { width: 340px; }
}
@media (max-width: 820px) {
  .brand span { display: none; }
  .tabs { margin-left: 0; flex: 1; }
  .panel.left, .panel.right { top: auto; left: 8px; right: 8px; width: auto; max-width: none; bottom: max(8px, env(safe-area-inset-bottom, 0px)); max-height: 46%; }
  .panel.left { display: none; }
  .panel .collapse { display: inline-flex; align-items: center; justify-content: center; }
  .panel.collapsed .body { display: none; }
  .toolbar { top: 8px; left: 8px; right: 8px; transform: none; overflow-x: auto; scrollbar-width: none; }
  .legend { bottom: auto; top: 52px; font-size: 11px; gap: 8px; padding: 4px 8px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.panel header .cat-hide { margin-left: 8px; }
.cat-show { position: absolute; top: 12px; left: max(12px, env(safe-area-inset-left, 0px)); z-index: 3; box-shadow: var(--shadow); }
@media (max-width: 820px) { .cat-show { display: none; } }
