:root {
  color-scheme: dark;
  --bg: #0d1217;
  --panel: #131a21;
  --panel-2: #18212a;
  --line: #24303b;
  --text: #d9e2ea;
  --dim: #8496a6;
  --faint: #5d6e7d;
  --client: #63c7b2;
  --server: #7fa8ff;
  --airlock: #e8b04a;
  --ok: #5fbf7f;
  --bad: #f0707a;
  --warn: #e8b04a;
  --drift: #b18cff;
  --sel: #1e2d3a;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-2: #f0f3f6;
    --line: #dde3e9;
    --text: #1b2630;
    --dim: #5a6b7a;
    --faint: #8a99a6;
    --client: #13866f;
    --server: #3563d6;
    --airlock: #a86d00;
    --ok: #2e8b4f;
    --bad: #c8323f;
    --warn: #a86d00;
    --drift: #7a4fd6;
    --sel: #e6eef6;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  display: grid;
  grid-template-rows: auto auto 1fr;
  overflow: hidden;
}

code, pre, .time, .lat, .cmd { font-family: var(--mono); }

/* ------------------------------------------------------------ top bar */

.top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { font-weight: 650; letter-spacing: .02em; display: flex; align-items: center; gap: 9px; font-size: 15px; }

.mark {
  width: 18px; height: 18px; border-radius: 5px;
  border: 2px solid var(--airlock);
  background: linear-gradient(90deg, transparent 30%, var(--client) 30% 42%, transparent 42% 58%, var(--client) 58% 70%, transparent 70%);
}

.mode { font-weight: 400; color: var(--faint); font-size: 12px; margin-left: 2px; }

select, input[type="search"], .open-btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
}

select { max-width: 46ch; }
.open-btn { cursor: pointer; }
.open-btn:hover { border-color: var(--faint); }
.hint { color: var(--faint); font-size: 12.5px; }
.status { margin-left: auto; color: var(--dim); }

/* ------------------------------------------------------------ summary */

.summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 24px;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.cmd { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prompt { color: var(--faint); }

.facts { grid-column: 1; display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--dim); font-size: 13px; }

.tallies { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 8px; align-items: center; }

.tally {
  font: inherit; font-size: 12.5px; color: var(--dim);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 11px; cursor: pointer;
}
.tally b { color: var(--text); font-size: 13.5px; }
.tally.bad b { color: var(--bad); }
.tally.warn b { color: var(--warn); }
.tally.drift b { color: var(--drift); }

.integrity { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--dim); }
.integrity .ok { color: var(--ok); }
.integrity .ok:first-child::before { content: "✓ "; }
.integrity .bad { color: var(--bad); }
.integrity .bad:first-child::before { content: "✕ "; }
.integrity .sep { color: var(--faint); }
.integrity.pending { color: var(--faint); }

/* --------------------------------------------------------------- main */

main {
  display: grid;
  grid-template-columns: minmax(520px, 1.15fr) minmax(380px, 1fr);
  min-height: 0;
}

.list { display: grid; grid-template-rows: auto 1fr; min-height: 0; border-right: 1px solid var(--line); }

.toolbar { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line); }

#filters { display: flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 2px; }
#filters button {
  font: inherit; font-size: 12.5px; color: var(--dim);
  background: none; border: 0; border-radius: 5px; padding: 3px 9px; cursor: pointer;
}
#filters button.on { background: var(--sel); color: var(--text); }
#search { width: 13ch; padding: 3px 8px; font-size: 12.5px; }
.count { margin-left: auto; color: var(--faint); font-size: 12px; }

#rows { list-style: none; margin: 0; padding: 4px 0 24px; overflow: auto; }

.row {
  display: grid;
  grid-template-columns: 64px 18px minmax(0, 1fr) auto 104px;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  border-left: 3px solid transparent;
  cursor: pointer;
  font-size: 13px;
}
.row:hover { background: var(--panel); }
.row.sel { background: var(--sel); border-left-color: var(--airlock); }

.time { color: var(--faint); font-size: 11.5px; }
.arrow { text-align: center; font-size: 12px; }
.from-client .arrow { color: var(--client); }
.from-server .arrow { color: var(--server); }
.row.event .arrow { color: var(--airlock); }

.what { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.what b { font-weight: 600; }
.what .method { font-weight: 450; color: var(--dim); font-family: var(--mono); font-size: 12.5px; }
.what .sub { margin-left: 10px; color: var(--faint); font-family: var(--mono); font-size: 12px; }

.lat { position: relative; text-align: right; color: var(--dim); font-size: 11.5px; padding-bottom: 3px; }
.lat .bar { position: absolute; right: 0; bottom: 0; height: 2px; width: var(--w, 0); background: var(--server); opacity: .55; border-radius: 2px; }
.row.blocked .lat .bar { background: var(--bad); }

.row.note .what, .row.meta .what { color: var(--dim); }
.row.meta { font-size: 12px; }
.row.meta .what { color: var(--faint); font-style: italic; }
.row.stderr .what { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.row.stderr .arrow { color: var(--faint); }
.row.stopped .what .method { text-decoration: line-through; }

.row.blocked { border-left-color: color-mix(in srgb, var(--bad) 70%, transparent); }
.row.ev-drift { border-left-color: var(--drift); }
.row.ev-drift .arrow, .row.ev-drift b { color: var(--drift); }
.row.ev-suspicious .arrow, .row.ev-new_tool .arrow { color: var(--warn); }
.row.sel.blocked, .row.sel.ev-drift { border-left-color: var(--airlock); }

.chips { display: flex; gap: 4px; justify-content: flex-end; }
.chip {
  font-size: 11px; line-height: 16px; padding: 0 7px; border-radius: 999px;
  border: 1px solid currentColor; white-space: nowrap; font-weight: 500;
}
.chip.ok { color: var(--ok); border-color: transparent; background: color-mix(in srgb, var(--ok) 13%, transparent); }
.chip.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.chip.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.chip.dim { color: var(--faint); }

/* ------------------------------------------------------------- detail */

.detail { overflow: auto; padding: 16px 22px 40px; min-height: 0; }
.empty { color: var(--faint); }

.dhead { display: flex; align-items: baseline; gap: 12px; justify-content: space-between; }
.dhead h2 { margin: 0 0 8px; font-size: 17px; font-weight: 620; }
.dhead h2 b { font-weight: 650; color: var(--drift); }
.dhead .m { margin-left: 10px; font: 400 12.5px var(--mono); color: var(--faint); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 4px 0 10px; font-size: 13px; }
dl.facts dt { color: var(--faint); }
dl.facts dd { margin: 0; font-family: var(--mono); font-size: 12.5px; }

.reason { margin: 8px 0; padding: 8px 11px; border-radius: 7px; background: var(--panel); border: 1px solid var(--line); }
.reason.bad { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.reason.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }

section > h3 { margin: 18px 0 6px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); font-weight: 600; }

pre {
  margin: 0; padding: 10px 12px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
}
.j-key { color: var(--server); }
.j-str { color: var(--text); }
.j-num, .j-bool { color: var(--client); }
.j-null { color: var(--faint); }
.dim { color: var(--faint); }

.hid {
  border-radius: 3px; padding: 0 3px; margin: 0 1px;
  font-style: italic; outline: 1px dashed currentColor; outline-offset: -1px;
}
.hid.tag { color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, transparent); }
.hid.tag::before { content: "hidden: "; font-style: normal; opacity: .75; }
.hid.inv { color: var(--warn); font-size: 11px; }
.redacted { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); border-radius: 3px; padding: 0 2px; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
td, th { text-align: left; padding: 4px 8px 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--faint); font-weight: 500; font-size: 12px; }
table.flags td:last-child { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }

.wdiff { padding: 10px 12px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; }
.wdiff .del { color: var(--bad); text-decoration: line-through; background: color-mix(in srgb, var(--bad) 10%, transparent); }
.wdiff .ins { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }

.ldiff { padding: 6px 0; }
.ldiff div { padding: 0 12px; }
.ldiff .sign { display: inline-block; width: 1.4em; color: var(--faint); user-select: none; }
.ldiff .del { background: color-mix(in srgb, var(--bad) 11%, transparent); color: var(--bad); }
.ldiff .ins { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.ldiff .eq { color: var(--dim); }

/* ------------------------------------------------------------- drop zone */

.dropzone { display: none; }
body.dropping .dropzone {
  display: grid; place-items: center;
  position: fixed; inset: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border: 3px dashed var(--airlock); border-radius: 14px; margin: 12px;
  font-size: 20px; color: var(--airlock);
}

@media (max-width: 980px) {
  body { overflow: auto; display: block; }
  main { grid-template-columns: 1fr; }
  .list { border-right: 0; }
  #rows { max-height: 60vh; }
  .hint { display: none; }
  .summary { grid-template-columns: 1fr; }
  .tallies { grid-column: 1; grid-row: auto; flex-wrap: wrap; }
}
