:root {
  --bg: #ffffff;
  --panel: #f6f6f7;
  --card: #ffffff;
  --line: #e4e4e7;
  --text: #111113;
  --muted: #6b6b73;
  --accent: #111113;
  --accent-text: #ffffff;
  --hover: #ececee;
  --series: #2a78d6;
  --series-area: rgb(42 120 214 / .12);
  --grid: #ececee;
  --good: #0ca30c;
  --warning: #d48a00;
  --critical: #d03b3b;
  --note-bg: #fff7ed;
  --note-text: #7c2d12;
  --note-line: #fed7aa;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f10;
    --panel: #18181a;
    --card: #141416;
    --line: #2a2a2e;
    --text: #f0efec;
    --muted: #9d9da6;
    --accent: #f0efec;
    --accent-text: #111113;
    --hover: #222225;
    --series: #3987e5;
    --series-area: rgb(57 135 229 / .18);
    --grid: #232326;
    --warning: #fab219;
    --critical: #e66767;
    --note-bg: #2a1d10;
    --note-text: #fed7aa;
    --note-line: #5c3a14;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f10;
  --panel: #18181a;
  --card: #141416;
  --line: #2a2a2e;
  --text: #f0efec;
  --muted: #9d9da6;
  --accent: #f0efec;
  --accent-text: #111113;
  --hover: #222225;
  --series: #3987e5;
  --series-area: rgb(57 135 229 / .18);
  --grid: #232326;
  --warning: #fab219;
  --critical: #e66767;
  --note-bg: #2a1d10;
  --note-text: #fed7aa;
  --note-line: #5c3a14;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
code { font: 13px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

#app { max-width: 1240px; margin: 0 auto; padding: 0 16px 32px; }

/* ---------- кнопки й поля ---------- */
.btn {
  font: inherit; font-size: 14px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 7px 12px; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.on, .btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); padding: 10px 16px; width: 100%; }
.btn:focus-visible, input:focus-visible, .sort:focus-visible, .tabs a:focus-visible { outline: 2px solid var(--series); outline-offset: 2px; }
input {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}

/* ---------- вхід ---------- */
#app.login { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  width: min(360px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); display: grid; gap: 12px; text-align: center;
}
.login-card img { margin: 0 auto; border-radius: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; text-align: left; font-size: 14px; color: var(--muted); }
.error { color: var(--critical); min-height: 1em; font-size: 14px; }

/* ---------- шапка ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 0 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.brand img { border-radius: 8px; }
.top-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pill { font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; color: var(--muted); vertical-align: 2px; }

.tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs a {
  text-decoration: none; padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent;
  white-space: nowrap; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }

/* ---------- плитки ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile.warn { box-shadow: inset 3px 0 0 var(--warning); }
.tile-label { color: var(--muted); font-size: 13px; }
.tile-value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-value small { font-size: 16px; font-weight: 500; color: var(--muted); margin-left: 1px; }
.tile-value .io { display: block; font-size: 18px; font-weight: 600; }
.tile-sub { color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }

.meter { height: 6px; border-radius: 3px; background: var(--line); margin: 8px 0 4px; overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 3px; background: var(--good); }
.meter.warning span { background: var(--warning); }
.meter.critical span { background: var(--critical); }

/* ---------- стан ---------- */
.strip { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 12px; }
.strip.in-card { margin: 12px 0 0; }
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; white-space: nowrap; }
.status > span { font-size: 11px; }
.status.good > span { color: var(--good); }
.status.warning > span { color: var(--warning); }
.status.critical > span { color: var(--critical); }
.status.muted { color: var(--muted); }

.note {
  background: var(--note-bg); color: var(--note-text); border: 1px solid var(--note-line);
  border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px;
}

/* ---------- картки й графіки ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; background: var(--card); min-width: 0; }
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
.card p.small { margin: 8px 0 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + * { margin-top: 12px; }
@media (max-width: 820px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }

.chart { width: 100%; min-height: 180px; }
.chart-svg { display: block; max-width: 100%; height: auto; touch-action: pan-y; }
.chart-svg .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-svg .grid { stroke: var(--grid); stroke-width: 1; }
.chart-svg .base { stroke: var(--line); stroke-width: 1; }
.chart-svg .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .area { fill: var(--series-area); }
.chart-svg .bar { fill: var(--series); }
.chart-svg .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-svg .dot { fill: var(--series); stroke: var(--card); stroke-width: 2; }
.chart-svg .hit { fill: transparent; cursor: crosshair; }
.chart-svg .empty { fill: var(--muted); font-size: 13px; }

.tip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 10px; font-size: 13px;
  box-shadow: 0 6px 24px rgb(0 0 0 / .12);
}

/* ---------- таблиці ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--panel); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sort { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.sort:hover { color: var(--text); }
th.num .sort { text-align: right; }

.nick { display: inline-flex; align-items: center; gap: 8px; }
.av {
  width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  background: var(--panel); border: 1px solid var(--line); font-size: 13px; font-weight: 600;
}
.users td:first-child .small { margin-left: 36px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.toolbar input { width: 220px; flex: 0 1 220px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.toolbar #ucount { margin-left: auto; }

table.rank td { padding: 6px 8px; }
.bar-row { position: relative; padding: 2px 6px; min-width: 0; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--series-area); border-radius: 4px; }
.bar-k { position: relative; overflow-wrap: anywhere; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.foot { margin-top: 20px; text-align: center; }

@media (max-width: 560px) {
  .top-actions .updated { display: none; }
  .tile-value { font-size: 24px; }
  .toolbar input { flex: 1 1 100%; width: 100%; }
  .toolbar #ucount { margin-left: 0; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
}
.users td, td:first-child { white-space: nowrap; }
.bar-row, .card table.rank td:first-child { white-space: normal; }
@media (max-width: 560px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 12px; }
  .tile-value { font-size: 22px; }
}
