:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --text: #1c2233;
  --muted: #6b7385;
  --line: #e4e7ef;
  --side: #121826;
  --side-text: #c4cad8;
  --side-active: #1f2a40;
  --accent: #4f5bd5;
  --accent-soft: #eceefe;
  --up: #12855a;
  --down: #c63b3b;
  --error: #d64545;
  --warning: #d98a1c;
  --notice: #4f7fd5;
  --good: #1f9d6b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e121b; --panel: #161c28; --text: #e6e9f0; --muted: #8d95a8; --line: #273044;
    --side: #0a0e16; --side-active: #1b2336; --accent: #8790f0; --accent-soft: #232a4a;
    --up: #3ccf8e; --down: #f07272; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Sidebar */
.side { width: 230px; flex: 0 0 230px; background: var(--side); color: var(--side-text); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 18px; padding: 4px 10px 14px; }
.brand:hover { text-decoration: none; }
.brand i { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #6d78f2, #33c5a3); display: inline-block; }
.side select { width: 100%; background: #1d2536; color: #fff; border: 1px solid #2c3650; border-radius: 6px; padding: 7px 8px; margin: 0 0 12px; }
.side .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6f7890; padding: 12px 10px 4px; }
.side nav a { display: block; color: var(--side-text); padding: 7px 10px; border-radius: 6px; }
.side nav a:hover { background: var(--side-active); color: #fff; text-decoration: none; }
.side nav a.on { background: var(--side-active); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #6d78f2; }

main { flex: 1; min-width: 0; padding: 22px 28px 60px; }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.top .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Panels & grids */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.kpi .d { font-size: 12px; margin-top: 2px; }
.up { color: var(--up); }
.down { color: var(--down); }

/* Tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--panel); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
td .url { word-break: break-all; }
a.sort { color: var(--muted); }
.pager { display: flex; gap: 14px; align-items: center; justify-content: flex-end; padding: 10px 2px 0; font-size: 13px; flex-wrap: wrap; }
.trunc { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }

/* Forms & buttons */
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 90px; }
label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 4px; }
label .muted { font-weight: 400; }
.btn, button { font: inherit; font-weight: 600; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 7px; padding: 8px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover, button:hover { filter: brightness(1.08); text-decoration: none; }
.btn.ghost, button.ghost { background: transparent; color: var(--accent); }
.btn.danger, button.danger { background: transparent; border-color: var(--error); color: var(--error); }
.btn.sm, button.sm { padding: 4px 9px; font-size: 12px; }
button:disabled { opacity: .55; cursor: wait; }
.inline { display: inline; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.row > .shrink { flex: 0 0 auto; min-width: 0; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; }
.chip { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip:hover { text-decoration: none; border-color: var(--accent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--text); border-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* Badges & indicators */
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.badge.error { background: color-mix(in srgb, var(--error) 15%, transparent); color: var(--error); }
.badge.warning { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge.notice { background: color-mix(in srgb, var(--notice) 15%, transparent); color: var(--notice); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); }
.tag.informational { background: #e8f1fd; color: #2f69b8; }
.tag.commercial { background: #f3ecfd; color: #7a46c4; }
.tag.transactional { background: #e6f6ee; color: #188154; }
.tag.branded { background: #fdf0e3; color: #b0630f; }
@media (prefers-color-scheme: dark) {
  .tag.informational, .tag.commercial, .tag.transactional, .tag.branded { background: var(--accent-soft); }
}
.score { width: 112px; height: 112px; border-radius: 50%; display: grid; place-items: center; font-size: 30px; font-weight: 800; margin: 4px auto 8px;
  background: conic-gradient(var(--c, var(--good)) calc(var(--v) * 1%), var(--line) 0); position: relative; }
.score::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--panel); }
.score span { position: relative; }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.hbar { display: flex; align-items: center; gap: 8px; margin: 5px 0; font-size: 13px; }
.hbar .lbl { width: 70px; color: var(--muted); }
.hbar .bar { flex: 1; }
.hbar .val { width: 60px; text-align: right; font-variant-numeric: tabular-nums; }
svg.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.6; }
.pos { font-weight: 700; font-variant-numeric: tabular-nums; }
.check { list-style: none; padding: 0; margin: 0; }
.check li { padding: 5px 0; }
.check li::before { content: "○"; margin-right: 8px; color: var(--muted); }
.check li.ok::before { content: "●"; color: var(--good); }

/* Flash messages */
.flash { border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: color-mix(in srgb, var(--good) 10%, var(--panel)); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.flash.warn { background: color-mix(in srgb, var(--warning) 12%, var(--panel)); border-color: color-mix(in srgb, var(--warning) 40%, transparent); }
.flash.error { background: color-mix(in srgb, var(--error) 10%, var(--panel)); border-color: color-mix(in srgb, var(--error) 40%, transparent); }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty h3 { color: var(--text); }
.help { background: var(--accent-soft); border-radius: 8px; padding: 12px 14px; font-size: 13px; }
.help ol, .help ul { margin: 6px 0 0; padding-left: 20px; }
canvas { max-width: 100%; }
.chartbox { position: relative; height: 260px; }

/* Auth pages */
.auth { margin: auto; width: 100%; max-width: 380px; padding: 16px; }
.auth .card { padding: 26px; }

@media (max-width: 960px) {
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  body { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; flex: none; }
  .side nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .side .grp { width: 100%; }
  main { padding: 16px; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .trunc { max-width: 220px; }
}
