:root {
  --bg: #e9edf1;
  --surface: #ffffff;
  --sunk: #f4f6f8;
  --ink: #18222d;
  --ink-2: #4a5866;
  --ink-3: #7a8794;
  --line: #d5dce3;
  --led: #2e86ff;
  --led-glow: rgba(46, 134, 255, .45);
  --fault: #c8372d;
  --ok: #1f8a4c;
  --glass: #1d2630;
  --glass-2: #27323e;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12181e; --surface: #1a222b; --sunk: #151c23; --ink: #e6edf3; --ink-2: #a9b6c2;
    --ink-3: #7d8a96; --line: #2a3540; --glass: #0d1217; --glass-2: #18212a; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font);
  display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--led); outline-offset: 2px; }

/* ---------- top bar ---------- */
.bar {
  display: flex; align-items: center; gap: 16px; padding: 10px 18px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font: 600 16px var(--font-display); }
.mark { width: 26px; height: 26px; fill: var(--glass); }
.mark circle { fill: #3a4653; }
.mark .led { fill: var(--led); filter: drop-shadow(0 0 3px var(--led-glow)); }
.link-pill {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line);
  background: var(--sunk); border-radius: 999px; padding: 5px 12px; cursor: pointer; color: var(--ink-2);
}
.link-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.link-pill.on .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(31,138,76,.15); }
.link-pill.on { color: var(--ink); }
.bar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.count { color: var(--ink-3); font-size: 12.5px; margin-right: 6px; }

.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 7px 14px; cursor: pointer;
  background: var(--sunk); font-weight: 500;
}
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.primary { background: var(--led); color: #fff; }
.btn.primary:hover { background: #1f74e8; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--sunk); }
.btn.ghost[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.danger { background: var(--fault); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 330px 1fr; min-height: 0; }
.rail { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.rail-head { padding: 12px; border-bottom: 1px solid var(--line); }
.rail-head input {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--sunk);
}
.list { overflow: auto; padding: 6px 0 16px; }
.group-name { padding: 14px 16px 6px; color: var(--ink-3); font-size: 12.5px; font-weight: 600; }
.dev {
  display: grid; grid-template-columns: 56px 1fr; gap: 2px 10px; width: 100%; text-align: left;
  padding: 8px 16px; border: 0; background: transparent; cursor: pointer; border-left: 3px solid transparent;
}
.dev:hover { background: var(--sunk); }
.dev[aria-current="true"] { background: var(--sunk); border-left-color: var(--led); }
.dev .addr { grid-row: span 2; font: 600 17px var(--font-display); align-self: center; }
.dev .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev .name.empty { color: var(--ink-3); font-weight: 400; font-style: italic; }
.dev .model { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- detail ---------- */
.detail { overflow: auto; padding: 26px 32px 40px; min-height: 0; }
.empty-state { max-width: 460px; margin: 12vh auto 0; text-align: center; color: var(--ink-2); }
.empty-state h2 { font: 600 22px var(--font-display); color: var(--ink); margin: 0 0 8px; }
.empty-state p { margin: 0 0 18px; }
.empty-state svg { width: 120px; margin-bottom: 18px; }

.dhead { display: flex; gap: 20px; align-items: flex-start; margin-bottom: 22px; }
.dhead .big-addr {
  font: 600 34px/1 var(--font-display); padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; min-width: 96px; text-align: center;
}
.dhead h1 { font: 600 24px/1.2 var(--font-display); margin: 2px 0 4px; }
.dhead h1.unnamed { color: var(--ink-3); font-weight: 400; }
.dhead .sub { color: var(--ink-2); }
.dhead .actions { margin-left: auto; display: flex; gap: 8px; flex-shrink: 0; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 10px; color: var(--ink-2); font-size: 13px; }
.facts b { color: var(--ink); font-weight: 600; }

.section { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; }
.section h2 { font: 600 16px var(--font-display); margin: 0 0 4px; }
.section .hint { color: var(--ink-3); margin: 0 0 14px; font-size: 13px; }
.loading { color: var(--ink-3); display: flex; align-items: center; gap: 10px; }
.spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--led); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* channels */
.channels { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.chan {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--sunk);
}
.chan .n { font-weight: 600; }
.chan .lvl { color: var(--ink-3); font-size: 12.5px; }
.switch { position: relative; width: 40px; height: 22px; border-radius: 999px; background: #bcc6cf; border: 0; cursor: pointer; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--led); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.chan input[type=range] { width: 100%; accent-color: var(--led); }
.chan.dim { flex-direction: column; align-items: stretch; }
.chan.dim .top { display: flex; justify-content: space-between; }

/* ---------- the panel face ---------- */
.panel-wrap { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: start; }
.pages { display: flex; gap: 6px; margin-bottom: 12px; }
.pages button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 3px 12px; cursor: pointer; color: var(--ink-2); }
.pages button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.face {
  width: 300px; padding: 22px 18px; border-radius: 18px;
  background: linear-gradient(160deg, var(--glass-2), var(--glass));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.07), 0 10px 24px rgba(16, 24, 32, .18);
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.face .screen {
  grid-column: 1 / -1; height: 54px; border-radius: 8px; background: #0a0f14; margin-bottom: 6px;
  display: flex; align-items: center; justify-content: center; color: #6c7a88; font-size: 12px;
  border: 1px solid rgba(255,255,255,.05);
}
.key {
  position: relative; display: flex; align-items: center; gap: 9px; min-height: 52px; padding: 8px 10px;
  border-radius: 10px; border: 1px solid rgba(255,255,255,.06); background: rgba(255,255,255,.03);
  color: #c9d3dc; cursor: pointer; text-align: left;
}
.key:hover { background: rgba(255,255,255,.07); }
.key[aria-pressed="true"] { border-color: var(--led); background: rgba(46,134,255,.12); }
.key .lamp { width: 9px; height: 9px; border-radius: 50%; background: #3b4754; flex-shrink: 0; }
.key.used .lamp { background: #5a6774; }
.key.lit .lamp { background: var(--led); box-shadow: 0 0 8px 2px var(--led-glow); }
.key .kn { font-size: 11px; color: #7d8a96; }
.key .kl { font-size: 12.5px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.key.unused .kl { color: #5d6a77; }

.btn-detail h3 { font: 600 20px var(--font-display); margin: 0 0 2px; }
.btn-detail .mode { color: var(--ink-2); margin-bottom: 16px; }
.targets { list-style: none; margin: 0 0 18px; padding: 0; border-top: 1px solid var(--line); }
.targets li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.targets .i { color: var(--ink-3); font-size: 12.5px; padding-top: 2px; }
.targets .t { font-size: 15px; }
.targets .k { color: var(--ink-3); font-size: 12.5px; }
.targets .ha { color: var(--led); font-weight: 600; }
.btn-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.note { color: var(--ink-3); font-size: 13px; margin-top: 12px; }

/* ---------- monitor ---------- */
.monitor[hidden] { display: none; }
.monitor { height: 34vh; border-top: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.monitor-head { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.monitor-head input[type=search] { padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--sunk); width: 240px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.monitor-body { overflow: auto; flex: 1; }
.monitor table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.monitor td { padding: 4px 16px 4px 0; border-bottom: 1px solid var(--sunk); white-space: nowrap; }
.monitor td:first-child { padding-left: 16px; color: var(--ink-3); }
.monitor .out td { color: var(--ink-3); }
.monitor .dir { width: 18px; }
.monitor .bytes { font-family: var(--mono); color: var(--ink-2); white-space: normal; word-break: break-all; }

/* ---------- dialogs ---------- */
.dlg { border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 30px 70px rgba(16,24,32,.35); }
.dlg::backdrop { background: rgba(18, 26, 34, .45); }
.dlg form { padding: 24px 26px 22px; display: flex; flex-direction: column; gap: 14px; }
.dlg h2 { margin: 0; font: 600 20px var(--font-display); }
.dlg .lede { margin: -6px 0 0; color: var(--ink-2); }
.dlg label { display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); font-size: 13px; }
.dlg input, .dlg select { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--sunk); color: var(--ink); font-size: 14px; }
.dlg .row { display: flex; gap: 8px; }
.dlg .row > * { flex: 1; }
.dlg .row > .btn { flex: 0 0 auto; }
.adv summary { cursor: pointer; color: var(--ink-2); }
.adv .row { margin-top: 10px; }
.gw-list { display: flex; flex-direction: column; gap: 6px; }
.gw-list button { text-align: left; border: 1px solid var(--line); background: var(--sunk); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.gw-list button b { font-weight: 600; }
.dlg .error { color: var(--fault); margin: 0; min-height: 1em; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.warnbox { background: #fff6e5; color: #6b4a00; border-radius: 10px; padding: 10px 12px; font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--surface); padding: 9px 16px; border-radius: 10px; pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--fault); color: #fff; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .panel-wrap { grid-template-columns: 1fr; }
  .detail { padding: 18px 16px 32px; }
}

/* ---------- editing ---------- */
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.sec-head h2 { margin: 0; }
.tabs { display: inline-flex; background: var(--sunk); border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.tabs button { border: 0; background: transparent; padding: 4px 14px; border-radius: 999px; cursor: pointer; color: var(--ink-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(16,24,32,.12); }
.editor h3 { font: 600 20px var(--font-display); margin: 0 0 12px; }
.editor label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); flex: 1; min-width: 110px; }
.editor label.wide { flex: 2 1 220px; }
.editor label.narrow { flex: 0 0 82px; min-width: 0; }
.editor input, .editor select { padding: 7px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 14px; width: 100%; }
.ed-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.presets { margin: 2px 0 14px; }
.ed-targets { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.tcard { position: relative; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px 12px; margin: 0; background: var(--sunk); }
.tcard legend { font-size: 12.5px; color: var(--ink-3); padding: 0 4px; }
.tcard .x { position: absolute; top: -2px; right: 10px; border: 0; background: transparent; color: var(--fault); cursor: pointer; font-size: 12.5px; }
.tcard .preview { font-size: 13.5px; color: var(--ink); border-top: 1px dashed var(--line); padding-top: 8px; }
.ed-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.editor .error { color: var(--fault); margin: 8px 0 0; min-height: 1em; }
.col-all { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; color: var(--ink-2); }
.col-all label { display: flex; align-items: center; gap: 6px; }
.col-table { border-collapse: collapse; width: 100%; max-width: 360px; }
.col-table th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: 12.5px; padding: 4px 0; }
.col-table td { padding: 4px 0; border-top: 1px solid var(--line); }
input[type=color] { width: 54px; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: var(--surface); cursor: pointer; }

/* ---------- wireless ---------- */
.danger-text { color: var(--fault); }
.dim { color: var(--ink-3); font-weight: 400; font-size: 14px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--sunk); border: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); }
.chip.warn { background: #fff6e5; color: #6b4a00; border-color: #f1d8a6; }
.rf { display: flex; flex-wrap: wrap; gap: 8px 32px; margin: 0 0 14px; }
.rf dt { font-size: 12.5px; color: var(--ink-3); }
.rf dd { margin: 2px 0 0; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.pairing-live { border-color: var(--led); box-shadow: 0 0 0 3px rgba(46,134,255,.12); }
.count-down { font: 600 18px var(--font-display); color: var(--led); }
.steps { margin: 0 0 14px; padding-left: 18px; color: var(--ink-2); }
.steps li { margin-bottom: 6px; }
.mini { font: 600 14px var(--font-display); margin: 6px 0 6px; }
.joined { list-style: none; padding: 0; margin: 0; }
.joined li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.joined li button { margin-left: auto; }
.found p { margin: 0 0 10px; }
.found label, .section .ed-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); max-width: 160px; }
.found input { padding: 7px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.dhead .actions { flex-wrap: wrap; justify-content: flex-end; max-width: 420px; }

/* ---------- health check (0.4) ---------- */
.chip.bad { background: #fdecea; color: var(--fault); border-color: #f3c3be; }
.chip.ok { background: #e8f5ee; color: var(--ok); border-color: #b9e0c9; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 4px; border-radius: 999px; font-size: 11.5px; line-height: 18px; text-align: center; }
.badge.bad { background: var(--fault); color: #fff; }
.badge.ok { background: #e8f5ee; color: var(--ok); }
.issues { list-style: none; margin: 0 0 16px; padding: 0; border-top: 1px solid var(--line); }
.issues li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.issues .itext { font-size: 14px; }
.issues .k { color: var(--ink-3); font-size: 12.5px; }
.issues .chip { font-size: 11.5px; padding: 1px 8px; margin-top: 1px; }
.key.flag-bad::after, .key.flag-warn::after {
  content: ""; position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%;
}
.key.flag-bad::after { background: #ff5a4f; box-shadow: 0 0 0 2px rgba(255,90,79,.25); }
.key.flag-warn::after { background: #f2b33d; }
.bases td.mono { font-family: var(--mono); font-size: 12.5px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chip.bad { background: #3a1c1a; border-color: #5a2a26; color: #ff8a80; }
  :root:not([data-theme="light"]) .chip.ok, :root:not([data-theme="light"]) .badge.ok { background: #16301f; border-color: #234a31; color: #7fd6a0; }
  :root:not([data-theme="light"]) .chip.warn { background: #3a2e14; border-color: #5a4720; color: #f2c56b; }
}
.col-table.bases { width: 100%; margin-bottom: 14px; border-collapse: collapse; }
.col-table.bases th, .col-table.bases td { padding: 7px 10px 7px 0; text-align: left; }
.col-table.bases { max-width: none; }
.dlg label.check { display: flex; flex-direction: row; align-items: center; gap: 8px; margin-top: 12px; text-align: left; }
.dlg label.check input { width: auto; margin: 0; }
.dlg .row > label { flex: 1; min-width: 0; }
.dlg .row > label input { width: 100%; }

/* ---------- trace & debug (0.5) ---------- */
.mon-spacer { flex: 1; }
.monitor .mean { color: var(--ink); white-space: normal; min-width: 220px; }
table.trace { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13.5px; }
table.trace th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: 12.5px; padding: 6px 12px 6px 0; border-bottom: 1px solid var(--line); }
table.trace td { padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.trace .k { color: var(--ink-3); font-size: 12px; }
table.trace .mono, .mono { font-family: var(--mono); }
table.trace tr.bad td:first-child { box-shadow: inset 3px 0 0 var(--fault); padding-left: 8px; }
table.trace tr.ok td:first-child { box-shadow: inset 3px 0 0 var(--ok); padding-left: 8px; }

/* ---------- server edition (0.6) ---------- */
.icon-btn { padding: 6px 8px; display: inline-flex; align-items: center; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.wide-dlg { width: min(640px, calc(100vw - 32px)); }
.set-sec { border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.set-sec h3 { margin: 0; font: 600 15px var(--font-display); }
.set-steps { margin: 0; padding-left: 20px; color: var(--ink-2); display: flex; flex-direction: column; gap: 6px; }
.set-steps .k, .kv .k, .bridges .k { color: var(--ink-3); font-size: 12.5px; }
.kv { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kv .k { min-width: 96px; }
.kv code { font-family: var(--mono); font-size: 13px; background: var(--sunk); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; overflow-wrap: anywhere; }
.kv code.blur { filter: blur(4px); cursor: pointer; }
.bridges { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.bridges .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; }
.set-lic { display: flex; flex-direction: column; gap: 8px; }
