:root {
  --bg: #08080A;
  --panel: #0C0C0F;
  --card: #101014;
  --raise: #16161B;
  --line: #1F1F25;
  --line-2: #17171C;
  --edge: #232329;
  --ink: #F2F0ED;
  --ink-2: #B4AEA6;
  --ink-3: #948E86;
  --ink-4: #7A746C;
  --accent: #E8443A;
  --brand: #BC0000;
  --ok: #35C46F;
  --warn: #E0A32E;
  --err: #E8443A;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Archivo, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--ink); text-decoration: none; }
a:hover { color: var(--accent); }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
}

.mono { font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--raise);
  border: 1px solid var(--edge);
  border-radius: 7px;
  padding: 5px 11px;
}

.dot { width: 7px; height: 7px; border-radius: 999px; flex-shrink: 0; }
.dot.ok   { background: var(--ok);   box-shadow: 0 0 0 3px rgba(53,196,111,.16); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(224,163,46,.16); }
.dot.err  { background: var(--err);  box-shadow: 0 0 0 3px rgba(232,68,58,.16); }
.dot.off  { background: var(--ink-4); box-shadow: 0 0 0 3px rgba(122,116,108,.14); }

.muted  { color: var(--ink-3); }
.dim    { color: var(--ink-4); }
.c-ok   { color: var(--ok); }
.c-warn { color: var(--warn); }
.c-err  { color: var(--err); }
.c-off  { color: var(--ink-4); }

.grow { flex-grow: 1; }
.row { display: flex; align-items: center; gap: 12px; }

/* ── вход ─────────────────────────────────────────────── */

#login {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
body.state-login #login { display: flex; }
body.state-login #app { display: none; }

#login form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 30px 28px;
}

#login svg { width: 116px; height: auto; display: block; }

#login input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: var(--raise);
  color: var(--ink);
  font: inherit;
}
#login input:focus { outline: none; border-color: var(--ink-4); }

#login button {
  padding: 12px;
  border-radius: 10px;
  background: var(--accent);
  color: #0A0709;
  font-weight: 600;
  text-align: center;
}
#login button:disabled { opacity: .5; cursor: default; }

.error { color: var(--err); font-size: 13px; min-height: 18px; }

/* ── каркас ───────────────────────────────────────────── */

#app { display: none; min-height: 100vh; }
body.state-app #app { display: flex; }

#sidebar {
  display: flex;
  flex-direction: column;
  width: 268px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid #1A1A1F;
  position: sticky;
  top: 0;
  height: 100vh;
}

#sidebar .brand { padding: 22px 20px 20px; }
#sidebar .brand svg { width: 104px; height: auto; display: block; }

.navlist { flex-grow: 1; overflow-y: auto; padding: 0 12px 12px; }

.group {
  padding: 4px 11px 9px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-3);
}
.group.tight { padding-top: 18px; }

.nav {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 13.5px;
  color: var(--ink-2);
}
.nav:hover { background: #131317; }
.nav.active { background: var(--raise); border-color: var(--edge); color: var(--ink); }
.nav svg { width: 16px; height: 16px; flex-shrink: 0; }

.tree-item { display: flex; align-items: center; border-radius: 9px; border: 1px solid transparent; }
.tree-item:hover { background: #131317; }
.tree-item.active { background: var(--raise); border-color: var(--edge); }

.caret {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 38px;
  flex-shrink: 0;
}
.caret svg { width: 11px; height: 11px; transition: transform .16s; }
.caret.open svg { transform: rotate(90deg); }
.caret.hidden { visibility: hidden; pointer-events: none; }

.tree-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-grow: 1;
  min-width: 0;
  padding: 8px 11px 8px 0;
}
.tree-name {
  font-size: 13.5px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-item.active .tree-name { color: var(--ink); font-weight: 600; }
.tree-sub {
  font-size: 11.5px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.branch {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 3px 0 5px 26px;
  padding-left: 13px;
  border-left: 1px solid #1E1E24;
}
.branch .srv {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 10px;
  font-size: 11.5px;
  color: var(--ink-3);
}
.branch .srv .dot { width: 5px; height: 5px; box-shadow: none; }

.serverbox { padding: 14px 16px 16px; border-top: 1px solid #1A1A1F; }
.meter { height: 3px; border-radius: 999px; background: #1E1E24; overflow: hidden; }
.meter > div { height: 100%; border-radius: 999px; }

/* ── содержимое ───────────────────────────────────────── */

#main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; }

#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 66px;
  flex-shrink: 0;
  padding: 0 28px;
  border-bottom: 1px solid var(--line-2);
}

#content { flex-grow: 1; padding: 24px 28px 32px; }

.title {
  font-size: 29px;
  font-weight: 700;
  letter-spacing: -.025em;
  line-height: 1;
}

.iconbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 7px;
  border: 1px solid var(--edge);
  background: #0F0F13;
}
.iconbtn svg { width: 16px; height: 16px; }
.iconbtn:hover { border-color: var(--ink-4); }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px;
  border-radius: 9px;
  background: var(--accent);
  color: #0A0709;
  font-size: 13px;
  font-weight: 600;
}
.btn-primary:disabled { opacity: .55; cursor: default; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 28px; }
.metric { display: flex; flex-direction: column; gap: 9px; }
.metric .label { font-size: 12px; color: var(--ink-3); }
.metric .value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.metric .unit { font-size: 12px; color: var(--ink-3); }
.metric .note { font-size: 11.5px; color: var(--ink-3); }

.summary-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 0;
  border-bottom: 1px solid #1A1A20;
}
.summary-row:last-child { border-bottom: 0; }
.badge-circle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 999px;
}
.badge-circle svg { width: 17px; height: 17px; }

.tbl-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px 12px;
  font-size: 12px;
  color: var(--ink-3);
}
.tbl-row {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 12px 20px;
  border-top: 1px solid var(--line-2);
}
.tbl-row:hover { background: #131317; }
.col { text-align: right; flex-shrink: 0; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 42px 20px;
  text-align: center;
}
.empty svg { width: 22px; height: 22px; opacity: .55; }
.empty p { margin: 0; font-size: 13px; color: var(--ink-3); max-width: 420px; line-height: 1.5; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.tile { display: flex; flex-direction: column; gap: 10px; padding: 14px 17px; }
.tile .head { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--ink-3); }
.tile .chip { width: 8px; height: 8px; border-radius: 2px; }
.tile .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.tile .note { font-size: 11.5px; color: var(--ink-3); }

.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 18px; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.stack-sm { display: flex; flex-direction: column; gap: 12px; }

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--line-2);
}
.list-row:first-of-type { border-top: 0; }

.meta-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px; padding: 16px 22px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  padding: 11px 18px;
  border-radius: 10px;
  background: var(--raise);
  border: 1px solid var(--edge);
  font-size: 13px;
  box-shadow: 0 16px 40px rgba(0,0,0,.6);
  z-index: 20;
}

.spin { animation: spin 1s linear infinite; transform-origin: 50% 50%; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: static; border-right: 0; border-bottom: 1px solid #1A1A1F; }
  .navlist { max-height: 320px; }
  #topbar { padding: 0 16px; gap: 10px; }
  #topbar .search { display: none; }
  #content { padding: 18px 16px 28px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col, .overview-top { grid-template-columns: minmax(0, 1fr) !important; }
  .meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .title { font-size: 24px; }
  .hide-sm { display: none !important; }
}
