:root {
  color-scheme: light;
  --page: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --text: #191919;
  --text-2: #666666;
  --border: rgba(11, 11, 11, 0.09);
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --accent: #257de0;
  --accent-soft: #e6f0fc;
  --s1: #257de0; --s2: #f47230; --s3: #00b894; --s4: #f2a600;
  --s5: #ee7fac; --s6: #008a17; --s7: #6a4ce2; --s8: #ec4647;
  --good: #0aac23; --good-text: #006c10; --warning: #fbb315; --serious: #f18a59; --critical: #dc3c3d;
  --info: #257de0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.04);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0b0b0b; --surface: #191919; --surface-2: #222222; --text: #efefef; --text-2: #9c9c9c;
    --border: rgba(255, 255, 255, 0.09); --grid: #303030; --axis: #474747; --accent: #338ced; --accent-soft: #15263b;
    --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05; --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263;
    --good-text: #53c556; --info: #338ced;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b0b0b; --surface: #191919; --surface-2: #222222; --text: #efefef; --text-2: #9c9c9c;
  --border: rgba(255, 255, 255, 0.09); --grid: #303030; --axis: #474747; --accent: #338ced; --accent-soft: #15263b;
  --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05; --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263;
  --good-text: #53c556; --info: #338ced;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text); font: 14px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-2); }
button, select, input { font: inherit; color: inherit; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px; box-shadow: var(--shadow);
}
.login-card form { display: grid; gap: 12px; margin-top: 16px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); outline: none; font-size: 16px;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { color: var(--critical); margin: 0; font-size: 13px; }
.btn-primary {
  padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.06); }

/* ---------- Header ---------- */
.brand { white-space: nowrap; display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; min-width: 0; }
.brand-lg { font-size: 20px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 21l5-6 4 4 9-10' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat;
}
.host { font-weight: 500; color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.inline { display: inline; margin: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2); white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--axis); }
.pill.ok::before { background: var(--good); }
.pill.warn::before { background: var(--warning); }
.pill.bad::before { background: var(--critical); }
.icon-btn { font-size: 16px; line-height: 1; padding: 6px 9px; }
.icon-btn, .btn-ghost {
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 6px 10px; cursor: pointer;
}
.icon-btn:hover, .btn-ghost:hover { background: var(--surface-2); }

/* ---------- Controls ---------- */
.controls, .tabs, main, .foot { max-width: 1280px; margin-left: auto; margin-right: auto; padding-left: 16px; padding-right: 16px; }
.controls { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding-top: 14px; flex-wrap: wrap; }
.seg {
  display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none; max-width: 100%;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap; color: var(--text-2);
  font-weight: 500;
}
.seg button.on { background: var(--accent); color: #fff; }
.seg button[data-r="realtime"]::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--critical); margin-right: 6px;
  vertical-align: 1px; animation: blink 1.6s infinite;
}
@keyframes blink { 50% { opacity: .25; } }
.site-select select, .mini-select {
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 30px 8px 12px; max-width: 260px;
  appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.mini-select { padding: 5px 28px 5px 10px; font-size: 13px; max-width: 200px; }
.tabs {
  display: flex; gap: 4px; margin-top: 12px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none;
  position: sticky; top: 53px; z-index: 15; background: var(--page);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: none; padding: 10px 12px; cursor: pointer; white-space: nowrap; color: var(--text-2); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Layout ---------- */
main { padding-top: 16px; padding-bottom: 24px; }
.tab { display: none; }
.tab.on { display: block; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.grid-2.inner { margin: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  margin-bottom: 14px; min-width: 0;
}
.grid-2 > .card { margin-bottom: 0; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h h3 { margin: 0; font-size: 15px; font-weight: 650; }
.sub { color: var(--text-2); font-size: 12px; }
.chart { position: relative; height: 230px; }
.chart-lg { height: 290px; }

/* ---------- Tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
  min-width: 0;
}
.tile .k { color: var(--text-2); font-size: 12px; font-weight: 500; display: flex; justify-content: space-between; gap: 6px; }
.tile .v { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .v small { font-size: 14px; font-weight: 600; color: var(--text-2); margin-left: 3px; }
.tile .d { color: var(--text-2); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { height: 6px; border-radius: 999px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .4s ease; }
.meter.warn > i { background: var(--warning); }
.meter.bad > i { background: var(--critical); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
th { color: var(--text-2); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
th:first-child, td:first-child { text-align: left; }
tbody tr:hover td { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.path { max-width: 340px; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 12px; text-align: left; }
td .site-tag { display: block; color: var(--text-2); font-family: var(--font); font-size: 11px; }
.num-strong { font-weight: 650; }
.dim { color: var(--text-2); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; }
.empty { color: var(--text-2); padding: 18px 4px; text-align: center; font-size: 13px; }

/* ---------- Bar lists ---------- */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { color: var(--text-2); font-size: 12px; text-align: right; }
.bar-row .val b { color: var(--text); font-weight: 650; font-size: 13px; }
.bar-row .track { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-row .track > i { display: block; height: 100%; background: var(--s1); border-radius: 999px; }
.flag { margin-right: 6px; }

/* ---------- Insights ---------- */
.ins { display: grid; gap: 10px; }
.ins-item { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.ins-item .ico {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700;
}
.lv-critical .ico { background: var(--critical); }
.lv-serious .ico { background: var(--serious); }
.lv-warning .ico { background: var(--warning); color: #0b0b0b; }
.lv-info .ico { background: var(--info); }
.lv-good .ico { background: var(--good); }
.ins-item .t { font-weight: 600; }
.ins-item .lab { font-size: 11px; color: var(--text-2); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; margin-left: 6px; }
.ins-item p { margin: 3px 0 0; color: var(--text-2); font-size: 13px; }

/* ---------- Key/values ---------- */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.conf-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.conf-grid h4 { margin: 0 0 8px; font-size: 13px; }

.cap-hero .v { font-size: 30px; }
.limit { padding: 10px 0; border-bottom: 1px solid var(--border); }
.limit:last-child { border-bottom: 0; }
.limit .row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.limit .row b { font-size: 15px; }
.limit p { margin: 4px 0 0; color: var(--text-2); font-size: 12px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; margin-left: 6px; }
.badge.red { background: color-mix(in srgb, var(--critical) 16%, transparent); color: var(--critical); }

.foot { color: var(--text-2); font-size: 12px; padding-bottom: 28px; text-align: center; }
.foot a { color: var(--text-2); }
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--text); color: var(--page);
  padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 50; max-width: 90vw;
}
.loading { opacity: .55; transition: opacity .2s; }

/* ---------- Responsif ---------- */
@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .conf-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .grid-2 > .card { margin-bottom: 0; }
  .host { display: none; }
  .controls { flex-direction: column; align-items: stretch; }
  .site-select select { max-width: none; width: 100%; }
  .seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .seg button { padding: 8px 6px; }
  .chart { height: 210px; }
  .chart-lg { height: 240px; }
  .tile .v { font-size: 22px; }
  .tile .d { white-space: normal; }
  .card { padding: 14px; }
  .conf-grid { grid-template-columns: 1fr; }
  .tabs { top: 51px; }
}
@media (max-width: 480px) {
  .pill { padding: 4px 8px; font-size: 0; gap: 0; }
  .pill::before { width: 10px; height: 10px; }
}
@media (max-width: 380px) {
  .tiles { gap: 10px; }
  .tile { padding: 12px; }
  .tile .v { font-size: 20px; }
}
