:root {
  --bg: #0b0f14;
  --bg-2: #10161d;
  --card: #131b23;
  --card-2: #18222c;
  --line: #233140;
  --line-2: #2d3e50;
  --text: #e6edf3;
  --muted: #8b9bab;
  --accent: #10b981;
  --accent-2: #34d399;
  --accent-ink: #04261a;
  --bad: #f05252;
  --bad-bg: rgba(240, 82, 82, .12);
  --warn: #f5a524;
  --warn-bg: rgba(245, 165, 36, .12);
  --ok-bg: rgba(16, 185, 129, .12);
  --mute-bg: rgba(139, 155, 171, .12);
  --radius: 12px;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -200px, rgba(16,185,129,.08), transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { font-family: var(--mono); font-size: 12px; background: var(--card-2); padding: 1px 5px; border-radius: 5px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; font-size: 16px; }
.brand-lg { font-size: 22px; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); position: relative; flex: none;
  box-shadow: 0 0 0 4px rgba(16,185,129,.15);
}
.logo::after {
  content: ""; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 20h7l4-8h7' stroke='%23052e1f' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat;
}

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line-2); background: var(--card-2); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 500; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s; white-space: nowrap;
}
.btn:hover { background: #1e2a36; border-color: #3a4f64; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--card-2); color: var(--text); border-color: var(--line); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--card-2); color: var(--text); border-color: var(--line); }
.icon-btn.danger:hover { color: var(--bad); border-color: rgba(240,82,82,.35); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; display: grid; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-card p { margin: -6px 0 6px; }

/* ---------- forms ---------- */
label, .lbl { display: grid; gap: 6px; font-size: 13px; color: #c3cfda; font-weight: 500; }
.lbl { display: block; margin-bottom: 6px; }
input, select {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line-2); color: var(--text);
  border-radius: 9px; padding: 9px 11px; font: inherit; font-weight: 400; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(16,185,129,.18); }
input::placeholder { color: #5b6b7b; }
input[type=number] { font-family: var(--mono); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; line-height: 1.4; }
.row { display: flex; gap: 14px; }
.row > * { min-width: 0; }
.grow { flex: 1; }
.w-port { width: 130px; flex: none; }
.row-inline { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.form-err { background: var(--bad-bg); color: #ffb4b4; border: 1px solid rgba(240,82,82,.3); padding: 9px 12px; border-radius: 9px; font-size: 13px; }

.seg { display: flex; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--muted); padding: 6px 8px; border-radius: 7px;
  font: inherit; font-weight: 600; font-size: 13px; cursor: pointer;
}
.seg button.on { background: var(--card-2); color: var(--text); box-shadow: 0 0 0 1px var(--line-2); }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; background: rgba(11,15,20,.82); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-meta { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.top-actions { display: flex; gap: 4px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--line-2); background: var(--card);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--accent-2); border-color: rgba(16,185,129,.35); background: var(--ok-bg); }
.pill.bad { color: var(--bad); border-color: rgba(240,82,82,.35); background: var(--bad-bg); }
.pill-ghost { color: var(--muted); font-weight: 500; }
.pill-ghost::before { display: none; }

/* ---------- layout ---------- */
.wrap { max-width: 1240px; margin: 0 auto; padding: 24px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
  position: relative; overflow: hidden;
}
.stat .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; margin-top: 4px; }
.stat .k { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }
.stat .k::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; background: var(--line-2); }
.stat.ok .k::before { background: var(--accent); }
.stat.bad .k::before { background: var(--bad); }
.stat.bad { border-color: rgba(240,82,82,.35); }
.stat.bad .v { color: var(--bad); }

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.search { flex: 1; min-width: 220px; max-width: 420px; }
.toolbar-right { display: flex; gap: 10px; align-items: center; margin-left: auto; flex-wrap: wrap; }

/* ---------- rules ---------- */
.rules { display: grid; gap: 10px; }
.rule {
  display: grid; grid-template-columns: minmax(180px, 1.3fr) minmax(150px, 1fr) 24px minmax(230px, 1.3fr) 120px 150px auto;
  gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; transition: border-color .15s, background .15s;
}
.rule:hover { border-color: var(--line-2); background: #151e27; }
.rule.off { opacity: .55; }
.r-name { display: flex; gap: 12px; align-items: center; min-width: 0; }
.r-name b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.r-name .muted { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.ok { background: var(--accent); box-shadow: 0 0 0 4px rgba(16,185,129,.15); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 4px rgba(240,82,82,.15); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 4px rgba(245,165,36,.15); }
.cap { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; margin-bottom: 2px; }
.r-node .mono { font-size: 13px; color: #c3cfda; overflow-wrap: anywhere; }
.arrow { color: var(--line-2); font-size: 18px; text-align: center; }
.bridge {
  display: flex; align-items: center; gap: 4px; background: var(--bg-2); border: 1px dashed rgba(16,185,129,.45);
  border-radius: 9px; padding: 5px 5px 5px 11px; min-width: 0;
}
.bridge .mono { flex: 1; font-size: 14px; font-weight: 600; color: var(--accent-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tags { display: flex; gap: 5px; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--card-2); border: 1px solid var(--line-2); color: #c3cfda; letter-spacing: .3px; }
.tag.pp { color: #a5b4fc; border-color: rgba(165,180,252,.35); }
.status-btn {
  display: grid; gap: 5px; background: transparent; border: 0; color: inherit; text-align: left; padding: 0; cursor: pointer; font: inherit;
}
.chip { display: inline-flex; align-items: center; font-size: 12px; font-weight: 650; padding: 2px 9px; border-radius: 999px; width: max-content; }
.chip.ok { background: var(--ok-bg); color: var(--accent-2); }
.chip.bad { background: var(--bad-bg); color: #ff8a8a; }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.muted { background: var(--mute-bg); color: var(--muted); }
.spark { display: flex; gap: 2px; height: 14px; align-items: flex-end; }
.spark i { width: 4px; border-radius: 2px; background: var(--line-2); height: 100%; }
.spark i.ok { background: var(--accent); height: 60%; }
.spark i.bad { background: var(--bad); }
.spark i.warn { background: var(--warn); height: 80%; }
.ago { font-size: 11px; color: var(--muted); }
.r-actions { display: flex; gap: 2px; justify-content: flex-end; }

.empty {
  text-align: center; padding: 60px 20px; background: var(--card); border: 1px dashed var(--line-2); border-radius: 16px;
}
.empty h3 { margin: 0 0 6px; font-size: 18px; }
.empty p { margin: 0 auto 18px; max-width: 460px; }

/* ---------- dialogs ---------- */
.dlg {
  width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--line-2);
  border-radius: 16px; background: var(--card); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.55);
}
.dlg-sm { width: min(480px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(3,6,10,.7); backdrop-filter: blur(3px); }
.dlg[open] { animation: pop .16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 0; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.dlg-body { padding: 18px 22px; display: grid; gap: 14px; }
.dlg-body h3 { margin: 6px 0 -4px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.dlg-foot { display: flex; gap: 8px; align-items: center; padding: 14px 22px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.spacer { flex: 1; }
.x { background: transparent; border: 0; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.x:hover { background: var(--card-2); color: var(--text); }

.flow { display: flex; align-items: center; gap: 8px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.flow-node { flex: 1; display: grid; gap: 2px; text-align: center; padding: 6px; border-radius: 9px; min-width: 0; }
.flow-node .mono { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow-cap { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.flow-accent { background: var(--ok-bg); }
.flow-accent .mono { color: var(--accent-2); }
.flow-arrow { width: 28px; height: 2px; background: linear-gradient(90deg, var(--line-2), var(--accent)); position: relative; flex: none; }
.flow-arrow::after { content: ""; position: absolute; right: -2px; top: -4px; border: 5px solid transparent; border-left-color: var(--accent); }

.check-box { border: 1px solid var(--line-2); background: var(--bg-2); border-radius: 12px; padding: 14px; display: grid; gap: 10px; }
.check-box.ok { border-color: rgba(16,185,129,.4); }
.check-box.bad { border-color: rgba(240,82,82,.4); }
.check-box.warn { border-color: rgba(245,165,36,.4); }
.check-head { display: flex; gap: 10px; align-items: center; }
.check-sum { margin: 0; color: #c3cfda; }
.kv { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.kv div { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.kv span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.kv b { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.loading { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.loader { width: 16px; height: 16px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }

.hist { display: grid; gap: 6px; max-height: 340px; overflow: auto; }
.hist-row { display: grid; grid-template-columns: 130px 120px 1fr; gap: 10px; align-items: start; padding: 8px 10px; background: var(--bg-2); border-radius: 8px; font-size: 13px; }
.hist-row .ago { font-size: 12px; }

.code { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 12px/1.5 var(--mono); max-height: 300px; overflow: auto; margin: 0; white-space: pre; }

/* ---------- нагрузка на мост ---------- */
.sysbar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 18px; }
.sys {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
  display: grid; gap: 3px; min-width: 0;
}
.sys .k { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.sys b { font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sys .sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { display: block; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 3px; }
.meter > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .4s; }
.meter > i.warn { background: var(--warn); }
.meter > i.bad { background: var(--bad); }
.tag.conn { color: #7dd3fc; border-color: rgba(125,211,252,.35); }
.h-chips { display: flex; gap: 5px; flex-wrap: wrap; }
.h-adv { grid-column: 2 / -1; font-size: 12px; border-radius: 8px; padding: 6px 10px; }
.h-adv.bad { color: #ffb4b4; background: var(--bad-bg); }
.h-adv.ok { color: var(--accent-2); background: var(--ok-bg); }
.kv2 { grid-template-columns: 1fr 1fr; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tab {
  appearance: none; background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  font: inherit; font-weight: 600; padding: 10px 14px; margin-bottom: -1px; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.seg-inline { width: auto; }
.seg-inline button { flex: none; padding: 6px 12px; }

/* ---------- hosts ---------- */
.host {
  display: grid; grid-template-columns: 22px minmax(170px, 1.2fr) minmax(150px, 1fr) 24px minmax(210px, 1.2fr) 190px auto;
  gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; transition: border-color .15s, background .15s;
}
.host:hover { border-color: var(--line-2); background: #151e27; }
.host.off { opacity: .6; }
.host .pick { display: flex; }
.host .pick input:disabled { opacity: .25; }
.h-status { display: flex; gap: 6px; flex-wrap: wrap; }
.h-warn { grid-column: 2 / -1; font-size: 12px; color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 6px 10px; }
.note-warn { font-size: 13px; color: var(--warn); background: var(--warn-bg); border: 1px solid rgba(245,165,36,.3); border-radius: 9px; padding: 9px 12px; }
.r-actions .btn-sm { display: inline-flex; align-items: center; gap: 6px; }
.r-actions .btn-sm svg { width: 14px; height: 14px; }
.tag.rw { color: var(--accent-2); border-color: rgba(16,185,129,.35); }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; }
.toast {
  background: var(--card-2); border: 1px solid rgba(16,185,129,.4); padding: 10px 14px;
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 380px; animation: pop .16s ease-out;
}
.toast.err { border-color: rgba(240,82,82,.45); background: #2a1719; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .sysbar { grid-template-columns: repeat(3, 1fr); }
  .rule { grid-template-columns: 1fr 1fr; }
  .arrow { display: none; }
  .r-name { grid-column: 1 / -1; }
  .r-actions { justify-content: flex-start; }
  .host { grid-template-columns: 22px 1fr 1fr; row-gap: 10px; }
  .host .arrow { display: none; }
  .host .r-name { grid-column: 2 / -1; }
  .host .r-node { grid-column: 2; }
  .host .h-addr { grid-column: 3; min-width: 0; }
  .host .h-status { grid-column: 2; }
  .host .r-actions { grid-column: 3; justify-content: flex-end; }
}
@media (max-width: 760px) {
  .wrap { padding: 16px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; gap: 8px; }
  .top-meta { order: 3; flex-basis: 100%; }
  .top-actions { margin-left: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .sysbar { grid-template-columns: repeat(2, 1fr); }
  .rule { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; }
  .host { grid-template-columns: 22px 1fr; }
  .host .r-node, .host .h-addr, .host .h-status, .host .r-actions { grid-column: 2; }
  .host .r-actions { justify-content: flex-start; }
  .row { flex-direction: column; }
  .w-port { width: 100%; }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .hist-row { grid-template-columns: 1fr; gap: 2px; }
  .toolbar-right { margin-left: 0; width: 100%; }
  .toolbar-right .btn-primary { flex: 1; }
  .flow { flex-direction: column; }
  .flow-arrow { width: 2px; height: 16px; background: var(--line-2); }
  .flow-arrow::after { display: none; }
  .flow-node { width: 100%; }
}
