/* ---------- theme tokens ---------- */
:root {
  --bg: #111217;
  --panel: #181b1f;
  --panel-2: #22252b;
  --panel-3: #2a2d33;
  --border: rgba(204, 204, 220, 0.12);
  --border-strong: rgba(204, 204, 220, 0.2);
  --text: #ccccdc;
  --text-strong: #ffffff;
  --muted: rgba(204, 204, 220, 0.65);
  --faint: rgba(204, 204, 220, 0.4);
  --primary: #6e9fff;
  --primary-bg: #3d71d9;
  --primary-bg-hover: #5a86e0;
  --hover: rgba(204, 204, 220, 0.06);
  --match: rgba(110, 159, 255, 0.14);
  --match-edge: #6e9fff;
  --focus: rgba(255, 184, 0, 0.18);
  --focus-edge: #ffb800;
  --error: #ff5286;
  --error-bg: rgba(209, 14, 92, 0.15);
  --ok: #6ccf8e;
  --guide: rgba(204, 204, 220, 0.12);
  --grid: rgba(204, 204, 220, 0.07);
  --cp: #e7e7f0;
  --shade: rgba(17, 18, 23, 0.7);
  --input-bg: #111217;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --row-h: 28px;
  --topbar-h: 48px;
  --mono: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f5; --panel: #ffffff; --panel-2: #f4f5f5; --panel-3: #e9eaeb;
    --border: rgba(36, 41, 46, 0.12); --border-strong: rgba(36, 41, 46, 0.25);
    --text: #24292e; --text-strong: #000; --muted: rgba(36, 41, 46, 0.72); --faint: rgba(36, 41, 46, 0.45);
    --primary: #1f62e0; --primary-bg: #3d71d9; --primary-bg-hover: #2c5bc5;
    --hover: rgba(36, 41, 46, 0.05); --match: rgba(61, 113, 217, 0.12); --match-edge: #3d71d9;
    --focus: rgba(255, 184, 0, 0.22); --focus-edge: #d99a00;
    --error: #e0226e; --error-bg: rgba(224, 34, 110, 0.1); --ok: #1a7f4b;
    --guide: rgba(36, 41, 46, 0.14); --grid: rgba(36, 41, 46, 0.07); --cp: #24292e;
    --shade: rgba(244, 245, 245, 0.75); --input-bg: #fff; --shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4f5f5; --panel: #ffffff; --panel-2: #f4f5f5; --panel-3: #e9eaeb;
  --border: rgba(36, 41, 46, 0.12); --border-strong: rgba(36, 41, 46, 0.25);
  --text: #24292e; --text-strong: #000; --muted: rgba(36, 41, 46, 0.72); --faint: rgba(36, 41, 46, 0.45);
  --primary: #1f62e0; --primary-bg: #3d71d9; --primary-bg-hover: #2c5bc5;
  --hover: rgba(36, 41, 46, 0.05); --match: rgba(61, 113, 217, 0.12); --match-edge: #3d71d9;
  --focus: rgba(255, 184, 0, 0.22); --focus-edge: #d99a00;
  --error: #e0226e; --error-bg: rgba(224, 34, 110, 0.1); --ok: #1a7f4b;
  --guide: rgba(36, 41, 46, 0.14); --grid: rgba(36, 41, 46, 0.07); --cp: #24292e;
  --shade: rgba(244, 245, 245, 0.75); --input-bg: #fff; --shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  color-scheme: light;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12px; }
button { font: inherit; color: inherit; }
h1, h2, h3 { color: var(--text-strong); margin: 0; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--input-bg);
  border: 1px solid var(--border-strong); border-radius: 2px; padding: 4px 8px; height: 32px;
}
textarea { height: auto; font-family: var(--mono); font-size: 12px; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent;
}
input[type="checkbox"] { height: auto; accent-color: var(--primary-bg); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 2px; border: 1px solid var(--border-strong); background: var(--panel-2);
  color: var(--text); cursor: pointer; font-size: 14px; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--panel-3); text-decoration: none; }
.btn-primary { background: var(--primary-bg); border-color: transparent; color: #fff; }
.btn-primary:hover { background: var(--primary-bg-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--error); }
.btn-danger:hover { background: var(--error-bg); }
.notice { margin-top: 12px; padding: 8px 12px; border-left: 3px solid var(--error); background: var(--error-bg); font-size: 13px; line-height: 1.5; }
.notice a { color: inherit; text-decoration: underline; }
.th-note { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.btn-ghost:hover { background: var(--hover); }
.btn-sm { height: 24px; padding: 0 8px; font-size: 12px; }
.btn.icon { padding: 0 8px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn svg { flex: none; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text-strong); font-weight: 500; }
.brand svg { color: var(--primary); }
.brand:hover { text-decoration: none; }
.crumbs { color: var(--muted); font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs b { color: var(--text); font-weight: 500; }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; }

main { padding: 16px; max-width: 100%; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 2px; }
.panel + .panel { margin-top: 8px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-3); color: var(--text-strong); padding: 8px 16px; border-radius: 2px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: all .18s ease; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--error); color: #fff; }

/* ---------- upload page ---------- */
.upload-page { max-width: 880px; margin: 24px auto; }
.upload-page .panel { padding: 24px; }
.upload-page h1 { font-size: 22px; margin-bottom: 4px; }
.upload-page h2 { font-size: 16px; margin-bottom: 12px; }
.dropzone {
  margin-top: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 40px 16px; border: 1px dashed var(--border-strong); border-radius: 2px;
  background: var(--panel-2); cursor: pointer; text-align: center; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--match); }
.dropzone svg { color: var(--muted); }
.dropzone .dz-title { color: var(--text-strong); font-size: 16px; font-weight: 500; }
.dropzone u { color: var(--primary); text-decoration: none; }
.upload-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.paste-box { margin-top: 16px; }
.paste-box summary { cursor: pointer; color: var(--muted); }
.paste-box textarea { width: 100%; min-height: 160px; margin: 8px 0; }
.status { margin-top: 12px; min-height: 22px; }
.status.err { color: var(--error); }
.result-box {
  margin-top: 16px; padding: 12px 16px; border: 1px solid var(--border); background: var(--panel-2);
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.result-box input { flex: 1; min-width: 240px; font-family: var(--mono); font-size: 12px; }
pre.cmd {
  margin: 0; padding: 12px; background: var(--panel-2); border: 1px solid var(--border);
  overflow-x: auto; white-space: pre; color: var(--text);
}
.cmd-row { display: flex; gap: 8px; align-items: center; }
.cmd-row pre.cmd { flex: 1; min-width: 0; }
.cmd-row .btn { flex: none; }
.recent { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; gap: 12px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--border); }
.recent li:first-child { border-top: 0; }
.recent .r-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .r-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- trace header ---------- */
.trace-head { padding: 12px 16px; }
.th-top { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.th-top h1 { font-size: 18px; min-width: 0; overflow-wrap: anywhere; }
.th-top h1 .svc { color: var(--muted); font-weight: 400; }
.th-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.th-actions select { max-width: 340px; }
.th-meta { display: flex; flex-wrap: wrap; gap: 4px 24px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.th-meta b { color: var(--text); font-weight: 500; }
.th-meta .mono { font-size: 12px; }
.tag-err { color: var(--error); }
.copyable { cursor: pointer; border-bottom: 1px dotted var(--faint); }
.copyable:hover { color: var(--text-strong); }

/* ---------- span filters ---------- */
.filters { padding: 8px 16px 12px; }
.filters-head { display: flex; align-items: center; gap: 8px; }
.filters-head h3 { font-size: 14px; }
.filters-head .count { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.filters-head .count b { color: var(--text); font-weight: 500; }
.f-grid { display: grid; grid-template-columns: minmax(240px, 2.4fr) minmax(140px, 1fr) minmax(170px, 1fr) minmax(110px, .7fr); gap: 8px 12px; margin-top: 8px; }
.f-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f-field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.f-field input, .f-field select { width: 100%; }
.f-dur { display: flex; gap: 6px; align-items: center; }
.f-dur input { min-width: 0; }
.f-search { position: relative; }
.f-search svg { position: absolute; left: 8px; top: 9px; color: var(--muted); pointer-events: none; }
.f-search input { padding-left: 28px; }
.f-opts { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 10px; align-items: center; font-size: 13px; }
.f-opts label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.f-opts .spacer { flex: 1; }
.hint { font-size: 12px; color: var(--faint); }

/* ---------- latency hotspots ---------- */
.hotspots { padding: 8px 16px 10px; }
.hotspots summary { cursor: pointer; display: flex; align-items: center; gap: 8px; list-style: none; }
.hotspots summary::-webkit-details-marker { display: none; }
.hotspots summary h3 { font-size: 14px; }
.hotspots summary .chev { transition: transform .15s; color: var(--muted); }
.hotspots[open] summary .chev { transform: rotate(90deg); }
.hs-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }
.hs-item {
  display: grid; grid-template-columns: minmax(0, 1fr) 180px 72px 64px; gap: 12px; align-items: center;
  padding: 4px 8px; border-radius: 2px; cursor: pointer; font-size: 13px;
}
.hs-item:hover { background: var(--hover); }
.hs-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hs-name .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.hs-bar { height: 6px; background: var(--panel-3); border-radius: 3px; overflow: hidden; }
.hs-bar i { display: block; height: 100%; border-radius: 3px; }
.hs-num { text-align: right; font-family: var(--mono); font-size: 12px; }
.hs-pct { text-align: right; color: var(--muted); font-size: 12px; }

/* ---------- timeline ---------- */
.timeline { --name-w: 30%; position: relative; }
.minimap { position: relative; padding: 0 0 0 0; border-bottom: 1px solid var(--border); user-select: none; }
.mm-ticks { position: relative; height: 22px; font-size: 11px; color: var(--muted); }
.mm-ticks span { position: absolute; top: 4px; transform: translateX(-50%); white-space: nowrap; }
.mm-ticks span:first-child { transform: none; padding-left: 4px; }
.mm-ticks span:last-child { transform: translateX(-100%); padding-right: 4px; }
.mm-canvas-wrap { position: relative; height: 60px; cursor: crosshair; }
.mm-canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.mm-shade { position: absolute; top: 0; bottom: 0; background: var(--shade); pointer-events: none; }
.mm-win { position: absolute; top: 0; bottom: 0; border-left: 2px solid var(--primary); border-right: 2px solid var(--primary); pointer-events: none; }
.mm-sel { position: absolute; top: 0; bottom: 0; background: rgba(110, 159, 255, 0.25); border: 1px solid var(--primary); pointer-events: none; }
.mm-grid { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--grid); pointer-events: none; }
.zoom-bar { position: absolute; right: 8px; top: 26px; z-index: 2; }

.tl-header {
  position: sticky; top: var(--topbar-h); z-index: 20; display: flex; height: 32px;
  background: var(--panel-2); border-bottom: 1px solid var(--border); font-size: 12px;
}
.tl-name-h { width: var(--name-w); flex: none; display: flex; align-items: center; gap: 2px; padding: 0 4px 0 8px; position: relative; color: var(--muted); }
.tl-name-h .lbl { font-weight: 500; color: var(--text); margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-name-h .btn { height: 22px; padding: 0 4px; color: var(--muted); }
.tl-name-h .btn:hover { color: var(--text-strong); }
.tl-ticks { position: relative; flex: 1; min-width: 0; cursor: crosshair; user-select: none; overflow: hidden; }
.tl-ticks span { position: absolute; top: 7px; color: var(--muted); white-space: nowrap; padding-left: 4px; }
.tl-ticks span:last-child { transform: translateX(-100%); padding: 0 6px 0 0; }
.tl-ticks i { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border); }
.tl-ticks .sel { position: absolute; top: 0; bottom: 0; background: rgba(110, 159, 255, 0.25); border: 1px solid var(--primary); }
.resizer {
  position: absolute; right: -4px; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 3;
}
.resizer::after { content: ""; position: absolute; left: 3px; top: 0; bottom: 0; width: 2px; background: var(--border-strong); }
.resizer:hover::after, .resizer.active::after { background: var(--primary); }

.tl-body { position: relative; overflow: hidden; }
.tl-grid { position: absolute; top: 0; bottom: 0; right: 0; left: var(--name-w); pointer-events: none; }
.tl-grid i { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--grid); }
.tl-grid .name-edge { left: 0; background: var(--border); }

.row {
  position: absolute; left: 0; right: 0; height: var(--row-h); display: flex; cursor: pointer;
  border-bottom: 1px solid transparent;
}
.row:hover { background: var(--hover); }
.row.match { background: var(--match); }
.row.match .nc { box-shadow: inset 2px 0 0 var(--match-edge); }
.row.focused { background: var(--focus); }
.row.focused .nc { box-shadow: inset 2px 0 0 var(--focus-edge); }
.row.dim .nc .op, .row.dim .nc .svc { opacity: .5; }
.row.dim .bar { opacity: .35; }
.row.open { background: var(--panel-2); }

.nc {
  width: var(--name-w); flex: none; display: flex; align-items: center; gap: 4px; min-width: 0;
  padding-right: 8px; white-space: nowrap; overflow: hidden; border-right: 1px solid var(--border);
}
.ind {
  flex: none; height: 100%;
  background-image: repeating-linear-gradient(to right, transparent 0 9px, var(--guide) 9px 10px, transparent 10px 16px);
}
.tg {
  flex: none; width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; padding: 0; cursor: pointer; color: var(--muted); border-radius: 2px;
}
.tg:hover { background: var(--panel-3); color: var(--text-strong); }
.tg svg { transition: transform .12s; }
.tg.collapsed svg { transform: rotate(-90deg); }
.tg-sp { flex: none; width: 18px; }
.sw { flex: none; width: 4px; height: 16px; border-radius: 1px; }
.nc .svc { color: var(--text-strong); font-weight: 500; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; max-width: 45%; }
.nc .op { color: var(--muted); overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; min-width: 30px; }
.badge {
  flex: none; font-size: 11px; line-height: 16px; padding: 0 5px; border-radius: 8px; background: var(--panel-3);
  color: var(--muted);
}
.err-ic { flex: none; color: var(--error); display: inline-flex; }

.tc { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.bar {
  position: absolute; top: 7px; height: 14px; border-radius: 2px; min-width: 2px;
}
.bar.err { box-shadow: 0 0 0 1px var(--error); }
.cp { position: absolute; top: 13px; height: 2px; background: var(--cp); pointer-events: none; opacity: .85; }
.ev { position: absolute; top: 5px; width: 1px; height: 18px; background: var(--text-strong); opacity: .6; pointer-events: none; }
.dur { position: absolute; top: 5px; font-size: 11px; color: var(--muted); white-space: nowrap; pointer-events: none; }
.off-l, .off-r { position: absolute; top: 6px; font-size: 11px; color: var(--faint); }
.off-l { left: 4px; } .off-r { right: 4px; }

/* ---------- span detail ---------- */
.detail {
  position: absolute; left: 0; right: 0; padding: 0 0 0 0; background: var(--panel-2);
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); cursor: default;
}
.detail-inner { margin-left: calc(var(--name-w) * 0.25); border-left: 3px solid var(--c); padding: 12px 16px 14px; background: var(--panel); }
.d-head { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.d-title { font-size: 15px; color: var(--text-strong); font-weight: 500; overflow-wrap: anywhere; }
.d-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.d-meta { display: flex; flex-wrap: wrap; gap: 2px 20px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.d-meta b { color: var(--text); font-weight: 500; }
.d-status-err { margin-top: 8px; padding: 6px 10px; background: var(--error-bg); border-left: 3px solid var(--error); color: var(--text); font-size: 13px; overflow-wrap: anywhere; }
.d-sec { margin-top: 10px; }
.d-sec > summary { cursor: pointer; font-size: 13px; font-weight: 500; color: var(--text); list-style: none; display: flex; align-items: center; gap: 6px; }
.d-sec > summary::-webkit-details-marker { display: none; }
.d-sec > summary .chev { color: var(--muted); transition: transform .12s; }
.d-sec[open] > summary .chev { transform: rotate(90deg); }
.d-sec > summary .n { color: var(--muted); font-weight: 400; }
.kv { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 12px; table-layout: fixed; }
.kv td { padding: 3px 8px; border-top: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.kv tr:nth-child(odd) td { background: var(--panel-2); }
.kv td.k { width: 32%; color: var(--muted); font-family: var(--mono); }
.kv td.v { font-family: var(--mono); color: var(--text); white-space: pre-wrap; }
.kv td.v.num { color: #73bf69; }
.kv td.v.bool { color: #ff9830; }
.ev-list { margin-top: 6px; display: grid; gap: 6px; }
.ev-item { border: 1px solid var(--border); padding: 6px 10px; }
.ev-item .ev-h { display: flex; gap: 12px; font-size: 12px; }
.ev-item .ev-h b { color: var(--text-strong); font-weight: 500; }
.ev-item.exception { border-color: var(--error); }
.d-foot { margin-top: 10px; font-size: 12px; color: var(--muted); display: flex; gap: 20px; flex-wrap: wrap; }

.empty, .loading { padding: 48px; text-align: center; color: var(--muted); }
.error-page { max-width: 560px; margin: 64px auto; padding: 32px; text-align: center; }
.error-page h1 { font-size: 20px; margin-bottom: 8px; }

@media (max-width: 900px) {
  .f-grid { grid-template-columns: 1fr 1fr; }
  .f-grid .f-search-field { grid-column: 1 / -1; }
  .hs-item { grid-template-columns: minmax(0, 1fr) 80px 64px; }
  .hs-item .hs-bar { display: none; }
  .timeline { --name-w: 40% !important; }
}
@media (max-width: 560px) {
  main { padding: 8px; }
  .f-grid { grid-template-columns: 1fr; }
  .crumbs { display: none; }
}
