:root {
    --bg: #f4f6f9;
    --card: #ffffff;
    --border: #e2e6ec;
    --text: #1b2330;
    --muted: #6b7686;
    --accent: #2f6fde;
    --accent-2: #8a5cd6;
    --good: #1f9d55;
    --warn: #d98a00;
    --bad: #d6363f;
    --track: #e9edf2;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f141b;
        --card: #171e27;
        --border: #263140;
        --text: #e4e9f0;
        --muted: #8b97a8;
        --accent: #5b93f0;
        --accent-2: #a888e6;
        --good: #3cc47c;
        --warn: #f0b03c;
        --bad: #f2646b;
        --track: #222c38;
        --shadow: none;
    }
}

:root[data-theme="dark"] {
    --bg: #0f141b;
    --card: #171e27;
    --border: #263140;
    --text: #e4e9f0;
    --muted: #8b97a8;
    --accent: #5b93f0;
    --accent-2: #a888e6;
    --good: #3cc47c;
    --warn: #f0b03c;
    --bad: #f2646b;
    --track: #222c38;
    --shadow: none;
}

* { 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;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; display: flex; align-items: center; gap: 10px; }
h2 { font-size: 15px; }
p { margin: 2px 0 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-weight: 400; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

button, .button, select, input {
    font: inherit;
    color: var(--text);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
}
button, .button { cursor: pointer; }
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button:disabled { opacity: .6; cursor: progress; }
.ghost { background: transparent; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px 24px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

main { max-width: 1400px; margin: 0 auto; padding: 20px 24px 32px; }

.pill {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--track);
    color: var(--muted);
}
.pill.good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid;
}
.alert.warn { color: var(--warn); border-color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, var(--card)); }
.alert.bad { color: var(--bad); border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, var(--card)); }
#alerts:not(:empty) { margin-bottom: 12px; }

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.tile, .card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.tile { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile .value.small { font-size: 18px; padding: 6px 0 4px; }
.tile .sub { color: var(--muted); font-size: 12px; }

.bar { height: 6px; background: var(--track); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--good); transition: width .4s, background .4s; }
.bar i.warn { background: var(--warn); }
.bar i.bad { background: var(--bad); }

.grid-2 {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 16px;
    margin-bottom: 16px;
}
.grid-2 > .card { margin-bottom: 0; }
.card { padding: 16px; margin-bottom: 16px; min-width: 0; }
.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.card-head.spaced { margin-top: 18px; }
.chart-box { position: relative; height: 260px; }
.chart-box.short { height: 140px; }

.collapsible > summary { cursor: pointer; list-style: none; user-select: none; }
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible:not([open]) > summary { margin-bottom: 0; }
.chevron { display: inline-block; color: var(--muted); transition: transform .2s; }
.collapsible[open] .chevron { transform: rotate(90deg); }

.specs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 12px 20px;
    margin: 0;
}
.specs div { min-width: 0; }
.specs dt { color: var(--muted); font-size: 12px; }
.specs dd { margin: 2px 0 0; font-weight: 500; overflow-wrap: anywhere; }

.disk { margin-bottom: 12px; }
.disk-row { display: flex; justify-content: space-between; margin-bottom: 4px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left;
    color: var(--muted);
    font-weight: 500;
    font-size: 12px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
td { padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.cmd { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 8px;
    background: var(--muted);
    vertical-align: middle;
}
.dot.good { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 20%, transparent); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 20%, transparent); }
.text-good { color: var(--good); }
.text-warn { color: var(--warn); }
.text-bad { color: var(--bad); }

.services { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.service {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    min-width: 0;
}
.service .name { font-weight: 600; }
.service .meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabs { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.tabs button { border: 0; border-radius: 0; padding: 4px 12px; background: transparent; }
.tabs button.active { background: var(--accent); color: #fff; }

.footer { text-align: center; font-size: 12px; margin-top: 8px; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
    width: 100%;
    max-width: 340px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.login-card h1 { font-size: 22px; }
.login-card p { margin-bottom: 8px; }
.login-card button { background: var(--accent); color: #fff; border: 0; padding: 10px; margin-top: 6px; }

@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .topbar, main { padding-left: 16px; padding-right: 16px; }
    .tile .value { font-size: 22px; }
}

/* ---------- navigation ---------- */
.nav { display: flex; gap: 4px; margin-top: 6px; }
.nav a {
    padding: 3px 10px;
    border-radius: 6px;
    color: var(--muted);
    font-size: 13px;
}
.nav a:hover { background: var(--track); text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; }

.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
button.small { padding: 2px 8px; }

/* ---------- recent errors (dashboard) ---------- */
.recent-errors { display: flex; flex-direction: column; }
.recent-error {
    display: grid;
    grid-template-columns: 80px 140px 1fr;
    gap: 10px;
    padding: 8px 4px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    min-width: 0;
}
.recent-error:last-child { border-bottom: 0; }
.recent-error:hover { background: var(--track); text-decoration: none; }
.recent-error .msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- logs page ---------- */
.logs-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}
.log-sources { position: sticky; top: 92px; max-height: calc(100vh - 110px); overflow-y: auto; margin-bottom: 0; }
.log-viewer { margin-bottom: 0; }

.source { border-bottom: 1px solid var(--border); padding: 6px 0; }
.source:last-child { border-bottom: 0; }
.source summary { cursor: pointer; display: flex; flex-direction: column; padding: 4px 2px; list-style: none; }
.source summary::-webkit-details-marker { display: none; }
.source summary strong::before { content: '▸ '; color: var(--muted); }
.source[open] summary strong::before { content: '▾ '; }
.file-group { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 8px 0 2px 4px; }
.file {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    border: 0;
    border-radius: 6px;
    padding: 5px 8px;
    background: transparent;
    text-align: left;
}
.file:hover { background: var(--track); }
.file.active { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); font-weight: 600; }

.log-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.log-toolbar input[type="search"] { flex: 1; min-width: 200px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.chip b { font-weight: 600; margin-left: 2px; }
.chip.bad b { color: var(--bad); }
.chip.warn b { color: var(--warn); }
.chip.info b { color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.active b { color: #fff; }

.toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.entries { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; transition: opacity .2s; }
.entries.loading { opacity: .5; }
.entries .empty { padding: 24px; text-align: center; margin: 0; }
.entry { border-bottom: 1px solid var(--border); }
.entry:last-child { border-bottom: 0; }
.entry-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 7px 12px;
    cursor: pointer;
    min-width: 0;
}
.entry-head:hover { background: var(--track); }
.entry.open .entry-head { background: var(--track); }
.entry .time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 62px; }
.entry .msg { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry.open .msg { white-space: normal; overflow-wrap: anywhere; }
.entry .method { font-weight: 600; font-size: 12px; min-width: 44px; }
.entry .user { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.entry-body { position: relative; padding: 0 12px 12px; background: var(--track); }
.entry-body pre {
    margin: 0;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    max-height: 480px;
    overflow: auto;
}
.entry-body .copy { position: absolute; top: 6px; right: 22px; background: var(--card); }
.entry.flash { animation: flash 2s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 25%, transparent); } to { background: transparent; } }

.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 999px;
    text-transform: uppercase;
    white-space: nowrap;
    background: var(--track);
    color: var(--muted);
}
.badge.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.badge.info { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

.load-more { text-align: center; margin-top: 12px; }

@media (max-width: 900px) {
    .logs-layout { grid-template-columns: 1fr; }
    .log-sources { position: static; max-height: 320px; }
    .recent-error { grid-template-columns: 70px 1fr; }
    .recent-error .src { display: none; }
}
@media (max-width: 600px) {
    .entry .user, .entry .method + .msg + .small { display: none; }
}

/* ---------- live visitors ---------- */
.live-count {
    display: inline-block;
    min-width: 34px;
    padding: 0 10px;
    margin-left: 4px;
    border-radius: 999px;
    background: var(--good);
    color: #fff;
    font-size: 15px;
    text-align: center;
}
.live-count.zero { background: var(--track); color: var(--muted); }
#visitor-sites:not(:empty) { margin-bottom: 10px; }
