:root {
  --bg: #f3f6fa; --panel: #ffffff; --line: #e2e8ef; --text: #1f3148; --muted: #6f7f93;
  --side: #102338; --side-text: #d3deec; --side-muted: #8ea3bd; --accent: #168d76; --accent-soft: #e4f6f0;
  --down: #2f6fc0; --down-soft: #e8f1ff; --up: #138a6f; --up-soft: #e2f6ef; --bad: #b4452f; --bad-soft: #fdeee9;
  --code-bg: #14243b; --code-text: #c4ecdf;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1722; --panel: #16202d; --line: #263445; --text: #e3eaf3; --muted: #93a3b6;
    --side: #0b121b; --accent-soft: #173a33; --down-soft: #18304f; --up-soft: #14372f; --bad-soft: #43221b;
    --down: #7fb1f2; --up: #5fd3b8; --bad: #f39a85;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }
input, select, button { font: inherit; font-size: 14px; border-radius: 8px; border: 1px solid var(--line); padding: 9px 12px; background: var(--panel); color: inherit; }
button { cursor: pointer; font-weight: 600; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: wait; }
button:focus-visible, input:focus-visible, select:focus-visible, tr:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

aside { width: 260px; flex-shrink: 0; background: var(--side); color: var(--side-text); padding: 24px 16px; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; gap: 14px; }
.brand { font-size: 22px; font-weight: 800; letter-spacing: 1px; color: #5fd3b8; }
.brand small { display: block; font-size: 13px; font-weight: 500; letter-spacing: 0; color: var(--side-muted); margin-top: 2px; }
.brand.dark { color: var(--accent); }
.brand.dark small { color: var(--muted); }
aside input { background: #1b304a; border-color: #2e4560; color: #fff; width: 100%; }
#groups { overflow: auto; flex: 1; }
.side-heading { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--side-muted); margin: 16px 8px 6px; }
.side-empty { font-size: 13px; color: var(--side-muted); margin: 4px 8px; }
.group { position: relative; display: block; width: 100%; text-align: left; background: transparent; border: 0; color: var(--side-text); padding: 10px 40px 10px 10px; margin-bottom: 2px; font-weight: 500; }
.group b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group small { display: block; font-size: 12px; color: var(--side-muted); margin-top: 2px; overflow-wrap: anywhere; }
.group.selected, .group:hover { background: #22405f; color: #fff; }
.count { position: absolute; right: 10px; top: 12px; font-size: 12px; color: #5fd3b8; }
.account { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.account span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account button { background: #1b304a; border-color: #2e4560; color: #5fd3b8; padding: 6px 10px; font-size: 13px; }
.readonly { font-size: 12px; color: var(--side-muted); margin: 0; border-top: 1px solid #253a52; padding-top: 12px; }

main { margin-left: 260px; padding: 28px 32px; width: calc(100% - 260px); min-width: 0; }
header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
h1 { font-size: 28px; margin: 0 0 6px; }
header p { color: var(--muted); margin: 0; max-width: 640px; line-height: 1.5; }
.connection { display: flex; align-items: center; gap: 8px; font-size: 14px; background: var(--panel); padding: 10px 14px; border: 1px solid var(--line); border-radius: 20px; max-width: 360px; }
#lamp { width: 10px; height: 10px; border-radius: 50%; background: #d29d40; flex-shrink: 0; }
#lamp.live { background: #19b58e; box-shadow: 0 0 0 4px var(--accent-soft); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 22px 0; }
.stats article { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.stats span { color: var(--muted); font-size: 14px; }
.stats strong { display: block; font-size: 28px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.stats article:nth-child(2) strong { color: var(--down); }
.stats article:nth-child(3) strong { color: var(--up); }
.stats .warn strong { color: var(--bad); }

.workspace { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
h2 { font-size: 18px; margin: 0 0 4px; }
.toolbar small { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 20px; }
.filters input[type=search] { flex: 1; min-width: 180px; }
.filters select { max-width: 320px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.check input { width: 18px; height: 18px; }
#visible { font-size: 13px; color: var(--muted); }

.log-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; border-top: 1px solid var(--line); min-height: 460px; }
.table-wrap { overflow: auto; max-height: 620px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { position: sticky; top: 0; text-align: left; background: var(--bg); font-size: 13px; color: var(--muted); font-weight: 600; padding: 10px 12px; }
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
td small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.chosen { background: var(--accent-soft); }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 6px; white-space: nowrap; background: var(--bg); color: var(--muted); margin-top: 2px; }
.badge.down { background: var(--down-soft); color: var(--down); }
.badge.up { background: var(--up-soft); color: var(--up); }
.badge.bad { background: var(--bad-soft); color: var(--bad); margin-top: 6px; }

.detail { padding: 18px; border-left: 1px solid var(--line); min-width: 0; }
.detail-heading { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 12px; }
.detail p { color: var(--muted); line-height: 1.6; }
.detail h3 { font-size: 17px; margin: 12px 0; }
.issues { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.issues ul { margin: 6px 0 0; padding-left: 18px; }
.detail .ok { color: var(--up); font-weight: 600; }
dl { font-size: 14px; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--code-bg); color: var(--code-text); font-size: 13px; padding: 14px; border-radius: 8px; line-height: 1.6; max-height: 380px; overflow: auto; }
.detail button { margin-top: 12px; font-size: 13px; }
.warning { color: var(--bad) !important; }
#empty { text-align: center; padding: 80px 24px; color: var(--muted); }
#empty b { color: var(--text); }
.note { font-size: 13px; color: var(--muted); line-height: 1.6; margin-top: 16px; max-width: 900px; }
#notice { color: var(--accent); font-size: 14px; margin: 8px 0; min-height: 1em; }

.login-page { align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(400px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { font-size: 24px; margin: 8px 0 0; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.login-card .primary { padding: 12px; font-size: 15px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
#error { color: var(--bad); margin: 0; min-height: 1em; }

@media (max-width: 1100px) {
  .log-layout { grid-template-columns: 1fr; }
  .detail { border-left: 0; border-top: 1px solid var(--line); }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  body:not(.login-page) { display: block; }
  aside { position: relative; width: 100%; padding: 16px; }
  #groups { max-height: 220px; }
  main { margin-left: 0; width: 100%; padding: 18px 16px; }
  header { display: block; }
  .connection { margin-top: 12px; max-width: none; }
  .toolbar { flex-direction: column; align-items: flex-start; padding: 14px 16px; }
  .filters { padding: 12px 16px; }
  .filters select { max-width: 100%; flex: 1; }
  table { min-width: 560px; }
}
