:root {
  color-scheme: light dark;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #fafbfc;
  --border: #e3e6ea;
  --border-strong: #d2d7dd;
  --text: #14181d;
  --text-muted: #616b78;
  --accent: #3f6fd8;
  --accent-soft: #eaf0fd;
  --ok: #1f8a4c;
  --ok-soft: #e6f4ec;
  --warn: #a76a00;
  --warn-soft: #fdf1de;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.05);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #161a20;
    --surface-alt: #1b2027;
    --border: #262c35;
    --border-strong: #333b46;
    --text: #e7ebf0;
    --text-muted: #949eab;
    --accent: #6f9bff;
    --accent-soft: #1b2740;
    --ok: #4ecb84;
    --ok-soft: #14301f;
    --warn: #e0a742;
    --warn-soft: #33270f;
    --danger: #ff7b6b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

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

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

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #8c5bd8);
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.status-cluster {
  display: flex;
  align-items: center;
  gap: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.stat-value {
  font-size: 20px;
  font-weight: 640;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.connection {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 12px;
  color: var(--text-muted);
}

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

.connection[data-state="live"] {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: transparent;
}
.connection[data-state="live"] .dot {
  background: var(--ok);
  animation: pulse 2s ease-in-out infinite;
}
.connection[data-state="down"] {
  color: var(--danger);
  border-color: var(--danger);
}
.connection[data-state="down"] .dot {
  background: var(--danger);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* --- layout ------------------------------------------------------------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  padding: 20px 24px;
  align-items: start;
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.hint {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* --- table -------------------------------------------------------------- */

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

.server-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.server-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 10px 18px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.server-table td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.server-table tbody tr {
  cursor: pointer;
  transition: background 0.12s ease;
}

.server-table tbody tr:hover {
  background: var(--surface-alt);
}

.server-table tbody tr[aria-selected="true"] {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.server-table tbody tr.leaving {
  opacity: 0.35;
}

.room {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
}

.muted {
  color: var(--text-muted);
}

.players {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar {
  display: block;
  margin-top: 5px;
  width: 68px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.bar.full span {
  background: var(--warn);
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge[data-status="active"] {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: transparent;
}
.badge[data-status="in_progress"] {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}
.badge[data-status="full"],
.badge[data-status="starting"] {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: transparent;
}

.heartbeat {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  white-space: nowrap;
}

.heartbeat[data-stale="true"] {
  color: var(--warn);
  font-weight: 600;
}

.empty {
  margin: 0;
  padding: 40px 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* --- detail panel ------------------------------------------------------- */

.detail-panel .fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
  padding: 18px;
}

.field {
  min-width: 0;
}

.field.wide {
  grid-column: 1 / -1;
}

.field dt {
  margin: 0 0 3px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.field dd {
  margin: 0;
  font-size: 14px;
  word-break: break-word;
}

.field dd.mono {
  font-family: var(--mono);
  font-size: 13px;
}

.users {
  border-top: 1px solid var(--border);
  padding: 14px 18px 18px;
}

.users h3 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
}

.avatar {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 650;
  color: #fff;
  background: var(--accent);
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
}

.user-id {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
  line-height: 1.25;
}

.footer {
  padding: 12px 24px 20px;
  font-size: 12px;
  color: var(--text-muted);
}

/* --- console shell ------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  padding: 3px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 6px 13px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

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

.tab[aria-current="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.view-root {
  flex: 1;
  padding: 20px 24px;
}

.panel-body {
  padding: 18px;
}

.panel-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 960px) {
  .grid-two {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* --- buttons ------------------------------------------------------------- */

.button {
  appearance: none;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.button:hover {
  background: var(--surface-alt);
}

.button:disabled {
  opacity: 0.55;
  cursor: default;
}

.button-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.button-primary:hover {
  background: var(--accent);
  filter: brightness(1.08);
}

.button-danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.button-danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.button-quiet {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
  padding: 5px 11px;
  font-size: 12px;
}

.button-quiet:hover {
  color: var(--text);
  background: var(--surface-alt);
}

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* --- forms --------------------------------------------------------------- */

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.form-input,
.form-select,
.form-textarea {
  font: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text);
  width: 100%;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  background: var(--surface);
}

.form-textarea {
  min-height: 74px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.checkbox-grid {
  display: grid;
  gap: 8px;
}

.check {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  cursor: pointer;
}

.check:hover {
  border-color: var(--border-strong);
}

.check input {
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.check-text {
  min-width: 0;
}

.check-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--mono);
}

.check-desc {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* --- notices and toasts -------------------------------------------------- */

.notice {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
}

.notice-error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.notice-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.notice-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.notice-info {
  background: var(--accent-soft);
  color: var(--accent);
}

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}

.toast {
  padding: 11px 15px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 360px;
  animation: toast-in 0.18s ease;
}

.toast[data-kind="error"] {
  border-color: var(--danger);
  color: var(--danger);
}

.toast[data-kind="ok"] {
  border-color: var(--ok);
  color: var(--ok);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* --- credential and integration cards ------------------------------------ */

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
}

.card {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-alt);
  padding: 13px 15px;
}

.card[data-disabled="true"] {
  opacity: 0.6;
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.card-title {
  font-size: 14px;
  font-weight: 640;
  margin: 0;
}

.card-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
}

.chip {
  font-size: 11px;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.chip-muted {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.card-foot {
  margin-top: 11px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* --- secrets and code ---------------------------------------------------- */

.secret-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: 9px;
  background: var(--surface-alt);
  margin: 12px 0;
}

.secret-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.secret-value {
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-all;
  flex: 1;
  min-width: 200px;
}

.secret-value.break {
  font-size: 11px;
}

.code-block {
  position: relative;
  margin: 0;
  padding: 14px 15px;
  border-radius: 9px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.code-block code {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
  color: var(--text);
}

.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 16px 0 7px;
}

.code-head h4 {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

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

.var-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
}

.var-table td:first-child {
  color: var(--text-muted);
  white-space: nowrap;
  width: 1%;
}

.details-block {
  margin: 12px 0;
  font-size: 13px;
}

.details-block summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
}

/* --- auth pages ---------------------------------------------------------- */

.auth-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: 100%;
  max-width: 460px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 26px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.auth-title {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 640;
}

.auth-lede {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.auth-form,
.auth-form-inline {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form-inline {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.auth-foot {
  margin: 22px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

.recovery-block {
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--warn);
  border-radius: 9px;
  background: var(--warn-soft);
}

.recovery-block h3 {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--warn);
}

.recovery-list {
  list-style: none;
  margin: 10px 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  font-family: var(--mono);
  font-size: 13px;
}

/* --- misc ---------------------------------------------------------------- */

.kv-list {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 13px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--border);
}

.kv:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.kv-key {
  color: var(--text-muted);
}

.kv-value {
  font-family: var(--mono);
  font-size: 12px;
  text-align: right;
  word-break: break-word;
}

.log-list {
  list-style: none;
  margin: 0;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 12px;
}

.log-list li {
  display: flex;
  gap: 10px;
  color: var(--text-muted);
}

.log-time {
  font-family: var(--mono);
  white-space: nowrap;
}

/* --- inline connect panel inside a credential card ---------------------- */

.inline-connect {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.inline-guide {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inline-guide .code-block {
  max-height: 260px;
}

/* --- empty-state signpost ----------------------------------------------- */

.empty-help {
  max-width: 520px;
  margin: 0 auto;
  text-align: left;
  color: var(--text);
  font-size: 14px;
}

.empty-help > p {
  margin: 0 0 12px;
  color: var(--text-muted);
}

.empty-steps {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  line-height: 1.55;
}

.link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.link:hover {
  text-decoration: underline;
}

/* --- test-server panel + detail actions --------------------------------- */

.test-server-panel > summary {
  cursor: pointer;
  list-style: none;
}

.test-server-panel > summary::-webkit-details-marker {
  display: none;
}

.test-server-panel > summary::after {
  content: "+";
  margin-left: auto;
  font-weight: 600;
  color: var(--text-muted);
  padding-left: 12px;
}

.test-server-panel[open] > summary::after {
  content: "-";
}

.form-grid-cols {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 720px) {
  .form-grid-cols {
    grid-template-columns: 1fr;
  }
}

.detail-actions {
  padding: 14px 18px 18px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}
