/* StageManager design system (M5) – dark navy/anthracite, cyan accent, desktop first.
   No external fonts or resources; no blur/animations (Raspberry Pi friendly). */

:root {
  color-scheme: dark;
  /* surfaces */
  --bg: #0d141d;
  --panel: #131c27;
  --panel-2: #182331;
  --panel-3: #1e2b3b;
  --line: #243245;
  --line-strong: #31445c;
  /* text */
  --text: #e7edf4;
  --text-dim: #a3b2c4;
  --text-faint: #7a8a9e;
  /* accent + semantics */
  --accent: #22d3ee;
  --accent-strong: #06b6d4;
  --accent-ink: #062830;
  --accent-soft: rgba(34, 211, 238, 0.14);
  --accent-line: rgba(34, 211, 238, 0.55);
  --warn: #f5a524;
  --warn-soft: rgba(245, 165, 36, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --ok: #34d399;
  /* type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Liberation Sans", sans-serif;
  --fs-xs: 11px; --fs-s: 12px; --fs-m: 13px; --fs-l: 15px; --fs-xl: 18px;
  /* spacing 4/8/12/16 */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px;
  --radius: 4px;
  --row: 31px;
  --control: 28px;
  --sidebar: 76px;
  --topbar: 44px;
  --timeline: 34px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: var(--fs-m)/1.4 var(--font);
  display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr);
  grid-template-rows: var(--topbar) var(--timeline) auto minmax(0, 1fr);
  grid-template-areas: "nav top" "nav tl" "nav msg" "nav main";
  overflow: hidden;
}
h2 { font-size: var(--fs-l); margin: 0 0 var(--s3); font-weight: 600; letter-spacing: .2px; }
h3 { font-size: var(--fs-m); margin: var(--s4) 0 var(--s2); font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: .6px; }
a { color: var(--accent); }
a:hover { color: #67e8f9; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--text-faint); font-style: normal; }

/* ------------------------------------------------------------ controls */
button, input, select, textarea { font: inherit; color: var(--text); }
button {
  height: var(--control); padding: 0 var(--s3); border-radius: var(--radius); cursor: pointer;
  background: var(--panel-3); border: 1px solid var(--line-strong); white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--accent-line); background: #22324a; }
button:disabled { opacity: .45; cursor: default; }
button.danger { color: var(--danger); border-color: rgba(248, 113, 113, .35); background: transparent; }
button.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
form button:not([type=button]), .primary { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-ink); font-weight: 600; }
form button:not([type=button]):hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
input, select, textarea {
  min-height: var(--control); padding: 3px var(--s2); border-radius: var(--radius);
  background: var(--bg); border: 1px solid var(--line-strong);
}
input:hover, select:hover, textarea:hover { border-color: #41587a; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
input[type=checkbox], input[type=radio] { min-height: 0; accent-color: var(--accent-strong); }
input[type=color] { padding: 2px; width: 44px; height: var(--control); }
input[type=number] { font-variant-numeric: tabular-nums; }
input::placeholder { color: var(--text-faint); }
label { display: inline-flex; flex-direction: column; gap: 2px; color: var(--text-dim); font-size: var(--fs-s); }
label > input, label > select, label > textarea { font-size: var(--fs-m); }
label:has(> input[type=checkbox]), label:has(> input[type=radio]) { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: var(--fs-m); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s2) var(--s3) var(--s3); display: flex; flex-wrap: wrap; gap: var(--s2); }
legend { color: var(--text-dim); font-size: var(--fs-s); padding: 0 var(--s1); }
details > summary { cursor: pointer; color: var(--text-dim); }
form, .actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: end; margin-bottom: var(--s3); }

/* ------------------------------------------------------------ sidebar */
.sidebar {
  grid-area: nav; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: stretch; gap: 2px; padding: var(--s2) 6px;
}
.sidebar .brand { display: grid; place-items: center; height: 32px; margin-bottom: 2px; color: var(--accent); }
.sidebar .brand svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.sidebar { overflow-y: auto; scrollbar-width: thin; gap: 1px !important; padding-top: 4px !important; }
.sidebar hr { border: none; border-top: 1px solid var(--line); margin: 2px 8px; flex: 0 0 auto; }
.sidebar .nav-bottom { margin-top: auto; }
.sidebar button {
  height: auto; padding: 3px 0 2px; flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; border: 1px solid transparent; color: var(--text-dim); border-radius: 6px;
}
.sidebar button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sidebar button span { font-size: 10px; letter-spacing: .1px; line-height: 1.2; }
.sidebar button:hover:not(:disabled) { background: var(--panel-3); color: var(--text); border-color: transparent; }
.sidebar button[aria-current="page"] { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }

/* ------------------------------------------------------------ topbar + timeline */
.topbar {
  grid-area: top; display: flex; align-items: center; gap: var(--s4); padding: 0 var(--s4);
  background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0;
}
.app-name { font-size: var(--fs-l); letter-spacing: .4px; }
.ctx { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.band-pick { flex-direction: row; align-items: center; gap: var(--s2); }
.band-pick select { min-width: 160px; }
.pill:not(:empty) { padding: 2px var(--s2); border: 1px solid var(--line-strong); border-radius: 999px; color: var(--text-dim); font-size: var(--fs-s); white-space: nowrap; }
.pill button { height: 20px; padding: 0 var(--s2); font-size: var(--fs-xs); }
.status-line { margin-left: auto; color: var(--text-dim); font-size: var(--fs-s); white-space: nowrap; font-variant-numeric: tabular-nums; }

.timeline {
  grid-area: tl; display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s4);
  background: var(--bg); border-bottom: 1px solid var(--line); font-size: var(--fs-s); min-width: 0; overflow: hidden;
}
.tl-band { color: var(--text-dim); white-space: nowrap; }
.tl-empty { color: var(--text-faint); }
.tl-list { display: flex; list-style: none; margin: 0; padding: 0; gap: 2px; min-width: 0; }
.tl-seg { display: flex; gap: 6px; align-items: baseline; padding: 3px 10px; background: var(--panel); border: 1px solid var(--line); white-space: nowrap; }
.tl-seg:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.tl-seg:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.tl-label { color: var(--text-dim); }
.tl-time { font-variant-numeric: tabular-nums; }
.tl-seg.past { opacity: .5; }
.tl-seg.active { background: var(--accent-soft); border-color: var(--accent-line); }
.tl-seg.active .tl-label { color: var(--accent); font-weight: 600; }
.tl-next { margin-left: auto; color: var(--text-dim); white-space: nowrap; }

/* ------------------------------------------------------------ messages */
#message {
  grid-area: msg; margin: var(--s2) var(--s4) 0; padding: 6px var(--s3); border-radius: var(--radius);
  border: 1px solid var(--danger); background: var(--danger-soft); color: var(--text);
}
#message::before { content: "⚠ "; color: var(--danger); }
#message[data-kind="info"] { border-color: var(--accent-line); background: var(--accent-soft); }
#message[data-kind="info"]::before { content: "ℹ "; color: var(--accent); }

/* ------------------------------------------------------------ views */
.view { grid-area: main; min-height: 0; min-width: 0; overflow: auto; }
.view[hidden] { display: none !important; }
.table-view { display: flex; flex-direction: column; padding: 0 var(--s4) var(--s2); overflow: hidden; }
#view-hardware { padding: var(--s4); }

/* management view: three panels */
.manage { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(360px, 1.4fr) minmax(380px, 1.5fr); gap: var(--s3); padding: var(--s3) var(--s4); align-items: start; }
.manage > section { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: var(--s3) var(--s4); min-width: 0; }
#prod-list, #band-list { list-style: none; padding: 0; margin: var(--s2) 0 0; display: flex; flex-direction: column; gap: 2px; }
#band-list { counter-reset: band; }
#prod-list li, #band-list li {
  display: flex; align-items: center; gap: var(--s2); padding: 4px var(--s2); border-radius: var(--radius);
  color: var(--text-faint); font-size: var(--fs-s); border: 1px solid transparent;
}
#band-list li::before { counter-increment: band; content: counter(band); color: var(--text-faint); min-width: 16px; text-align: right; font-variant-numeric: tabular-nums; }
#prod-list li:hover, #band-list li:hover { background: var(--panel-2); }
#prod-list li > button:first-child, #band-list li > button:first-child {
  background: transparent; border: none; padding: 0 2px; height: auto; color: var(--text); font-size: var(--fs-m); text-align: left;
  overflow: hidden; text-overflow: ellipsis;
}
#band-list li > button:first-child { flex: 0 1 auto; min-width: 7em; max-width: 45%; }
#band-list li > button:not(:first-child) { height: 22px; padding: 0 6px; }
#band-list li > button:nth-child(2) { margin-left: auto; }
button.active { color: var(--accent) !important; font-weight: 600; }
li:has(> button.active) { background: var(--accent-soft) !important; border-color: var(--accent-line) !important; }
.hint { list-style: none; color: var(--warn); background: var(--warn-soft); border-radius: var(--radius); padding: 4px var(--s2); margin-bottom: 4px; }
.hint::before { content: "⚠ "; }
#hints { padding: 0; margin: 0; }
#band-channels { color: var(--text-dim); }

/* ------------------------------------------------------------ toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 6px var(--s2); align-items: center; padding: var(--s2) 0; }
.toolbar label { flex-direction: row; align-items: center; gap: 6px; }
.toolbar input[type=number] { width: 64px; }
.toolbar input[type=search] { width: 180px; }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px; }
.toolbar .export { color: var(--text-faint); font-size: var(--fs-s); }
.grid-info { margin-left: auto; color: var(--text-dim); font-size: var(--fs-s); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ grid */
.grid-host { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.grid-host:focus-visible { outline: 1px solid var(--accent-line); outline-offset: 0; }
.grid table { border-collapse: separate; border-spacing: 0; width: 100%; table-layout: fixed; }
.grid thead th { position: sticky; top: 0; z-index: 3; background: var(--panel-2); border-bottom: 1px solid var(--line-strong); padding: 0; text-align: left; }
.grid thead button.sort {
  all: unset; display: block; width: 100%; box-sizing: border-box; padding: 7px var(--s2); cursor: pointer;
  color: var(--text-dim); font-size: var(--fs-s); font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}
.grid thead button.sort:hover { color: var(--text); }
.grid thead button.sort:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid thead th[aria-sort] button.sort { color: var(--accent); }
.grid tbody td, .grid tbody th {
  height: var(--row); padding: 0 var(--s2); border-bottom: 1px solid var(--line); border-right: 1px solid rgba(36, 50, 69, .6);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: cell; font-variant-numeric: tabular-nums;
}
.grid tbody th { position: sticky; left: 0; z-index: 1; background: var(--panel-2); text-align: right; font-weight: 600; color: var(--text-dim); }
.grid tbody tr:hover > td { background: rgba(255, 255, 255, .025); }
.grid tbody tr.empty > th { color: var(--text-faint); font-weight: 400; }
.grid tbody tr.boundary > * { box-shadow: inset 0 2px 0 var(--accent-line); }
.grid tbody tr.boundary > th { color: var(--accent); }
.grid tbody tr.match > td { background: rgba(245, 165, 36, .10); }
.grid td.ro { cursor: default; color: var(--text-dim); }
.grid .sel { background: var(--accent-soft) !important; }
.grid .active { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid td.editing { padding: 0; overflow: visible; }
.grid .cell-editor { width: 100%; height: 100%; border: none; border-radius: 0; padding: 0 var(--s2); background: var(--bg); box-shadow: inset 0 0 0 2px var(--accent); }
.grid .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); }
.grid .warn-icon { margin-left: 6px; color: var(--warn); font-weight: 700; }
.grid td.warn { background: var(--warn-soft); }
.grid td.override { color: #fbd38d; }
.grid .badge { margin-left: 6px; font-size: 10px; border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; text-transform: uppercase; letter-spacing: .4px; }
.grid .muted { color: var(--text-faint); font-style: italic; }

/* ------------------------------------------------------------ hardware */
#view-hardware h2 { margin-top: var(--s2); }
#view-hardware p.muted { margin: 0 0 var(--s3); }
table.hw { border-collapse: collapse; margin-bottom: var(--s4); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
table.hw th { text-align: left; padding: 6px var(--s2); color: var(--text-dim); font-size: var(--fs-s); text-transform: uppercase; letter-spacing: .5px; background: var(--panel-2); border-bottom: 1px solid var(--line-strong); }
table.hw td { padding: 4px var(--s2); border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.hw td.actions { display: table-cell; white-space: nowrap; }
table.hw td.actions button { height: 24px; padding: 0 var(--s2); }
table.hw input.num { width: 64px; }
form.inline { flex-direction: row; }

/* ------------------------------------------------------------ import */
.import-panel { border: 1px solid var(--accent-line); border-radius: 6px; padding: var(--s2) var(--s3); margin-bottom: var(--s2); max-height: 55vh; overflow: auto; background: var(--panel); }
.import-panel h2 { margin: 4px 0; }
.import-panel fieldset { margin: var(--s2) 0; }
.import-panel .status { white-space: nowrap; }
.import-panel .status.apply { color: var(--ok); }
.import-panel .status.apply::before { content: "✔ "; }
.import-panel .status.skip { color: var(--text-faint); }
.import-panel .status.skip::before { content: "– "; }
.import-panel .status.error { color: var(--danger); }
.import-panel .status.error::before { content: "✖ "; }
.import-panel .summary { font-weight: 600; }
.loom-hint { color: var(--warn); }
.loom-hint button { margin-left: var(--s2); }
.raw-table tr.is-header td { color: var(--accent); font-weight: 600; }

/* ------------------------------------------------------------ split view + stage */
.split { display: flex; flex: 1; min-height: 0; }
.split-left { display: flex; flex-direction: column; min-width: 0; flex: 0 0 55%; }
.split-right { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: auto; padding-left: var(--s3); }
.split-divider { flex: 0 0 6px; cursor: col-resize; background: var(--line); border-radius: 3px; margin: var(--s2) 0; }
.split-divider:hover, .split-divider:focus-visible { background: var(--accent-line); outline: none; }
.stage-wrap { flex: 1; min-height: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.stage-svg { width: 100%; height: 100%; max-height: 64vh; display: block; user-select: none; touch-action: none; color: var(--text); }
.stage-svg .stage-area { fill: #101a25; stroke: var(--line-strong); stroke-width: 2; }
.stage-svg .grid { stroke: rgba(122, 138, 158, .14); stroke-width: 1; }
.stage-svg .axis { stroke: rgba(122, 138, 158, .35); stroke-width: 1; stroke-dasharray: 6 6; }
.stage-svg .orient { fill: var(--text-dim); font-size: 15px; letter-spacing: 3px; font-weight: 600; }
.stage-svg .el { cursor: grab; outline: none; }
.stage-svg .el:active { cursor: grabbing; }
.stage-svg .el .hit { fill: transparent; stroke: none; }
.stage-svg .el .icon * { fill: none; stroke: #cfe3f2; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.stage-svg .el .icon .f { fill: #cfe3f2; }
.stage-svg .el .icon .icon-text { fill: #cfe3f2; stroke: none; font-size: 12px; font-weight: 700; }
.stage-svg .el .icon .icon-tag { font-size: 9px; letter-spacing: 1.5px; }
.stage-svg .el.selected .icon .f, .stage-svg .el.selected .icon .icon-text { fill: var(--accent); }
.stage-svg .el .label { fill: var(--text); font-size: 14px; font-weight: 600; }
.stage-svg .el .chs { fill: var(--text-dim); font-size: 12px; }
.stage-svg .el.linked .hit { fill: var(--accent-soft); }
.stage-svg .el.selected .hit, .stage-svg .el:focus-visible .hit { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.stage-svg .el.selected .icon * { stroke: var(--accent); }
.inspector { margin-top: var(--s2); padding: var(--s2) var(--s3); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.inspector h3 { margin: 2px 0 var(--s2); color: var(--text); text-transform: none; letter-spacing: 0; font-size: var(--fs-l); }
.inspector p { margin: var(--s2) 0; color: var(--text-dim); }
.insp-row { display: flex; flex-wrap: wrap; gap: var(--s2); }
.ch-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px var(--s3); max-height: 160px; overflow: auto; padding: var(--s2) 0; }
.ch-list label { flex-direction: row; gap: 6px; color: var(--text); font-size: var(--fs-m); }
.ch-list label.muted { color: var(--text-faint); }

/* ------------------------------------------------------------ compact laptop widths */
@media (max-width: 1500px) {
  .manage { grid-template-columns: minmax(230px, 0.9fr) minmax(320px, 1.3fr) minmax(340px, 1.4fr); gap: var(--s2); padding: var(--s2) var(--s3); }
  .topbar { gap: var(--s3); }
  .app-name { display: none; }
  .table-view { padding: 0 var(--s3) var(--s2); }
  .toolbar input[type=search] { width: 130px; }
}

/* ------------------------------------------------------------ module pages (M7) */
.page { padding: var(--s3) var(--s4); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); }
.swatch.big { width: 16px; height: 16px; vertical-align: -3px; }
.warn-text { color: var(--warn); }
.ok-text { color: var(--ok); }
.state-off { color: var(--warn); font-weight: 600; }
.ov-head { display: flex; align-items: baseline; gap: var(--s3); margin-bottom: var(--s3); }
.ov-head h2 { margin: 0; font-size: var(--fs-xl); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s2); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: var(--s2) var(--s3); display: flex; flex-direction: column; }
.stat-value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--text-dim); }
.stat-hint { color: var(--text-faint); font-size: var(--fs-s); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: var(--s2) var(--s4) var(--s3); margin-bottom: var(--s3); max-width: 900px; }
.panel h3 { margin-top: var(--s2); }
table.kv th { text-align: left; color: var(--text-dim); font-weight: 400; padding: 3px var(--s4) 3px 0; white-space: nowrap; vertical-align: top; }
table.kv td { padding: 3px 0; }
.history-list td.val { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-list tr.act-delete td { color: var(--danger); }
.history-list tr.act-restore td { color: var(--accent); }
table.hw td.num, table.hw .num { font-variant-numeric: tabular-nums; }
table.matrix td { white-space: nowrap; }

/* console patch */
.console-body { display: flex; gap: var(--s3); flex: 1; min-height: 0; }
.console-body[hidden] { display: none; }
.console-body .grid-host { flex: 1; }
.side-panel { flex: 0 0 300px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: var(--s2) var(--s3); }
.side-panel h3 { margin-top: var(--s2); }
.empty-state { padding: var(--s4); background: var(--panel); border: 1px dashed var(--line-strong); border-radius: 6px; margin-top: var(--s3); }
.toolbar[hidden] { display: none; }
.live-note { color: var(--text-faint); font-size: var(--fs-s); border: 1px dashed var(--line-strong); border-radius: 999px; padding: 2px var(--s2); }

/* loom occupancy */
.loom-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--s3); }
.loom-card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: var(--s2) var(--s3); }
.loom-head { display: flex; align-items: center; gap: 6px; margin-bottom: var(--s2); }
.ports { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.ports li { display: flex; gap: var(--s2); padding: 2px 6px; border-radius: 3px; background: var(--panel-2); font-size: var(--fs-s); }
.ports li.free { color: var(--text-faint); }
.ports li.conflict { background: var(--warn-soft); color: var(--warn); }
.port-no { min-width: 22px; text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* system designer: the plan fills the page, details live in the side panel */
.view.sys-view { display: flex; flex-direction: column; padding: var(--s2) var(--s4) var(--s3); overflow: hidden; }
.sys-view:fullscreen { background: var(--bg); padding: var(--s3); }
.sys-head { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.sys-head h2 { margin: var(--s2) 0; }
.sys-status { margin: 0; font-size: var(--fs-s); }
.sys-toolbar { padding: 0 0 var(--s2); }
.sys-toolbar .spacer { flex: 1; }
.sys-toolbar button[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.sys-zoom { min-width: 46px; text-align: center; color: var(--text-dim); font-size: var(--fs-s); font-variant-numeric: tabular-nums; }
.sys-body { flex: 1; min-height: 0; display: flex; gap: var(--s3); }
.sys-stage { flex: 1; min-width: 0; background: #0a1017; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.sys-side { width: 270px; flex: none; overflow: auto; padding: var(--s2) var(--s3); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.sys-side h3 { margin: var(--s2) 0; color: var(--text); text-transform: none; letter-spacing: 0; font-size: var(--fs-l); }
.sys-side h3:not(:first-child) { margin-top: var(--s4); padding-top: var(--s3); border-top: 1px solid var(--line); }
.sys-side p { margin: var(--s2) 0; }
.sys-side .actions { margin: var(--s2) 0 0; }
.sys-field { display: flex; flex-direction: column; gap: 3px; margin-bottom: var(--s2); }
.sys-field > span { color: var(--text-dim); font-size: var(--fs-s); }
.sys-field input, .sys-field select, .sys-field textarea { width: 100%; box-sizing: border-box; }
.sys-legend { display: flex; flex-direction: column; gap: 6px; color: var(--text-dim); font-size: var(--fs-s); }
.sys-legend svg { vertical-align: middle; }
.sys-warnings .hint { list-style: none; margin: 0 0 6px; }
button.linklike { all: unset; cursor: pointer; color: inherit; }
button.linklike:hover, button.linklike:focus-visible { text-decoration: underline; }

.sys-canvas { width: 100%; height: 100%; display: block; user-select: none; touch-action: none; cursor: grab; outline: none; }
.sys-canvas:focus-visible { outline: 2px solid var(--accent-line); outline-offset: -2px; }
.sys-canvas.connecting, .sys-canvas.connecting .node { cursor: crosshair; }
.sys-canvas .sys-bg { fill: #0a1017; }
.sys-canvas .sys-dot { fill: rgba(122, 138, 158, .28); }
.sys-canvas .sys-grid-rect { pointer-events: none; }

.sys-canvas .zone { outline: none; }
.sys-canvas .zone-box { fill-opacity: .16; stroke-width: 2; stroke-opacity: .7; }
.sys-canvas .zone-head { fill-opacity: .22; cursor: move; }
.sys-canvas.locked .zone-head, .sys-canvas.locked .node, .sys-canvas.locked .zone-grip { cursor: default; }
.sys-canvas .zone-name { fill: var(--text); font-size: 15px; font-weight: 700; letter-spacing: 3px; pointer-events: none; }
.sys-canvas .zone-grip { fill-opacity: .8; cursor: nwse-resize; }
.sys-canvas .zone.selected .zone-box, .sys-canvas .zone:focus-visible .zone-box { stroke-width: 3.5; stroke-opacity: 1; }
.zone.c-blue .zone-box, .zone.c-blue .zone-head, .zone.c-blue .zone-grip { fill: #3b82f6; stroke: #3b82f6; }
.zone.c-amber .zone-box, .zone.c-amber .zone-head, .zone.c-amber .zone-grip { fill: #f59e0b; stroke: #f59e0b; }
.zone.c-green .zone-box, .zone.c-green .zone-head, .zone.c-green .zone-grip { fill: #22c55e; stroke: #22c55e; }
.zone.c-purple .zone-box, .zone.c-purple .zone-head, .zone.c-purple .zone-grip { fill: #a855f7; stroke: #a855f7; }
.zone.c-red .zone-box, .zone.c-red .zone-head, .zone.c-red .zone-grip { fill: #ef4444; stroke: #ef4444; }
.zone.c-cyan .zone-box, .zone.c-cyan .zone-head, .zone.c-cyan .zone-grip { fill: #06b6d4; stroke: #06b6d4; }
.zone.c-gray .zone-box, .zone.c-gray .zone-head, .zone.c-gray .zone-grip { fill: #94a3b8; stroke: #94a3b8; }

.sys-canvas .node { cursor: grab; outline: none; }
.sys-canvas .node-box { fill: #1b2634; stroke: #5b6b80; stroke-width: 1.5; }
.sys-canvas .node-edge { fill: #7a8a9e; }
.sys-canvas .node.selected .node-box, .sys-canvas .node:focus-visible .node-box { stroke: var(--accent); stroke-width: 3; }
.sys-canvas .node.connect-from .node-box { stroke: var(--ok); stroke-width: 3; stroke-dasharray: 6 4; }
.sys-canvas .node.warn .node-box { stroke: var(--warn); stroke-dasharray: 5 3; }
.sys-canvas .node-name { fill: var(--text); font-size: 15px; font-weight: 700; pointer-events: none; }
.sys-canvas .node-type { fill: var(--text-dim); font-size: 12px; pointer-events: none; }
.sys-canvas .node-badge { fill: var(--text-faint); font-size: 11px; font-weight: 700; letter-spacing: 1px; pointer-events: none; }
.sys-canvas .node.t-console .node-edge, .sys-canvas .node.t-engine .node-edge { fill: #c026d3; }
.sys-canvas .node.t-console .node-badge, .sys-canvas .node.t-engine .node-badge { fill: #e879f9; }
.sys-canvas .node.t-stagebox .node-edge, .sys-canvas .node.t-splitter .node-edge { fill: #94a3b8; }
.sys-canvas .node.t-switch .node-edge { fill: #22d3ee; }
.sys-canvas .node.t-rf .node-edge, .sys-canvas .node.t-iem .node-edge { fill: #34d399; }
.sys-canvas .node.t-amp .node-edge, .sys-canvas .node.t-processor .node-edge { fill: #f59e0b; }
.sys-canvas .node.t-computer .node-edge, .sys-canvas .node.t-recorder .node-edge { fill: #a855f7; }
.sys-canvas .node.t-note .node-box { fill: #3a3317; stroke: #b59f3b; }
.sys-canvas .node.t-note .node-name { fill: #fde68a; font-size: 13px; }
.sys-canvas .note-text { fill: #f1e9c9; font-size: 12px; pointer-events: none; }

.link { stroke-width: 3; fill: none; stroke-linejoin: round; }
.link.proto-analog { stroke: #4ade80; }
.link.proto-dante_primary { stroke: #f87171; }
.link.proto-dante_secondary { stroke: #fb923c; }
.link.proto-avb_primary { stroke: #38bdf8; }
.link.proto-avb_secondary { stroke: #818cf8; }
.link.proto-aes { stroke: #c084fc; }
.link.proto-madi { stroke: #e879f9; }
.link.proto-control { stroke: #94a3b8; }
.sys-canvas .link-g { cursor: pointer; outline: none; }
.sys-canvas .link-hit { fill: none; stroke: transparent; stroke-width: 16; }
.sys-canvas .link-g.selected .link, .sys-canvas .link-g:focus-visible .link { stroke-width: 5.5; }
.sys-canvas .badge-bg { fill: #0a1017; stroke-width: 1.5; }
.sys-canvas .badge-bg.proto-analog { stroke: #4ade80; }
.sys-canvas .badge-bg.proto-dante_primary { stroke: #f87171; }
.sys-canvas .badge-bg.proto-dante_secondary { stroke: #fb923c; }
.sys-canvas .badge-bg.proto-avb_primary { stroke: #38bdf8; }
.sys-canvas .badge-bg.proto-avb_secondary { stroke: #818cf8; }
.sys-canvas .badge-bg.proto-aes { stroke: #c084fc; }
.sys-canvas .badge-bg.proto-madi { stroke: #e879f9; }
.sys-canvas .badge-bg.proto-control { stroke: #94a3b8; }
.sys-canvas .link-g.selected .badge-bg { stroke-width: 3; }
.sys-canvas .badge-text { fill: var(--text); font-size: 11px; font-weight: 700; pointer-events: none; }

@media (max-width: 1100px) { .sys-side { width: 220px; } }
@media print {
  body.print-system * { visibility: hidden !important; }
  body.print-system .sys-stage, body.print-system .sys-stage * { visibility: visible !important; }
  body.print-system .sys-stage { position: fixed; inset: 0; border: 0; border-radius: 0; }
  body.print-system { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ------------------------------------------------------------ login */
.user-box { display: flex; align-items: center; gap: var(--s2); color: var(--text-dim); font-size: var(--fs-s); white-space: nowrap; }
.user-box button { height: 24px; padding: 0 var(--s2); }
body.locked .sidebar, body.locked .topbar, body.locked .timeline, body.locked .view { visibility: hidden; }
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.login[hidden] { display: none; }
.login-card { width: min(360px, 92vw); display: flex; flex-direction: column; align-items: stretch; gap: var(--s3);
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: var(--s4) 20px; margin: 0; }
.login-card h1 { margin: 0; font-size: 20px; color: var(--accent); letter-spacing: .5px; }
.login-card p { margin: 0; }
.login-card button { height: 34px; }
.login-error { color: var(--danger); }
.login code { display: block; margin-top: 4px; padding: 4px 6px; background: var(--bg); border-radius: 3px; color: var(--text); font-size: 12px; overflow-wrap: anywhere; }

/* ------------------------------------------------------------ export/import + timetable */
a.button-link { display: inline-flex; align-items: center; height: var(--control); padding: 0 var(--s3); border-radius: var(--radius);
  background: var(--panel-3); border: 1px solid var(--line-strong); color: var(--text); text-decoration: none; }
a.button-link:hover { border-color: var(--accent-line); }
label.file-pick { margin-top: var(--s2); }
label.file-pick input { font-size: var(--fs-s); }
.tt { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: var(--s2) var(--s3); overflow-x: auto; }
.tt-row { display: grid; grid-template-columns: 170px minmax(600px, 1fr); align-items: center; min-height: 34px; border-bottom: 1px solid var(--line); }
.tt-head { min-height: 28px; position: sticky; top: 0; background: var(--panel); z-index: 2; }
.tt-name { justify-self: start; background: transparent; border: none; color: var(--text); font-weight: 600; text-align: left; padding: 0 var(--s2) 0 0; height: auto; }
.tt-clash .tt-name { color: var(--warn); }
.tt-axis, .tt-track { position: relative; height: 26px; }
.tt-axis { height: 22px; }
.tt-tick { position: absolute; top: 2px; transform: translateX(-50%); color: var(--text-dim); font-size: var(--fs-xs); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tt-tick small { color: var(--text-faint); }
.tt-bar { position: absolute; top: 3px; height: 20px; border-radius: 3px; overflow: hidden; font-size: 11px; line-height: 20px; padding: 0 4px; white-space: nowrap; border: 1px solid transparent; }
.tt-getin { background: repeating-linear-gradient(45deg, #2a3a50 0 4px, #22324a 4px 8px); color: var(--text-dim); border-color: #3a4f6b; }
.tt-setup { background: #2a3a50; color: var(--text-dim); border-color: #41587a; }
.tt-soundcheck { background: rgba(245, 165, 36, .25); border-color: var(--warn); color: #fde4b5; }
.tt-show { background: rgba(34, 211, 238, .28); border-color: var(--accent); color: #d9f8fd; font-weight: 600; }
.tt-now { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--danger); }
.tt-legend { display: flex; flex-wrap: wrap; gap: var(--s3); color: var(--text-dim); font-size: var(--fs-s); margin-bottom: var(--s2); }
.tt-swatch { display: inline-block; width: 22px; height: 12px; border-radius: 2px; vertical-align: -2px; border: 1px solid transparent; }
.tt-nowkey { width: 3px; background: var(--danger); }
.tt-stage h3 { margin: var(--s3) 0 var(--s1); }

/* ------------------------------------------------------------ sync status */
.status-line::before { content: "●"; margin-right: 6px; color: var(--text-faint); }
.status-line[data-state="online"]::before { color: var(--ok); }
.status-line[data-state="offline"]::before { color: var(--warn); }
.status-line[data-state="conflict"]::before, .status-line[data-state="error"]::before { color: var(--danger); }
.status-line[data-state="local"]::before { color: var(--accent); }
.panel table.hw td { vertical-align: top; }

/* band times: one date, clock times side by side */
.time-grid { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); flex-basis: 100%; }
.time-grid label { display: flex; flex-direction: column; gap: 2px; }
#band-times-own, #band-times-note { flex-basis: 100%; margin: 0; }
#band-times-own summary { cursor: pointer; color: var(--text-faint); }
.tt-edit input[type=time] { width: 6.2em; }
.tt-edit input[type=date] { width: 9.5em; }
.tt-edit td { white-space: nowrap; }

/* import: the file also holds the other list */
.also-hint { margin: var(--s2) 0; padding: var(--s2) var(--s3); border: 1px solid var(--accent-line); border-radius: var(--radius); background: var(--accent-soft); }
.also-hint[hidden] { display: none; }
/* I/O split view: patch on the right uses the full width */
.io-right { padding-left: var(--s3); overflow: hidden; }
.io-right .console-body { min-height: 0; }
.matrix-out { margin-bottom: var(--s4); }

/* stage plot tab */
.stageplot-host { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
#view-stageplot .stageplot-host { overflow: hidden; }
#view-stageplot .stageplot-host .stage-wrap { flex: 1; min-height: 0; }
#view-stageplot .stageplot-host .stage-svg { max-height: none; height: 100%; }
#view-stageplot .toolbar .spacer { flex: 1; }
.inline-title { margin: 0; font-size: var(--fs-xl); }

/* print sheet of a band (built on demand, only visible when printing) */
#print-sheet { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body.print-band { background: #fff !important; display: block !important; height: auto !important; overflow: visible !important; }
  body.print-band > *:not(#print-sheet) { display: none !important; }
  body.print-band #print-sheet { display: block; width: 100%; color: #000; font: 10pt/1.35 var(--font); }
  #print-sheet h1 { font-size: 18pt; margin: 0 0 2mm; color: #000; }
  #print-sheet h2 { font-size: 12pt; margin: 6mm 0 2mm; color: #000; text-transform: none; letter-spacing: 0; break-after: avoid; }
  #print-sheet header p { margin: 0 0 1mm; }
  #print-sheet .notes { font-style: italic; }
  #print-sheet table { width: 100%; border-collapse: collapse; }
  #print-sheet th, #print-sheet td { border: 0.3mm solid #999; padding: 1mm 1.5mm; text-align: left; color: #000; background: #fff; }
  #print-sheet th { background: #e8e8e8; font-weight: 700; text-transform: none; letter-spacing: 0; }
  #print-sheet tr { break-inside: avoid; }
  #print-sheet td.num { text-align: right; width: 10mm; }
  #print-sheet .print-plot { break-before: page; }
  #print-sheet .print-plot svg { display: block; width: 100%; height: auto; max-height: 245mm; }
  #print-sheet .stage-area { fill: #fff; stroke: #000; }
  #print-sheet .grid { stroke: #e2e2e2; }
  #print-sheet .axis { stroke: #bbb; }
  #print-sheet .orient, #print-sheet .label, #print-sheet .chs { fill: #000; }
  #print-sheet .el .hit { fill: none; stroke: none; }
  #print-sheet .el .icon * { stroke: #000; }
  #print-sheet .el .icon .f, #print-sheet .el .icon .icon-text { fill: #000; }
  #print-sheet footer { margin-top: 4mm; font-size: 8pt; color: #555; }
  body.print-band #print-sheet { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* account scope */
.scope-picker { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s2); }
.scope-tree { display: flex; flex-direction: column; gap: var(--s2); max-height: 280px; overflow: auto; padding: var(--s2); border: 1px solid var(--line); border-radius: var(--radius); }
.scope-tree[hidden] { display: none; }
.scope-prod { display: flex; flex-direction: column; gap: 4px; }
.scope-sub { display: flex; flex-wrap: wrap; gap: 4px var(--s3); padding-left: var(--s4); }
.scope-item { display: inline-flex; align-items: center; gap: 4px; }
.scope-edit { margin-top: var(--s2); }
.user-create .scope-new { flex-basis: 100%; }

/* two-factor login */
.totp-qr svg { display: block; max-width: 100%; height: auto; background: #fff; border-radius: var(--radius); }
.totp-secret { font-size: 1.05em; letter-spacing: .04em; word-break: break-all; }
.recovery-codes { columns: 2; max-width: 360px; font-size: 1.1em; }
.table-scroll { max-width: 100%; overflow-x: auto; }
.login-error.login-hint { color: var(--text); }
/* phones: the top bar must not push the page sideways */
@media (max-width: 700px) {
  .status-line { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .user-box .user-name { display: none; }
  .band-pick select { min-width: 0; max-width: 40vw; }
}
form[hidden] { display: none; }                 /* forms are flex containers: keep the hidden attribute working */
form button.danger:not([type=button]) { background: transparent; color: var(--danger); border-color: rgba(248, 113, 113, .35); font-weight: 400; }
form button.danger:not([type=button]):hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
