/* LoadForge — style.css
   Dark elegant theme. Teal → violet gradient accents.
   Deliberately NOT the warm-paper look: deep navy #0A0F1E, glassy panels,
   soft shadows, 14–16px radii. */

:root {
  --bg: #0a0f1e;
  --bg-2: #0d1428;
  --surface: #111a2e;
  --surface-2: #151f36;
  --surface-3: #1a2745;
  --border: #232f4d;
  --border-soft: #1b2742;
  --text: #e6eaf2;
  --text-dim: #93a0b8;
  --text-faint: #64748f;
  --accent-teal: #2dd4bf;
  --accent-violet: #8b5cf6;
  --accent: #7c6cf0;
  --grad: linear-gradient(135deg, #2dd4bf 0%, #38bdf8 45%, #8b5cf6 100%);
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.12);
  --ok-soft: rgba(52, 211, 153, 0.12);
  --warn-soft: rgba(251, 191, 36, 0.12);
  --radius: 14px;
  --radius-lg: 16px;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.55);
  --shadow-sm: 0 4px 14px rgba(2, 6, 23, 0.4);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --topbar-h: 60px;
  --charts-h: 220px;
  --tabbar-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, rgba(139, 92, 246, 0.14), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, rgba(45, 212, 191, 0.10), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; color: var(--text); }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2a3a5f; border-radius: 99px; }
::-webkit-scrollbar-track { background: transparent; }

#app { display: flex; flex-direction: column; height: 100dvh; }
#app[hidden], #shareNotice[hidden] { display: none; }
#shareNotice {
  margin: 12vh auto 0; width: min(92%, 420px); padding: 24px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
#shareNotice p { margin-bottom: 12px; }
#shareNotice a { text-decoration: none; }

/* ---------- Top bar ---------- */
#topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: linear-gradient(180deg, rgba(21, 31, 54, 0.92), rgba(17, 26, 46, 0.92));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 11px;
  background: var(--grad); display: grid; place-items: center;
  font-size: 18px; color: #06121f; font-weight: 800;
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.45);
}
.brand-name { font-size: 17px; font-weight: 800; letter-spacing: 0.2px; white-space: nowrap; }
.brand-name em { font-style: normal; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-sub { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
@media (max-width: 1100px) { .brand-sub { display: none; } }

.saved { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.saved .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.saved.saving .dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.saved.shared-copy .dot { background: var(--accent-violet); box-shadow: 0 0 8px var(--accent-violet); }
#backToDraft { color: var(--accent-teal); }

.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  color: var(--text-dim); border: 1px solid transparent; font-size: 15px;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn.active { color: var(--accent-teal); border-color: var(--border); background: var(--surface-2); }

.tb-sep { width: 1px; height: 26px; background: var(--border); flex: 0 0 auto; }

.load-block { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.load-block label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; }
#loadValue { font-size: 19px; font-weight: 800; font-family: var(--mono); }
.load-block .unit { font-size: 11px; color: var(--text-dim); margin-left: -6px; white-space: nowrap; }
#loadMultBtn {
  padding: 4px 9px; border-radius: 9px; font-family: var(--mono); font-weight: 700; font-size: 12px;
  background: var(--surface-3); border: 1px solid var(--border); color: var(--accent-teal);
}
#loadMultBtn:hover { border-color: var(--accent-teal); }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 150px; height: 6px; border-radius: 99px; background: linear-gradient(90deg, var(--accent-teal), var(--accent-violet)); outline: none; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent-violet); box-shadow: var(--shadow-sm); cursor: pointer;
}
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--accent-violet); cursor: pointer; }

.readouts { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.readout { text-align: right; padding: 4px 12px; border-radius: 11px; min-width: 86px; }
.readout .ro-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; }
.readout .ro-value { font-family: var(--mono); font-size: 16px; font-weight: 700; line-height: 1.2; white-space: nowrap; }
.readout.ok .ro-value { color: var(--ok); }
.readout.warn .ro-value { color: var(--warn); }
.readout.danger .ro-value { color: var(--danger); }
@media (max-width: 1250px) { .readout.hide-mid { display: none; } }

.transport { display: flex; align-items: center; gap: 4px; }
#btnSpeed { min-width: 52px; font-family: var(--mono); font-weight: 700; font-size: 12px; padding: 0 8px; width: auto; color: var(--accent-teal); }

.btn {
  padding: 8px 14px; border-radius: 12px; font-weight: 700; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn:hover { border-color: #3b4d7d; background: var(--surface-3); }
.btn-gradient {
  background: var(--grad); border: none; color: #06121f;
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.35);
}
.btn-gradient:hover { filter: brightness(1.08); background: var(--grad); }
.btn-danger { color: var(--danger); border-color: rgba(251, 113, 133, 0.4); }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 10px; }
.btn.active { border-color: var(--accent-teal); color: var(--accent-teal); background: var(--surface-3); }

/* popover menus */
.popover {
  position: absolute; top: calc(var(--topbar-h) - 6px); z-index: 60;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 8px; min-width: 210px;
}
.popover[hidden] { display: none; }
.popover .menu-item {
  display: flex; width: 100%; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: 10px; text-align: left; font-size: 13px; color: var(--text);
}
.popover .menu-item:hover { background: var(--surface-3); }
.popover .menu-item .kbd { margin-left: auto; color: var(--text-faint); font-size: 11px; font-family: var(--mono); }
.popover .menu-item.checked { color: var(--accent-teal); font-weight: 700; }
.popover h4 { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; padding: 6px 10px 4px; }
#designMenu { position: fixed; width: max-content; max-width: calc(100vw - 16px); overflow: auto; }
#linkPanel { min-width: 380px; right: 14px; padding: 14px; }
#linkPanel p { font-size: 12.5px; color: var(--text-dim); margin-bottom: 10px; }
#linkField {
  width: 100%; padding: 9px 11px; border-radius: 10px; font-size: 12px; font-family: var(--mono);
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
}
#linkPanel .row { display: flex; gap: 8px; margin-top: 10px; }
#linkStatus { font-size: 12px; color: var(--ok); min-height: 16px; margin-top: 8px; }
#linkStatus.error { color: var(--danger); }
#btnCopyLink:disabled, #btnCopyLinkAgain:disabled { opacity: 0.55; cursor: default; filter: none; }

/* ---------- Main layout ---------- */
#main { flex: 1; display: flex; min-height: 0; position: relative; }
#palette {
  width: 248px; flex: 0 0 248px; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0;
}
#palette.hidden, #inspector[hidden] { display: none; }
#paletteSearch {
  margin: 12px 12px 6px; padding: 9px 12px; border-radius: 11px;
  background: var(--bg-2); border: 1px solid var(--border); font-size: 13px; outline: none;
}
#paletteSearch:focus { border-color: var(--accent-violet); }
#paletteGroups { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.pal-group { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.09em; padding: 12px 8px 5px; }
.pal-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 11px; border: 1px solid transparent; font-size: 13px;
}
.pal-item:hover { background: var(--surface-2); border-color: var(--border); }
.pal-item .pal-ico {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 9px; display: grid; place-items: center; font-size: 14px;
}
.pal-item small { display: block; color: var(--text-faint); font-size: 11px; }
.grp-traffic .pal-ico { background: rgba(139, 92, 246, 0.18); color: #c4b5fd; }
.grp-compute .pal-ico { background: rgba(45, 212, 191, 0.14); color: #5eead4; }
.grp-data .pal-ico { background: rgba(56, 189, 248, 0.14); color: #7dd3fc; }
.grp-stores .pal-ico { background: rgba(251, 191, 36, 0.13); color: #fcd34d; }
.grp-messaging .pal-ico { background: rgba(244, 114, 182, 0.14); color: #f9a8d4; }
.grp-control .pal-ico { background: rgba(251, 146, 60, 0.14); color: #fdba74; }

#canvasWrap { flex: 1; position: relative; min-width: 0; background: var(--bg); overflow: hidden; }
#canvasContainer { position: absolute; inset: 0; }
#canvasContainer svg.lf-canvas-svg { display: block; width: 100%; height: 100%; }
#canvasPanelControls {
  position: absolute; left: 14px; bottom: 14px; display: flex; gap: 8px; z-index: 5;
}
#zoomControls {
  position: absolute; right: 14px; bottom: 14px; display: flex; gap: 4px; z-index: 5;
  background: rgba(17, 26, 46, 0.92); border: 1px solid var(--border); border-radius: 12px; padding: 4px;
}
#zoomControls .icon-btn { width: 30px; height: 30px; }
#zoomLabel {
  min-width: 52px; display: flex; align-items: center; justify-content: center; gap: 5px;
  border-radius: 8px; font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--text-dim);
}
#zoomLabel::after {
  content: ""; width: 5px; height: 5px; margin-top: 3px;
  border: solid currentColor; border-width: 1.5px 1.5px 0 0; transform: rotate(-45deg);
}
#zoomLabel:hover, #zoomLabel[aria-expanded="true"] { background: var(--surface-3); color: var(--accent-teal); }
#zoomPopover {
  position: fixed; inset: auto; top: calc(var(--zoom-anchor-y) - 7px); left: var(--zoom-anchor-x);
  transform: translate(-50%, -100%); width: max-content; margin: 0; padding: 8px 10px;
  overflow: visible; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.zoom-popover-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding-bottom: 5px; border-bottom: 1px solid var(--border);
}
.zoom-popover-head label { color: var(--text-dim); font-size: 10px; font-weight: 700; text-transform: uppercase; }
#zoomValue { color: var(--accent-teal); font-size: 13px; font-weight: 700; }
.zoom-ruler {
  --zoom-thumb-height: 24px;
  --zoom-thumb-shape: polygon(0 24%, 58% 24%, 58% 8%, 100% 50%, 58% 92%, 58% 76%, 0 76%);
  display: flex; gap: 6px; margin-top: 5px;
}
#zoomSlider {
  writing-mode: vertical-lr; direction: rtl; width: 44px;
  height: clamp(104px, calc(var(--zoom-anchor-y) - 64px), 218px); border-radius: 6px;
  background: linear-gradient(to top, var(--accent-teal) var(--zoom-progress), var(--text-faint) var(--zoom-progress))
    center / 4px calc(100% - var(--zoom-thumb-height)) no-repeat;
  cursor: ns-resize; touch-action: none;
}
#zoomSlider:focus-visible { outline: 2px solid var(--accent-teal); }
#zoomSlider::-webkit-slider-thumb {
  width: 34px; height: var(--zoom-thumb-height); border: 0; border-radius: 0;
  background: var(--accent-teal); clip-path: var(--zoom-thumb-shape); box-shadow: none; cursor: inherit;
}
#zoomSlider::-moz-range-track, #zoomSlider::-moz-range-progress { background: transparent; }
#zoomSlider::-moz-range-thumb {
  width: 34px; height: var(--zoom-thumb-height); border: 0; border-radius: 0;
  background: var(--accent-teal); clip-path: var(--zoom-thumb-shape); cursor: inherit;
}
#zoomTicks {
  display: flex; flex-direction: column; justify-content: space-between;
  width: 44px; margin-block: calc((var(--zoom-thumb-height) - 1px) / 2); pointer-events: none;
}
#zoomTicks > span { position: relative; width: 6px; height: 1px; background: var(--text-faint); }
#zoomTicks .major { width: 11px; background: var(--text-dim); }
#zoomTicks .major span {
  position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
  color: var(--text-dim); font-size: 10px; line-height: 1;
}
#legendPanel {
  position: absolute; left: 14px; bottom: 56px; z-index: 5; width: 250px;
  background: rgba(17, 26, 46, 0.95); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 12px 14px; box-shadow: var(--shadow); font-size: 12.5px;
}
#legendPanel[hidden] { display: none; }
#legendPanel h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 8px; }
#legendPanel li { list-style: none; display: flex; gap: 9px; align-items: center; padding: 3px 0; color: var(--text-dim); }
#legendPanel .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; }
#legendPanel p { color: var(--text-faint); font-size: 11.5px; margin-top: 8px; }

/* event log */
#eventLog {
  position: absolute; right: 14px; bottom: 64px; width: 320px; max-height: 220px; z-index: 6;
  background: rgba(17, 26, 46, 0.95); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden;
}
#eventLog[hidden] { display: none; }
#eventLog header { display: flex; align-items: center; padding: 10px 12px 6px; font-size: 12px; font-weight: 700; }
#eventLog header button { margin-left: auto; color: var(--text-dim); font-size: 15px; }
#eventLogList { overflow-y: auto; padding: 0 12px 10px; font-size: 12.5px; }
#eventLogList li { list-style: none; display: flex; gap: 8px; padding: 4px 0; border-top: 1px solid var(--border-soft); color: var(--text-dim); }
#eventLogList .t { font-family: var(--mono); color: var(--accent-teal); flex: 0 0 auto; }
#eventLogToggle {
  position: absolute; right: 14px; bottom: 64px; z-index: 5;
}

/* ---------- Inspector ---------- */
#inspector {
  flex: 0 0 clamp(300px, 28vw, 360px); min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; color-scheme: dark;
  background: var(--bg-2); border-left: 1px solid var(--border);
}
#inspectorBody {
  flex: 1; min-height: 0; padding: 14px; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-gutter: stable; overflow-wrap: anywhere;
}
#inspectorContainer, .insp-placeholder { max-width: 520px; margin-inline: auto; }
#inspectorContainer > * + * { margin-top: 12px; }
#btnInspect svg { flex: none; }
#inspector :is(input, select, button, summary):focus-visible, #btnInspect:focus-visible {
  outline: 2px solid var(--accent-teal); outline-offset: 2px;
}
#inspector .btn:disabled { opacity: 0.45; cursor: default; background: var(--surface-2); border-color: var(--border); }

.insp-bar {
  display: flex; flex: none; align-items: center; gap: 10px; padding: 12px 14px;
  background: linear-gradient(135deg, var(--surface-2), var(--surface)); border-bottom: 1px solid var(--border);
}
.insp-bar-icon, .insp-placeholder-icon, .insp-kind-icon { display: grid; place-items: center; flex: none; }
.insp-bar-icon, .insp-placeholder-icon {
  color: var(--accent-teal); border: 1px solid rgba(45, 212, 191, 0.22); background: rgba(45, 212, 191, 0.08);
}
.insp-bar-icon { width: 34px; height: 34px; border-radius: 10px; }
.insp-bar h2 { font-size: 16px; line-height: 1.25; }
.insp-bar p { font-size: 12px; color: var(--text-dim); }
#btnCloseInspector { flex: none; margin-left: auto; border-color: var(--border); font-size: 22px; line-height: 1; }
#btnCloseInspector:hover { background: var(--surface-3); border-color: #3b4d7d; }

.insp-placeholder {
  padding: 28px 16px; text-align: center; border: 1px dashed var(--border);
  border-radius: var(--radius); background: var(--surface);
}
.insp-placeholder-icon { width: 58px; height: 58px; margin: 0 auto 14px; border-radius: 16px; }
.insp-placeholder h3 { font-size: 15px; }
.insp-placeholder p { max-width: 31ch; margin: 4px auto 0; color: var(--text-dim); font-size: 13px; }
.insp-empty { padding: 28px 20px; text-align: center; color: var(--text-dim); font-size: 13px; }
.insp-empty .big { font-size: 26px; margin-bottom: 8px; }

.insp-head, .insp-section { padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.insp-head {
  --insp-kind-color: var(--accent-teal);
  background: linear-gradient(135deg, color-mix(in srgb, var(--insp-kind-color) 9%, transparent), transparent 72%), var(--surface);
}
.insp-identity { display: flex; align-items: center; gap: 10px; }
.insp-kind-icon {
  width: 42px; height: 42px; border-radius: 12px; color: var(--insp-kind-color);
  background: color-mix(in srgb, currentColor 12%, transparent); border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
}
.insp-kind-icon svg, .insp-name-field svg {
  width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.insp-name-block { flex: 1; min-width: 0; }
.insp-kind { margin-bottom: 4px; color: var(--insp-kind-color); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.insp-name-field { position: relative; }
.insp-name-field svg { position: absolute; top: 50%; right: 9px; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-dim); pointer-events: none; }
.insp-blurb { margin-top: 10px; color: var(--text-dim); font-size: 12.5px; }

.insp-section-title { margin-bottom: 10px; color: var(--text); font-size: 12px; font-weight: 750; letter-spacing: 0.07em; text-transform: uppercase; }
.insp-note { color: var(--text-dim); font-size: 12px; }
.insp-note:empty, .fault-param:empty { display: none; }
.insp-utilization {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 8px;
  background: linear-gradient(135deg, rgba(45, 212, 191, 0.07), transparent 72%), var(--surface);
}
.insp-utilization .insp-section-title { margin-bottom: 0; }
.insp-busy-value { color: var(--insp-busy-color, var(--ok)); font-size: 18px; line-height: 1.2; font-weight: 750; }
.insp-meter, .insp-utilization .insp-note { grid-column: 1 / -1; }
.insp-meter { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.insp-meter-fill { height: 100%; border-radius: inherit; background: var(--insp-busy-color, var(--ok)); transition: width 0.25s; }
@media (prefers-reduced-motion: reduce) { .insp-meter-fill { transition: none; } }

.insp-name, .insp-number, .insp-select {
  min-width: 0; max-width: 100%; min-height: 32px; padding: 5px 8px; border-radius: 8px;
  background: var(--bg-2); border: 1px solid var(--border); font-size: 13px;
}
.insp-name { width: 100%; padding-right: 29px; font-size: 16px; font-weight: 700; }
.insp-name:hover, .insp-number:hover, .insp-select:hover { border-color: #3b4d7d; }
.insp-field + .insp-field { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-soft); }
.insp-field-head, .insp-row, .conn-header, .conn-controls { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.insp-field-head { flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.insp-field-label { color: var(--text); font-size: 13px; font-weight: 600; }
.insp-field-unit { color: var(--text-dim); font-size: 11px; font-weight: 400; }
.insp-field-value { padding: 1px 6px; border-radius: 6px; color: var(--accent-teal); background: var(--surface-3); font-size: 11px; }
.insp-field .insp-select { width: 100%; margin-top: 5px; }
.insp-field .insp-slider { display: block; width: 100%; height: 24px; background: var(--grad) center / 100% 4px no-repeat; cursor: pointer; }
.insp-field .insp-note { margin-top: 4px; }
.insp-field-stepper { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 8px; }
.insp-field-stepper .insp-note { grid-column: 1 / -1; }
.insp-stepper { display: grid; grid-template-columns: 29px 54px 29px; gap: 4px; }
.insp-stepper .btn { padding: 0; justify-content: center; border-radius: 8px; font-size: 16px; }
.insp-stepper .insp-number { width: 100%; padding-inline: 3px; text-align: center; appearance: textfield; }
.insp-stepper .insp-number::-webkit-inner-spin-button { appearance: none; }
.insp-inline-control { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--text-dim); font-size: 12px; }
.insp-check { display: flex; align-items: baseline; gap: 8px; font-size: 13px; cursor: pointer; }
#inspector :is(input[type="checkbox"], input[type="radio"]) { flex: none; accent-color: var(--accent-teal); }
.insp-check + .insp-note { margin: 2px 0 0 21px; }
.insp-note + .insp-check { margin-top: 10px; }

.insp-row { align-items: baseline; padding: 5px 0; font-size: 12px; }
.insp-row + .insp-row { border-top: 1px solid var(--border-soft); }
.insp-k { color: var(--text-dim); }
.insp-v { max-width: 60%; flex: none; text-align: right; font-weight: 700; }
.insp-metrics + .insp-note { margin-top: 8px; }

.conn-list { display: grid; gap: 8px; }
.conn-row { display: grid; gap: 8px; min-width: 0; padding: 9px; border: 1px solid var(--border-soft); border-radius: 10px; background: var(--bg-2); }
.conn-destination { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.conn-direction { padding: 1px 5px; border-radius: 5px; color: var(--accent-teal); background: var(--surface-3); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.conn-name { min-width: 0; font-size: 13px; font-weight: 650; }
.conn-row.is-cut { border-color: rgba(251, 191, 36, 0.35); }
.conn-row.is-cut .conn-direction { color: var(--warn); background: var(--warn-soft); }
.conn-controls { flex-wrap: wrap; }
.conn-weight .insp-number { width: 68px; }
.conn-faults { padding-top: 5px; border-top: 1px solid var(--border-soft); }
.conn-faults summary { padding: 3px 2px; border-radius: 5px; color: var(--text-dim); font-size: 12px; cursor: pointer; }
.conn-faults summary:hover { color: var(--text); }
.conn-fault-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }

.insp-fault-status {
  display: flex; align-items: center; gap: 7px; padding: 7px 9px; border-radius: 8px;
  background: var(--bg-2); color: var(--text-dim); font-size: 12px;
}
.insp-fault-status::before { content: ''; width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--text-faint); }
.insp-fault-status.is-applied { color: var(--danger); background: var(--danger-soft); }
.insp-fault-status.is-applied::before { background: currentColor; }
.insp-fault-types { margin: 10px 0 8px; min-inline-size: 0; border: 0; }
.fault-radios { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.fault-radio {
  display: flex; align-items: center; gap: 5px; padding: 4px 7px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg-2); color: var(--text-dim); font-size: 12px; cursor: pointer;
}
.fault-radio:hover { color: var(--text); }
.fault-radio:has(input:checked) { border-color: var(--accent-teal); color: var(--text); }
.fault-param { margin-top: 8px; }
.insp-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.insp-section > .insp-actions { margin: 10px 0; }
.insp-section > .insp-note + .btn { margin-top: 6px; }
.insp-component-actions .btn { flex: 1 1 auto; justify-content: center; }

/* ---------- Charts strip ---------- */
#chartsWrap {
  flex: 0 0 var(--charts-h); background: var(--surface); border-top: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
#chartsWrap[hidden] { display: none; }
#chartsBar { display: flex; align-items: center; gap: 8px; padding: 8px 14px 0; }
#chartsBar h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-dim); }
#chartsBar .spacer { flex: 1; }
#chartsContainer { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 8px 14px 12px; min-height: 0; }
.chart-card {
  background: var(--bg-2); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 10px 12px; display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}
.chart-card h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.chart-card .big { font-family: var(--mono); font-size: 21px; font-weight: 800; line-height: 1.15; }
.chart-card .big small { font-size: 11px; color: var(--text-dim); font-weight: 400; }
.chart-card .legend { font-size: 11px; color: var(--text-dim); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-card svg { flex: 1; min-height: 0; width: 100%; }
.chart-empty { color: var(--text-faint); font-size: 12px; text-align: center; padding-top: 22px; }

/* ---------- Command palette / toasts ---------- */
#cmdPalette {
  position: fixed; inset: 0; background: rgba(4, 8, 20, 0.6); backdrop-filter: blur(3px);
  display: grid; justify-items: center; align-items: start; padding-top: 14vh; z-index: 100;
}
#cmdPalette[hidden] { display: none; }
.cmd-box { width: min(560px, 92vw); background: var(--surface-2); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
#cmdInput { width: 100%; padding: 15px 18px; background: transparent; border: none; outline: none; font-size: 15px; border-bottom: 1px solid var(--border); }
#cmdList { max-height: 320px; overflow-y: auto; padding: 6px; }
#cmdList button { display: flex; width: 100%; gap: 10px; padding: 9px 12px; border-radius: 10px; text-align: left; font-size: 13.5px; }
#cmdList button.sel, #cmdList button:hover { background: var(--surface-3); }
#cmdList .kbd { margin-left: auto; color: var(--text-faint); font-family: var(--mono); font-size: 11px; }

#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 12px;
  padding: 9px 16px; font-size: 13px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center;
}
.toast button { color: var(--accent-teal); font-weight: 700; }
.toast.err { border-color: var(--danger); color: #fecdd3; }

.hidden-input { display: none; }
#tabbar { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .load-block input[type="range"] { width: 90px; }
  .readout { min-width: 0; padding: 4px 8px; }
}
@media (max-width: 720px) {
  :root { --topbar-h: auto; }
  #topbar { flex-wrap: wrap; height: auto; padding: 8px 10px; gap: 8px; }
  .brand-sub, .saved span { display: none; }
  .load-block { order: 3; flex: 1 1 100%; min-width: 0; }
  .load-block input[type="range"] { flex: 1; width: auto; min-width: 0; }
  .readouts { margin-left: 0; }
  #app { padding-bottom: var(--tabbar-h); }
  #palette, #inspector {
    position: absolute; left: 0; right: 0; bottom: 0; top: auto; z-index: 30;
    width: auto; flex: none; height: 45dvh; border-right: none; border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  }
  #palette.hidden-m { display: none; }
  #inspector { height: min(58dvh, 100%); border-left: none; }
  #inspector:has(#inspectorEmpty:not([hidden])) { height: auto; max-height: 100%; }
  #inspector:has(#inspectorEmpty:not([hidden])) #inspectorBody { padding-block: 10px; }
  .insp-placeholder:not([hidden]) {
    display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: 10px;
    padding: 0; border: 0; background: none; text-align: start;
  }
  .insp-placeholder-icon { grid-row: span 2; width: 38px; height: 38px; margin: 0; border-radius: 10px; }
  .insp-placeholder-icon svg { width: 24px; height: 24px; }
  .insp-placeholder h3 { font-size: 13px; }
  .insp-placeholder p { max-width: none; margin: 0; font-size: 12px; }
  #btnCloseInspector { width: 40px; height: 40px; }
  #inspector :is(.insp-number, .insp-select) { font-size: 16px; }
  #chartsWrap { flex-basis: 190px; }
  #chartsContainer { grid-template-columns: repeat(2, 1fr); overflow-y: auto; }
  #tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar-h); z-index: 50;
    background: rgba(17, 26, 46, 0.97); border-top: 1px solid var(--border);
  }
  #tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--text-dim); }
  #tabbar button.active { color: var(--accent-teal); }
  #tabbar button .ico { font-size: 17px; }
  #eventLog { width: calc(100vw - 28px); right: 14px; }
  #linkPanel { min-width: 0; left: 10px; right: 10px; }
}

/* ---------- Canvas overlays (created by canvas.js) ----------
   Size the SVG wrapper and hide its built-in Key and legend;
   the app supplies those controls in #canvasWrap. */
.lf-canvas-host { position: absolute; inset: 0; }
.lf-canvas-wrap { position: absolute; inset: 0; overflow: hidden; }
.lf-canvas-svg {
  position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; cursor: grab;
  -webkit-user-select: none; user-select: none;
}
.lf-canvas-svg:active { cursor: grabbing; }
.lf-key-btn, .lf-legend { display: none !important; }
.lf-rename-input { position: absolute; z-index: 8; background: var(--surface-2); color: var(--text); border: 1.5px solid var(--accent-teal); border-radius: 8px; padding: 4px 8px; font-size: 13px; font-weight: 700; outline: none; }
.lf-node-name { font-size: 13px; font-weight: 700; font-family: var(--font, inherit); }
.lf-node-kind { font-size: 11px; font-weight: 600; }
.lf-node-live { font-size: 11px; font-family: var(--mono); }
.lf-node-badge { font-size: 13px; font-weight: 800; }
.lf-edge-rate { font-size: 11px; font-family: var(--mono); }
.lf-node.lf-selected .lf-node-card { stroke: #2DD4BF; stroke-width: 2.5; }
.lf-node { cursor: grab; }
.lf-node:active { cursor: grabbing; }

/* ---------- Connections: drag from a port, hover an edge to delete it --- */
.lf-port, .lf-port-hit { cursor: crosshair; }
.lf-port-hit { pointer-events: all; }
.lf-node:hover .lf-port { stroke-width: 3.5; }
.lf-edge-hit { cursor: pointer; }
.lf-edge-group:hover .lf-edge { stroke: #A5B4D4; }
.lf-edge-delete { cursor: pointer; }
.lf-edge-delete text { pointer-events: none; font-size: 15px; font-weight: 800; }
.lf-edge-delete:hover circle { fill: #EF4444; }
.lf-node.lf-connect-target .lf-node-card { stroke: #2DD4BF; stroke-width: 2.5; stroke-dasharray: 6 4; }
