:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #dfe3e8;
    --text: #17202b;
    --muted: #66717f;
    --accent: #315efb;
    --accent-text: #ffffff;
    --ok: #157f3b;
    --ok-bg: #e3f5e9;
    --warn: #9a5b00;
    --warn-bg: #fff2d9;
    --bad: #b42318;
    --bad-bg: #fde7e5;
    --info: #3d4b5c;
    --info-bg: #e9edf2;
    --code-bg: #0f1722;
    --code-text: #d8e1ec;
    --radius: 8px;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1117;
        --surface: #151b23;
        --surface-2: #1c2430;
        --border: #2a3441;
        --text: #e3e8ee;
        --muted: #8b96a5;
        --accent: #5b82ff;
        --ok: #4cc47a;
        --ok-bg: #12301f;
        --warn: #f0b24d;
        --warn-bg: #352710;
        --bad: #ff7b6e;
        --bad-bg: #3a1714;
        --info: #b8c4d2;
        --info-bg: #222c38;
        --code-bg: #0a0e14;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h2.inline { display: inline; margin: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; }
.brand-mark { width: 18px; height: 18px; border-radius: 5px; background: var(--accent); }
.topbar-user { display: flex; gap: 14px; align-items: center; font-size: 13px; }

.page { padding: 16px 20px 40px; max-width: 1600px; margin: 0 auto; }
.page-narrow { max-width: 440px; padding-top: 64px; }
.breadcrumbs { margin: 0 0 10px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
}

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; margin-bottom: 14px; }
.grid > .card { margin-bottom: 0; min-width: 0; }

.button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.button:hover { background: var(--surface-2); text-decoration: none; }
.button-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button-primary:hover { background: var(--accent); filter: brightness(1.08); }
.button-ghost { border-color: transparent; background: transparent; }
.button-danger { color: var(--bad); }
.button-small { padding: 3px 8px; font-size: 12px; }
.button-block { display: flex; justify-content: center; width: 100%; }

input, select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.filters { padding: 12px 16px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 8px; }
.filter-row label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.filter-row label.grow { flex: 1 1 220px; }
.filter-row label.checkbox, label.checkbox { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; padding-bottom: 7px; }
.filter-row .field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.multiselect { position: relative; font-size: 14px; color: var(--text); }
.multiselect > summary {
    list-style: none;
    cursor: pointer;
    min-width: 90px;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    height: 30px;
    line-height: 16px;
    padding: 6px 26px 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    position: relative;
}
.multiselect > summary::-webkit-details-marker { display: none; }
.multiselect > summary::after { content: "▾"; position: absolute; right: 8px; color: var(--muted); }
.multiselect[open] > summary { outline: 2px solid var(--accent); outline-offset: -1px; }
.multiselect-menu {
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    max-height: 320px;
    overflow-y: auto;
    padding: 6px 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgb(0 0 0 / 0.15);
}
.filter-row .multiselect-menu label.checkbox { padding: 4px 8px; white-space: nowrap; border-radius: 4px; cursor: pointer; }
.multiselect-menu label.checkbox:hover { background: var(--surface-2); }
.filter-advanced summary { cursor: pointer; color: var(--muted); margin: 4px 0 10px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }

.notice { padding: 10px 12px; border-radius: 6px; background: var(--info-bg); color: var(--info); margin-bottom: 12px; }
.notice-error { background: var(--bad-bg); color: var(--bad); }
.notice-success { background: var(--ok-bg); color: var(--ok); }
.share-created { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; margin-bottom: 0; }
.share-created input { flex: 1 1 320px; }

.table-card { padding: 0; overflow: hidden; }
.table-meta { padding: 10px 16px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); }
.table-scroll { overflow-x: auto; }
.empty { padding: 24px 16px; color: var(--muted); margin: 0; }
table { border-collapse: collapse; width: 100%; }
table.logs th {
    position: sticky;
    top: 0;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    background: var(--surface-2);
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.logs td { padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.logs tbody tr { cursor: pointer; }
table.logs tbody tr:hover { background: var(--surface-2); }
td.path { min-width: 260px; }
td.path .route { display: block; font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
td.error-cell { color: var(--bad); max-width: 320px; font-size: 12.5px; }
td.entities { min-width: 140px; }
.slow { color: var(--warn); font-weight: 600; }

.tag, .chip {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 10px;
    background: var(--info-bg);
    color: var(--info);
    font-size: 12px;
    white-space: nowrap;
}
.chip { font-family: var(--mono); font-size: 11.5px; margin: 0 4px 3px 0; }

.status { display: inline-block; min-width: 38px; text-align: center; padding: 1px 6px; border-radius: 4px; font-family: var(--mono); font-weight: 600; font-size: 12px; }
.status-lg { font-size: 15px; padding: 3px 10px; }
.status-2xx { background: var(--ok-bg); color: var(--ok); }
.status-3xx, .status-unknown { background: var(--info-bg); color: var(--info); }
.status-4xx { background: var(--warn-bg); color: var(--warn); }
.status-5xx { background: var(--bad-bg); color: var(--bad); }

.pager { padding: 12px 16px; display: flex; justify-content: flex-end; }

.request-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.request-title h1 { margin: 0; font-size: 17px; word-break: break-all; }
.method { font-family: var(--mono); font-weight: 700; color: var(--accent); }
.request-facts { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; color: var(--text); align-items: center; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: flex-start; }
.share { position: relative; }
.share summary { list-style: none; }
.share summary::-webkit-details-marker { display: none; }
.share-form {
    position: absolute;
    z-index: 5;
    top: 40px;
    left: 0;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.15);
}
.share-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

.error-card { border-color: var(--bad); background: var(--bad-bg); }
.error-card h2, .error-card p { color: var(--bad); margin-bottom: 4px; }

table.kv th {
    text-align: left;
    vertical-align: top;
    font-weight: 500;
    color: var(--muted);
    padding: 4px 16px 4px 0;
    white-space: nowrap;
    width: 1%;
}
table.kv td { padding: 4px 0; vertical-align: top; word-break: break-word; }
.trace-link { margin-left: 8px; font-family: system-ui, sans-serif; font-size: 12px; }

table.queries td { padding: 4px 10px 4px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
details > summary { cursor: pointer; }

.code-wrap { position: relative; }
.code-wrap .copy { position: absolute; top: 8px; right: 8px; }
pre.code {
    margin: 0;
    padding: 14px;
    max-height: 640px;
    overflow: auto;
    background: var(--code-bg);
    color: var(--code-text);
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.5;
    white-space: pre;
}

form.inline { display: inline; }
.login h1 { margin-bottom: 6px; }
.login .button-block { margin-top: 16px; }
.dev-login { margin-top: 24px; padding-top: 16px; border-top: 1px dashed var(--border); }
.dev-login label { font-size: 12px; color: var(--muted); }
.input-row { display: flex; gap: 8px; margin-top: 6px; }
.input-row input { flex: 1; }

/* log detail side panel on the list page */
:root { --panel-w: 50vw; --topbar-h: 45px; }
.topbar { position: sticky; top: 0; z-index: 20; }
table.logs tbody tr.is-active,
table.logs tbody tr.is-active:hover { background: var(--info-bg); box-shadow: inset 3px 0 0 var(--accent); }
body.panel-open .page { max-width: none; margin: 0 var(--panel-w) 0 0; }
/* entities + error columns are in the panel anyway; keep status/duration in view */
body.panel-open table.logs :is(th, td):nth-child(n+8) { display: none; }
body.panel-open td.path { min-width: 140px; word-break: break-all; }
body.panel-open td.env .tag { max-width: 96px; overflow: hidden; text-overflow: ellipsis; vertical-align: top; }
body.panel-resizing { cursor: col-resize; user-select: none; }
.log-panel {
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    bottom: 0;
    z-index: 10;
    width: var(--panel-w);
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border-left: 1px solid var(--border);
    box-shadow: -6px 0 18px rgb(0 0 0 / 0.08);
}
.log-panel[hidden] { display: none; }
.log-panel-resize { position: absolute; left: -4px; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 1; }
.log-panel-resize:hover, body.panel-resizing .log-panel-resize { background: var(--accent); opacity: 0.35; }
.log-panel-bar { display: flex; gap: 6px; align-items: center; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--border); }
.log-panel-close { margin-left: auto; font-size: 15px; }
.log-panel-body { flex: 1; overflow-y: auto; padding: 14px; }
.log-panel-body.is-loading { opacity: 0.5; transition: opacity 0.1s 0.15s; }
.log-panel-body .grid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

@media (max-width: 900px) {
    :root { --panel-w: 100vw !important; }
    .log-panel-resize { display: none; }
}

@media (max-width: 700px) {
    .page { padding: 12px 16px 32px; }
    .grid { grid-template-columns: 1fr; }
    .topbar-user .muted { display: none; }
}
