:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2026;
  --muted: #6a7280;
  --line: #e2e5ea;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --good: #1f7a4d;
  --good-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;
  --bad: #b42318;
  --bad-bg: #fde7e5;
  --track: #eceef2;
  --radius: 8px;
  color-scheme: light;
}

/* Dark: follows the system unless Light is picked, or forced by picking Dark. Keep the two blocks equal. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c;
    --panel: #1c2027;
    --text: #e6e8ec;
    --muted: #9aa3b0;
    --line: #2d333d;
    --accent: #7c9cff;
    --accent-text: #0e1320;
    --good: #6fd3a0;
    --good-bg: #173326;
    --warn: #f0c46a;
    --warn-bg: #3a2d10;
    --bad: #ff8a80;
    --bad-bg: #3d1a18;
    --track: #262b34;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171c;
  --panel: #1c2027;
  --text: #e6e8ec;
  --muted: #9aa3b0;
  --line: #2d333d;
  --accent: #7c9cff;
  --accent-text: #0e1320;
  --good: #6fd3a0;
  --good-bg: #173326;
  --warn: #f0c46a;
  --warn-bg: #3a2d10;
  --bad: #ff8a80;
  --bad-bg: #3d1a18;
  --track: #262b34;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

[hidden] { display: none !important; }

/* Left menu. On narrow screens it turns into a bar across the top. */
body { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 220px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 12px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  z-index: 2;
}
.brand { font-weight: 650; font-size: 15px; padding: 0 10px; margin: 0; }
.card > .brand { padding: 0; margin-bottom: 6px; color: var(--muted); }
nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group {
  margin: 14px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.nav-group:first-child { margin-top: 0; }
nav button {
  text-align: left;
  background: transparent;
  color: var(--text);
  border-color: transparent;
  padding: 7px 10px;
}
nav button:hover { background: var(--bg); }
nav button.active { background: var(--bg); border-color: var(--line); color: var(--accent); font-weight: 550; }
.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 10px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.content { flex: 1; min-width: 0; }

@media (max-width: 800px) {
  body { flex-direction: column; }
  .sidebar {
    width: auto;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; }
  nav { flex-direction: row; overflow-x: auto; order: 3; width: 100%; }
  nav button { flex: none; }
  .nav-group { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; flex-direction: row; align-items: center; }
  main { padding: 16px; }
}

main { padding: 20px; max-width: 1280px; margin: 0 auto; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.narrow { max-width: 380px; margin: 40px auto; }

label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 6px;
  padding: 7px 12px;
  white-space: nowrap;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin: 16px 0 0; }
.row input[type=search] { flex: 1; min-width: 200px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 12px; }
.split { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }

.list { display: flex; flex-direction: column; gap: 4px; }
.list button {
  text-align: left;
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
  overflow: hidden;
  text-overflow: ellipsis;
}
.list button.selected { border-color: var(--accent); }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 550; font-size: 12px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
td .row { margin: 0; flex-wrap: nowrap; }

.badge { display: inline-block; white-space: nowrap; padding: 1px 7px; border-radius: 999px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); }
.badge.good { color: var(--good); background: var(--good-bg); border-color: transparent; }
.badge.warn { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.badge.bad { color: var(--bad); background: var(--bad-bg); border-color: transparent; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.why { font-size: 15px; margin-bottom: 8px; }

.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: var(--radius); }
.banner.error { background: var(--bad-bg); color: var(--bad); }
.banner.ok { background: var(--good-bg); color: var(--good); }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); min-width: 340px; max-width: 90vw; }
dialog::backdrop { background: rgb(0 0 0 / .35); }
pre { white-space: pre-wrap; word-break: break-word; max-height: 50vh; overflow: auto; background: var(--bg); padding: 8px; border-radius: 6px; }

.choice { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
label.radio { flex-direction: row; align-items: center; gap: 8px; margin: 0; color: var(--text); font-size: 14px; cursor: pointer; }
.note { font-size: 13px; margin: 0 0 12px; }
.note.warn { color: var(--warn); background: var(--warn-bg); padding: 8px 10px; border-radius: 6px; }
.break { overflow-wrap: anywhere; }

/* Theme switch */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; padding: 2px; gap: 2px; background: var(--bg); }
.segmented button { background: transparent; color: var(--muted); border: 0; padding: 3px 8px; font-size: 12px; border-radius: 4px; }
.segmented button[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--line); }

/* Dashboard */
.row.tight { margin: 0; gap: 10px; }
.attention { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.attention button { font-size: 13px; padding: 6px 12px; }
.attention .warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.attention .bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.attention .calm { background: var(--good-bg); color: var(--good); border-color: transparent; cursor: default; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile-label { color: var(--muted); font-size: 12px; margin: 0 0 6px; }
.tile-value { font-size: 26px; font-weight: 600; line-height: 1.15; margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-value.small { font-size: 18px; }
.tile-sub { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.tile-sub.bad { color: var(--bad); }
button.tile { text-align: left; color: var(--text); font: inherit; white-space: normal; }
button.tile:hover { border-color: var(--accent); }

.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-card h3 { margin-bottom: 2px; }
.chart-total { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.chart { display: block; width: 100%; height: 140px; }
.chart .bar { fill: var(--accent); }
.chart .bar.today { fill: var(--accent); opacity: .55; }
.chart .zero { fill: var(--track); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.chart-max { color: var(--muted); font-size: 11px; text-align: right; margin: 0 0 2px; font-variant-numeric: tabular-nums; }

.load { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.load-track { flex: 1; height: 6px; background: var(--track); border-radius: 3px; overflow: hidden; }
.load-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.load-fill.high { background: var(--warn); }
.load-fill.full { background: var(--bad); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

@media (max-width: 1000px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 800px) { .charts { grid-template-columns: 1fr; } }
#dash-servers table { min-width: 620px; }
#dash-servers td:first-child { white-space: nowrap; }

/* Users list */
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-align: left; white-space: normal; overflow-wrap: anywhere; }
button.link:hover { text-decoration: underline; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }
.back { margin-bottom: 12px; }
#users-list table { min-width: 640px; }

/* Dialog: multi-line profile box and file loader */
dialog textarea { width: 100%; min-height: 180px; resize: vertical; font-size: 12px; line-height: 1.4; white-space: pre; }
dialog .field { margin-bottom: 12px; }
dialog .field label { margin-bottom: 6px; }
label.file { flex-direction: row; align-items: center; gap: 8px; font-size: 12px; }
label.file input { padding: 0; border: 0; background: none; font-size: 12px; }
#dialog { width: min(560px, 92vw); }

/* Server addresses */
.address { display: flex; align-items: center; gap: 6px; white-space: nowrap; margin-bottom: 4px; }
.small-text { font-size: 12px; }
button.off { color: var(--muted); border-style: dashed; }
#servers-list td .row { flex-wrap: wrap; min-width: 180px; }

/* Top bar: theme switch, who is signed in, log out */
.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.topbar .spacer { flex: 1; }
@media (max-width: 800px) {
  .topbar { position: static; padding: 8px 16px; gap: 10px; flex-wrap: wrap; }
  .topbar .spacer { display: none; }
}

/* Page title in the top bar */
.page-title { font-size: 17px; font-weight: 650; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.row.end-only { justify-content: flex-end; }
@media (max-width: 800px) { .page-title { width: 100%; } }
