:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #17202b;
  --muted: #6b7684;
  --accent: #2557d6;
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --ok-bg: #e6f6ec;
  --err: #d64545;
  --err-bg: #fdecec;
  --warn: #c98a0c;
  --neutral: #8a94a3;
  --edge: #b7c0cc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --surface: #171d24; --surface-2: #1f262f; --border: #2c3540;
    --text: #e6eaef; --muted: #8b96a5; --accent: #5b8cff; --accent-text: #0b1020;
    --ok: #3ccf7f; --ok-bg: #12301f; --err: #ff6b6b; --err-bg: #3a1a1a; --warn: #f0b429;
    --neutral: #7d8896; --edge: #46515e; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --surface: #171d24; --surface-2: #1f262f; --border: #2c3540;
  --text: #e6eaef; --muted: #8b96a5; --accent: #5b8cff; --accent-text: #0b1020;
  --ok: #3ccf7f; --ok-bg: #12301f; --err: #ff6b6b; --err-bg: #3a1a1a; --warn: #f0b429;
  --neutral: #7d8896; --edge: #46515e; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; letter-spacing: .01em; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.error { color: var(--err); }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger:hover { border-color: var(--err); color: var(--err); }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 14px; height: 14px; border-radius: 4px; background: var(--accent); display: inline-block; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 28px; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px;
}
.login-card p { margin: 0; }
input[type=password] {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font: inherit;
}

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.spacer { flex: 1; }
main { max-width: 1280px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }

.pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.error { background: var(--err-bg); color: var(--err); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(170px, 100%), 1fr)); gap: 12px; }
.table-scroll { overflow-x: auto; }
.tile { padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 20px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.bar { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.warn > i { background: var(--warn); }
.bar.crit > i { background: var(--err); }

.diagram-wrap { padding: 12px; overflow-x: auto; }
#diagram { display: block; min-width: 900px; width: 100%; }
#diagram .col-title { fill: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
#diagram .node rect { fill: var(--surface); stroke: var(--border); stroke-width: 1; }
#diagram .node.ok rect { stroke: var(--ok); }
#diagram .node.error rect { stroke: var(--err); fill: var(--err-bg); }
#diagram .node .t { fill: var(--text); font-size: 12px; font-weight: 600; }
#diagram .node .s { fill: var(--muted); font-size: 10.5px; }
#diagram .node .st { stroke: none; }
#diagram .node .st.ok { fill: var(--ok); }
#diagram .node .st.error { fill: var(--err); }
#diagram .node .st.neutral { fill: var(--neutral); }
#diagram .edge { fill: none; stroke: var(--edge); stroke-width: 1.4; }
#diagram .edge.link { stroke-dasharray: 4 3; }
#diagram .edge:hover, #diagram .edge.hl { stroke: var(--accent); stroke-width: 2.2; }
#diagram .node { cursor: default; }
#diagram .node:hover rect { stroke: var(--accent); }

.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.dot.ok { background: var(--ok); } .dot.error { background: var(--err); } .dot.neutral { background: var(--neutral); }

.systems { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(380px, 100%), 1fr)); gap: 14px; }
.sys { min-width: 0; }
.kv span { overflow-wrap: anywhere; }
.sys { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.sys-head { display: flex; align-items: flex-start; gap: 10px; }
.sys-head .title { font-weight: 600; }
.sys-head .pill { margin-left: auto; flex-shrink: 0; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 3px 10px; font-size: 12.5px; }
.kv .k { color: var(--muted); }
.kv a { color: var(--accent); text-decoration: none; }
.units { display: flex; flex-direction: column; gap: 4px; }
.unit { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 7px 9px; background: var(--surface-2); border-radius: 7px; font-size: 12.5px; }
.unit-main { display: flex; align-items: baseline; gap: 8px; flex: 1 1 200px; min-width: 0; flex-wrap: wrap; }
.unit-main .dot { align-self: center; }
.unit .name { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.unit .meta { color: var(--muted); font-size: 11.5px; }
.unit-actions { display: flex; gap: 6px; margin-left: auto; }
.unit .btn { padding: 2px 8px; font-size: 11.5px; }
.health { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-family: var(--mono); font-size: 11.5px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); }
.chip.ok { color: var(--ok); } .chip.error { color: var(--err); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-note { padding: 10px 14px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); }

.job { padding: 14px 16px; }
.job pre, #modal pre {
  margin: 10px 0 0; max-height: 360px; overflow: auto; padding: 10px 12px; background: var(--surface-2);
  border-radius: 8px; font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all;
}

dialog {
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  width: min(960px, calc(100vw - 32px)); padding: 18px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(10, 14, 20, .55); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
#modal pre { max-height: 65vh; }

/* --- навигация и документация --- */
.tabs { display: flex; gap: 4px; }
.tab { padding: 5px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--text); background: var(--surface-2); }
.docs { max-width: 1280px; margin: 0 auto; padding: 24px; display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 18px; align-items: start; }
.docs-nav { padding: 10px; position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
.docs-nav .group { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 10px 8px 4px; }
.docs-nav a { display: block; padding: 6px 8px; border-radius: 7px; color: var(--text); text-decoration: none; font-size: 13px; }
.docs-nav a:hover { background: var(--surface-2); }
.docs-nav a.active { background: var(--surface-2); color: var(--accent); font-weight: 600; }
.docs-body { padding: 26px 32px; min-width: 0; }
.md { line-height: 1.6; font-size: 14.5px; }
.md h1 { font-size: 24px; margin: 0 0 6px; }
.md h2 { font-size: 18px; margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 15.5px; margin: 22px 0 8px; }
.md h4 { font-size: 14px; margin: 18px 0 6px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 3px 0; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
.md pre { background: var(--surface-2); padding: 12px 14px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; white-space: pre; overflow-wrap: normal; }
.md blockquote { margin: 10px 0; padding: 6px 14px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; color: var(--text); }
.md .table-wrap { overflow-x: auto; margin: 10px 0; }
.md table { font-size: 13px; }
.md th, .md td { padding: 7px 10px; vertical-align: top; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

@media (max-width: 720px) {
  .docs { grid-template-columns: 1fr; padding: 16px; }
  .docs-nav { position: static; max-height: none; }
  .docs-body { padding: 18px; }
  main { padding: 16px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .systems { grid-template-columns: 1fr; }
  #updated { display: none; }
  .legend { display: none; }
  .kv { grid-template-columns: 90px 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
