:root {
  --bg: #0a0f18;
  --bg-2: #0f1623;
  --panel: #131c2b;
  --panel-2: #182335;
  --line: #233148;
  --line-2: #2d3d57;
  --text: #e7edf6;
  --text-2: #a3b0c4;
  --text-3: #74839a;
  --blue: #3fa9ff;
  --blue-ink: #04121f;
  --blue-soft: rgba(63, 169, 255, 0.12);
  --green: #3ccf8e;
  --green-soft: rgba(60, 207, 142, 0.13);
  --amber: #f2b63c;
  --amber-soft: rgba(242, 182, 60, 0.13);
  --red: #ff5d6c;
  --red-soft: rgba(255, 93, 108, 0.13);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--blue); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 0.86em; letter-spacing: 0.01em; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 550; font-size: 14px;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #3a4d6b; background: #1d2a3f; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.btn.primary:hover { background: #63baff; }
.btn.good { color: var(--green); border-color: rgba(60,207,142,.4); background: var(--green-soft); }
.btn.bad { color: var(--red); border-color: rgba(255,93,108,.4); background: var(--red-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 550; }
input[type=text], input[type=password], select {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 10px 12px; outline: none;
}
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.msg { border-radius: 8px; padding: 10px 12px; font-size: 14px; margin: 0 0 14px; }
.msg.err { background: var(--red-soft); color: #ffb3ba; border: 1px solid rgba(255,93,108,.35); }
.msg.ok { background: var(--green-soft); color: #9ef0c8; border: 1px solid rgba(60,207,142,.35); }

/* ---------- auth page ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr;
}
.auth-hero {
  padding: 56px 56px 40px; display: flex; flex-direction: column; justify-content: space-between;
  background:
    radial-gradient(circle at 26% 34%, rgba(63,169,255,.13), transparent 45%),
    #0b1220;
  border-right: 1px solid var(--line);
  position: relative; overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 19px; letter-spacing: -0.01em; }
.brand img { width: 34px; height: 34px; border-radius: 8px; }
.hero-emblem { display: block; width: 180px; height: 180px; margin: 0 0 18px -14px; border-radius: 24px; filter: drop-shadow(0 0 28px rgba(63,169,255,.28)); }
.brand b { color: var(--blue); font-weight: 750; }
.hero-copy h1 { font-size: 40px; line-height: 1.1; letter-spacing: -0.025em; margin: 0 0 16px; max-width: 14ch; }
.hero-copy p { color: var(--text-2); max-width: 46ch; margin: 0 0 22px; font-size: 16px; }
.hero-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; max-width: 46ch; }
.hero-points li { display: flex; gap: 10px; color: var(--text-2); font-size: 14px; }
.hero-points li::before { content: ""; flex: 0 0 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 4px var(--blue-soft); }
.hero-rings { position: absolute; right: -120px; bottom: -120px; width: 420px; height: 420px; opacity: .5; pointer-events: none; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 380px; }
.tabs { display: flex; gap: 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin-bottom: 22px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 600; }
.tabs button[aria-selected=true] { background: var(--panel-2); color: var(--text); }
.auth-card h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.auth-card .sub { color: var(--text-2); margin: 0 0 20px; font-size: 14px; }
.auth-card .btn.primary { width: 100%; padding: 11px; margin-top: 4px; }
.fineprint { color: var(--text-3); font-size: 12.5px; margin-top: 18px; }

/* ---------- app shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; padding: 12px 24px;
  background: rgba(10,15,24,.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar .spacer { flex: 1; }
.status-chip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid var(--line-2); }
.status-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-chip.ok { color: var(--green); background: var(--green-soft); border-color: rgba(60,207,142,.3); }
.status-chip.warn { color: var(--amber); background: var(--amber-soft); border-color: rgba(242,182,60,.3); }
.status-chip.bad { color: var(--red); background: var(--red-soft); border-color: rgba(255,93,108,.3); }
.status-chip.idle { color: var(--text-2); }
.who { color: var(--text-2); font-size: 14px; }

.nav { display: flex; gap: 2px; padding: 0 24px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.nav button { border: 0; background: none; padding: 12px 14px; cursor: pointer; color: var(--text-2); font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; white-space: nowrap; }
.nav button:hover { color: var(--text); }
.nav button[aria-selected=true] { color: var(--text); border-bottom-color: var(--blue); }
.nav .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.view h2 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.view-head p { margin: 0; color: var(--text-2); font-size: 14px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel h3 { margin: 0 0 12px; font-size: 15px; letter-spacing: -0.005em; }
.panel h3 .faint { font-weight: 500; }

.grid-overview { display: grid; grid-template-columns: minmax(320px, 1fr) 1.15fr; gap: 18px; }
.stack { display: grid; gap: 18px; align-content: start; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile .k { font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.tile .v { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile.bad .v { color: var(--red); }
.tile.warn .v { color: var(--amber); }
.tile.good .v { color: var(--green); }

/* radar */
.radar { width: 100%; max-width: 440px; display: block; margin: 0 auto; }
.radar .ring { fill: none; stroke: var(--line-2); stroke-width: 1; }
.radar .edge { fill: rgba(63,169,255,.05); stroke: var(--blue); stroke-width: 1.5; stroke-dasharray: 5 5; }
.radar .core { fill: var(--blue); }
.radar .lbl { fill: var(--text-3); font-size: 11px; font-family: var(--sans); }
.radar .dev { stroke: var(--bg); stroke-width: 2; }
.radar .dev.trusted { fill: var(--green); }
.radar .dev.unknown { fill: var(--amber); }
.radar .dev.blocked { fill: var(--red); }
.legend { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-top: 10px; font-size: 12.5px; color: var(--text-2); }
.legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.legend .t::before { background: var(--green); }
.legend .u::before { background: var(--amber); }
.legend .b::before { background: var(--red); }

/* lists */
.list { display: grid; gap: 0; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; padding-top: 2px; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .meta { color: var(--text-3); font-size: 12.5px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.row .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.empty { color: var(--text-3); font-size: 14px; padding: 18px 0 8px; text-align: center; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; border: 1px solid transparent; }
.pill.trusted { color: var(--green); background: var(--green-soft); }
.pill.unknown { color: var(--amber); background: var(--amber-soft); }
.pill.blocked { color: var(--red); background: var(--red-soft); }
.pill.live { color: var(--blue); background: var(--blue-soft); }
.pill.neutral { color: var(--text-2); background: var(--panel-2); }

.bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; vertical-align: -1px; }
.bars i { width: 3px; background: var(--line-2); border-radius: 1px; }
.bars i:nth-child(1) { height: 4px; } .bars i:nth-child(2) { height: 7px; } .bars i:nth-child(3) { height: 10px; } .bars i:nth-child(4) { height: 12px; }
.bars i.on { background: var(--blue); }

/* devices table */
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-2); background: transparent; color: var(--text-2); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 13px; font-weight: 600; }
.chip[aria-pressed=true] { background: var(--panel-2); color: var(--text); border-color: #3a4d6b; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--text-3); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; padding: 0 10px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 14px; }
.table tr:last-child td { border-bottom: 0; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions .btn + .btn { margin-left: 4px; }
.dev-name { font-weight: 600; overflow-wrap: anywhere; }
.dev-sub { color: var(--text-3); font-size: 12.5px; }
.rename { display: flex; gap: 6px; }
.rename input { padding: 6px 9px; }

/* alerts */
.alert { display: grid; grid-template-columns: 4px 1fr auto; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line); }
.alert:first-child { border-top: 0; }
.alert .bar { border-radius: 2px; background: var(--line-2); }
.alert.high .bar { background: var(--red); }
.alert.medium .bar { background: var(--amber); }
.alert.low .bar { background: var(--blue); }
.alert .t { font-weight: 600; }
.alert .d { color: var(--text-2); font-size: 14px; overflow-wrap: anywhere; }
.alert .when { color: var(--text-3); font-size: 12.5px; white-space: nowrap; }
.alert.unread .t::after { content: "New"; margin-left: 8px; font-size: 11px; font-weight: 700; color: var(--blue); background: var(--blue-soft); padding: 1px 6px; border-radius: 6px; vertical-align: 1px; }
.alert .acts { grid-column: 2 / 4; display: flex; gap: 6px; flex-wrap: wrap; }

/* sensors */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.sensor .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.sensor dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 14px; font-size: 13.5px; }
.sensor dt { color: var(--text-3); }
.sensor dd { margin: 0; color: var(--text-2); overflow-wrap: anywhere; }
.online { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 650; }
.online::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.online.on { color: var(--green); } .online.on::before { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.online.off { color: var(--text-3); }
.token-box { background: var(--bg-2); border: 1px dashed var(--blue); border-radius: var(--radius); padding: 16px; margin-bottom: 18px; }
.token-box h3 { color: var(--blue); }
pre.code { background: #070b12; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; margin: 8px 0 12px; white-space: pre; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form label.field { margin: 0; flex: 1 1 200px; }

/* settings */
.settings { display: grid; gap: 14px; max-width: 760px; }
.setting { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; }
.setting .n { font-weight: 600; }
.setting .h { color: var(--text-2); font-size: 13.5px; }
.slider-row { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
input[type=range] { flex: 1; accent-color: var(--blue); }
.readout { min-width: 190px; font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 13.5px; }
.readout b { color: var(--text); }
.switch { position: relative; width: 44px; height: 26px; flex: 0 0 auto; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 13px; background: var(--line-2); transition: background .15s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--blue); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }
.danger-zone { border-color: rgba(255,93,108,.35); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.4); }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .grid-overview { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { padding: 28px 20px; border-right: 0; border-bottom: 1px solid var(--line); }
  .hero-copy h1 { font-size: 28px; margin-top: 4px; }
  .hero-emblem { width: 120px; height: 120px; margin: 18px 0 12px -8px; }
  .hero-points { display: none; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .who { display: none; }
  .nav { padding: 0 8px; }
  main { padding: 16px; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--line); padding: 10px 0; }
  .table td { border: 0; padding: 3px 0; }
  .table td.actions { text-align: left; padding-top: 8px; white-space: normal; }
  .setting { grid-template-columns: 1fr; }
  .readout { min-width: 0; }
}
@media (max-width: 420px) {
  .status-chip .txt { display: none; }
}

.mt { margin-top: 18px; }
.mb { margin-bottom: 18px; }
.m0 { margin: 0 !important; }
.strong { font-weight: 600; }

.grid-overview > .panel { align-self: start; }
@media (max-width: 560px) {
  .row { grid-template-columns: 1fr; gap: 8px; }
  .row .actions { justify-content: flex-start; }
}

.no-trust { display: inline-flex; align-items: center; padding: 0 4px; white-space: nowrap; }
.tip { margin: 12px 0 0; }
