:root {
  color-scheme: dark;
  --bg: #0f141a;
  --panel: #171f27;
  --panel-2: #202a33;
  --panel-3: #111820;
  --text: #edf3f7;
  --muted: #9aaab8;
  --faint: #6f7f8c;
  --border: #2b3945;
  --border-strong: #3b4c5b;
  --accent: #2d8790;
  --accent-hover: #38a1ac;
  --accent-soft: #18343a;
  --success: #47b887;
  --warn: #d39a32;
  --danger: #e15f66;
  --danger-soft: #321d24;
  --shadow: 0 18px 42px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  letter-spacing: 0;
}

button, input, textarea, select { font: inherit; }

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  border-radius: 8px;
  min-height: 36px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 600;
}
button:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button:disabled { cursor: not-allowed; opacity: .46; }
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(56, 161, 172, .72);
  outline-offset: 2px;
}
button.secondary {
  background: var(--accent-soft);
  color: #dff6f7;
  border-color: #2f6f78;
}
button.secondary:hover:not(:disabled) { background: #21434a; border-color: var(--accent-hover); }
button.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
button.ghost:hover:not(:disabled) { background: var(--panel-2); border-color: var(--faint); }
button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}
button.danger:hover:not(:disabled) { background: #f06d74; border-color: #f06d74; }
.danger-text { color: #ff9aa0 !important; }

input, select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 10px;
  background: #0f161d;
  color: var(--text);
}
select { cursor: pointer; }
textarea {
  width: 100%;
  min-height: 190px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 10px;
  background: #0f161d;
  color: var(--text);
  resize: vertical;
  font: 12px/1.45 Consolas, monospace;
}
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.hidden { display: none !important; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font: 700 13px/1 Consolas, monospace;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 18px; line-height: 1.1; }
h2 { font-size: 17px; line-height: 1.2; }
h3 { font-size: 15px; line-height: 1.2; }
p { color: var(--muted); }

.error {
  min-height: 18px;
  color: #ff9aa0;
  font-size: 13px;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: #12191f;
  border-bottom: 1px solid var(--border);
}
.top-actions {
  display: flex;
  gap: 10px;
}

.workspace-relay {
  min-height: 0;
  overflow: auto;
  padding: 22px 24px 34px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: #151d24;
}
.panel-head p { margin-top: 4px; font-size: 12px; }

.empty-inline { padding: 16px; color: var(--muted); font-size: 13px; }

/* ---- accounts ---- */
.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  padding: 16px;
}
.account-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-3);
}
.account-card.in-pool { box-shadow: inset 3px 0 0 var(--success); }
.account-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.account-card-main { min-width: 0; }
.account-card-main strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-card-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-card-usage {
  color: var(--muted);
  font-size: 12px;
}
.account-card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}
.account-card-actions button { flex: 1; min-width: 0; }

/* ---- relay clients ---- */
.relay-clients-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
  padding: 16px;
}
.relay-client-card {
  padding: 14px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.relay-client-card.revoked { opacity: .72; border-color: rgba(224, 91, 103, .35); }
.relay-client-head { display: flex; align-items: center; gap: 10px; }
.relay-client-head strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.relay-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.relay-chip.ok { background: rgba(71, 184, 135, .18); color: #6fe0ab; }
.relay-chip.warn { background: rgba(224, 91, 103, .18); color: #ff9aa0; }
.relay-key-row { display: flex; align-items: center; gap: 8px; }
.relay-key {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(0, 0, 0, .25);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
}
.relay-usage {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--muted);
}
.relay-current {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
}
.relay-current-label {
  color: var(--faint);
  text-transform: uppercase;
  font-weight: 700;
  font-size: 11px;
}
.relay-current-value {
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.relay-client-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: auto;
}
.relay-client-actions select { flex: 1 1 140px; min-width: 0; }

/* ---- dialogs ---- */
dialog {
  width: min(420px, calc(100vw - 28px));
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  background: var(--panel);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(3, 7, 11, .72); }
dialog.wide-dialog { width: min(640px, calc(100vw - 28px)); }
dialog form {
  display: grid;
  gap: 16px;
  padding: 20px;
}
dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
  padding: 0;
}
.dialog-note {
  color: var(--muted);
  font-size: 13px;
}

code {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid #6e5224;
  background: #15130f;
  color: #ffe1a6;
  font-family: Consolas, monospace;
  overflow-wrap: anywhere;
}
.login-credential {
  display: block;
  white-space: pre-wrap;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 240px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: #10171d;
  color: var(--text);
  box-shadow: var(--shadow);
}

@media (max-width: 640px) {
  .app { grid-template-rows: auto minmax(0, 1fr); }
  .topbar {
    height: auto;
    min-height: 86px;
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
    gap: 12px;
  }
  .top-actions { justify-content: flex-end; }
  .workspace-relay { padding: 16px; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .accounts-grid, .relay-clients-list { grid-template-columns: 1fr; padding: 12px; }
  .account-card-actions { flex-direction: column; }
}

.relay-chip.mid { background:rgba(234,179,8,0.18); color:#eab308; }
