:root {
    --canvas: #eef1f4;
    --surface: #ffffff;
    --surface-2: #f6f8fa;
    --hover: #f1f4f8;
    --ink: #18212c;
    --ink-2: #4b5664;
    --ink-3: #7b8594;
    --rule: #dfe4ea;
    --rule-strong: #c9d0d9;
    --accent: #2f45c8;
    --accent-ink: #ffffff;
    --select: #e8ecff;
    --select-rule: #2f45c8;
    --ok: #1d7a4c;
    --ok-bg: #e5f4ec;
    --redirect: #5b54b8;
    --redirect-bg: #eeedfb;
    --client: #a65a00;
    --client-bg: #fdf0dc;
    --server: #c0262d;
    --server-bg: #fde7e7;
    --info-bg: #e9eefb;
    --warn-bg: #fdf3e1;
    --code-bg: #f6f8fa;
    --j-key: #7a3e9d;
    --j-str: #1d6b48;
    --j-num: #1f55b5;
    --j-lit: #a34a00;
    --bar: #9aa6b6;
    --bar-mid: #d49a2a;
    --bar-slow: #d0453e;
    --shadow: 0 8px 28px rgba(16, 24, 40, 0.14);
    --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
    --detail-w: 46%;
}

@media (prefers-color-scheme: dark) {
    :root {
        --canvas: #0d1117;
        --surface: #151b23;
        --surface-2: #1a212b;
        --hover: #1d2530;
        --ink: #e4e9f0;
        --ink-2: #a9b3c1;
        --ink-3: #7c8796;
        --rule: #262f3b;
        --rule-strong: #364152;
        --accent: #8597ff;
        --accent-ink: #0d1117;
        --select: #1f2850;
        --select-rule: #8597ff;
        --ok: #5cc98f;
        --ok-bg: #12301f;
        --redirect: #a9a2ff;
        --redirect-bg: #25234a;
        --client: #f0b252;
        --client-bg: #3a2a10;
        --server: #ff7b7b;
        --server-bg: #3d1719;
        --info-bg: #1b2440;
        --warn-bg: #352812;
        --code-bg: #10151c;
        --j-key: #d2a8ff;
        --j-str: #7ee2a8;
        --j-num: #79c0ff;
        --j-lit: #ffa657;
        --bar: #5b6676;
        --bar-mid: #d6a347;
        --bar-slow: #f06a63;
        --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { font: 13px/1.45 var(--font); background: var(--canvas); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-3); }
.grow { flex: 1; }
.clip { position: fixed; left: -9999px; top: 0; }

.btn {
    display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
    border: 1px solid var(--rule-strong); border-radius: 6px; background: var(--surface); cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.is-on { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-icon { width: 28px; padding: 0; justify-content: center; font-size: 16px; }
.btn-sm { height: 24px; padding: 0 8px; font-size: 12px; }
.btn-xs { height: 20px; padding: 0 6px; font-size: 11px; border-radius: 4px; }
input[type="text"], input[type="search"], input[type="number"], input[type="password"], input[type="datetime-local"], select {
    height: 28px; padding: 0 8px; border: 1px solid var(--rule-strong); border-radius: 6px; background: var(--surface);
}
select { padding-right: 4px; max-width: 220px; }

.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--canvas); z-index: 50; }
.login-box { width: min(340px, calc(100vw - 32px)); display: grid; gap: 6px; padding: 28px; background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; box-shadow: var(--shadow); }
.login-box h1 { font-size: 18px; }
.login-hint { color: var(--ink-2); margin-bottom: 10px; }
.login-box label { font-weight: 600; font-size: 12px; color: var(--ink-2); }
.login-box input { height: 34px; margin-bottom: 6px; }
.login-box .btn { height: 34px; justify-content: center; margin-top: 6px; }
.login-error { color: var(--server); min-height: 1.4em; }

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 14px; margin-right: 6px; letter-spacing: -0.01em; }
.search { position: relative; flex: 0 1 380px; min-width: 220px; }
.search input { width: 100%; padding-right: 28px; }
.search-key { position: absolute; right: 7px; top: 5px; font: 11px var(--mono); color: var(--ink-3); border: 1px solid var(--rule-strong); border-radius: 4px; padding: 0 5px; }
.search input:focus + .search-key { display: none; }
.topbar-spacer { flex: 1; }
.count:not(:empty) { margin-left: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.refresh-status { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.live { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; color: var(--ink-2); }
.live input { accent-color: var(--accent); }
.user { color: var(--ink-2); padding-left: 8px; border-left: 1px solid var(--rule); }

.filterbar { display: flex; align-items: center; gap: 12px; padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.quick { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 6px; overflow: hidden; }
.quick button { height: 26px; padding: 0 11px; border: 0; border-right: 1px solid var(--rule); background: var(--surface); cursor: pointer; color: var(--ink-2); }
.quick button:last-child { border-right: 0; }
.quick button:hover { background: var(--hover); }
.quick button.is-on { background: var(--select); color: var(--accent); font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 2px; height: 24px; padding: 0 2px 0 9px; border-radius: 12px; background: var(--select); color: var(--ink); font-size: 12px; max-width: 360px; }
.chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-x { width: 20px; height: 20px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; color: var(--ink-2); font-size: 14px; line-height: 1; }
.chip-x:hover { background: var(--rule); }

.advanced { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; padding: 10px 12px 12px; background: var(--surface-2); border-bottom: 1px solid var(--rule); }
.advanced label { display: grid; gap: 3px; font-size: 12px; color: var(--ink-2); }
.advanced label.check { display: flex; align-items: center; gap: 6px; height: 28px; }
.advanced .custom-range { display: none; }
.advanced.show-custom .custom-range { display: grid; }
.advanced-actions { display: flex; gap: 6px; margin-left: auto; }
.w-s { width: 120px; }
.w-m { width: 190px; }
.w-l { width: 300px; }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.workspace.has-detail { grid-template-columns: minmax(420px, 1fr) 6px var(--detail-w); }
.workspace.is-resizing { cursor: col-resize; user-select: none; }

.list { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.progress { position: absolute; top: 0; left: 0; right: 0; height: 2px; z-index: 3; overflow: hidden; }
.progress::after { content: ''; position: absolute; inset: 0; width: 30%; background: var(--accent); animation: slide 0.9s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.table-scroll { flex: 1; overflow: auto; min-height: 0; }
table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
thead th {
    position: sticky; top: 0; z-index: 2; background: var(--surface-2); border-bottom: 1px solid var(--rule);
    text-align: left; font-weight: 600; font-size: 12px; color: var(--ink-2); padding: 6px 8px; white-space: nowrap; user-select: none;
}
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { color: var(--ink); }
th.is-sorted { color: var(--ink); }
th.is-sorted::after { content: ' ↓'; color: var(--accent); }
th.is-sorted[data-dir="asc"]::after { content: ' ↑'; }
tbody tr { cursor: pointer; }
tbody td { padding: 0 8px; height: 30px; border-bottom: 1px solid var(--rule); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
tbody tr:hover td { background: var(--hover); }
tbody tr.is-selected td { background: var(--select); }
tbody tr.is-selected td:first-child { box-shadow: inset 3px 0 0 var(--select-rule); }
tbody.is-stale { opacity: 0.55; transition: opacity 0.15s 0.2s; }

.c-time { width: 128px; font: 12px var(--mono); font-variant-numeric: tabular-nums; color: var(--ink-2); }
thead .c-time { font: inherit; font-weight: 600; font-size: 12px; }
.c-method { width: 72px; }
.c-path { width: auto; }
.c-status { width: 62px; }
.c-duration { width: 140px; }
.c-tenant { width: 110px; color: var(--ink-2); }
.c-user { width: 130px; color: var(--ink-2); }
.c-rid { width: 190px; font: 12px var(--mono); color: var(--ink-2); }
thead .c-rid { font: inherit; font-weight: 600; font-size: 12px; }
.c-exc { width: 34px; text-align: center; }
tbody td.c-exc { padding: 0; text-overflow: clip; }
.workspace.has-detail .c-user, .workspace.has-detail .c-tenant, .workspace.has-detail .c-rid { display: none; }
@media (min-width: 1700px) {
    .workspace.has-detail .c-tenant { display: table-cell; }
}

.path { font-family: var(--mono); font-size: 12px; }
.query { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }

.method { display: inline-block; min-width: 50px; font: 600 11px var(--mono); letter-spacing: 0.02em; }
.m-get { color: var(--j-num); }
.m-post { color: var(--ok); }
.m-put, .m-patch { color: var(--client); }
.m-delete { color: var(--server); }
.m-other { color: var(--ink-3); }

.status { display: inline-block; padding: 1px 6px; border-radius: 4px; font: 600 12px var(--mono); }
.s2 { color: var(--ok); background: var(--ok-bg); }
.s3 { color: var(--redirect); background: var(--redirect-bg); }
.s4 { color: var(--client); background: var(--client-bg); }
.s5 { color: var(--server); background: var(--server-bg); }

.dur { display: grid; grid-template-columns: 58px 1fr; align-items: center; gap: 8px; }
.dur-text { font: 12px var(--mono); font-variant-numeric: tabular-nums; text-align: right; color: var(--ink-2); }
.dur-track { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar { display: block; height: 100%; width: var(--w); border-radius: 3px; background: var(--bar); }
.bar-mid { background: var(--bar-mid); }
.bar-slow { background: var(--bar-slow); }

.exc-dot { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--server); color: #fff; font: 700 11px var(--font); }

.list-message { padding: 40px 24px; }
.empty { display: grid; gap: 6px; justify-items: start; max-width: 520px; margin: 0 auto; color: var(--ink-2); }
.empty strong { color: var(--ink); font-size: 15px; }
.empty-actions { display: flex; gap: 8px; margin-top: 6px; }

.pager { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-top: 1px solid var(--rule); background: var(--surface-2); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.pager-keys { flex: 1; text-align: right; color: var(--ink-3); font-size: 12px; padding-right: 8px; }

.splitter { cursor: col-resize; background: var(--rule); border-left: 2px solid var(--canvas); border-right: 2px solid var(--canvas); }
.splitter:hover, .splitter:focus-visible, .is-resizing .splitter { background: var(--accent); }

.detail { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); border-left: 1px solid var(--rule); }
.detail.is-loading { opacity: 0.6; }
.detail-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--rule); display: grid; gap: 8px; }
.detail-title { display: flex; align-items: flex-start; gap: 8px; }
.detail-title .method { padding-top: 2px; min-width: 0; }
.detail-path { flex: 1; font: 13px/1.45 var(--mono); word-break: break-all; user-select: text; }
.detail-close { flex: none; margin: -3px -4px 0 0; border-color: transparent; font-size: 20px; color: var(--ink-2); }
.detail-facts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.fact { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.fact-exc { color: var(--server); font-weight: 600; }
.detail-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 16px; }
.meta dt { font-size: 11px; color: var(--ink-3); }
.meta dd { display: flex; align-items: center; gap: 6px; min-width: 0; }
.meta dd > span { font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: all; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.tabs { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--rule); background: var(--surface); }
.tab { position: relative; height: 34px; padding: 0 10px; border: 0; background: transparent; cursor: pointer; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { color: var(--ink); }
.tab.is-on { color: var(--ink); font-weight: 600; }
.tab.is-on::after { content: ''; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }
.tab-exc { color: var(--server); }
.tab-exc.is-on { color: var(--server); }
.tab-exc.is-on::after { background: var(--server); }
.tab-count { font-size: 11px; padding: 0 6px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--rule); color: var(--ink-2); font-weight: 600; }
.tab-body { flex: 1; overflow: auto; padding: 4px 14px 24px; min-height: 0; }

.section { border-bottom: 1px solid var(--rule); padding: 8px 0; }
.section:last-child { border-bottom: 0; }
.section > summary { display: flex; align-items: baseline; gap: 10px; cursor: pointer; padding: 4px 0 6px; list-style: none; }
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before { content: '▸'; color: var(--ink-3); font-size: 11px; width: 10px; }
.section[open] > summary::before { content: '▾'; }
.section-title { font-weight: 600; }
.section-meta { color: var(--ink-3); font: 12px var(--mono); }

.notice { display: flex; flex-wrap: wrap; gap: 4px 6px; padding: 8px 10px; border-radius: 6px; margin: 4px 0 8px; background: var(--surface-2); color: var(--ink-2); }
.notice strong { color: var(--ink); }
.notice-info { background: var(--info-bg); }
.notice-warn { background: var(--warn-bg); }
.notice-error { background: var(--server-bg); }
.notice-error strong { color: var(--server); }

.body-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 8px; }
.segmented { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 6px; overflow: hidden; }
.seg { height: 24px; padding: 0 9px; border: 0; border-right: 1px solid var(--rule); background: var(--surface); cursor: pointer; font-size: 12px; color: var(--ink-2); }
.seg:last-child { border-right: 0; }
.seg.is-on { background: var(--select); color: var(--accent); font-weight: 600; }

.code {
    font: 12px/1.55 var(--mono); background: var(--code-bg); border: 1px solid var(--rule); border-radius: 6px; padding: 10px 12px;
    white-space: pre-wrap; word-break: break-word; overflow: auto; max-height: 70vh; user-select: text; tab-size: 2;
}
.code-exc { color: var(--server); }
details.raw > summary { cursor: pointer; color: var(--ink-2); margin: 6px 0; }

.json-tree { font: 12px/1.6 var(--mono); background: var(--code-bg); border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px 8px 4px; overflow: auto; max-height: 70vh; user-select: text; }
.j-row { padding-left: 18px; white-space: pre-wrap; word-break: break-word; position: relative; }
.j-branch { padding-left: 18px; }
.j-children { padding-left: 16px; border-left: 1px dotted var(--rule-strong); margin-left: 7px; }
.j-close { display: none; }
.j-node > .j-row.is-open ~ .j-close { display: block; }
.j-row.is-open .j-summary, .j-row.is-open .j-close-inline { display: none; }
.j-toggle { position: absolute; left: 2px; top: 3px; width: 14px; height: 14px; border: 0; background: transparent; cursor: pointer; color: var(--ink-3); font-size: 10px; line-height: 14px; }
.j-toggle::before { content: '▸'; }
.j-toggle[aria-expanded="true"]::before { content: '▾'; }
.j-summary { color: var(--ink-3); cursor: pointer; margin: 0 4px; font-style: italic; }
.j-summary:hover { color: var(--accent); }
.j-key { color: var(--j-key); }
.j-index { color: var(--ink-3); }
.j-str { color: var(--j-str); }
.j-num { color: var(--j-num); }
.j-bool, .j-null { color: var(--j-lit); }
.j-punct { color: var(--ink-3); }
.j-redacted { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--warn-bg); color: var(--client); font: 600 11px var(--font); border: 1px dashed var(--client); }
.j-more { padding: 4px 0 4px 18px; }

.kv { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
.kv th, .kv td { padding: 4px 8px; border-bottom: 1px solid var(--rule); vertical-align: top; text-align: left; }
.kv th { width: 34%; font: 600 12px var(--mono); color: var(--ink-2); word-break: break-all; }
.kv td { font-family: var(--mono); word-break: break-all; user-select: text; }
.kv tr:last-child th, .kv tr:last-child td { border-bottom: 0; }

.exc-head { padding: 12px 0 8px; }
.exc-type { font: 600 13px var(--mono); color: var(--server); word-break: break-all; }
.exc-message { font-size: 14px; margin: 6px 0 4px; white-space: pre-wrap; word-break: break-word; user-select: text; }
.exc-inner { border-top: 1px solid var(--rule); padding: 10px 0; }
.exc-inner h4 { font-size: 12px; color: var(--ink-3); font-weight: 600; margin-bottom: 4px; }
.frames { list-style: none; font: 12px/1.55 var(--mono); background: var(--code-bg); border: 1px solid var(--rule); border-radius: 6px; padding: 6px 10px; margin-top: 6px; user-select: text; }
.frame { color: var(--ink-3); word-break: break-all; padding: 1px 0; }
.frame-app { color: var(--ink); font-weight: 600; }
.frame-group { padding: 2px 0; }

.log-list { list-style: none; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.log { border-bottom: 1px solid var(--rule); }
.log:last-child { border-bottom: 0; }
.log-head {
    width: 100%; display: grid; grid-template-columns: 64px 48px minmax(80px, 160px) 1fr auto; gap: 8px; align-items: center;
    padding: 5px 8px; border: 0; background: var(--surface); text-align: left; cursor: pointer;
}
.log-head:hover { background: var(--hover); }
.log.is-open .log-head { background: var(--surface-2); }
.log-offset { font: 12px var(--mono); color: var(--ink-3); font-variant-numeric: tabular-nums; text-align: right; }
.log-logger { font: 12px var(--mono); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-message { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log.is-open .log-message { white-space: normal; word-break: break-word; }
.log-exc { font-size: 11px; color: var(--server); font-weight: 600; }
.log-more { padding: 6px 10px 10px; background: var(--surface-2); }
.log-meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 12px; margin-bottom: 6px; }
.log-meta dt { color: var(--ink-3); }
.log-meta dd { font-family: var(--mono); word-break: break-all; }
.log-more .code { margin-bottom: 6px; max-height: 40vh; }
.level { display: inline-block; text-align: center; padding: 0 4px; border-radius: 4px; font: 600 11px var(--mono); }
.lv-trace, .lv-debug { color: var(--ink-3); background: var(--surface-2); }
.lv-info { color: var(--j-num); background: var(--info-bg); }
.lv-warn { color: var(--client); background: var(--client-bg); }
.lv-error, .lv-fatal { color: var(--server); background: var(--server-bg); }
.lv-row-error .log-head, .lv-row-fatal .log-head { box-shadow: inset 3px 0 0 var(--server); }
.lv-row-warn .log-head { box-shadow: inset 3px 0 0 var(--bar-mid); }

.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
    background: var(--ink); color: var(--surface); padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow); transition: opacity 0.15s, transform 0.15s; z-index: 60;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) {
    .workspace.has-detail { grid-template-columns: minmax(0, 1fr); }
    .workspace.has-detail .list, .workspace.has-detail .splitter { display: none; }
    .c-user, .c-rid { display: none; }
    .pager-keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
