:root {
  --bg: #0a0e14;
  --bg-soft: #0e141c;
  --panel: #111923;
  --panel-2: #141e2a;
  --line: rgba(148, 163, 184, 0.14);
  --line-strong: rgba(148, 163, 184, 0.26);
  --text: #e6edf5;
  --muted: #8494a8;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, 0.12);
  --blue: #60a5fa;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(94, 234, 212, 0.07), transparent 60%), var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- login */

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(360px, 100%);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.login-logo {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(94, 234, 212, 0.24);
  margin-bottom: 18px;
}

.login-card h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.login-sub { margin: 2px 0 24px; color: var(--muted); font-size: 13px; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

input, select {
  width: 100%;
  background: #0b1219;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--sans);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  border-color: rgba(94, 234, 212, 0.55);
  box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.1);
}

.login-error { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 12px; }
.login-hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; }

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

.app {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 20px 14px 16px;
  background: rgba(10, 15, 22, 0.72);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; color: var(--accent); }
.brand strong { display: block; color: var(--text); font-size: 15px; letter-spacing: -0.01em; }
.brand span { display: block; color: var(--muted); font-size: 11px; font-family: var(--mono); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item svg { width: 17px; height: 17px; flex: none; }
.nav-item:hover { background: rgba(148, 163, 184, 0.07); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 8px 0;
  border-top: 1px solid var(--line);
  font-size: 11px;
}

.live { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); }
.live i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.12);
}
.live i.ok { background: var(--accent); box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.14); }
.live i.bad { background: var(--danger); box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.14); }

.main { min-width: 0; padding: 0 28px 40px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 0 18px;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--bg) 70%, rgba(10, 14, 20, 0));
  z-index: 5;
}

.topbar h1 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.topbar p { margin: 2px 0 0; font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}

.content { display: flex; flex-direction: column; gap: 18px; }
.view { display: flex; flex-direction: column; gap: 18px; }

/* ------------------------------------------------------------- controls */

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #1a2634; border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06231e; font-weight: 600; }
.btn.primary:hover { background: #7df0dc; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(148, 163, 184, 0.08); }
.btn.block { width: 100%; padding: 10px 14px; }
.btn.small { padding: 5px 10px; font-size: 12px; }

.seg { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: 9px; background: #0b1219; }
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.seg button.active { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04); }

/* ---------------------------------------------------------------- cards */

.card {
  background: linear-gradient(180deg, rgba(20, 30, 42, 0.72), rgba(17, 25, 35, 0.72));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.card-head p { margin: 2px 0 0; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }

.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }

.stat {
  background: linear-gradient(180deg, rgba(20, 30, 42, 0.9), rgba(17, 25, 35, 0.9));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}
.stat .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.stat .value { margin-top: 6px; font-size: 24px; font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat .meta { margin-top: 4px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .value.good { color: var(--accent); }
.stat .value.bad { color: var(--danger); }

/* ---------------------------------------------------------------- chart */

.chart-wrap { height: 240px; position: relative; }
.chart { width: 100%; height: 100%; display: block; overflow: visible; }

.chart-foot { display: flex; align-items: center; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 9px; height: 9px; border-radius: 2px; display: inline-block; background: var(--muted); }
.swatch.accent { background: var(--accent); }
.swatch.blue { background: var(--blue); }
.swatch.danger { background: var(--danger); }
.swatch.muted { background: rgba(148, 163, 184, 0.5); }

/* ----------------------------------------------------------- bar lists */

.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.bar-row .name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .meta { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.bar-track { display: block; grid-column: 1 / -1; height: 7px; border-radius: 999px; background: rgba(148, 163, 184, 0.1); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, rgba(94, 234, 212, 0.55), var(--accent)); }

.error-list { display: flex; flex-direction: column; gap: 10px; max-height: 240px; overflow: auto; }
.error-item { border-left: 2px solid var(--danger); padding: 2px 0 2px 10px; }
.error-item .meta { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.error-item .msg { font-size: 12px; word-break: break-word; }

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

.table-wrap { overflow: auto; margin: 0 -8px; padding: 0 8px; }

.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: #101823;
}
.table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  white-space: nowrap;
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: rgba(148, 163, 184, 0.04); }
.table.compact td { padding: 7px 10px; }
.table .ellipsis { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.table .empty { color: var(--muted); text-align: center; padding: 26px 10px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-family: var(--mono);
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(148, 163, 184, 0.06);
}
.badge.ok { color: var(--accent); border-color: rgba(94, 234, 212, 0.3); background: rgba(94, 234, 212, 0.08); }
.badge.bad { color: var(--danger); border-color: rgba(248, 113, 113, 0.32); background: rgba(248, 113, 113, 0.08); }
.badge.warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.32); background: rgba(251, 191, 36, 0.08); }

/* ------------------------------------------------------------------ kv */

.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 0; }
.kv > div { padding: 9px 0; border-bottom: 1px solid rgba(148, 163, 184, 0.08); font-size: 12.5px; min-width: 0; }
.kv > div:nth-last-child(-n + 2) { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); word-break: break-all; }

.runtime-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.runtime-form .field.inline { margin: 0; }
.runtime-form .field.inline input { width: 96px; }
.runtime-form .muted { padding-bottom: 10px; }
.runtime-form b { color: var(--text); font-weight: 600; }

.test-row { display: flex; gap: 10px; margin-bottom: 12px; }
.test-row .select { flex: 1; }
.test-result {
  margin: 0;
  padding: 12px 14px;
  border-radius: 9px;
  background: #0b1219;
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 74px;
}

/* ---------------------------------------------------------- account pool */

.row-actions { display: flex; align-items: center; gap: 10px; }
.switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.switch input { accent-color: var(--accent); }
.account-list { display: flex; flex-direction: column; }
.account-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) repeat(3, minmax(0, 0.6fr)) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  font-size: 12.5px;
}
.account-row:last-child { border-bottom: 0; }
.account-row .name { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.account-row .name strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-row .sub { color: var(--muted); font-family: var(--mono); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-row .metric { display: flex; flex-direction: column; gap: 2px; }
.account-row .metric span:first-child { font-family: var(--mono); }
.account-row .metric span:last-child { color: var(--muted); font-size: 11px; }
.account-row .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.account-row.disabled { opacity: 0.55; }
.account-form { display: grid; grid-template-columns: 1fr 1.35fr 0.45fr auto; gap: 12px; align-items: end; }
.account-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.account-form input, .account-form select {
  background: #0b1219;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  padding: 9px 11px;
  font-family: inherit;
  font-size: 13px;
}
.account-form input:focus, .account-form select:focus { outline: none; border-color: var(--accent); }
.account-form .span-2 { grid-column: span 3; }
.account-form .span-3 { grid-column: 1 / -1; }
.account-form button { height: 38px; }

@media (max-width: 1100px) {
  .account-row { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; }
  .account-row .metric { display: none; }
}
@media (max-width: 900px) {
  .account-form { grid-template-columns: 1fr; }
  .account-form .span-2 { grid-column: span 1; }
  .account-form .span-3 { grid-column: span 1; }
}

/* --------------------------------------------------------------- modals */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 7, 12, 0.72);
  backdrop-filter: blur(3px);
}
.modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  animation: modal-in 0.16s ease-out;
}
.modal-panel.wide { width: min(760px, 100%); }
.modal-panel.narrow { width: min(420px, 100%); }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-head p { margin: 3px 0 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
.account-form .modal-actions,
.key-form .modal-actions { grid-column: 1 / -1; }
.icon-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.icon-btn:hover { color: var(--text); }
.btn.danger {
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
}
.btn.danger:hover { background: rgba(248, 113, 113, 0.1); }
.key-form { display: grid; grid-template-columns: 1fr; gap: 12px; }
.key-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.key-form input {
  background: #0b1219;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
}
.key-form input:focus { outline: none; border-color: var(--accent); }

/* ------------------------------------------------------------- account detail */

.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.detail-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  background: #0b1219;
}
.detail-block h3 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.detail-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.detail-stat { display: flex; flex-direction: column; gap: 2px; }
.detail-stat strong { font-family: var(--mono); font-size: 18px; font-weight: 500; }
.detail-stat span { color: var(--muted); font-size: 11px; }
.detail-lines { display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; }
.detail-lines > div { display: flex; justify-content: space-between; gap: 12px; }
.detail-lines .k { color: var(--muted); flex: none; }
.detail-lines .v { font-family: var(--mono); text-align: right; word-break: break-all; }

/* -------------------------------------------------------------- keys page */

.endpoint {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: #0b1219;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.endpoint code { flex: 1; font-family: var(--mono); font-size: 14px; overflow: auto; white-space: nowrap; }
.code-block {
  margin: 12px 0 0;
  padding: 12px 14px;
  background: #0b1219;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}
.empty-block { padding: 18px 0 4px; }
.key-list { display: flex; flex-direction: column; }
.key-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.2fr) minmax(0, 0.8fr) minmax(0, 0.8fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  font-size: 12.5px;
}
.key-row:last-child { border-bottom: 0; }
.key-row .name { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.key-row .name strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-row .sub { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-row .mask { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-row .actions { display: flex; gap: 6px; justify-content: flex-end; }
.key-row.disabled { opacity: 0.55; }
.reveal-key {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: #0b1219;
  border: 1px solid rgba(94, 234, 212, 0.3);
  border-radius: 10px;
}
.reveal-key code {
  flex: 1;
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-all;
  color: var(--accent);
}

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  min-width: 220px;
  max-width: 360px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.18s ease-out;
}
.toast.ok { border-color: rgba(94, 234, 212, 0.35); }
.toast.bad { border-color: rgba(248, 113, 113, 0.4); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all 0.18s ease-in; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .key-row { grid-template-columns: minmax(0, 1fr) auto; }
  .key-row .mask, .key-row .sub.meta { display: none; }
  .modal { padding: 12px; }
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1200px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 12px; overflow-x: auto; }
  .brand { flex: none; }
  .nav { flex-direction: row; }
  .nav-item { white-space: nowrap; }
  .sidebar-foot { display: none; }
  .main { padding: 0 16px 32px; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
