:root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --text: #1c2330;
    --dim: #6b7586;
    --line: #dfe3ea;
    --accent: #2f6fde;
    --accent-text: #ffffff;
    --chip: #eef1f6;
    --chip-key: #5b6678;
    --ok-bg: #e4f5e9;   --ok-text: #1d6b37;
    --err-bg: #fde8e8;  --err-text: #9b1c1c;
    --live: #1f8f4d;    --test: #b7791f;
    --row-hover: #f0f4fb;
    --mono: ui-monospace, "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12151b;
        --panel: #1a1f28;
        --text: #e3e7ee;
        --dim: #8b95a7;
        --line: #2b3240;
        --accent: #5b93f2;
        --accent-text: #0d1117;
        --chip: #252c39;
        --chip-key: #9aa5b8;
        --ok-bg: #173524;   --ok-text: #8fdcab;
        --err-bg: #3d1b1b;  --err-text: #f3a6a6;
        --live: #4cc47f;    --test: #e0a94a;
        --row-hover: #20262f;
    }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 20px; margin: 4px 0 14px; }
h2 { font-size: 15px; margin: 24px 0 8px; }
code, pre { font-family: var(--mono); font-size: 13px; }
.dim { color: var(--dim); font-weight: normal; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
    padding: 8px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--text); }
.nav { display: flex; gap: 2px; }
.nav a { padding: 5px 10px; border-radius: 6px; color: var(--text); }
.nav a:hover { background: var(--chip); text-decoration: none; }
.nav a.on { background: var(--accent); color: var(--accent-text); }
.ctx { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.ctx-form { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg a { padding: 4px 11px; color: var(--dim); }
.seg a:hover { text-decoration: none; background: var(--chip); }
.seg a.on { color: #fff; font-weight: 600; }
.seg a.on.live { background: var(--live); }
.seg a.on.test { background: var(--test); }
.user { display: flex; align-items: center; gap: 10px; }
.user form { margin: 0; }

.main { padding: 14px 16px 40px; }

/* ---------- controls ---------- */
input, select, button { font: inherit; color: inherit; }
input, select {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 8px;
    max-width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
    display: inline-block;
    padding: 5px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
}
.btn:hover { background: var(--chip); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.block { width: 100%; padding: 8px 12px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
button.link:hover { text-decoration: underline; }

.filters {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
}
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--dim); }
.filters label input, .filters label select { font-size: 14px; color: var(--text); }
.filters .pair { display: flex; gap: 4px; }
.filters .pair select { max-width: 170px; }
.filter-actions { display: flex; align-items: center; gap: 8px; }
label.check { flex-direction: row !important; align-items: center; gap: 5px !important; font-size: 13px !important; color: var(--text) !important; white-space: nowrap; }
form.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0; }

.flash { padding: 8px 12px; border-radius: 6px; margin: 0 0 12px; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.err { background: var(--err-bg); color: var(--err-text); }
.empty { color: var(--dim); padding: 28px 0; text-align: center; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; color: #fff; vertical-align: middle; }
.badge.live { background: var(--live); }
.badge.test { background: var(--test); }
.badge.off { background: var(--dim); }

/* ---------- log table ---------- */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--dim); white-space: nowrap; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td, table.kv tr:last-child td { border-bottom: 0; }
table.log tbody tr:hover { background: var(--row-hover); }
td.ts { white-space: nowrap; font-family: var(--mono); font-size: 12.5px; }
td.src { font-size: 12px; white-space: nowrap; }
a.ev { font-weight: 600; white-space: nowrap; }
td.details { min-width: 320px; }
.msg { font-family: var(--mono); font-size: 12.5px; margin-bottom: 4px; white-space: pre-wrap; word-break: break-word; }

.chip {
    display: inline-block;
    margin: 1px 4px 3px 0;
    padding: 1px 7px;
    border: 0;
    border-radius: 10px;
    background: var(--chip);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.5;
    word-break: break-word;
}
.chip:hover { text-decoration: none; outline: 1px solid var(--accent); }
.chip .k { color: var(--chip-key); }
.chip .k::after { content: "="; }
.chip .s { color: var(--dim); }
.chip.more { display: none; }
td.open .chip.more { display: inline-block; }
.chip.toggle { cursor: pointer; color: var(--accent); }

.pager { display: flex; gap: 8px; margin-top: 12px; }

table.kv { width: auto; min-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; border-collapse: separate; border-spacing: 0; }
table.kv th { padding-right: 20px; }
pre.msg-full, .keybox pre {
    background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
    padding: 10px 12px; white-space: pre-wrap; word-break: break-word; margin: 0 0 8px;
}

/* ---------- stats ---------- */
.bars {
    display: flex; align-items: flex-end; gap: 3px;
    height: 150px; padding: 10px 12px 0;
    background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; }
.bar i { display: block; width: 100%; min-height: 1px; background: var(--accent); border-radius: 3px 3px 0 0; }
.bar span { font-size: 10px; color: var(--dim); padding: 2px 0 4px; }

/* ---------- admin ---------- */
.keybox { background: var(--ok-bg); color: var(--ok-text); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.keybox pre, .keybox code.key { color: var(--text); }
code.key { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; user-select: all; }

/* ---------- login / installer ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px 24px; }
.auth-card.wide { max-width: 560px; }
.auth-card h1 { text-align: center; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--dim); }
.auth-card label input, .auth-card label select { font-size: 14px; color: var(--text); padding: 7px 9px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid2 .span2 { grid-column: span 2; }

@media (max-width: 700px) {
    .ctx { margin-left: 0; }
    .grid2 { grid-template-columns: 1fr; }
    .grid2 .span2 { grid-column: auto; }
    table.kv { min-width: 0; width: 100%; }
}
