:root {
  color-scheme: dark;
  --bg: #0a0f14;
  --panel: #121a22;
  --panel-2: #17222c;
  --border: #2a3946;
  --text: #edf5f7;
  --muted: #91a3ad;
  --good: #3ddc84;
  --bad: #ff6464;
  --warn: #ffc857;
  --accent: #6db6ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select {
  font: inherit;
}

button, select, input {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 11px;
}

button { cursor: pointer; }
button:hover { border-color: var(--accent); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 16px 22px;
  background: rgba(10, 15, 20, .96);
  border-bottom: 1px solid var(--border);
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 3px; font-size: 22px; }
h2 { font-size: 16px; }
.topbar p { margin-bottom: 0; color: var(--muted); }

.top-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}
.dot.waiting { background: var(--warn); }
.dot.online { background: var(--good); box-shadow: 0 0 10px var(--good); }
.dot.offline { background: var(--bad); }

main { padding: 20px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metrics article {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metrics strong {
  display: block;
  font-size: 26px;
  margin-top: 3px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 190px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 18px;
}

.toolbar label, .dialog-card label {
  display: grid;
  gap: 5px;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, .8fr);
  gap: 18px;
}

.layout > div, aside {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px;
  min-height: 420px;
}

.tree { display: grid; gap: 8px; }

.branch {
  border-left: 2px solid var(--border);
  margin-left: 10px;
  padding-left: 12px;
}

details {
  background: rgba(255,255,255,.018);
  border: 1px solid transparent;
  border-radius: 8px;
}

details[open] { border-color: var(--border); }

summary {
  list-style: none;
  cursor: pointer;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

summary::-webkit-details-marker { display: none; }

summary::before {
  content: "▸";
  width: 12px;
  color: var(--muted);
}

details[open] > summary::before { content: "▾"; }

.summary-main {
  flex: 1;
  min-width: 0;
}

.title {
  font-weight: 650;
  overflow-wrap: anywhere;
}

.subtitle {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  white-space: nowrap;
}

.badge.online { color: var(--good); }
.badge.offline { color: var(--bad); }
.badge.unassigned { color: var(--warn); }

.item-button {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 9px 10px;
}

.item-button:hover { background: var(--panel-2); }

.sensor-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}
.sensor-dot.online { background: var(--good); }
.sensor-dot.offline { background: var(--bad); }
.sensor-dot.unknown { background: var(--warn); }

.details dl {
  display: grid;
  grid-template-columns: 125px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
}

.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }

.raw {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #080c10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  max-height: 320px;
  overflow: auto;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.message {
  padding: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--warn);
  border-radius: 9px;
  background: rgba(255, 200, 87, .08);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  width: min(480px, calc(100% - 30px));
}

dialog::backdrop { background: rgba(0,0,0,.72); }

.dialog-card {
  display: grid;
  gap: 14px;
}

.dialog-card input, .dialog-card select { width: 100%; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 850px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .toolbar { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
}

@media (max-width: 560px) {
  .topbar { flex-direction: column; }
  .top-actions { width: 100%; flex-wrap: wrap; }
  main { padding: 12px; }
}
