:root {
  --bg: #0b1220;
  --card: #101a2f;
  --border: rgba(255, 255, 255, 0.08);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.68);
  --accent: #4f8cff;
  --good: #2bd576;
  --ok: #ffd36a;
  --weak: #ff9a6a;
  --bad: #ff5a6a;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: radial-gradient(1200px 900px at 10% -10%, #1a2d5a 0%, var(--bg) 55%),
    var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(16, 26, 47, 0.7);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand .title {
  font-weight: 700;
  letter-spacing: 0.2px;
}
.brand .subtitle {
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
}
.dot {
  margin: 0 8px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.top-nav .btn {
  padding: 8px 10px;
  font-size: 12px;
}

.top-nav .btn.active {
  border-color: rgba(79, 140, 255, 0.55);
  background: rgba(79, 140, 255, 0.18);
}
.container {
  max-width: 1100px;
  margin: 18px auto 60px;
  padding: 0 18px;
  display: grid;
  gap: 16px;
}

.main-tabs {
  position: sticky;
  top: 68px;
  z-index: 4;
  background: rgba(16, 26, 47, 0.7);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.main-tabs .tab {
  font-weight: 600;
}
.tabs.small .tab {
  padding: 6px 8px;
  font-size: 12px;
}

.card {
  background: rgba(16, 26, 47, 0.78);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-header h2 {
  margin: 0;
  font-size: 16px;
}

.card-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.kv {
  padding: 14px;
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 14px;
}
.kv.two-col {
  grid-template-columns: repeat(2, 120px 1fr);
}
.kv .k {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.62);
}
.kv .v {
  font-family: var(--mono);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
}
.kv .v.err {
  color: var(--bad);
}

.code {
  margin: 0;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-family: var(--mono);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow: auto;
}

.input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.input.small {
  width: auto;
  min-width: 140px;
  padding: 6px 10px;
  font-size: 12px;
}
.input:focus {
  border-color: rgba(79, 140, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.12);
}
textarea.input {
  resize: vertical;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  user-select: none;
}
.check input {
  width: 16px;
  height: 16px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.1);
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  border-color: rgba(79, 140, 255, 0.55);
  background: rgba(79, 140, 255, 0.18);
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.04);
}

.tabs {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tab {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
}
.tab.active {
  border-color: rgba(79, 140, 255, 0.55);
  background: rgba(79, 140, 255, 0.18);
}

.status {
  font-weight: 600;
}
.status-good {
  color: var(--good);
}
.status-bad {
  color: var(--bad);
}
.status-unknown {
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
}
.node-row {
  cursor: pointer;
}
.node-row:hover td {
  background: rgba(255, 255, 255, 0.04);
}
.table th,
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  text-align: left;
  font-size: 13px;
}
.table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.62);
  white-space: nowrap;
}
.table th.sortable {
  cursor: pointer;
  user-select: none;
}
.table th.sortable:hover {
  color: rgba(255, 255, 255, 0.82);
}
.table th.sorted-asc::after {
  content: " ▲";
  font-size: 10px;
  opacity: 0.8;
}
.table th.sorted-desc::after {
  content: " ▼";
  font-size: 10px;
  opacity: 0.8;
}
.col-id {
  font-family: var(--mono);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.72);
}
.col-ch-index {
  width: 50px;
}
.col-role {
  width: 120px;
}
.col-device {
  width: 120px;
}
.col-snr {
  width: 80px;
}
.col-hops {
  width: 70px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
}
.pill.good {
  border-color: rgba(43, 213, 118, 0.4);
  background: rgba(43, 213, 118, 0.14);
}
.pill.ok {
  border-color: rgba(255, 211, 106, 0.4);
  background: rgba(255, 211, 106, 0.14);
}
.pill.weak {
  border-color: rgba(255, 154, 106, 0.4);
  background: rgba(255, 154, 106, 0.14);
}
.pill.bad {
  border-color: rgba(255, 90, 106, 0.4);
  background: rgba(255, 90, 106, 0.14);
}

.messages {
  padding: 10px 14px 14px;
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
}
.messages.compact {
  max-height: 240px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.messages.compact .msg {
  max-width: 100%;
}
.msg {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
  max-width: 78%;
  align-self: flex-start;
}
.msg.outgoing {
  align-self: flex-end;
  background: rgba(79, 140, 255, 0.18);
  border-color: rgba(79, 140, 255, 0.4);
}
.msg .meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: rgba(255, 255, 255, 0.65);
  font-size: 12px;
}
.msg .meta .mono {
  font-family: var(--mono);
  font-size: 11px;
}
.msg .text {
  font-size: 13px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.send {
  padding: 14px;
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--border);
}
.divider {
  border-top: 1px solid var(--border);
  margin: 6px 0;
}
.node-chat h4 {
  margin: 0;
  font-size: 13px;
}
.field label {
  display: block;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.62);
  margin-bottom: 6px;
}
.hint {
  margin-top: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 9;
}
.modal {
  position: fixed;
  left: 50%;
  top: 72px;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 24px));
  background: rgba(16, 26, 47, 0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 10;
  overflow: hidden;
}
.node-modal {
  width: min(820px, calc(100vw - 24px));
}
.modal-header,
.modal-footer {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.modal-footer {
  border-bottom: none;
  border-top: 1px solid var(--border);
}
.modal-body {
  padding: 14px;
  display: grid;
  gap: 12px;
}
.modal h3 {
  margin: 0;
  font-size: 15px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(16, 26, 47, 0.92);
  box-shadow: var(--shadow);
  min-width: 240px;
  max-width: min(560px, calc(100vw - 36px));
  z-index: 11;
  font-size: 13px;
}
.toast.ok {
  border-color: rgba(43, 213, 118, 0.35);
}
.toast.err {
  border-color: rgba(255, 90, 106, 0.35);
}

.stats-grid {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.stat {
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 10px 12px;
}
.stat .label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.62);
}
.stat .value {
  font-size: 18px;
  margin-top: 6px;
  font-family: var(--mono);
}

.stats-panels {
  padding: 0 14px 14px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.status-meta {
  padding: 0 14px 8px;
}
.status-grid {
  padding: 0 14px 14px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

@media (max-width: 1100px) {
  .status-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }
}
.panel {
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 10px 12px;
}
.panel.wide {
  grid-column: 1 / -1;
}
.panel h3 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.78);
}
.bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-height: 70px;
}
.bar {
  width: 14px;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, rgba(79, 140, 255, 0.95), rgba(79, 140, 255, 0.35));
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 3px;
}
.bar span {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.8);
}

.list {
  display: grid;
  gap: 6px;
}
.list-row {
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(90px, 1fr) auto minmax(80px, 1fr);
  font-size: 12px;
  align-items: center;
  color: rgba(255, 255, 255, 0.8);
  word-break: break-word;
}
.list-row .mono {
  font-family: var(--mono);
  font-size: 11px;
}

.hidden {
  display: none;
}

@media (max-width: 720px) {
  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .actions {
    flex-wrap: wrap;
  }
  .row {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .col-snr {
    width: auto;
  }
  .status-grid {
    grid-template-columns: 1fr;
  }
  .kv.two-col {
    grid-template-columns: 120px 1fr;
  }
}
