:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --bg2: var(--tg-theme-secondary-bg-color, #181b22);
  --card: var(--tg-theme-section-bg-color, var(--bg2));
  --text: var(--tg-theme-text-color, #e8eaed);
  --hint: var(--tg-theme-hint-color, #8b919c);
  --link: var(--tg-theme-link-color, #5aa7ff);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --danger: var(--tg-theme-destructive-text-color, #ef4444);
  --ok: #22c55e;
  --warn: #f59e0b;
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --c1: #3b82f6;
  --c2: #f97316;
  --c3: #a855f7;
  --c4: #14b8a6;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 16px 8px; }
.tabs { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; }
.tab { flex: 1; border: 0; background: none; padding: 7px; border-radius: 8px; color: var(--hint); font-weight: 600; }
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .15); }
main { padding: 4px 16px 24px; max-width: 760px; margin: 0 auto; }
.empty { color: var(--hint); text-align: center; padding: 40px 0; }
.err { color: var(--danger); }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }

.card { background: var(--card); border-radius: 14px; padding: 14px; margin: 10px 0; }
.card h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.server { cursor: pointer; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.name { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.bars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.bar label { font-size: 12px; color: var(--hint); display: flex; justify-content: space-between; }
.bar .track { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 4px; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 3px; }
.fill.warn { background: var(--warn); }
.fill.crit { background: var(--danger); }
.meta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--hint); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line); color: var(--text); white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.tile { background: var(--card); border-radius: 12px; padding: 10px 12px; }
.tile .k { font-size: 12px; color: var(--hint); }
.tile .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--hint); }

.btn { border: 0; background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 10px 14px; font-weight: 600; cursor: pointer; }
.btn.secondary { background: var(--bg2); color: var(--link); }
.btn.danger { background: none; color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.link { color: var(--link); background: none; border: 0; padding: 0; cursor: pointer; font-weight: 500; }

.seg { display: flex; gap: 4px; background: var(--bg2); border-radius: 9px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 5px 0; border-radius: 7px; font-size: 13px; color: var(--hint); }
.seg button.active { background: var(--card); color: var(--text); font-weight: 600; }

.chart { position: relative; height: 150px; margin-top: 4px; touch-action: pan-y; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .tip { position: absolute; top: 0; pointer-events: none; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 12px; white-space: nowrap; transform: translateX(-50%); z-index: 2; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--hint); }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th { text-align: left; color: var(--hint); font-weight: 500; padding: 4px 4px 6px 0; }
td { padding: 6px 4px 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
td.r, th.r { text-align: right; }
.ct-name { font-weight: 600; word-break: break-all; }
.ct-img { color: var(--hint); font-size: 12px; word-break: break-all; }

input.field { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); outline: none; }
input.field:focus { border-color: var(--accent); }
.form { display: grid; gap: 10px; }
.code { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; user-select: all; }

.verdicts { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.probe-list { max-height: 360px; overflow: auto; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--hint); }
.kv dd { margin: 0; word-break: break-word; }
.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin: 8px 0; }
.progress div { height: 100%; background: var(--accent); transition: width .3s; }

.modal { position: fixed; inset: 0; background: rgb(0 0 0 / .45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal.hidden { display: none; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto; }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 14px; z-index: 30; max-width: 90vw; }
.toast.hidden { display: none; }
@media (max-width: 420px) {
  .bars { gap: 8px; }
  .tile .v { font-size: 18px; }
}
