/* Tokens from the validated reference palette. Dark is a selected set of steps
   for the dark surface, not an inverted light mode. */
:root {
  color-scheme: light;
  --surface-0:  #f4f3f0;
  --surface-1:  #fcfcfb;
  --surface-2:  #f0efec;
  --border:     #e0dfda;
  --text-1:     #0b0b0b;
  --text-2:     #52514e;
  --text-3:     #85837c;
  --series-1:   #2a78d6;   /* humans */
  --series-2:   #eb6834;   /* bots */
  --series-1-soft: #cde2fb;
  --grid:       #eceae5;
  --danger:     #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #131312;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --border:    #383835;
    --text-1:    #ffffff;
    --text-2:    #c3c2b7;
    --text-3:    #8e8d84;
    --series-1:  #3987e5;
    --series-2:  #d95926;
    --series-1-soft: #184f95;
    --grid:      #2b2b29;
    --danger:    #e66767;
  }
}

* { box-sizing: border-box; }
/* An author `display` rule outranks the UA stylesheet's [hidden] rule, so
   .gate/.drawer would ignore the hidden attribute without this. */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-1);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", "PingFang TC", "Noto Sans TC", sans-serif;
}
h1, h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
.muted { color: var(--text-3); font-weight: 400; font-size: 12px; }
.err { color: var(--danger); font-size: 13px; }
button { font: inherit; cursor: pointer; }

/* ------------------------------------------------------------------- gate */
.gate {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--surface-0); z-index: 50; padding: 20px;
}
.gate-box {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; width: min(360px, 100%); display: grid; gap: 12px;
}
.gate-box input, .gate-box button {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-1); font-size: 14px;
}
.gate-box button { background: var(--series-1); color: #fff; border-color: transparent; font-weight: 600; }

/* ----------------------------------------------------------------- shell */
.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  justify-content: space-between; padding: 14px 20px;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.segmented { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button {
  border: 0; background: var(--surface-1); color: var(--text-2);
  padding: 6px 12px; font-size: 13px;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.on { background: var(--series-1); color: #fff; font-weight: 600; }

.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }
.ghost {
  border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-2); border-radius: 8px; padding: 6px 10px;
}

.tabs { display: flex; gap: 4px; padding: 10px 20px 0; background: var(--surface-1);
        border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  border: 0; background: none; color: var(--text-2); padding: 8px 12px;
  border-bottom: 2px solid transparent; font-size: 13px; white-space: nowrap;
}
.tabs button.on { color: var(--text-1); border-bottom-color: var(--series-1); font-weight: 600; }

main { padding: 20px; display: grid; gap: 16px; max-width: 1200px; margin: 0 auto; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.hint { margin: 10px 0 0; }
.note {
  margin: 0 0 14px; padding: 10px 12px; border-radius: 8px;
  background: var(--surface-2); color: var(--text-2); font-size: 13px;
  border-left: 3px solid var(--series-2);
}

/* ------------------------------------------------------------- stat tiles */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.tile .k { font-size: 12px; color: var(--text-3); }
.tile .v { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px;
           font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--text-3); }

/* ----------------------------------------------------------------- charts */
.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; }
.axis-text { fill: var(--text-3); font-size: 11px; }
.bar-label { fill: var(--text-1); font-size: 12px; }
.bar-value { fill: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.bar-row { cursor: pointer; }
.bar-row:hover .bar-rect { opacity: 0.82; }
.bar-row:hover .bar-label { fill: var(--series-1); }

/* ----------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-3); font-weight: 500; font-size: 12px; position: sticky; top: 0;
     background: var(--surface-1); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
.ip { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.clickable { cursor: pointer; color: var(--series-1); }
.clickable:hover { text-decoration: underline; }
.scroll { max-height: 640px; overflow: auto; }
.ua { color: var(--text-3); font-size: 12px; max-width: 320px;
      overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px;
  border: 1px solid var(--border); color: var(--text-2); background: var(--surface-2);
}
.tag.bot { border-color: var(--series-2); color: var(--series-2); }

/* ----------------------------------------------------------------- drawer */
.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex;
          justify-content: flex-end; }
.drawer-panel {
  background: var(--surface-0); width: min(760px, 100%); height: 100%;
  overflow-y: auto; padding: 20px; position: relative;
  border-left: 1px solid var(--border);
}
.drawer-panel .close { position: absolute; top: 14px; right: 16px; }
.drawer-panel .card { margin-bottom: 14px; }

/* --------------------------------------------------------------- tooltip */
.tip {
  position: fixed; pointer-events: none; z-index: 60;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 12px; color: var(--text-1);
  box-shadow: 0 4px 14px rgba(0,0,0,.16); white-space: nowrap;
}
.foot { padding: 8px 20px 24px; text-align: center; }
