:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-1-soft: #b7d3f6;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;
  --warn-ink: #8a5a00;
  --crit-ink: #b02a2a;
  --good-bg: #e7f5e7;
  --warn-bg: #fdf3dc;
  --crit-bg: #fbe8e8;
  --info-bg: #e6effa;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #31312e;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-1-soft: #184f95;
    --good-ink: #5fd35f; --warn-ink: #fab219; --crit-ink: #f07a7a;
    --good-bg: #16301a; --warn-bg: #352a0f; --crit-bg: #3a1a1a; --info-bg: #142640;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #31312e;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-1-soft: #184f95;
  --good-ink: #5fd35f; --warn-ink: #fab219; --crit-ink: #f07a7a;
  --good-bg: #16301a; --warn-bg: #352a0f; --crit-bg: #3a1a1a; --info-bg: #142640;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.num, td.num, .tile .v { font-variant-numeric: tabular-nums; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
[hidden] { display: none !important; }

/* ---------- верх ---------- */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px;
  padding: 0 24px; height: 52px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; color: var(--text); white-space: nowrap; }
#nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
#nav a { padding: 6px 10px; border-radius: 7px; color: var(--text-2); white-space: nowrap; }
#nav a:hover { background: var(--surface-2); text-decoration: none; }
#nav a.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.top-right { display: flex; align-items: center; gap: 10px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); color: var(--text-2); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; }

main { max-width: 1320px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
section { margin-bottom: 28px; }
section > h2 { margin-bottom: 12px; display: flex; align-items: baseline; gap: 10px; }
section > h2 .muted { font-weight: 400; font-size: 13px; }

/* ---------- карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr)); }
.g3 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 24px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .l { color: var(--text-2); font-size: 12px; }
.tile .v { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -.02em; }
.tile .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
a.tile { color: inherit; display: block; }
a.tile:hover { text-decoration: none; border-color: var(--accent); }

/* ---------- статусы: всегда значок + слово ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-ok { color: var(--good-ink); background: var(--good-bg); }
.b-warn { color: var(--warn-ink); background: var(--warn-bg); }
.b-crit { color: var(--crit-ink); background: var(--crit-bg); }
.b-info { color: var(--accent); background: var(--info-bg); }
.b-off { color: var(--text-2); background: var(--surface-2); }

/* ---------- сервер ---------- */
.srv { cursor: pointer; display: flex; flex-direction: column; gap: 12px; }
.srv:hover { border-color: var(--accent); }
.srv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.srv-head .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.meter .row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.meter .row b { color: var(--text); font-weight: 600; }
.bar { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--series-1); }
.bar > i.warn { background: var(--warning); }
.bar > i.crit { background: var(--critical); }
.srv-foot { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--text-2); border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- списки и таблицы ---------- */
.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 550; }
.item .d { color: var(--text-2); font-size: 13px; white-space: pre-line; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 550; color: var(--text-2); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.dim td { opacity: .55; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* ---------- кнопки, формы ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--text-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 550; }
.btn.danger { color: var(--crit-ink); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--text-2); padding: 5px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.filters input, .filters select { width: auto; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
label.check input { width: auto; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .full { grid-column: 1 / -1; }
.hint { font-size: 11px; color: var(--muted); }
.err { color: var(--crit-ink); font-size: 13px; min-height: 1em; }
.code { display: block; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; user-select: all; }

/* ---------- модальное окно ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal-card { background: var(--surface); border-radius: 14px; width: min(640px, 100%); padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal-card h2 { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }

/* ---------- графики ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.chart-head .now { font-size: 13px; color: var(--text-2); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tip { position: fixed; z-index: 60; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15); max-width: 280px; }
.tip .tt { color: var(--muted); margin-bottom: 3px; }
.tip .tr { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.tip .tr i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.hbar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 8px 10px; align-items: center; font-size: 13px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar .track { height: 14px; }
.hbar .track i { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .val { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 70; font-size: 13px; max-width: calc(100% - 32px); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.pill { display: inline-block; background: var(--surface-2); border-radius: 6px; padding: 1px 7px; font-size: 12px; margin: 0 4px 4px 0; }
.sticky-note { background: var(--info-bg); border-radius: 10px; padding: 12px 14px; font-size: 13px; margin-bottom: 16px; }

@media (max-width: 760px) {
  .top { padding: 0 16px; gap: 10px; height: auto; flex-wrap: wrap; padding-top: 8px; padding-bottom: 6px; }
  #nav { order: 3; flex-basis: 100%; }
  #updated { display: none; }
  main { padding: 16px; }
  .form { grid-template-columns: 1fr; }
  .meters { grid-template-columns: 1fr 1fr; }
  .tile .v { font-size: 20px; }
  .item { flex-wrap: wrap; }
  .item .grow { flex-basis: 100%; order: 3; }
}
