:root {
  --bg: #ffffff;
  --fg: #1a1d21;
  --muted: #6b7280;
  --border: #e2e5e9;
  --surface: #f7f8fa;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --fg: #e6e8eb;
    --muted: #9aa1ab;
    --border: #2b2f36;
    --surface: #1b1e23;
    --accent: #3b82f6;
    --accent-fg: #0b1220;
    --danger: #f87171;
    --ok: #4ade80;
    --warn: #fbbf24;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 32px 0 12px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar .brand { font-weight: 600; color: var(--fg); text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 16px; }
.topbar nav a { color: var(--muted); text-decoration: none; }
.topbar nav a:hover { color: var(--fg); }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

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

a.button, button, .button {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}

button:disabled { opacity: 0.4; cursor: not-allowed; }
button.danger { background: var(--danger); }
button.link-button { background: none; color: var(--muted); padding: 0; text-decoration: underline; }

.inline-form { display: inline-block; margin: 0; }

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.table th, .table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.table th { color: var(--muted); font-weight: 500; }
.table a { color: var(--accent); text-decoration: none; }

.row-actions form { display: inline; }

.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--surface);
  border: 1px solid var(--border);
}

.status-running, .status-success { color: var(--ok); border-color: var(--ok); }
.status-starting { color: var(--warn); border-color: var(--warn); }
.status-unhealthy { color: var(--warn); border-color: var(--warn); }
.status-crashed, .status-failed { color: var(--danger); border-color: var(--danger); }
.status-stopped { color: var(--muted); }

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 480px;
}

.form.inline {
  flex-direction: row;
  align-items: flex-end;
  max-width: none;
  margin-bottom: 20px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.88rem;
  color: var(--muted);
}

input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

textarea { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.85rem; resize: vertical; }

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.checkbox-label input { width: auto; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-size: 0.9rem;
}

.meta-grid .full { grid-column: 1 / -1; }
.meta-label { display: block; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; }

.copy-btn {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 3px 9px;
  font-size: 0.78rem;
  margin-left: 8px;
}

.log-viewer { max-height: 420px; overflow-y: auto; }

.log-box {
  background: #0d1117;
  color: #c9d1d9;
  padding: 14px;
  border-radius: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

code.pubkey {
  font-size: 0.78rem;
  word-break: break-all;
}

.error {
  background: #fee2e2;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.88rem;
}

@media (prefers-color-scheme: dark) {
  .error { background: #3f1d1d; color: #fca5a5; }
}

.hint { color: var(--muted); font-size: 0.85rem; }
.empty { color: var(--muted); }

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 320px;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.login-form h1 { text-align: center; margin-bottom: 8px; }
