:root {
  color-scheme: dark light;
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1c232c;
  --border: #29313d;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4c9aff;
  --accent-ink: #04101f;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --surface: #ffffff;
    --surface-2: #f0f3f6;
    --border: #d7dde5;
    --text: #1c2128;
    --muted: #62707f;
    --accent: #0a66c2;
    --accent-ink: #ffffff;
    --ok: #1a7f37;
    --warn: #9a6700;
    --bad: #cf222e;
  }
}

* { 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;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 1.05rem; letter-spacing: 0.01em; }
h2 { font-size: 0.95rem; }

code, pre { font-family: var(--mono); font-size: 0.85em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- top bar --- */

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

.brand { display: flex; align-items: baseline; gap: 10px; }

.logo {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
  align-self: center;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }

.key-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.key-field input {
  width: 190px;
  padding: 3px 0;
  border: 0;
  background: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
}
.key-field input:focus { outline: none; }

.icon-btn {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
  border-radius: 6px;
}
.icon-btn:hover { color: var(--text); background: var(--border); }

/* --- layout --- */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}
@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  /* Grid items default to min-width:auto, so the long token and the shell
     snippet would otherwise widen the column instead of wrapping/scrolling. */
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

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

.card p { margin: 0 0 12px; }

/* --- controls --- */

button.primary {
  padding: 7px 14px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 550;
  font-size: 0.88rem;
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.5; cursor: progress; }

button.ghost {
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
button.ghost:hover:not(:disabled) { color: var(--bad); border-color: var(--bad); }
button.ghost:disabled { opacity: 0.35; cursor: default; }

.auto-refresh { display: flex; align-items: center; gap: 6px; }

/* --- new connection --- */

.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 18px;
  margin: 0 0 14px;
  align-items: baseline;
}
.kv dt { color: var(--muted); font-size: 0.85rem; }
.kv dd { margin: 0; min-width: 0; }
.kv .token { word-break: break-all; color: var(--muted); }

.copyable { cursor: copy; }
.copyable:hover { color: var(--accent); }

.snippet {
  margin: 0;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre;
  color: var(--muted);
}

/* --- nodes --- */

.node-list { display: flex; flex-direction: column; gap: 10px; }

.node {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.node-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.node-head code { font-size: 0.9rem; }
.node-stats {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 12px;
  font-size: 0.8rem;
  color: var(--muted);
}
.node-stats b { color: var(--text); font-weight: 550; font-variant-numeric: tabular-nums; }

/* --- table --- */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th {
  text-align: left;
  font-weight: 550;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 9px 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

/* --- pills --- */

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 550;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill-ok      { color: var(--ok);   background: color-mix(in srgb, var(--ok) 14%, transparent);   border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.pill-warn    { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.pill-bad     { color: var(--bad);  background: color-mix(in srgb, var(--bad) 14%, transparent);  border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.pill-idle    { color: var(--muted); background: var(--surface-2); border-color: var(--border); }

/* --- banner --- */

.banner {
  margin: 0;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bad) 16%, var(--surface));
  border-bottom: 1px solid color-mix(in srgb, var(--bad) 40%, transparent);
  color: var(--text);
  font-size: 0.88rem;
}
.banner.ok {
  background: color-mix(in srgb, var(--ok) 14%, var(--surface));
  border-bottom-color: color-mix(in srgb, var(--ok) 35%, transparent);
}
