:root {
  --bg: #15191f;
  --panel: #1d222a;
  --panel2: #252b35;
  --line: #2c333f;
  --text: #d9dee6;
  --muted: #8a93a3;
  --faint: #5d6575;
  --ok: #3dbe8b;
  --warn: #e3a63a;
  --crit: #e5534b;
  --maint: #7d8696;
  --in: #74a9f7;
  --out: #b79af0;
  --focus: #74a9f7;
  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--text); text-decoration: none; }
a:hover { color: #fff; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* каркас */
header.top {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 52px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; background: var(--bg);
}
.brand { font-weight: 650; letter-spacing: .02em; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand i { width: 10px; height: 10px; border-radius: 2px; background: var(--ok); display: inline-block; box-shadow: 14px 0 0 var(--warn), 28px 0 0 var(--panel2); margin-right: 28px; }
nav { display: flex; gap: 4px; }
nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); }
nav a.on { color: var(--text); background: var(--panel); }
nav .cnt { background: var(--crit); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11.5px; margin-left: 5px; }
header .sp { flex: 1; }
main { padding: 24px; max-width: 1480px; margin: 0 auto; }
h1 { font-size: 20px; font-weight: 600; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 32px 0 12px; display: flex; align-items: baseline; gap: 10px; }
h2 .muted { font-weight: 400; font-size: 13px; }

button {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
button:hover { border-color: var(--faint); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: #2c4a78; border-color: #3a5f96; }
button.danger { color: #ffb3ae; }
button.ghost { background: none; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); }
button.sm { padding: 3px 9px; font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 10px; width: 100%;
}
input:focus { border-color: var(--focus); outline: none; }
input[type=checkbox] { width: auto; }
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 4px; }
label.f small { display: block; color: var(--faint); font-size: 12px; margin-top: 4px; }
label.chk { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }

/* статусы */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: var(--c, var(--maint)); }
.s-ok { --c: var(--ok); } .s-crit { --c: var(--crit); } .s-warn { --c: var(--warn); } .s-maint { --c: var(--maint); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap;
  background: color-mix(in srgb, var(--c, var(--maint)) 18%, transparent);
  color: color-mix(in srgb, var(--c, var(--maint)) 75%, white);
}
.v-warn { color: var(--warn); } .v-crit { color: var(--crit); } .v-ok { color: var(--ok); }

/* обзор */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar .sp { flex: 1; }
.nodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(380px, 100%), 1fr)); gap: 16px; }
.node { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: block; }
.node:hover { border-color: var(--faint); color: var(--text); }
.node.offline { opacity: .65; }
.node.has-crit { border-color: color-mix(in srgb, var(--crit) 55%, var(--line)); }
.node .hd { display: flex; align-items: center; gap: 8px; }
.node .hd b { font-size: 15px; font-weight: 600; }
.node .hd .sp { flex: 1; }
.node .sub { color: var(--muted); font-size: 12.5px; margin: 2px 0 12px 16px; }
.patch { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.patch .be {
  display: flex; align-items: center; gap: 3px; height: 22px; padding: 0 7px 0 6px; font-size: 12px; color: var(--muted);
  border-radius: 4px; background: var(--bg); border: 1px solid var(--line); border-left: 3px solid var(--c, var(--maint)); max-width: 100%;
}
.patch .be span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 3px; }
.patch .be .dot { width: 6px; height: 6px; }
.kv { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 12px; }
.kv div { min-width: 0; }
.kv small { display: block; color: var(--faint); font-size: 11.5px; text-transform: lowercase; }
.kv b { font-weight: 500; font-size: 13.5px; white-space: nowrap; }
.spark { margin-top: 12px; height: 46px; }
.node .al { margin-top: 10px; font-size: 12.5px; }
.node .al div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; }

/* страница ноды */
.nhead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.nhead .sp { flex: 1; }
.nsub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: none; color: var(--muted); padding: 5px 11px; }
.seg button.on { background: var(--panel2); color: var(--text); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.tile small { color: var(--muted); font-size: 12px; display: block; }
.tile b { font-size: 18px; font-weight: 500; display: block; margin-top: 2px; white-space: nowrap; }
.tile i { font-style: normal; color: var(--faint); font-size: 12px; }
.bar { height: 4px; background: var(--panel2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--c, var(--ok)); }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 12px; margin-top: 12px; }
.chart { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 10px 4px; min-width: 0; }
.chart h3 { font-size: 12.5px; font-weight: 500; color: var(--muted); margin: 0 0 4px 4px; }
.chart .plot { min-height: 150px; }
.mini .plot { min-height: 110px; }

.banner { border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; border: 1px solid color-mix(in srgb, var(--c) 45%, var(--line)); background: color-mix(in srgb, var(--c) 9%, var(--panel)); }
.banner b { display: block; margin-bottom: 2px; }
.banner pre { margin: 6px 0 0; white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; color: var(--text); }
.alist { display: grid; gap: 6px; margin-bottom: 8px; }
.alist .a { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start; padding: 9px 12px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--c); }
.alist .a pre { margin: 2px 0 0; white-space: pre-wrap; font: 12.5px/1.4 var(--mono); color: var(--muted); }

.bes { display: grid; gap: 14px; }
.becard { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--c, var(--maint)); border-radius: 10px; padding: 14px 16px; }
.becard .bh { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.becard .bh b { font-size: 15px; font-weight: 600; }
.becard .bh .st { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.becard .bh .st em { font-style: normal; color: var(--text); }
.becard .charts { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 10px; }
.becard .chart { background: var(--bg); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--faint); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 6px 8px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
.tbl { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 8px; overflow-x: auto; }
.becard table td { border-bottom-color: color-mix(in srgb, var(--line) 50%, transparent); }
.meter { display: inline-block; width: 70px; height: 5px; background: var(--panel2); border-radius: 3px; vertical-align: middle; margin-left: 8px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--c, var(--ok)); }
.err { color: var(--muted); font-size: 12px; max-width: 340px; }
.info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 13px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* вход */
.login { max-width: 340px; margin: 14vh auto 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login h1 { margin-bottom: 18px; display: flex; gap: 10px; align-items: center; }
.login .msg { color: var(--crit); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* настройки */
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(380px, 100%), 1fr)); gap: 16px; align-items: start; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.box h3 { margin: 0 0 14px; font-size: 14px; font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* модальное окно */
#modal .bg { position: fixed; inset: 0; background: rgba(5, 8, 12, .7); z-index: 50; display: grid; place-items: center; padding: 20px; }
#modal .dlg { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(760px, 100%); max-height: 90vh; overflow: auto; }
#modal h3 { margin: 0 0 14px; font-size: 16px; }
.code { position: relative; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px 70px 12px 12px; font: 12.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; margin: 6px 0 14px; }
.code button { position: absolute; top: 8px; right: 8px; }
.note { color: var(--muted); font-size: 13px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; }
#toast div { background: var(--panel2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; margin-top: 6px; }
#toast div.e { border-color: var(--crit); }

/* uPlot в тёмной теме */
.uplot { font-family: inherit; }
.u-legend { font-size: 11.5px; color: var(--muted); text-align: left; padding: 0 4px; }
.u-legend .u-marker { width: 9px; height: 3px; border: 0 !important; }
.u-legend th { font-weight: 400; color: var(--muted); padding: 0 2px; border: 0; font-size: 11.5px; }
.u-legend td { padding: 0 6px 0 0; border: 0; font-size: 11.5px; color: var(--text); }
.u-legend .u-series:first-child td { color: var(--faint); }
.u-legend .u-series { padding: 0 8px 0 0; }
.u-select { background: rgba(116, 169, 247, .12); }
.u-cursor-x, .u-cursor-y { border-color: var(--faint) !important; }

@media (max-width: 900px) {
  main { padding: 16px; }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .cols { grid-template-columns: 1fr; }
  .becard .charts { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
  .nodes { grid-template-columns: 1fr; }
  header.top { padding: 0 12px; gap: 10px; }
  .brand span { display: none; }
}

/* элементы сеток не растягиваются по содержимому — таблицы прокручиваются внутри */
.bes > *, .cols > *, .charts > *, .nodes > *, .settings > * { min-width: 0; }
@media (max-width: 600px) {
  header.top nav a { padding: 6px 7px; }
  header.top #logout { padding: 6px 4px; }
  .nhead h1 { font-size: 18px; }
}
