:root {
  --bg: #0b0e11; --surface: #13171b; --border: #282e33; --text: #edf1f3; --muted: #98a4ad;
  --green: #43d18d; --yellow: #efc66d; --red: #ff6681; --blue: #70b8ef;
  --mono: "Fira Mono", ui-monospace, Consolas, monospace;
  --sans: Montserrat, system-ui, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 var(--sans); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 24px; display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.login-card label.check { display: flex; align-items: center; gap: 8px; }
input:not([type=checkbox]) { background: var(--bg); border: 1px solid var(--border); border-radius: 5px; color: var(--text); padding: 9px 10px; font: inherit; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.login-card button { background: var(--blue); color: #06121b; border: 0; border-radius: 5px; padding: 10px; font-weight: 600; }
.error { color: var(--red); min-height: 1.2em; margin: 0; font-size: 12px; }

.layout { display: grid; grid-template-columns: minmax(380px, 440px) 1fr; height: 100vh; }
.side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--bg); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.side-head h1 { font-size: 16px; }
.actions { display: flex; gap: 4px; }
.icon { background: transparent; border: 1px solid transparent; border-radius: 5px; width: 30px; height: 30px; color: var(--muted); }
.icon:hover { border-color: var(--border); color: var(--text); }
.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 16px; }
.counter { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.counter .num { font-size: 20px; color: var(--text); }
.counter.ok .num { color: var(--green); }
.counter.bad .num { color: var(--red); }
#source-line { padding: 8px 16px 4px; margin: 0; }

.nodes { list-style: none; margin: 0; padding: 4px 8px 16px; overflow-y: auto; flex: 1; min-height: 0; }
.node { display: grid; grid-template-columns: 24px 1fr auto auto auto; align-items: center; gap: 8px; min-height: 36px; padding: 4px 8px; border-radius: 5px; border-bottom: 1px solid var(--border); }
.node:hover { background: var(--surface); }
.node .flag { font-size: 16px; text-align: center; }
.node .name { background: none; border: 0; padding: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .name:hover { text-decoration: underline; }
.badge { font-size: 11px; color: var(--blue); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; margin-left: 6px; }
.node .users { color: var(--muted); font-size: 12px; min-width: 3ch; text-align: right; }
.node .st { font-size: 12px; min-width: 7ch; text-align: right; }
.node.online .st { color: var(--green); }
.node.offline .st, .node.unknown .st { color: var(--red); }
.node.connecting .st, .node.disabled .st { color: var(--yellow); }
.node.blocked .st { color: var(--red); }
.node.warn .st { color: var(--yellow); }
.scan { display: inline-flex; align-items: center; gap: 4px; font-family: var(--mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.scan svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.scan.ok { color: var(--green); }
.scan.warn { color: var(--yellow); }
.scan.block { color: var(--red); }
.scan.stale { opacity: .55; }
.scan[hidden] { display: none; }
.strip { display: grid; grid-template-columns: repeat(48, 1fr); gap: 1px; margin: 8px 0 4px; }
.strip i { height: 16px; background: var(--border); border-radius: 1px; }
.strip i.ok { background: var(--green); }
.strip i.warn { background: var(--yellow); }
.strip i.block { background: var(--red); }
.scanners { margin: 8px 0 0; padding: 0; list-style: none; max-height: 180px; overflow-y: auto; font-size: 12px; border-top: 1px solid var(--border); }
.scanners li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--border); }
.scanners .v-ok { color: var(--green); }
.scanners .v-bad { color: var(--red); }
.scanners .v-unk { color: var(--muted); }
#nd-result.ok { color: var(--green); }
#nd-result.err { color: var(--red); }
.node .detail { grid-column: 2 / -1; font-size: 12px; color: var(--muted); display: none; }
body.full .node { min-height: 56px; }
body.full .node .detail { display: block; }

.main { padding: 20px 24px; overflow-y: auto; display: grid; align-content: start; gap: 14px; }
.main-head { display: flex; align-items: center; justify-content: space-between; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { background: var(--surface); border: 0; padding: 6px 12px; font-size: 12px; color: var(--muted); }
.seg button[aria-pressed=true] { background: var(--border); color: var(--text); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.panel.warn { border-color: var(--yellow); color: var(--yellow); }
.big { font-size: 32px; }

.infra { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.infra-item { border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; background: var(--bg); }
.infra-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; }
.infra-head .name { background: none; border: 0; padding: 0; text-align: left; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.infra-head .name:hover { text-decoration: underline; }
.chip { font-size: 11px; white-space: nowrap; color: var(--muted); }
.infra-item.ok .chip { color: var(--green); }
.infra-item.warn .chip { color: var(--yellow); }
.infra-item.bad .chip { color: var(--red); }
.infra-item.bad { border-color: var(--red); }
.infra-full { display: grid; gap: 6px; padding-top: 6px; }
.infra-full[hidden] { display: none; }
.infra-full .bars { grid-template-columns: repeat(3, 1fr); }
.clients { font-size: 12px; color: var(--muted); }
.clients[hidden] { display: none; }
.panel-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.panel-head h3 { margin: 0; }
.panel-head .link { margin-left: auto; }
.map-panel { display: none; }
body.full .map-panel { display: block; }
.map-panel.collapsed #map-body { display: none; }
.map-host { width: 100%; min-height: 240px; }
.map-svg { width: 100%; height: auto; display: block; }
.map-svg .grid line { stroke: var(--border); stroke-width: 1; opacity: .45; }
.map-svg .route { fill: none; stroke: var(--blue); stroke-width: 1.2; opacity: .45; transition: opacity .15s, stroke-width .15s; }
.map-svg .particle { fill: var(--blue); opacity: .9; transition: opacity .15s; }
.map-svg.has-hot .route:not(.hot), .map-svg.has-hot .particle:not(.hot) { opacity: .1; }
.map-svg.has-hot .pt:not(.hot) { opacity: .55; }
.map-svg .route.hot { opacity: 1; stroke-width: 2; }
.map-svg .pt { cursor: pointer; outline: none; transition: opacity .15s; }
.map-svg .pt .dot { fill: var(--green); }
.map-svg .pt .halo { fill: var(--green); opacity: .16; }
.map-svg .pt.warn .dot, .map-svg .pt.warn .halo { fill: var(--yellow); }
.map-svg .pt.bad .dot, .map-svg .pt.bad .halo { fill: var(--red); }
.map-svg .pt:focus-visible .halo { opacity: .45; }
.map-svg .lbl-bg { fill: var(--bg); stroke: var(--border); opacity: .94; }
.map-svg .lbl { fill: var(--text); font: 600 11px var(--mono); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 8px; font-size: 12px; }
.legend[hidden] { display: none; }
.legend-group { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.legend-title { color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.legend-item.warn .dot { background: var(--yellow); }
.legend-item.bad .dot { background: var(--red); }
.legend-item.none .dot { background: var(--muted); }
.node.related { background: var(--surface); }
.cnode { display: inline-flex; gap: 12px; align-items: baseline; }
.st-ok { color: var(--green); } .st-warn { color: var(--yellow); } .st-bad { color: var(--red); }
.num.tick { animation: tick .35s ease-out; }
@keyframes tick { from { opacity: .35; } to { opacity: 1; } }
.node.flash.f-g { animation: flash-g .9s ease-out; }
.node.flash.f-y { animation: flash-y .9s ease-out; }
.node.flash.f-r { animation: flash-r .9s ease-out; }
@keyframes flash-g { from { background: rgba(67, 209, 141, .25); } to { background: transparent; } }
@keyframes flash-y { from { background: rgba(239, 198, 109, .25); } to { background: transparent; } }
@keyframes flash-r { from { background: rgba(255, 102, 129, .28); } to { background: transparent; } }

.extra { grid-column: 2 / -1; display: grid; gap: 6px; padding: 4px 0 6px; }
.bars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.bar { display: grid; grid-template-columns: 1fr auto; gap: 0 6px; font-size: 11px; color: var(--muted); }
.bar .bv { color: var(--text); }
.track { grid-column: 1 / -1; display: block; height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; margin-top: 3px; }
.track i { display: block; height: 100%; width: 0; background: var(--blue); transition: width .35s ease; }
.bar[data-level="warn"] .track i { background: var(--yellow); }
.bar[data-level="crit"] .track i { background: var(--red); }
.netline { font-family: var(--mono); font-size: 11px; }
.cats { display: grid; gap: 3px; }
.cat { display: grid; grid-template-columns: 84px auto 1fr; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); }
.cat[hidden] { display: none; }
.cat .track { margin: 0; grid-column: auto; }
.cat.ok .track i { background: var(--green); }
.cat.sig .track i { background: var(--red); }
.cat.unk .track i { background: var(--yellow); }
.cat.none .track i { background: var(--muted); }
.strip.mini { margin: 2px 0 0; }
.strip.mini i { height: 10px; }

.feed li { transition: transform .12s ease, background .12s ease; }
.feed li:not(.day):hover { transform: scale(1.008); }
ul.plain { list-style: none; margin: 0 0 10px; padding: 0; font-size: 13px; }
ul.plain li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
ul.plain .sub { display: block; color: var(--muted); font-size: 12px; }
ul.plain .v-ok { color: var(--green); } ul.plain .v-bad { color: var(--red); }
.acts { display: flex; align-items: center; gap: 8px; }
button.link { background: none; border: 0; color: var(--blue); padding: 2px 4px; font-size: 12px; text-decoration: underline; }
button.link.danger { color: var(--red); }
input.days { width: 64px; padding: 4px 6px !important; }
.userform { display: grid; gap: 8px; }
select { background: var(--bg); border: 1px solid var(--border); border-radius: 5px; color: var(--text); padding: 9px 10px; font: inherit; }
dialog.wide { width: min(640px, calc(100vw - 32px)); }
#settings-tabs { margin: 0 0 12px; }
#settings-body h3 { font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.panel h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.feed li { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: baseline; padding: 6px 8px; border-radius: 5px; font-size: 13px; }
.feed li:hover { background: rgba(255, 255, 255, .03); }
.feed .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); align-self: center; }
.feed .red .dot { background: var(--red); }
.feed .green .dot { background: var(--green); }
.feed .yellow .dot { background: var(--yellow); }
.feed .blue .dot { background: var(--blue); }
.feed .when { color: var(--muted); font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.feed .sub { display: block; color: var(--muted); font-size: 12px; }
.feed li.day { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 10px 8px 2px; }
.feed li.day:hover { background: none; }
.feed li.fresh { animation: fresh 2s ease-out; }
@keyframes fresh { from { background: rgba(112, 184, 239, .22); } to { background: transparent; } }
button.primary { background: var(--blue); color: #06121b; border: 0; border-radius: 5px; padding: 8px 12px; font-weight: 600; margin-top: 8px; }
button.primary:disabled { opacity: .5; cursor: default; }
#tg-result.ok { color: var(--green); }
#tg-result.err { color: var(--red); }

dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 18px 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog .close { position: absolute; top: 8px; right: 8px; }
dl { margin: 12px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
dt { color: var(--muted); }
dd { margin: 0; font-family: var(--mono); word-break: break-all; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .side { border-right: 0; border-bottom: 1px solid var(--border); }
  .nodes { max-height: none; overflow: visible; }
  .main { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
