:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e3e6ef;
  --text: #161a26;
  --muted: #6b7286;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --good: #15803d;
  --good-soft: #e8f7ee;
  --bad: #c2410c;
  --bad-soft: #fdf0e8;
  --human: #4f46e5;
  --bot: #f59e0b;
  --shadow: 0 1px 2px rgb(16 24 40 / .04), 0 4px 16px rgb(16 24 40 / .05);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* bot category colors */
  --c-search: #2563eb;
  --c-ai_crawler: #7c3aed;
  --c-ai_assistant: #c026d3;
  --c-seo: #d97706;
  --c-social_preview: #0284c7;
  --c-monitoring: #0d9488;
  --c-http_client: #475569;
  --c-headless: #ea580c;
  --c-security_scanner: #dc2626;
  --c-bad: #b91c1c;
  --c-other: #6b7280;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --surface: #161b24;
    --surface-2: #1d2330;
    --border: #2a3140;
    --text: #e7eaf2;
    --muted: #8d95a8;
    --accent: #818cf8;
    --accent-soft: #23264a;
    --accent-text: #0e1117;
    --good: #4ade80;
    --good-soft: #13291c;
    --bad: #fb923c;
    --bad-soft: #2d1a10;
    --human: #818cf8;
    --bot: #fbbf24;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
code, textarea, input { font-family: var(--mono); }
.sprite { display: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.muted { color: var(--muted); font-weight: 400; }
[hidden] { display: none !important; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 20px; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; text-decoration: none; letter-spacing: -.01em; }
.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 6px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 550;
}
.tabs a:hover { color: var(--text); background: var(--surface-2); }
.tabs a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.status { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.down { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

main.wrap { padding-top: 28px; padding-bottom: 24px; }
.tab { display: grid; gap: 18px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2, .card-title { margin: 0; font-size: 15px; font-weight: 650; }
.card-title { margin-bottom: 0; }

/* Forms */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.label { font-size: 13px; font-weight: 600; }
textarea, input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  resize: vertical;
}
textarea:focus, input:focus, .btn:focus-visible, .chip:focus-visible, th:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.row { display: flex; gap: 14px; align-items: end; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.ip { flex: 1 1 240px; }
.actions { display: flex; gap: 10px; margin-left: auto; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { height: 30px; padding: 0 8px; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.chip {
  border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 11px; background: var(--surface); color: var(--text);
  font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

progress { width: 100%; height: 6px; accent-color: var(--accent); }

/* Result */
.result { display: grid; gap: 14px; animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.summary { display: flex; gap: 16px; align-items: center; }
.avatar {
  flex: none; width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.avatar svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.avatar.bot { background: color-mix(in srgb, var(--cat, var(--c-other)) 14%, transparent); color: var(--cat, var(--c-other)); }
.summary-text { flex: 1; min-width: 0; }
.headline { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -.015em; }
.subline { margin: 2px 0 0; color: var(--muted); }
.summary-actions { margin-left: auto; display: flex; gap: 6px; }

.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.badge svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.badge.cat { background: color-mix(in srgb, var(--cat) 14%, transparent); color: var(--cat); }
.badge.verified { background: var(--good-soft); color: var(--good); }
.badge.failed { background: var(--bad-soft); color: var(--bad); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--surface-2); border-radius: 11px; padding: 11px 13px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-weight: 600; overflow-wrap: anywhere; }
.tile .v.none { color: var(--muted); font-weight: 400; }

details.raw { margin-top: 14px; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 600; }
details.raw pre {
  margin: 10px 0 0; padding: 14px; border-radius: 10px;
  background: var(--surface-2); overflow: auto; max-height: 340px;
  font: 12.5px/1.55 var(--mono);
}

.error {
  margin: 0; padding: 12px 14px; border-radius: 10px;
  background: var(--bad-soft); color: var(--bad); font-weight: 550;
}

/* History */
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.history-list button {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 8px 10px; border: 0; border-radius: 9px;
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.history-list button:hover { background: var(--surface-2); }
.history-list .ua { color: var(--muted); font: 12px var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-list .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.history-list .what { font-weight: 600; white-space: nowrap; }
.mini { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--human); }
.mini.bot { background: var(--cat, var(--bot)); }

/* Batch */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.table-card { padding: 0; overflow: auto; max-height: 70vh; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  position: sticky; top: 0; background: var(--surface);
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  cursor: pointer; user-select: none; white-space: nowrap;
}
.table th[aria-sort="ascending"]::after { content: " ↑"; }
.table th[aria-sort="descending"]::after { content: " ↓"; }
.table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table td.ua { font: 12px var(--mono); color: var(--muted); max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .num { width: 1%; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Stats */
.stats-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.stats-head h1 { margin: 0; font-size: 21px; letter-spacing: -.015em; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.kpi .k { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12.5px; color: var(--muted); }
.ratio { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin-top: 10px; background: var(--surface-2); }
.ratio i { display: block; height: 100%; }
.ratio .human, .sw.human { background: var(--human); }
.ratio .bot, .sw.bot { background: var(--bot); }

.legend { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 8px; }
.daily svg { display: block; width: 100%; height: 150px; }
.daily-axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.daily-max { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.daily .h { fill: var(--human); }
.daily .b { fill: var(--bot); }
.daily .grid { stroke: var(--border); stroke-width: 1; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.bars li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; font-size: 13.5px; }
.bars .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .c { color: var(--muted); font-variant-numeric: tabular-nums; }
.bars .track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bars .fill { display: block; height: 100%; border-radius: 3px; background: var(--cat, var(--accent)); }
.empty { color: var(--muted); font-size: 13.5px; margin: 0; }

.footer { padding: 8px 20px 32px; font-size: 12.5px; text-align: center; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 13.5px;
  animation: rise .2s ease-out;
}

@media (max-width: 640px) {
  .topbar-inner { gap: 12px; }
  .brand span { display: none; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; justify-content: center; }
  .summary { flex-wrap: wrap; gap: 12px; }
  .avatar { width: 44px; height: 44px; }
  .headline { font-size: 18px; }
  .summary-actions { margin-left: 56px; }
  .actions .btn { padding: 0 10px; }
  .card { padding: 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
