:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --seq-bar: #cde2fb;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --bad-text: #b42323;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --seq-bar: #184f95;
    --good-text: #0ca30c;
    --bad-text: #e66767;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--text-2); }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 12px; }
code, pre { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; }
pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; margin: 0; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; gap: 8px; align-items: center; font-weight: 650; color: var(--text); font-size: 15px; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 4px; align-items: center; }
.topbar nav a { color: var(--text-2); padding: 6px 10px; border-radius: 6px; }
.topbar nav a.active { color: var(--text); background: var(--surface-2); }
.topbar nav a:hover { text-decoration: none; background: var(--surface-2); }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }

button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 7px; cursor: pointer; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
button.danger { color: var(--bad-text); }
button:disabled { opacity: .5; cursor: default; }

input, select { font: inherit; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 100%; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.error { color: var(--bad-text); font-size: 13px; min-height: 18px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-sites { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

/* Segmented control for ranges / tabs */
.segmented { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 8px; gap: 2px; }
.segmented button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; color: var(--text-2); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 10px 14px; color: var(--text-2); white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--series-1); font-weight: 600; }

/* Site cards */
.site-card { display: block; color: var(--text); transition: border-color .15s; }
.site-card:hover { text-decoration: none; border-color: var(--axis); }
.site-card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
.site-card .name { font-weight: 600; font-size: 15px; }
.site-card .domain { color: var(--muted); font-size: 12px; }
.site-card .nums { display: flex; gap: 24px; margin-bottom: 10px; }
.site-card .badges { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat .label { font-size: 12px; color: var(--text-2); }
.stat .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat .value.sm { font-size: 18px; }
.delta { font-size: 12px; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--bad-text); }
.delta.flat { color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; }
.status.up .dot { background: var(--good); }
.status.down .dot { background: var(--critical); }
.status.unknown .dot { background: var(--muted); }
.status.up { color: var(--good-text); }
.status.down { color: var(--bad-text); }
.status.unknown { color: var(--muted); }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.live .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* Charts */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.tooltip { position: fixed; pointer-events: none; z-index: 50; background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,.12); padding: 8px 10px; border-radius: 8px; font-size: 12px; min-width: 120px; }
.tooltip .t { color: var(--text-2); margin-bottom: 4px; }
.tooltip .row { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tooltip .row i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }

/* Bar lists (top pages, referrers…) */
.barlist { width: 100%; border-collapse: collapse; table-layout: fixed; }
.barlist th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); padding: 0 0 6px; text-transform: uppercase; letter-spacing: .03em; }
.barlist th.num, .barlist td.num { text-align: right; width: 72px; font-variant-numeric: tabular-nums; }
.barlist td { padding: 2px 0; }
.barlist td.num { padding-left: 10px; }
.barlist .bar { position: relative; padding: 5px 8px; border-radius: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; width: 100%; }
.barlist .bar::before { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--w); background: var(--seq-bar); border-radius: 4px; z-index: 0; }
.barlist .bar span { position: relative; z-index: 1; }
.barlist tr:hover .bar::before { filter: brightness(.95); }
.empty { color: var(--muted); font-size: 13px; padding: 16px 0; text-align: center; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
table.data th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Auth screens */
.auth { max-width: 380px; margin: 10vh auto; }
.auth h1 { margin-bottom: 4px; }
.auth p { margin: 0 0 20px; }

/* Dialog */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); width: min(560px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog form { padding: 20px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.sites-table td:last-child { text-align: right; white-space: nowrap; }
.notice { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; font-size: 13px; color: var(--text-2); }
.notice.err { color: var(--bad-text); }

@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .row-2 { grid-template-columns: 1fr; }
}
