:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d9dee6;
  --text: #17202b;
  --muted: #5d6877;
  --accent: #1d6fd8;
  --accent-text: #ffffff;
  --go: #2e7d32;
  --stop: #c62828;
  --warn: #b85c00;
  --ok: #2e7d32;
  --grid: #e3e7ed;
  --axis: #6b7684;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #18202a;
    --surface-2: #212b37;
    --border: #2e3a48;
    --text: #e6ebf1;
    --muted: #9aa6b4;
    --accent: #5aa2ff;
    --accent-text: #08111c;
    --go: #4caf50;
    --stop: #ef5350;
    --warn: #ffa64d;
    --ok: #66bb6a;
    --grid: #26313d;
    --axis: #8d99a7;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.mono, .log { font-family: ui-monospace, Consolas, "Cascadia Mono", monospace; }
.center { text-align: center; }
.err { color: var(--stop); min-height: 1.2em; }
h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 12px 0 6px; }

/* top bar */
.sticky { position: sticky; top: 0; z-index: 5; }
.topbar {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 28px; height: 28px; border-radius: 6px; background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1 9h3l2-6 3 10 2-4h4' fill='none' stroke='black' stroke-width='2'/%3E%3C/svg%3E") center/80% no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1 9h3l2-6 3 10 2-4h4' fill='none' stroke='black' stroke-width='2'/%3E%3C/svg%3E") center/80% no-repeat; }
.title { font-weight: 600; font-size: 16px; }
.sub { font-size: 12px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.btn {
  font: inherit; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.go { background: var(--go); border-color: var(--go); color: #fff; font-weight: 600; min-width: 92px; }
.btn.stop { background: var(--stop); border-color: var(--stop); color: #fff; font-weight: 600; min-width: 92px; }
.btn.rec-on { background: var(--stop); border-color: var(--stop); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.danger { color: var(--stop); }

.pill, .chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.pill.run { background: var(--go); border-color: var(--go); color: #fff; }
.pill.rec { background: var(--stop); border-color: var(--stop); color: #fff; }
.pill.warn, .chip.warn { color: var(--warn); border-color: var(--warn); }
.chip.ok { color: var(--ok); border-color: var(--ok); }
.chip.err { color: var(--stop); border-color: var(--stop); }

/* tabs */
.tabs { display: flex; gap: 2px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; }
.tabs button { font: inherit; background: none; border: 0; padding: 10px 14px; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 16px; max-width: 1800px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px; box-shadow: var(--shadow);
  margin-bottom: 14px; min-width: 0; }
.statusline { font-size: 12px; margin-bottom: 10px; min-height: 1.2em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr)); gap: 14px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

/* node cards */
.node-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.node-head h2 { margin: 0; }
.plot { width: 100%; height: 240px; display: block; }
.vals { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.vals td { padding: 2px 6px; border-top: 1px solid var(--grid); }
.vals td.v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.vals td.t { text-align: right; font-variant-numeric: tabular-nums; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* forms / tables */
.form-row { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: 8px 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 16px; }
label { display: inline-flex; align-items: center; gap: 6px; }
.form-grid label { display: flex; flex-direction: column; align-items: stretch; gap: 3px; font-size: 12px; color: var(--muted); }
.form-grid label.check { flex-direction: row; align-items: center; color: var(--text); font-size: 14px; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: 4px 6px; min-width: 0; }
input[type=checkbox] { width: 16px; height: 16px; }
input.num { width: 72px; }
input:disabled, select:disabled { opacity: .55; background: var(--surface-2); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.table-wrap { overflow-x: auto; }
.tbl { border-collapse: collapse; width: 100%; font-size: 13px; }
.tbl th, .tbl td { padding: 4px 6px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; }
.tbl td.r { text-align: right; font-variant-numeric: tabular-nums; }
.tbl input:not([type=checkbox]) { width: 100%; min-width: 60px; }
.tbl select { width: 100%; }
details.bus { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; background: var(--surface); }
details.bus > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
details.bus > div { padding: 0 14px 14px; }
.node-box { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-weight: 600; }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.err { color: var(--stop); border-color: var(--stop); }
.info { font-size: 12px; margin: 6px 0; }
progress { width: 100%; height: 8px; margin: 8px 0; }

.log { margin: 0; max-height: 70vh; overflow: auto; font-size: 12px; white-space: pre-wrap; word-break: break-word; }

.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--bg); padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; }
.overlay.dim { background: rgba(0, 0, 0, .45); z-index: 25; }
.dialog-card { width: min(480px, 100%); margin: 0; }
.dialog-card p { white-space: pre-wrap; margin: 0 0 14px; }
.dialog-btns { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 30; max-width: min(640px, calc(100% - 32px));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; white-space: pre-wrap; box-shadow: var(--shadow); }

@media (max-width: 640px) {
  main { padding: 10px; }
  .topbar { padding: 8px 10px; }
  .plot { height: 200px; }
}

/* ---- hub additions ---- */
a { color: var(--accent); }
.crumbs { font-size: 13px; margin-bottom: 10px; }
.crumbs a { text-decoration: none; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 14px; }
.tile { display: block; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px; box-shadow: var(--shadow); min-height: 120px; }
.tile:hover { border-color: var(--accent); }
.tile.off { opacity: .55; pointer-events: none; }
.tile h2 { font-size: 18px; margin: 0 0 6px; }
.tile .big { font-size: 13px; color: var(--muted); }
.dev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 14px; }
.dev { display: block; text-decoration: none; color: var(--text); }
.dev:hover .card { border-color: var(--accent); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.dot.on { background: var(--ok); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.subtabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 6px 0 14px; overflow-x: auto; }
.subtabs button { font: inherit; background: none; border: 0; padding: 8px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.subtabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.token { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 8px; border-radius: 6px; word-break: break-all; user-select: all; }
.userbox { font-size: 12px; }
.home-link { text-decoration: none; color: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.chips .chip { font-weight: 500; }
.param-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 8px 16px; margin: 6px 0; }
.param-checks label.check { align-items: flex-start; gap: 8px; }
.param-checks label.check input { margin-top: 2px; flex: none; }
.param-sel { font-size: 12px; padding: 1px 4px; margin-right: 6px; }
