:root {
  --bg: #0f1216;
  --panel: #171c23;
  --panel-2: #1e242d;
  --border: #2a323d;
  --text: #e6eaf0;
  --muted: #9aa6b4;
  --accent: #4c8bf5;
  --accent-hover: #3f7ae0;
  --green: #3ecf8e;
  --amber: #f5b34c;
  --red: #f56c6c;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Light theme: swap the neutral roles; accents adjust for the light surface. */
body.light {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-2: #eceff3;
  --border: #d7dce3;
  --text: #1b2430;
  --muted: #5a6675;
  --accent: #2a78d6;
  --accent-hover: #1c5cab;
  --green: #0ca30c;
  --amber: #c98500;
  --red: #d03b3b;
}
body.light .log { background: #f6f7f9; }
body.light .log .info { color: var(--text); }
body.light .state-pill { background: var(--panel-2); }
body.light .dot { box-shadow: 0 0 0 3px rgba(0,0,0,0.05); }

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  /* fixed header + tab bar; each tab's content scrolls inside <main> */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 12px; }
img.logo { width: 32px; height: 32px; border-radius: 8px; display: block; }

/* centered realm indicator */
.realm-ind {
  position: absolute; left: 50%; transform: translateX(-50%);
  display: flex; align-items: baseline; gap: 8px; max-width: 38%;
}
.realm-lbl { font-size: 10px; color: #6b7684; text-transform: uppercase; letter-spacing: .07em; }
.realm-host { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.state-right { display: flex; align-items: center; gap: 10px; }

/* status pill goes green/red with state */
.state-pill.ok  { color: var(--green); border-color: rgba(62,207,142,.45); background: rgba(62,207,142,.08); }
.state-pill.bad { color: var(--red);   border-color: rgba(245,108,108,.45); background: rgba(245,108,108,.08); }
.state-pill.mid { color: var(--amber); border-color: rgba(245,179,76,.45);  background: rgba(245,179,76,.08); }
.brand h1 { font-size: 16px; margin: 0; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 3px rgba(255,255,255,0.04); }
.dot[data-state="connected"] { background: var(--green); }
.dot[data-state="connecting"] { background: var(--amber); }
.dot[data-state="error"] { background: var(--red); }
.dot[data-state="disconnected"] { background: var(--muted); }

.state-pill {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--muted); background: var(--panel-2);
}

.tabs {
  display: flex;
  gap: 2px;
  width: 100%;
  padding: 14px 24px 0;
  border-bottom: 1px solid var(--border);
  flex: none;
  background: var(--bg);
}
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  padding: 8px 14px;
  margin-bottom: -1px;
  font-size: 14px;
  cursor: pointer;
}
.tab:hover:not(.active) { color: var(--text); border-bottom-color: var(--border); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-badge {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}
.tab-badge[hidden] { display: none; }

main { flex: 1 1 0; width: 100%; overflow-y: auto; padding: 20px 24px; }
.panel { display: flex; flex-direction: column; gap: 16px; width: 100%; }
.panel[hidden] { display: none; }
/* Config is a form — keep it a comfortable width, centered. Data views go full-bleed. */
#panel-home { max-width: 860px; margin: 0 auto; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0 0 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
input, select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 14px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.checkbox { flex-direction: row; align-items: center; gap: 8px; grid-column: 1 / -1; color: var(--text); }
.checkbox input { width: auto; }
.checkbox small { color: var(--muted); }

.actions { grid-column: 1 / -1; display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }
button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 16px; font-size: 14px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: white; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 4px 8px; }

.status-grid { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.status-grid dt { color: var(--muted); font-size: 12px; }
.status-grid dd { margin: 0; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }

/* Realm-size stat tiles (Status page) — mirrors the Home view's .tile look. */
.realm-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.rstat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.rstat-n { font-size: 26px; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.rstat-l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }
.realm-substats { margin-top: 12px; }
.realm-substats b { color: var(--text); font-weight: 650; }
@media (max-width: 620px) { .realm-stats { grid-template-columns: repeat(2, 1fr); } }

.log {
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  background: #0b0e12; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; height: 200px; overflow-y: auto; white-space: pre-wrap;
}
.log .l { display: block; }
.log .t { color: var(--muted); }
.log .info { color: var(--text); }
.log .warn { color: var(--amber); }
.log .error { color: var(--red); }

.note p { color: var(--muted); line-height: 1.6; margin: 0; }
.note code { font-family: var(--mono); background: var(--panel-2); padding: 1px 5px; border-radius: 4px; color: var(--text); }
a { color: var(--accent); }

body.light .state-pill.ok  { color: #0ca30c; border-color: rgba(12,163,12,.45); background: rgba(12,163,12,.07); }
body.light .state-pill.bad { color: #d03b3b; border-color: rgba(208,59,59,.45); background: rgba(208,59,59,.07); }
body.light .state-pill.mid { color: #c98500; border-color: rgba(201,133,0,.45); background: rgba(201,133,0,.07); }
body.light .realm-lbl { color: #8b95a3; }
