:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7c7b76;
  --grid: #e8e7e2;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --warning-text: #8a5a00;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-text: #b02a2a;
  --critical-bg: #fbeaea;
  --warning-bg: #fdf4e0;
  --good-bg: #e8f5e8;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #8d8c85;
    --grid: #2a2a27;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good-text: #4cc94c;
    --warning-text: #fab219;
    --critical-text: #ff7b7b;
    --critical-bg: #3a1c1c;
    --warning-bg: #3a2e14;
    --good-bg: #16301a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
  --text: #ffffff; --text-2: #c3c2b7; --text-3: #8d8c85; --grid: #2a2a27;
  --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926;
  --good-text: #4cc94c; --warning-text: #fab219; --critical-text: #ff7b7b;
  --critical-bg: #3a1c1c; --warning-bg: #3a2e14; --good-bg: #16301a; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .86em; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- каркас ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.top-inner {
  max-width: 1200px; margin: 0 auto; padding: 10px 16px 0;
}
.top-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { font-size: 18px; white-space: nowrap; }
.brand .sub { color: var(--text-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.fresh { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.fresh .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.fresh.stale .pulse { background: var(--critical); }
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin-top: 8px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; border: 0; background: none; font: inherit; font-size: 14px;
  color: var(--text-2); padding: 8px 12px 10px; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 16px 16px 48px; }
.section { margin-top: 16px; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.section-head .muted { font-size: 13px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px;
}
.grid { display: grid; gap: 12px; }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
@media (min-width: 700px) { #kpis { grid-template-columns: repeat(3, 1fr); } }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.charts { grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); }
@media (max-width: 860px) { .grid.charts { grid-template-columns: 1fr; } }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

/* ---------- статус ---------- */
.banner {
  display: flex; gap: 12px; align-items: flex-start;
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
  border: 1px solid var(--border); background: var(--surface);
}
.banner.good { background: var(--good-bg); border-color: transparent; }
.banner.warning { background: var(--warning-bg); border-color: transparent; }
.banner.critical { background: var(--critical-bg); border-color: transparent; }
.banner ul { margin: 4px 0 0; padding-left: 18px; }
.banner strong { display: block; }
.banner .info-line { margin-top: 6px; font-size: 13px; color: var(--text-2); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-3); }
.dot.good { background: var(--good); }
.dot.warning { background: var(--warning); }
.dot.serious { background: var(--serious); }
.dot.critical { background: var(--critical); }
.dot.info { background: var(--accent); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; line-height: 1;
  padding: 4px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2);
  white-space: nowrap;
}
.pill.good { color: var(--good-text); background: var(--good-bg); }
.pill.warning { color: var(--warning-text); background: var(--warning-bg); }
.pill.critical { color: var(--critical-text); background: var(--critical-bg); }

.icon { width: 16px; height: 16px; flex: none; }

/* ---------- KPI ---------- */
.kpi .label { font-size: 13px; color: var(--text-2); display: flex; justify-content: space-between; gap: 8px; }
.kpi .value { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin-top: 2px; }
.kpi .value small { font-size: 14px; font-weight: 500; color: var(--text-2); letter-spacing: 0; }
.kpi .hint { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--good); }
.meter > i.warning { background: var(--warning); }
.meter > i.critical { background: var(--critical); }

/* ---------- списки и таблицы ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--border); min-width: 0; }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 500; }
.list .meta { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; }
.list .right { text-align: right; font-size: 13px; color: var(--text-2); white-space: nowrap; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; padding: 6px 10px 8px; white-space: nowrap; }
td { padding: 9px 10px; border-top: 1px solid var(--border); vertical-align: top; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.sub td { border-top: 0; padding-top: 0; }

/* ---------- архитектура ---------- */
.server-box {
  border: 1.5px dashed var(--border); border-radius: 16px; padding: 14px; background: var(--surface);
}
.server-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; margin-bottom: 14px; }
.server-head h2 { font-size: 18px; }
.flow {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--text-2);
  margin: 0 0 10px;
}
.flow .node { background: var(--surface-2); border-radius: 6px; padding: 3px 8px; font-family: var(--mono); font-size: 11.5px; }
.flow .arrow { color: var(--text-3); }
.lane { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }
.lane:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.lane-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.proj { display: flex; flex-direction: column; gap: 8px; }
.proj-head { display: flex; align-items: center; gap: 8px; }
.proj-head h3 { flex: 1; min-width: 0; }
.proj-desc { font-size: 13px; color: var(--text-2); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.svc { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 6px 8px; background: var(--surface-2); border-radius: 8px; }
.svc .name { font-family: var(--mono); font-size: 12px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.svc .stat { color: var(--text-2); white-space: nowrap; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.lock { color: var(--text-3); font-size: 12px; }

/* ---------- графики ---------- */
.range { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.range button {
  appearance: none; border: 0; background: none; font: inherit; font-size: 13px; color: var(--text-2);
  padding: 4px 10px; border-radius: 6px; cursor: pointer;
}
.range button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.chart-card h3 { font-size: 14px; }
.chart-card .now { font-size: 13px; color: var(--text-2); }
.chart-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 2px; border-radius: 1px; }
.chart { position: relative; margin-top: 8px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--text-3); font-size: 11px; }
.chart .ref { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .ref-label { fill: var(--text-3); font-size: 11px; }
.chart .cross { stroke: var(--text-3); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: .1; }
.chart .hover-dot { stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 120px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12); padding: 8px 10px; font-size: 12px;
}
.tooltip .t { color: var(--text-3); margin-bottom: 4px; }
.tooltip .row { display: flex; align-items: center; gap: 8px; }
.tooltip .row i { width: 12px; height: 2px; border-radius: 1px; }
.tooltip .row b { font-size: 14px; }
.tooltip .row span { color: var(--text-2); }

.bars .bar-row { display: grid; grid-template-columns: minmax(0, 1.4fr) 2fr auto; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.bars .bar-row .path { font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bars .track i { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }

.hourly { display: flex; gap: 2px; align-items: flex-end; height: 28px; margin-top: 6px; }
.hourly i { flex: 1; background: var(--series-1); border-radius: 2px 2px 0 0; min-height: 1px; opacity: .5; }
.hourly i.other { background: var(--critical); opacity: 1; }
.errline { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); padding: 4px 0; border-top: 1px dashed var(--border); overflow-wrap: anywhere; }

.empty { color: var(--text-3); font-size: 13px; padding: 8px 0; }

/* ---------- вход ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login h1 { font-size: 20px; margin-bottom: 4px; }
.login form { display: grid; gap: 12px; margin-top: 18px; }
.login label { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.login input {
  font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.login button {
  font: inherit; font-weight: 600; padding: 11px; border-radius: 8px; border: 0;
  background: var(--accent); color: #fff; cursor: pointer; margin-top: 4px;
}
.login .err { color: var(--critical-text); background: var(--critical-bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; }

@media (max-width: 560px) {
  .brand .sub { display: none; }
  .kpi .value { font-size: 22px; }
  .card { padding: 12px 14px; }
  td, th { padding-left: 6px; padding-right: 6px; }
  .hide-sm { display: none; }
}

/* ---------- журнал входов ---------- */
.whoami { font-size: 13px; color: var(--text-2); background: var(--surface-2); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.acts { display: flex; flex-wrap: wrap; gap: 4px; }
.act { font-size: 12px; background: var(--surface-2); color: var(--text-2); border-radius: 6px; padding: 2px 7px; white-space: nowrap; }
.act.ip { background: var(--warning-bg); color: var(--warning-text); }
.user-tag { font-weight: 600; }
@media (max-width: 560px) { .whoami { display: none; } }
