:root {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #171e26;
  --surface-2: #1f2832;
  --border: #2b3640;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4ca3ff;
  --accent-text: #06121f;
  --green: #4cc38a;
  --yellow: #e5b84b;
  --red: #f0716b;
  --radius: 10px;

  /* Chart tokens. Account colors: dark categorical slots, validated on --surface (#171e26). */
  --series-0: #3987e5;
  --series-1: #d95926;
  --series-2: #199e70;
  --series-3: #c98500;
  --series-4: #d55181;
  --series-5: #008300;
  --series-6: #9085e9;
  --series-7: #e66767;
  /* Status: always shown with an icon or label, never color alone. */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --grid: #222c36;
  --axis: #34414d;
}

* { box-sizing: border-box; }

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

body.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.1rem; margin-bottom: 12px; }
h3 { font-size: 1rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--red); margin: 8px 0 0; }
.center-text { text-align: center; }
p { margin: 8px 0; }

input, select, button {
  font: inherit;
  color: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 8px 12px;
}
input, select { width: 100%; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button { cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.6; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--red); }

label, .label { display: block; margin: 12px 0 0; font-weight: 500; }
label input, label select { margin-top: 4px; font-weight: 400; }
label small { display: block; font-weight: 400; margin-top: 4px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 20px; }
.row input { flex: 1; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.login-card { width: 100%; max-width: 360px; }
.login-card button { width: 100%; margin-top: 20px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px 24px; flex-wrap: wrap;
  padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a {
  color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-weight: 500;
}
.tabs a:hover { color: var(--text); background: var(--surface-2); }
.tabs a.active { color: var(--text); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--accent); }

main { max-width: 1200px; margin: 0 auto; padding: 24px 16px; }


.accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.account { display: flex; flex-direction: column; gap: 8px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.actions { margin-top: auto; padding-top: 8px; }

.badge { font-size: 0.75rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.online { background: rgba(76, 195, 138, 0.15); color: var(--green); }
.badge.paused, .badge.connecting, .badge.retrying { background: rgba(229, 184, 75, 0.15); color: var(--yellow); }
.badge.guard, .badge.error { background: rgba(240, 113, 107, 0.15); color: var(--red); }

.games { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.games li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.games li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.games li .muted { font-variant-numeric: tabular-nums; }

.inline-form input.code { text-transform: uppercase; letter-spacing: 0.2em; font-family: ui-monospace, monospace; }

dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
dialog.wide { width: min(900px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

#account-form.editing .new-only { display: none; }
#account-form:not(.editing) .edit-only { display: none; }

details { margin-top: 16px; }
summary { cursor: pointer; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 0.85rem; }
.chip button { border: 0; background: none; padding: 0 6px; color: var(--muted); }

.results { list-style: none; margin: 4px 0 0; padding: 0; }
.results button { width: 100%; text-align: left; border: 0; border-radius: 6px; background: none; }
.results button:hover { background: var(--surface-2); }

pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; max-height: 60vh; overflow: auto; font-size: 0.8rem; white-space: pre-wrap; word-break: break-word;
}

@media (max-width: 600px) {
  .topbar { padding: 12px 16px; }
  .accounts { grid-template-columns: 1fr; }
}

a { color: var(--accent); }
.banner { margin: 0 0 16px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { font-size: 1.15rem; margin: 0; }
.inline-label { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 400; color: var(--muted); }
.inline-label select { width: auto; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; }
.page > * + * { margin-top: 16px; }
.page > .page-head + * { margin-top: 0; }
.card h2 { font-size: 1rem; margin: 0 0 12px; }
.card-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-title h2 { margin: 0; }
.card-title p { margin: 4px 0 0; }
.small { font-size: 0.85rem; }

/* health banner */
.health { display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; background: var(--surface); }
.health ul { margin: 6px 0 4px; padding-left: 18px; }
.health p { margin: 4px 0 0; color: var(--muted); }
.health-icon { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; flex: none; font-weight: 700; color: #0b0b0b; }
.health-ok .health-icon { background: var(--good); }
.health-warn .health-icon { background: var(--warning); }
.health-error .health-icon { background: var(--critical); color: #fff; }
.health-info .health-icon { background: var(--accent); }
.health-error { border-color: rgba(208, 59, 59, 0.5); }
.health-warn { border-color: rgba(250, 178, 25, 0.4); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
@media (max-width: 600px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat small { color: var(--muted); }
.stat-value { font-size: 1.75rem; font-weight: 650; line-height: 1.2; display: flex; align-items: center; gap: 8px; }
.stat-icon { font-size: 1rem; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); color: var(--muted); }
.stat.good .stat-icon { background: var(--good); color: #0b0b0b; }
.stat.warn .stat-icon { background: var(--warning); color: #0b0b0b; }
.stat-sub { color: var(--muted); font-size: 0.85rem; }

/* legend + swatches */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.85rem; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.swatch.kind-idling { background: var(--good); }
.swatch.kind-paused { background: var(--warning); }
.swatch.kind-problem { background: var(--critical); }
.swatch.kind-off { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--axis); }

/* column chart */
.chart { position: relative; overflow: hidden; }
.chart-svg { display: block; max-width: 100%; height: auto; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.value-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.hit { fill: transparent; cursor: default; outline: none; }
.band-wash { fill: transparent; }
.col:hover .band-wash, .col:focus-within .band-wash { fill: rgba(255, 255, 255, 0.04); }
.empty-chart { padding: 40px 0; text-align: center; }
.table-view { margin-top: 8px; }
.table-view summary { font-size: 0.85rem; }

/* tooltip */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; min-width: 160px; max-width: 280px;
  background: #0b1016; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.85rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
.tip-title { font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; }
.tip-row strong { margin-left: auto; font-variant-numeric: tabular-nums; }
.tip-key { width: 10px; height: 2px; border-radius: 1px; flex: none; }
.tip-label { color: var(--muted); }
.tip-note { color: var(--muted); margin-top: 4px; }

/* 24 h uptime rows */
.up-list { display: flex; flex-direction: column; }
.up-row { display: grid; grid-template-columns: 260px minmax(0, 1fr) 230px; gap: 16px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.up-row:first-child { border-top: 0; }
.up-row.up-axis { border-top: 0; padding-top: 0; }
.up-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.up-name > div { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; min-width: 0; }
.up-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.up-strip { min-width: 0; }
.timeline { display: block; width: 100%; height: 14px; overflow: visible; }
.timeline-track { fill: var(--surface-2); }
.up-nums { display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; }
.up-nums small { color: var(--muted); }
.axis-ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.verify.good { color: var(--text); }
.verify.good > span:first-child, .verify.good::first-letter { color: var(--good); }
.verify.warn { color: var(--yellow); }

/* tables */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 0.8rem; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.game-name { display: flex; align-items: center; gap: 8px; }
.target-cell { display: flex; flex-direction: column; gap: 4px; min-width: 110px; }
.meter { display: block; height: 6px; border-radius: 3px; background: rgba(57, 135, 229, 0.22); overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--series-0); border-radius: 3px; }

/* key/value list */
.kv { margin: 0; display: flex; flex-direction: column; }
.kv-row { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 0.9rem; }
.kv-row:first-child { border-top: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.warn-text { color: var(--yellow); }
.ok-text { color: var(--green); margin: 8px 0 0; }

/* events */
.events { list-style: none; margin: 0; padding: 0; }
.event { display: grid; grid-template-columns: 18px auto minmax(0, 1fr); gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); font-size: 0.9rem; align-items: baseline; }
.event:first-child { border-top: 0; }
.event time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.event span:last-child { overflow-wrap: anywhere; }
.event-icon { text-align: center; color: var(--muted); }
.event.success .event-icon { color: var(--good); }
.event.warn .event-icon { color: var(--warning); }
.event.error .event-icon { color: var(--critical); }

/* account cards */
.name-row { display: flex; align-items: flex-start; gap: 10px; }
.name-row .swatch { margin-top: 6px; }
.games li.done span:first-child { color: var(--muted); text-decoration: line-through; }
.badge.sleeping, .badge.stopped { background: var(--surface-2); color: var(--muted); }

/* settings */
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.settings-card h2 { margin-bottom: 4px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 16px 0 0; padding: 8px 14px 12px; }
legend { color: var(--muted); padding: 0 6px; font-size: 0.85rem; }
label.check { display: block; font-weight: 400; margin-top: 8px; line-height: 2.1; }
label.check input[type=checkbox] { width: 16px; height: 16px; margin: 0 8px 0 0; vertical-align: -2px; accent-color: var(--accent); }
input.num-input { width: 76px; margin: 0 4px; padding: 3px 8px; display: inline-block; }
label .row input.num-input { margin-left: 0; }
input.num-input.wide { width: 120px; }
label .row { margin-top: 4px; }
.link-btn { background: none; border: 0; color: var(--accent); padding: 4px 0; margin-top: 4px; }
.sub-h { font-size: 0.9rem; margin: 16px 0 6px; color: var(--muted); font-weight: 500; }
.devices { list-style: none; margin: 0; padding: 0; }
.device { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); }
.device:first-child { border-top: 0; }
.device .badge { margin-left: 8px; }
.form-msg { margin: 12px 0 0; }
.schedule input[type=time] { width: auto; }
.schedule .row { margin-top: 8px; }

@media (max-width: 1000px) {
  .grid-2, .settings-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .up-row { grid-template-columns: 1fr; gap: 8px; }
  .up-row.up-axis > div:empty { display: none; }
  .up-nums { flex-direction: row; flex-wrap: wrap; gap: 4px 14px; }
}
@media (max-width: 600px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .tabs { order: 3; flex-basis: 100%; }
  .stat-value { font-size: 1.4rem; }
  .kv-row { grid-template-columns: 1fr; gap: 2px; }
}
