:root, [data-theme="night"] {
  --bg: #0b1220;
  --bg-glow: #172554;
  --surface: #141c2b;
  --surface-2: #1b2538;
  --border: #2b3a52;
  --text: #e8eef8;
  --muted: #93a4bd;
  --accent: #3b82f6;
  --ex: #f59e0b;
  --em: #38bdf8;
  --tr: #94a3b8;
  --danger: #ef4444;
  --ok: #22c55e;
  --topbar-bg: rgba(11, 18, 32, 0.92);
  --canvas-bg: #0a101c;
  --wire-bg: #0f172a;
  --wire-panel: #1e293b;
  --wire-panel-border: #334155;
  --wire-header: #243447;
  --wire-header-border: #3b4d66;
  --wire-row: #1e293b;
  --wire-row-border: #334155;
  --wire-text: #e2e8f0;
  --wire-muted: #94a3b8;
  --wire-marker-fill: #0f172a;
  --dialog-backdrop: rgba(0, 0, 0, 0.55);
  --beam-halo: rgba(11, 18, 32, 0.85);
}

[data-theme="day"] {
  --bg: #edf2f7;
  --bg-glow: #d5e0ef;
  --surface: #f7f9fc;
  --surface-2: #ffffff;
  --border: #9aa8bc;
  --text: #0f172a;
  --muted: #334155;
  --accent: #1d4ed8;
  --ex: #b45309;
  --em: #0369a1;
  --tr: #475569;
  --danger: #b91c1c;
  --ok: #15803d;
  --topbar-bg: rgba(255, 255, 255, 0.96);
  --canvas-bg: #e8eef6;
  --wire-bg: #f8fafc;
  --wire-panel: #ffffff;
  --wire-panel-border: #94a3b8;
  --wire-header: #e2e8f0;
  --wire-header-border: #94a3b8;
  --wire-row: #ffffff;
  --wire-row-border: #94a3b8;
  --wire-text: #0f172a;
  --wire-muted: #334155;
  --wire-marker-fill: #ffffff;
  --dialog-backdrop: rgba(15, 23, 42, 0.4);
  --beam-halo: rgba(255, 255, 255, 0.92);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(circle at top left, var(--bg-glow) 0%, var(--bg) 42%);
  color: var(--text);
  overflow: hidden;
}
.hidden { display: none !important; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
}
.brand h1 { margin: 0.15rem 0 0; font-size: 1.05rem; }
.ver { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.back { color: var(--accent); text-decoration: none; font-size: 0.85rem; }
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.badge {
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
}
.badge.auth { color: var(--ok); background: rgba(34,197,94,0.12); }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  height: calc(100vh - 64px);
}
.sidebar {
  overflow: auto;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.sidebar.right { border-right: none; border-left: 1px solid var(--border); }
.panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem;
  display: grid;
  gap: 0.45rem;
}
.panel h2 {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.meta, .status { color: var(--muted); font-size: 0.82rem; margin: 0; }
.path-glass {
  margin-top: 0.35rem;
  color: #86efac;
  line-height: 1.35;
  word-break: break-word;
}
.station-sub.glass-on { fill: #86efac; }
.station-sub.hole { fill: #94a3b8; font-style: italic; }
[data-theme="day"] .path-glass { color: #15803d; }
[data-theme="day"] .station-sub.glass-on { fill: #15803d; }
[data-theme="day"] .station-sub.hole { fill: #64748b; }
[data-theme="day"] .twincam-path-note {
  background: rgba(22, 163, 74, 0.08);
  border-color: rgba(22, 163, 74, 0.25);
  color: #166534;
}
.twincam-path-note {
  margin-top: 0.65rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  background: rgba(134, 239, 172, 0.08);
  border: 1px solid rgba(134, 239, 172, 0.2);
  font-size: 0.8rem;
  color: #bbf7d0;
}
.twincam-path-head { font-weight: 600; margin-bottom: 0.2rem; }
.twincam-path-row { opacity: 0.9; margin-left: 0.25rem; }
.status { padding: 0 0.2rem; }

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  font: inherit;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); }
.btn-danger { background: transparent; border-color: rgba(239,68,68,0.4); color: var(--danger); }
.btn-secondary { background: var(--surface); border-color: var(--border); }

select, input, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  font: inherit;
}
#system-select { height: 160px; }
.panel-hint {
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}
.panel-sub {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}
.field-label {
  display: block;
  margin: 0.35rem 0 0.2rem;
  color: var(--muted);
  font-size: 0.75rem;
}
.panel-channels.locked {
  opacity: 0.72;
}
.panel-channels #filter-set-select { margin-bottom: 0.45rem; }
.channel-list, .device-groups, .catalog-results, .intensity-list, .fluor-list {
  display: grid;
  gap: 0.3rem;
  max-height: 220px;
  overflow: auto;
}
.channel-set-heading {
  margin-top: 0.35rem;
  padding: 0.2rem 0.35rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.channel-set-heading:first-child { margin-top: 0; }
.channels-empty {
  margin: 0.4rem 0;
  color: var(--muted);
  font-size: 0.82rem;
}
.channel-item, .device-item, .catalog-item, .fluor-item {
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--bg);
  cursor: pointer;
  font-size: 0.85rem;
}
.fluor-item.fluor-toggle {
  cursor: default;
  display: flex;
  gap: 0.45rem;
  align-items: flex-start;
}
.fluor-item.fluor-toggle input {
  margin-top: 0.15rem;
  flex-shrink: 0;
}
.fluor-item.fluor-toggle span {
  line-height: 1.35;
}
.channel-item.active, .device-item.active {
  border-color: var(--accent);
  background: rgba(59,130,246,0.12);
}
.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.chk { display: flex; gap: 0.35rem; align-items: center; color: var(--muted); font-size: 0.82rem; }
.chk input { width: auto; }

.canvas-wrap {
  position: relative;
  min-width: 0;
  background:
    linear-gradient(color-mix(in srgb, var(--text) 6%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--text) 6%, transparent) 1px, transparent 1px),
    var(--canvas-bg);
  background-size: 24px 24px, 24px 24px, auto;
}
#schematic { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#schematic:active { cursor: grabbing; }
.canvas-toolbar {
  position: absolute;
  z-index: 2;
  top: 0.6rem;
  left: 0.6rem;
  right: 0.6rem;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  pointer-events: none;
}
.canvas-toolbar > * { pointer-events: auto; }
.toolbar-right { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
#system-title {
  background: var(--topbar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  font-size: 0.85rem;
}
.view-controls {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  background: var(--topbar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.15rem 0.25rem;
}
.btn-icon {
  min-width: 1.8rem;
  padding: 0.2rem 0.4rem;
  font-size: 1rem;
  line-height: 1;
}
.zoom-label {
  min-width: 3.2rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  margin: 0;
  pointer-events: none;
  z-index: 1;
}
.empty[hidden],
.empty.hidden {
  display: none !important;
}
.group-box {
  stroke: #475569;
  stroke-width: 1.25;
  rx: 10;
}
.group-box.selected {
  stroke: var(--accent);
  stroke-width: 2;
}
.group-box.vibration-table {
  rx: 4;
  stroke: #64748b;
  stroke-width: 1.5;
}
.group-drag-handle.active {
  cursor: grab;
}
.group-drag-handle.active:hover {
  fill: rgba(56, 189, 248, 0.16) !important;
}
.vibration-table-label {
  font-size: 11px;
  font-weight: 700;
  fill: #e2e8f0;
  pointer-events: none;
}
[data-theme="day"] .vibration-table-label {
  fill: #1e293b;
}
[data-theme="day"] .group-box.vibration-table {
  fill: rgba(148, 163, 184, 0.45);
}
.group-label {
  fill: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
}
.disk-l {
  fill: #334155;
  stroke: #94a3b8;
  stroke-width: 1.5;
}
.disk-l.on-path {
  fill: #3f4f6a;
  stroke: #fbbf24;
  stroke-width: 2.4;
}
.disk-l.selected { stroke: var(--accent); stroke-width: 2.6; }
.disk-l.dimmed { opacity: 0.28; }
.disk-arm-label { font-size: 9px; font-weight: 700; }
.disk-laser-label { font-size: 10px; font-weight: 700; }
.station-box { fill: #1e293b; stroke: #64748b; stroke-width: 1.5; rx: 6; }
.station-box.selected { stroke: var(--accent); stroke-width: 2.5; }
.station-box.on-path {
  fill: #243b5c;
  stroke: #fbbf24;
  stroke-width: 2.6;
}
.station-box.dimmed { opacity: 0.28; }
.station-label { fill: var(--text); font-size: 11px; pointer-events: none; }
.station-label.dimmed { fill: #64748b; }
.station-sub { font-size: 9px; font-weight: 500; }
.laser-chip { stroke: #cbd5e1; stroke-width: 1; fill: #f8fafc; }
.laser-chip.on { stroke: #1e293b; stroke-width: 2; }
.laser-chip.off { fill: #0f172a; stroke: #475569; }
.laser-chip.dimmed { fill: #1e293b; stroke: #334155; }
.laser-chip-label { font-size: 8px; font-weight: 700; pointer-events: none; }
.laser-chip-label.on { fill: #0f172a; }
.laser-chip-label.off { fill: #64748b; }
.laser-chip-label.dimmed { fill: #475569; }
.beam { fill: none; stroke-width: 2.2; opacity: 0.55; }
.beam.excitation { stroke: var(--ex); }
.beam.emission { stroke: var(--em); }
.beam.transmitted { stroke: var(--tr); }
.beam.dimmed { opacity: 0.18; stroke-width: 1.6; }
.beam.on-path { opacity: 1; stroke-width: 4; filter: drop-shadow(0 0 3px currentColor); }
.beam-arrow-head { fill: #94a3b8; }
.beam-label {
  font-size: 9px;
  font-weight: 600;
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--beam-halo);
  stroke-width: 3px;
}
.beam-label.excitation { fill: #fbbf24; }
.beam-label.emission { fill: #7dd3fc; }
.beam-label.transmitted { fill: #cbd5e1; }
.beam-label.on-path { font-size: 10px; font-weight: 700; }
.beam-label.dimmed { fill: #64748b; opacity: 0.85; font-weight: 500; }

#spectrum-canvas {
  width: 100%;
  background: var(--canvas-bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.preview-row { display: flex; gap: 0.5rem; }
.preview-row canvas {
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #000;
  image-rendering: pixelated;
}
.inspector { font-size: 0.82rem; color: var(--muted); line-height: 1.4; }
.inspector strong { color: var(--text); }
.inspector-slot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.4rem;
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
}
.inspector-slot .slot-meta { flex: 1; min-width: 0; }
.inspector-slot .btn { flex-shrink: 0; padding: 0.15rem 0.45rem; font-size: 0.75rem; }
.inventory-summary {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
  max-height: 240px;
  overflow: auto;
}
.inventory-summary strong { color: var(--text); }
.inventory-summary .inv-block { margin-top: 0.45rem; }
.inventory-summary ul {
  margin: 0.2rem 0 0;
  padding-left: 1.1rem;
}
.wiring-summary {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
  max-height: 180px;
  overflow: auto;
  margin-bottom: 0.4rem;
}
.wiring-summary strong { color: var(--text); }
.wiring-summary ul {
  margin: 0.15rem 0 0.35rem;
  padding-left: 1.1rem;
}
#wiring-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--wire-bg);
  cursor: grab;
  touch-action: none;
}
#wiring-canvas.is-panning,
#wiring-canvas:active {
  cursor: grabbing;
}
.theme-switch,
.mode-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.theme-option {
  display: inline-flex;
  align-items: center;
  margin: 0;
  cursor: pointer;
  user-select: none;
}
.theme-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.theme-option span {
  padding: 0.28rem 0.65rem;
  font-size: 0.82rem;
  color: var(--muted);
  border-right: 1px solid var(--border);
}
.theme-option:last-child span { border-right: 0; }
.theme-option input:checked + span {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.mode-option {
  display: inline-flex;
  align-items: center;
  margin: 0;
  cursor: pointer;
  user-select: none;
}
.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.mode-option span {
  padding: 0.28rem 0.7rem;
  font-size: 0.82rem;
  color: var(--muted);
  border-right: 1px solid var(--border);
}
.mode-option:last-child span { border-right: 0; }
.mode-option input:checked + span {
  background: var(--accent, #3b82f6);
  color: #fff;
  font-weight: 600;
}
.mode-option input:disabled + span {
  opacity: 0.45;
  cursor: not-allowed;
}
.mode-switch.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}
.wiring-editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}
@media (max-width: 900px) {
  .wiring-editor-grid { grid-template-columns: 1fr; }
}
.wiring-editor-grid h3 {
  margin: 0 0 0.35rem;
  font-size: 0.92rem;
}
.wiring-link-list {
  max-height: 280px;
  overflow: auto;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem;
}
.wiring-link-row {
  display: flex;
  gap: 0.35rem;
  align-items: flex-start;
  padding: 0.35rem 0.3rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 6px;
}
.wiring-link-row:last-child { border-bottom: 0; }
.wiring-link-row.selected {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  outline: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.wiring-link-row .meta { flex: 1; min-width: 0; }
.wiring-link-row .btn { padding: 0.1rem 0.4rem; font-size: 0.72rem; }
.wire-cable-actions { flex-wrap: wrap; }
.wiring-tee-list {
  margin-top: 0.45rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.wire-card-row {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  margin: 0.25rem 0;
  flex-wrap: wrap;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 1rem;
  width: min(560px, 94vw);
  max-height: 90vh;
  overflow: auto;
}
dialog.dialog-wide { width: min(720px, 96vw); }
dialog::backdrop { background: var(--dialog-backdrop); }
dialog form { display: grid; gap: 0.55rem; }
dialog label { display: grid; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); }
dialog fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem 0.7rem;
  margin: 0;
}
dialog legend { color: var(--text); font-size: 0.82rem; padding: 0 0.25rem; }
.dialog-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}
.dialog-grid .full { grid-column: 1 / -1; }
.chk-block { display: flex !important; flex-direction: row; align-items: center; gap: 0.4rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }
.positions-grid, .device-fields { display: grid; gap: 0.4rem; }
.device-fields {
  max-height: min(60vh, 28rem);
  overflow-y: auto;
  padding-right: 0.25rem;
}
.device-fields label {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) minmax(8rem, 1.2fr);
  gap: 0.5rem;
  align-items: center;
  font-size: 0.85rem;
}
.device-fields label[hidden] {
  display: none;
}
.device-fields .field-hint {
  grid-column: 1 / -1;
  color: var(--muted, #8a93a4);
  font-size: 0.75rem;
  line-height: 1.35;
  margin-top: -0.2rem;
}
.device-fields .hp-control-wrap {
  grid-column: 1 / -1;
  overflow-x: auto;
}
.device-fields .hp-control-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.device-fields .hp-control-table th,
.device-fields .hp-control-table td {
  padding: 0.2rem 0.35rem;
  text-align: left;
  white-space: nowrap;
}
.device-fields .hp-control-table select {
  min-width: 4.5rem;
}
.device-fields input[type="checkbox"] {
  justify-self: start;
  width: auto;
}
.placement-dialog {
  max-width: min(920px, 96vw);
  max-height: min(88vh, 900px);
}
.placement-grid {
  display: grid;
  grid-template-columns: minmax(12rem, 1.4fr) 5.5rem minmax(14rem, 1.6fr);
  gap: 0.35rem 0.65rem;
  align-items: center;
  max-height: min(55vh, 28rem);
  overflow: auto;
  padding: 0.25rem 0.15rem 0.5rem 0;
}
.placement-grid-glass {
  grid-template-columns: minmax(14rem, 1.3fr) minmax(16rem, 1.5fr);
}
.placement-head {
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.75;
  position: sticky;
  top: 0;
  background: var(--panel, #1e293b);
  padding: 0.25rem 0;
  z-index: 1;
}
.placement-label {
  font-size: 0.82rem;
  line-height: 1.3;
  word-break: break-word;
}
.placement-grid select {
  width: 100%;
  font-size: 0.8rem;
}
dialog.placement-board-dialog {
  width: min(96vw, 1680px);
  height: min(90vh, 1040px);
  max-width: 98vw;
  max-height: 96vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 1.35rem;
}
dialog.placement-board-dialog form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  gap: 0.4rem;
}
dialog.placement-board-dialog h2,
dialog.placement-board-dialog .meta,
dialog.placement-board-dialog .dialog-actions,
dialog.placement-board-dialog .error {
  flex: 0 0 auto;
}
.dialog-resize {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  z-index: 4;
}
.dialog-resize::before {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid rgba(148, 163, 184, 0.85);
  border-bottom: 2px solid rgba(148, 163, 184, 0.85);
}
.glass-layout {
  display: grid;
  grid-template-columns: minmax(18rem, 24rem) minmax(0, 1fr);
  gap: 0.85rem;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
}
.glass-repo,
.glass-board {
  min-height: 0;
  max-height: none;
  height: 100%;
  overflow: auto;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 8px;
  padding: 0.55rem 0.65rem 0.75rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
}
.glass-repo.empty .glass-repo-list::after {
  content: "All filters placed";
  display: block;
  opacity: 0.55;
  font-size: 0.78rem;
  padding: 0.4rem 0.15rem;
}
.glass-col-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.8;
  position: sticky;
  top: 0;
  background: inherit;
  padding-bottom: 0.35rem;
  z-index: 1;
}
.glass-count {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}
.glass-col-hint {
  margin: 0 0 0.45rem;
  font-size: 0.75rem;
}
.glass-repo-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 3rem;
}
.glass-chip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.35rem;
  align-items: start;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.35);
  cursor: grab;
  user-select: none;
}
.glass-chip:active,
.glass-chip.dragging {
  cursor: grabbing;
  opacity: 0.55;
}
.glass-chip-role {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.1rem 0.28rem;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.25);
  color: #bfdbfe;
}
.glass-chip.role-em .glass-chip-role { background: rgba(16, 185, 129, 0.28); color: #a7f3d0; }
.glass-chip.role-dm .glass-chip-role { background: rgba(245, 158, 11, 0.28); color: #fde68a; }
.glass-chip.role-cube .glass-chip-role { background: rgba(168, 85, 247, 0.28); color: #e9d5ff; }
.glass-chip.role-obj .glass-chip-role { background: rgba(244, 114, 182, 0.28); color: #fbcfe8; }
.glass-chip-name {
  font-size: 0.86rem;
  line-height: 1.35;
  word-break: break-word;
  white-space: normal;
}
.glass-station {
  margin: 0.15rem 0 0.85rem;
}
.glass-station h3 {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  font-weight: 650;
}
.glass-slot-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17.5rem, 1fr));
  gap: 0.55rem;
}
.slot-box {
  width: auto;
  min-height: 7.6rem;
  border: 1px dashed rgba(148, 163, 184, 0.45);
  border-radius: 8px;
  padding: 0.45rem 0.5rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: rgba(148, 163, 184, 0.06);
}
.slot-box.drop-over,
.glass-repo.drop-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.slot-num {
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}
.slot-existing {
  font-size: 0.82rem;
  line-height: 1.35;
  opacity: 0.72;
  white-space: normal;
  word-break: break-word;
}
.slot-well {
  flex: 1;
  min-height: 4.4rem;
}
.slot-well:empty::after {
  content: "Drop filter";
  display: block;
  font-size: 0.78rem;
  opacity: 0.4;
  padding: 0.35rem 0.1rem;
}
@media (max-width: 820px) {
  .glass-layout {
    grid-template-columns: 1fr;
  }
  dialog.placement-board-dialog .glass-repo,
  dialog.placement-board-dialog .glass-board {
    max-height: none;
    height: auto;
    min-height: 12rem;
  }
}

.slots-dialog {
  max-width: min(640px, 96vw);
}
.slots-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 9.5rem;
  gap: 0.75rem;
  align-items: start;
  margin-top: 0.5rem;
}
.slots-list {
  display: grid;
  gap: 0.2rem;
  max-height: min(50vh, 22rem);
  overflow: auto;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 6px;
  padding: 0.35rem;
}
.slots-row {
  display: grid;
  grid-template-columns: 2.2rem minmax(0, 1fr);
  gap: 0.45rem;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0.35rem 0.45rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
}
.slots-row:hover {
  background: rgba(148, 163, 184, 0.12);
}
.slots-row.active {
  background: rgba(59, 130, 246, 0.22);
}
.slots-idx {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
  font-size: 0.8rem;
}
.slots-name {
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slots-name.empty {
  font-style: italic;
  opacity: 0.65;
}
.slots-side {
  display: grid;
  gap: 0.35rem;
}
.slots-side .btn {
  width: 100%;
  justify-content: center;
}
[data-theme="day"] .slots-list {
  border-color: rgba(100, 116, 139, 0.3);
}
[data-theme="day"] .slots-row:hover {
  background: rgba(100, 116, 139, 0.1);
}
[data-theme="day"] .slots-row.active {
  background: rgba(37, 99, 235, 0.12);
}
.positions-grid .pos-row { display: grid; gap: 0.2rem; }
.laser-checks, .build-kinds { display: grid; gap: 0.3rem; }
.build-channels {
  display: grid;
  gap: 0.25rem;
  max-height: 280px;
  overflow: auto;
}
.build-cam-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  padding: 0.15rem 0 0.35rem 0.35rem;
}
.btn-tiny {
  padding: 0.15rem 0.45rem;
  font-size: 0.75rem;
}
.dimmed-opt { opacity: 0.45; }
.sets-list { display: grid; gap: 0.4rem; margin-bottom: 0.5rem; }
.set-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
  align-items: center;
}
.error { color: var(--danger); font-size: 0.85rem; margin: 0; }

.dialog-path {
  width: min(1280px, 98vw);
  height: min(640px, 92vh);
  max-width: 98vw;
  max-height: 96vh;
  min-width: min(720px, 96vw);
  min-height: min(360px, 70vh);
  resize: both;
  overflow: auto;
}
.dialog-path form {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.dialog-path .dialog-actions { margin-top: auto; flex-shrink: 0; }
.dialog-path #path-caption,
.dialog-path .panel-hint,
.dialog-path #path-error { flex-shrink: 0; }
.path-track {
  display: flex;
  align-items: stretch;
  gap: 0.45rem;
  overflow: auto;
  padding: 0.35rem 0 0.75rem;
  min-height: 220px;
  flex: 1 1 auto;
}
.path-resize-hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
}
.path-arrow {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 1.25rem;
  flex: 0 0 auto;
  padding: 0 0.15rem;
}
.path-card {
  flex: 0 0 180px;
  background: #1e293b;
  border: 1.5px solid #64748b;
  border-radius: 8px;
  padding: 0.45rem 0.5rem 0.4rem;
  display: grid;
  gap: 0.2rem;
  align-content: start;
}
.path-card.phase-ex { border-color: #f59e0b; background: #2a2114; }
.path-card.phase-sample { border-color: #34d399; background: #14261c; }
.path-card.phase-em { border-color: #38bdf8; background: #14222b; }
.path-card.phase-cam { border-color: #94a3b8; background: #1b2230; }
.path-role {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.path-title { font-size: 0.82rem; font-weight: 700; color: var(--text); line-height: 1.25; }
.path-detail { font-size: 0.72rem; color: var(--muted); min-height: 1.6em; }
.path-spec {
  width: 100%;
  height: 64px;
  border-radius: 4px;
  border: 1px solid var(--border);
  margin-top: 0.2rem;
}
.sample-fluor-list {
  display: grid;
  gap: 0.25rem;
  max-height: 320px;
  overflow: auto;
  margin: 0.5rem 0;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

@media (max-width: 700px) {
  .dialog-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
  body { overflow: auto; }
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .canvas-wrap { min-height: 55vh; }
  .sidebar { max-height: none; }
}

/* Day theme: schematic + cards tuned for light canvas contrast */
[data-theme="day"] .btn-ghost {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-2);
}
[data-theme="day"] .btn-ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
[data-theme="day"] .badge {
  color: var(--text);
  border: 1px solid var(--border);
}
[data-theme="day"] .panel h2,
[data-theme="day"] .meta,
[data-theme="day"] .status,
[data-theme="day"] .panel-hint,
[data-theme="day"] .inspector,
[data-theme="day"] .wiring-summary,
[data-theme="day"] .inventory-summary,
[data-theme="day"] dialog label {
  color: var(--muted);
}
[data-theme="day"] .channel-item,
[data-theme="day"] .device-item,
[data-theme="day"] .catalog-item,
[data-theme="day"] .fluor-item {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="day"] .channel-item.active,
[data-theme="day"] .device-item.active {
  background: rgba(37, 99, 235, 0.12);
  border-color: var(--accent);
}
[data-theme="day"] .group-box {
  stroke: #64748b;
  fill: rgba(255, 255, 255, 0.35);
}
[data-theme="day"] .group-label {
  fill: #0f172a;
}
[data-theme="day"] .disk-l {
  fill: #e2e8f0;
  stroke: #475569;
}
[data-theme="day"] .disk-l.on-path {
  fill: #fef3c7;
  stroke: #b45309;
}
[data-theme="day"] .station-box {
  fill: #ffffff;
  stroke: #475569;
}
[data-theme="day"] .station-box.on-path {
  fill: #eff6ff;
  stroke: #1d4ed8;
}
[data-theme="day"] .station-label.dimmed {
  fill: #64748b;
}
[data-theme="day"] .laser-chip {
  fill: #ffffff;
  stroke: #64748b;
}
[data-theme="day"] .laser-chip.on {
  stroke: #0f172a;
}
[data-theme="day"] .laser-chip.off {
  fill: #cbd5e1;
  stroke: #64748b;
}
[data-theme="day"] .laser-chip.dimmed {
  fill: #e2e8f0;
  stroke: #94a3b8;
}
[data-theme="day"] .laser-chip-label.on { fill: #0f172a; }
[data-theme="day"] .laser-chip-label.off { fill: #334155; }
[data-theme="day"] .laser-chip-label.dimmed { fill: #64748b; }
[data-theme="day"] .beam-arrow-head { fill: #475569; }
[data-theme="day"] .beam-label.excitation { fill: #92400e; }
[data-theme="day"] .beam-label.emission { fill: #075985; }
[data-theme="day"] .beam-label.transmitted { fill: #334155; }
[data-theme="day"] .beam-label.dimmed { fill: #64748b; }
[data-theme="day"] .beam.on-path {
  filter: drop-shadow(0 0 1.5px currentColor);
}
[data-theme="day"] .path-card {
  background: #ffffff;
  border-color: #64748b;
}
[data-theme="day"] .path-card.phase-ex {
  border-color: #b45309;
  background: #fffbeb;
}
[data-theme="day"] .path-card.phase-sample {
  border-color: #047857;
  background: #ecfdf5;
}
[data-theme="day"] .path-card.phase-em {
  border-color: #0369a1;
  background: #f0f9ff;
}
[data-theme="day"] .path-card.phase-cam {
  border-color: #475569;
  background: #f8fafc;
}
[data-theme="day"] input,
[data-theme="day"] select,
[data-theme="day"] textarea {
  color: var(--text);
  background: #ffffff;
  border-color: var(--border);
}

.sf-tree {
  max-height: 240px;
  overflow: auto;
  font-size: 0.72rem;
  line-height: 1.35;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  color: var(--text);
  white-space: pre-wrap;
}

.dialog-parts {
  width: min(1280px, 98vw);
  height: min(820px, 94vh);
  max-width: 98vw;
  max-height: 96vh;
  min-width: min(720px, 96vw);
  min-height: min(480px, 90vh);
  resize: both;
  overflow: auto;
}
.dialog-parts form {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.dialog-parts .dialog-actions { margin-top: auto; }
.parts-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
  margin-bottom: 0;
  flex-shrink: 0;
}
.parts-toolbar label { margin: 0; }
.parts-search { flex: 1; min-width: 160px; }
.parts-table-wrap {
  flex: 1 1 auto;
  min-height: 220px;
  max-height: none;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.parts-resize-hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
}
.parts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  white-space: nowrap;
}
.parts-table th,
.parts-table td {
  padding: 0.28rem 0.45rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.parts-table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  z-index: 1;
}
.parts-table td.parts-desc {
  white-space: normal;
  min-width: 160px;
  max-width: 260px;
}
.parts-table tr:hover td { background: color-mix(in srgb, var(--accent) 8%, transparent); }

.dialog-ttl {
  width: min(1280px, 98vw);
  height: min(860px, 94vh);
  max-width: 98vw;
  max-height: 96vh;
  min-width: min(720px, 96vw);
  min-height: min(520px, 90vh);
  resize: both;
  overflow: auto;
}
.dialog-ttl form {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.dialog-ttl .dialog-actions { margin-top: auto; }
.ttl-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 0;
  flex-shrink: 0;
}
.ttl-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(420px, 1.4fr);
  gap: 0.85rem;
  flex: 1 1 auto;
  min-height: 0;
}
@media (max-width: 900px) {
  .ttl-layout { grid-template-columns: 1fr; }
}
.ttl-dips, .ttl-map-pane {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 0.55rem;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ttl-tabs { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.45rem; flex-shrink: 0; }
.ttl-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}
.ttl-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.ttl-dip-body {
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.dialog-ttl .ttl-dip-switch {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0;
  padding: 0.4rem 0.5rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  min-width: 0;
}
.dialog-ttl .ttl-dip-switch legend {
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0 0.25rem;
}
/* Override dialog label { display:grid } — keep checkbox | # | text in one row */
.dialog-ttl label.ttl-dip-row {
  display: grid;
  grid-template-columns: 1.15rem 1.35rem minmax(0, 1fr);
  column-gap: 0.5rem;
  row-gap: 0;
  align-items: start;
  margin: 0;
  padding: 0.22rem 0.15rem;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
}
.dialog-ttl label.ttl-dip-row:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.dialog-ttl label.ttl-dip-row input[type="checkbox"] {
  margin: 0.18rem 0 0;
  width: 0.95rem;
  height: 0.95rem;
  justify-self: center;
  flex: none;
}
.dialog-ttl .ttl-dip-pos {
  min-width: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding-top: 0.15rem;
  font-weight: 600;
}
.dialog-ttl .ttl-dip-label {
  min-width: 0;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ttl-face-wrap {
  display: flex;
  flex-direction: column;
  flex: 1 1 45%;
  min-height: 280px;
  margin-bottom: 0.45rem;
}
.ttl-face-wrap h3, .ttl-map-pane > h3 {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  flex-shrink: 0;
}
#ttl-faceplate {
  width: 100%;
  flex: 1 1 auto;
  min-height: 260px;
  height: auto;
  background: #f0f0ee;
  border: 1px solid var(--border);
  border-radius: 6px;
}
[data-theme="night"] #ttl-faceplate { background: #1e293b; }
.ttl-routes-wrap {
  overflow: auto;
  flex: 1 1 40%;
  min-height: 140px;
  max-height: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.45rem;
}
.ttl-resize-hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
}
.ttl-routes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
}
.ttl-routes-table th, .ttl-routes-table td {
  padding: 0.28rem 0.4rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.ttl-routes-table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
}
.ttl-route-row { cursor: pointer; }
.ttl-route-row.selected td,
.ttl-route-row:hover td {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.ttl-dest-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
}
.ttl-dest-bar label { flex: 1; min-width: 180px; }

.wiring-context-menu {
  position: fixed;
  z-index: 4000;
  min-width: 11rem;
  padding: 0.35rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}
.wiring-context-menu.hidden { display: none; }
.wiring-context-label {
  padding: 0.25rem 0.55rem 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.wiring-context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.wiring-context-menu button:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
