:root {
  color-scheme: dark;
  --bg: #12141a;
  --panel: #1a1d26;
  --panel-2: #22262f;
  --border: #2c313d;
  --text: #e7e9ee;
  --muted: #8b93a3;
  --accent: #5aa6ff;
  --accent-2: #7ee08a;
  --danger: #ff6b6b;
  --danger-bg: #3a1f22;
  --ok-bg: #1c3324;
  --err-bg: #3a1f22;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
code { background: var(--panel-2); padding: 0 4px; border-radius: 4px; font-size: 0.9em; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  padding: 12px 24px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-row { display: flex; align-items: center; gap: 18px; padding-bottom: 10px; }
.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0; object-fit: cover; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding-bottom: 8px; }
.tabs a {
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 500;
}
.tabs a:hover { background: var(--panel-2); color: var(--text); }
.tabs a.active { background: var(--accent); color: #061420; }
.logout-form, .header-restart-form { margin: 0; }
.logout-form { margin-left: auto; }
.header-restart-form button { align-self: center; }
.link-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 0.9rem; padding: 6px 10px;
}
.link-btn:hover { color: var(--text); }

.global-health {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 14px; font-size: 0.88rem; font-weight: 600;
  white-space: nowrap;
}
.global-health-label { color: var(--text); }

/* ---------------------------------------------------------------- layout */
main { max-width: 900px; margin: 28px auto; padding: 0 20px 60px; }
.grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 720px) { .grid { grid-template-columns: 1.3fr 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 1.1rem; }
.card h2.inline { display: inline; cursor: pointer; }
.card-header-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.button-row form { display: block; }

.flash { padding: 12px 16px; border-radius: 8px; margin: 0 auto 20px; max-width: 900px; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: var(--accent-2); }
.flash.error { background: var(--err-bg); color: var(--danger); }

/* ---------------------------------------------------------------- forms */
form { display: flex; flex-direction: column; gap: 14px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px 18px; margin: 0; }
legend { padding: 0 8px; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; color: var(--muted); }
label + label { margin-top: 10px; }
fieldset label { margin-top: 10px; }
fieldset label:first-of-type { margin-top: 0; }

input[type=text], input[type=password], input[type=number], select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.95rem;
  font-family: inherit;
}
textarea.raw-editor { width: 100%; resize: vertical; }
.inline-number { width: 80px; display: inline-block; }
.checkbox-row { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-row input[type=checkbox] { width: 17px; height: 17px; }

button {
  background: var(--accent);
  color: #061420;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  align-self: flex-start;
}
button:hover { filter: brightness(1.08); }
button.danger { background: var(--danger); color: #2a0a0a; }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.small { padding: 6px 12px; font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

/* ---------------------------------------------------------------- settings fields */
.field-row {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
fieldset .field-row:last-child { border-bottom: none; padding-bottom: 0; }
fieldset .field-row:first-child { padding-top: 0; }
.field-info { flex: 1 1 auto; min-width: 0; }
.field-label { display: block; font-weight: 600; color: var(--text); font-size: 0.94rem; }
.field-desc { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.field-control { flex: 0 0 auto; width: 220px; display: flex; justify-content: flex-end; }
.field-control input[type=text], .field-control input[type=password],
.field-control input[type=number], .field-control select { width: 100%; }

.slider-control { display: flex; align-items: center; gap: 10px; width: 100%; }
.slider-control input[type=range] {
  flex: 1; accent-color: var(--accent); height: 4px; background: transparent;
}
.slider-control output {
  min-width: 3.4em; text-align: right; font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.88rem; color: var(--text); background: var(--panel-2);
  border-radius: 6px; padding: 2px 6px;
}

.switch { display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 42px; height: 24px; border-radius: 999px; background: var(--panel-2);
  border: 1px solid var(--border); position: relative; transition: background 0.15s;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--muted); transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); background: #061420; }

@media (max-width: 560px) {
  .field-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .field-control { width: 100%; justify-content: stretch; }
}

/* ---------------------------------------------------------------- tables */
table.list { width: 100%; border-collapse: collapse; margin-top: 10px; }
table.list th, table.list td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
table.list th { color: var(--muted); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.tag {
  display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); font-size: 0.72rem; vertical-align: middle;
}

/* ---------------------------------------------------------------- version */
.version-list { display: flex; flex-direction: column; gap: 8px; }
.version-option {
  flex-direction: row; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px;
  cursor: pointer;
}
.version-option.is-current { border-color: var(--accent); }
.version-option input { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- health */
.health-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.health-stat { background: var(--panel-2); border-radius: 8px; padding: 12px 14px; }
.health-stat .label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.health-stat .value { font-size: 1.5rem; font-weight: 700; margin-top: 2px; }
.status-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 8px; flex-shrink: 0; }
.status-dot.healthy { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }
.status-dot.unhealthy { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.status-dot.starting { background: #e8b83c; box-shadow: 0 0 8px #e8b83c; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.status-line { font-size: 1.1rem; font-weight: 600; margin-bottom: 14px; }
.small-value { font-size: 1.05rem !important; }
.tag.ok { color: var(--accent-2); }
.tag.err { color: var(--danger); }

/* ---------------------------------------------------------------- login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 36px 34px; width: 320px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.login-icon { width: 56px; height: 56px; border-radius: 12px; display: block; margin: 0 auto; object-fit: cover; }
.login-card h1 { font-size: 1.2rem; text-align: center; margin: 0; }
.login-card p { text-align: center; margin: 0 0 6px; }
.login-card button { align-self: stretch; text-align: center; margin-top: 6px; }

/* ---------------------------------------------------------------- spinner */
.spinner-overlay {
  position: fixed; inset: 0; background: rgba(10,11,15,0.65);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  z-index: 100;
}
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid var(--panel-2); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner-label { color: var(--text); font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }
