:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --text-secondary: #b7bdca;
  --muted: #8b93a5;
  --series-1: #3987e5;
  --grid: #262b35;
  --axis: #3a404d;
  --accent: #d9a441;
  --accent-text: #1a1408;
  --ok: #4cc38a;
  --warn: #e0b341;
  --bad: #e5635c;
  --info: #6aa8ff;
  --radius: 10px;
  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}

.tab {
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}

.tab:hover {
  color: var(--text);
}

.node-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bad);
}

.node-dot[data-online="1"] {
  background: var(--ok);
}

.tab.active {
  background: var(--surface-2);
  color: var(--text);
}

.link-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.link-state[data-state="ok"] .dot { background: var(--ok); }
.link-state[data-state="bad"] .dot { background: var(--bad); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  padding: 16px 24px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

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

.log-card,
.perf-card {
  grid-column: 1 / -1;
}

.perf-system {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.perf-groups {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.perf-group {
  min-width: 0;
}

.perf-group-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin-bottom: 8px;
}

.perf-group-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.perf-proc {
  margin-left: 6px;
  color: var(--muted);
  font-weight: 400;
  font-size: 13px;
}

.perf-meta {
  color: var(--muted);
  font-size: 12.5px;
}

.perf-tiles {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px 8px;
  min-width: 0;
}

.tile-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.tile-label {
  color: var(--text-secondary);
  font-size: 13px;
}

.tile-value {
  font-size: 22px;
  font-weight: 600;
}

.tile-chart {
  position: relative;
  height: 72px;
  margin-top: 6px;
  border-radius: 4px;
  cursor: crosshair;
}

.tile-chart:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tile-chart svg {
  display: block;
  overflow: visible;
}

.tile-chart .grid,
.tile-chart .baseline {
  stroke: var(--grid);
  stroke-width: 1;
}

.tile-chart .baseline {
  stroke: var(--axis);
}

.tile-chart .line {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.tile-chart .area {
  fill: var(--series-1);
  opacity: 0.1;
}

.tile-chart .end-dot {
  fill: var(--series-1);
  stroke: var(--surface-2);
  stroke-width: 2;
}

.tile-chart .cross {
  stroke: var(--axis);
  stroke-width: 1;
}

.axis-max {
  position: absolute;
  top: -2px;
  left: 0;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.tile-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11.5px;
}

.tile-stats {
  color: var(--text-secondary);
  text-align: center;
}

.perf-hint {
  margin: 12px 0 0;
}

.chart-tip {
  position: fixed;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  white-space: nowrap;
}

.chart-tip strong {
  font-size: 14px;
}

.tip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 12px;
}

.tip-key {
  width: 12px;
  height: 2px;
  border-radius: 1px;
  background: var(--series-1);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.badge[data-state="running"] { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.badge[data-state="paused"],
.badge[data-state="pausing"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge[data-state="starting"],
.badge[data-state="stopping"] { color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, transparent); }
.badge[data-state="failed"],
.badge[data-state="offline"],
.badge[data-state="not_installed"] { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

.badge[data-state="starting"]::before,
.badge[data-state="stopping"]::before,
.badge[data-state="pausing"]::before {
  animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.25; }
}

.facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 16px;
  margin: 0;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}

.note {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
}

.note[data-tone="bad"] {
  color: var(--text);
  background: color-mix(in srgb, var(--bad) 16%, var(--surface-2));
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--muted);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn.danger {
  color: var(--bad);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.busy {
  opacity: 0.7;
  cursor: progress;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 12px 0 16px;
}

.params {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.params label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.params label.wide {
  grid-column: span 2;
}

.params span {
  color: var(--muted);
  font-size: 12.5px;
}

.params select,
.params input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

.params select:disabled,
.params input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.params select:focus,
.params input:focus,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--bad) 16%, var(--surface-2));
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.log {
  height: 52vh;
  min-height: 280px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
}

.log div {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.log .t { color: var(--muted); }
.log .kill { color: var(--ok); }
.log .elite { color: var(--accent); }
.log .err { color: var(--bad); }
.log .pause { color: var(--warn); }
.log .sys { color: var(--info); }

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 12px 16px 16px;
  }

  .topbar {
    padding: 10px 16px;
    gap: 12px;
  }

  .params {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .perf-groups {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 520px) {
  .link-state #link-text {
    display: none;
  }

  .facts {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }

  .facts dd {
    margin-bottom: 8px;
  }

  .perf-tiles {
    grid-template-columns: minmax(0, 1fr);
  }

  .perf-system {
    text-align: left;
  }

  .perf-card .card-head {
    flex-wrap: wrap;
  }
}

.btn-ghost {
  background: transparent;
  padding: 6px 12px;
  font-size: 13px;
}

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

.login-card {
  width: min(360px, 100%);
  padding: 28px 24px;
}

.login-card .brand {
  margin-bottom: 20px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.login-form span {
  color: var(--muted);
  font-size: 12.5px;
}

.login-form input {
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

.login-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.login-form .error {
  margin: 0;
}
