:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #161a22;
  --surface-2: #1b2029;
  --surface-3: #202632;
  --border: #2a3140;
  --border-strong: #394356;
  --text: #e7edf6;
  --muted: #94a3b8;
  --faint: #67748a;
  --accent: #7dd3fc;
  --accent-strong: #38bdf8;
  --good: #4ade80;
  --warn: #f59e0b;
  --bad: #f87171;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --radius: 8px;
  --radius-sm: 6px;
  --gap: 16px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

button,
input,
select,
textarea {
  border-radius: var(--radius-sm);
}

button {
  border: 1px solid var(--border-strong);
  background: linear-gradient(180deg, #243041, #1d2532);
  color: var(--text);
  padding: 0.65rem 0.9rem;
  min-height: 40px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease, opacity 0.12s ease;
}

button:hover:not(:disabled) {
  border-color: #4b5b73;
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.ghost {
  background: transparent;
}

button.danger {
  border-color: rgba(248, 113, 113, 0.35);
  color: #ffd7d7;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #0f141b;
  color: var(--text);
  padding: 0.7rem 0.8rem;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(125, 211, 252, 0.75);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}

textarea {
  resize: vertical;
  min-height: 90px;
}

label {
  color: var(--muted);
  font-size: 0.92rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.56rem 0.75rem;
  border-bottom: 1px solid rgba(42, 49, 64, 0.8);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0;
  font-weight: 600;
}

td {
  color: var(--text);
}

td button {
  min-height: 16px;
  padding: 0.04rem 0.28rem;
  line-height: 1.1;
}

td button + button {
  margin-left: 6px;
}

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

.public-shell,
.admin-gate {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(125, 211, 252, 0.06), transparent 34%),
    var(--bg);
}

.public-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px clamp(16px, 5vw, 56px);
  border-bottom: 1px solid var(--border);
  background: rgba(18, 22, 29, 0.78);
}

.public-main,
.admin-gate {
  display: grid;
  place-items: center;
  padding: clamp(20px, 5vw, 72px);
}

.join-hero {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: clamp(18px, 4vw, 44px);
  align-items: center;
}

.join-copy {
  display: grid;
  gap: 14px;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
}

.join-copy h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 4.2rem);
  line-height: 1.04;
  letter-spacing: 0;
}

.join-copy p {
  margin: 0;
  max-width: 560px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.8;
}

.join-card,
.admin-key-card {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0)), var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(18px, 4vw, 28px);
  display: grid;
  gap: 14px;
}

.join-card {
  min-width: 0;
}

.admin-key-card {
  width: min(460px, 100%);
}

.public-result {
  margin: 0;
  color: var(--muted);
  min-height: 24px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: 20px;
  border-right: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)),
    #12161d;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  scrollbar-gutter: stable;
}

.sidebar > * {
  width: 100%;
  min-width: 0;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0ea5e9, #22c55e);
  color: #03111c;
  font-weight: 800;
  letter-spacing: 0;
}

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

.brand-copy strong {
  font-size: 1.02rem;
}

.brand-copy span,
.status-meta,
.panel-head p,
.topbar p,
.mini-head span,
.quick-item span,
.metric span {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 12px;
}

.stack.narrow {
  gap: 8px;
}

.settings-panel {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  flex: 0 0 auto;
  width: 100%;
}

.settings-panel summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
}

.settings-panel summary::-webkit-details-marker {
  display: none;
}

.settings-panel summary::after {
  content: "▾";
  color: var(--muted);
  transition: transform 0.16s ease;
}

.settings-panel[open] summary::after {
  transform: rotate(180deg);
}

.settings-panel summary span {
  font-weight: 700;
}

.settings-panel summary small {
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: auto;
}

.settings-panel form {
  border-top: 1px solid var(--border);
  padding: 14px 16px 16px;
}

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

.connection-actions button {
  min-height: 38px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.connection-actions #loginBtn {
  grid-column: 1 / -1;
}

.connection-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 12px;
  row-gap: 8px;
  align-items: center;
}

.connection-options .checkline {
  min-height: 22px;
  align-items: center;
}

.connection-options .checkline span {
  line-height: 1;
  white-space: nowrap;
}

.field {
  display: grid;
  gap: 6px;
}

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

.row > * {
  min-width: 0;
}

.checkline {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.checkline input {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.status-card,
.mini-panel,
.panel {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), rgba(255, 255, 255, 0)),
    var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.status-card {
  padding: 16px;
  display: grid;
  gap: 14px;
  min-height: 0;
  flex: 0 0 auto;
  width: 100%;
}

.status-head,
.panel-head,
.mini-head,
.topbar,
.topbar-actions,
.status-grid,
.metric-grid,
.split-grid {
  display: flex;
  gap: 12px;
}

.status-head,
.mini-head,
.panel-head,
.topbar {
  align-items: center;
  justify-content: space-between;
}

.status-grid,
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.status-grid {
  grid-template-columns: 1fr;
}

.status-grid div,
.metric {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: grid;
  gap: 4px;
  min-width: 0;
}

.status-grid span,
.metric span {
  font-size: 0.82rem;
}

.status-grid strong,
.metric strong {
  font-size: 0.98rem;
  min-width: 0;
}

.status-grid strong {
  display: block;
  max-width: 100%;
  min-height: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.token-copy {
  width: 100%;
  max-width: 100%;
  min-height: 28px;
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-weight: 800;
  text-align: left;
  overflow-wrap: anywhere;
  white-space: normal;
  line-height: 1.35;
}

.token-copy:hover:not(:disabled) {
  transform: none;
  color: var(--accent);
}

.status-grid div {
  min-height: 72px;
}

.status-card .badge {
  align-self: start;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0.38rem 0.7rem;
  min-width: 62px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.badge.neutral {
  background: rgba(148, 163, 184, 0.12);
  border-color: rgba(148, 163, 184, 0.22);
  color: #d7e0ea;
}

.badge.good {
  background: rgba(74, 222, 128, 0.12);
  border-color: rgba(74, 222, 128, 0.22);
  color: #b7f5cf;
}

.badge.warn {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.24);
  color: #ffe0aa;
}

.badge.bad {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.24);
  color: #ffb7b7;
}

.tabs {
  display: grid;
  gap: 8px;
}

.tab-btn {
  width: 100%;
  justify-content: flex-start;
}

.tab-btn.active {
  border-color: rgba(125, 211, 252, 0.55);
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.18), rgba(29, 37, 50, 0.92));
}

.content {
  min-width: 0;
  padding: 20px;
  display: grid;
  gap: 16px;
  align-content: start;
}

.topbar {
  padding: 4px 0 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
}

.topbar p {
  margin: 4px 0 0;
}

.topbar-actions {
  align-items: center;
  flex-wrap: wrap;
}

.panel {
  display: none;
  padding: 18px;
  gap: 16px;
}

.tab-panel.active {
  display: grid;
}

.panel-head {
  align-items: flex-end;
}

.panel-head h2,
.mini-head h3 {
  margin: 0;
  font-size: 1rem;
}

.panel-head p {
  margin: 6px 0 0;
}

.metric-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.split-grid {
  align-items: start;
  flex-wrap: wrap;
}

.split-grid > .mini-panel {
  flex: 1 1 420px;
  min-width: min(100%, 420px);
}

.list-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

.list-grid > .mini-panel {
  min-width: 0;
  height: 100%;
  grid-template-rows: 30px auto minmax(180px, 1fr);
}

.list-grid .mini-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  height: 30px;
  min-height: 30px;
  align-items: center;
  overflow: hidden;
}

.list-grid .mini-head h3 {
  line-height: 30px;
}

.list-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 24px;
  line-height: 1;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.list-state.good {
  background: rgba(74, 222, 128, 0.12);
  border-color: rgba(74, 222, 128, 0.22);
  color: #b7f5cf;
}

.list-state.warn {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.24);
  color: #ffe0aa;
}

.list-state.neutral {
  background: rgba(148, 163, 184, 0.1);
  border-color: rgba(148, 163, 184, 0.18);
  color: #bfdbfe;
}

.list-grid .table-wrap {
  min-height: 180px;
}

.list-grid thead th {
  height: 40px;
  line-height: 1;
  vertical-align: middle;
}

.list-grid tbody td {
  vertical-align: middle;
  padding-top: 0;
  padding-bottom: 0;
  line-height: 1;
}

.list-grid tbody tr {
  height: 26px;
}

.mini-panel {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.mini-head span {
  font-size: 0.82rem;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.table-wrap table {
  min-width: 640px;
}

.table-wrap.log-wrap table {
  min-width: 100%;
}

.empty {
  color: var(--faint);
  text-align: center;
}

.quick-stack {
  display: grid;
  gap: 12px;
}

.quick-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.form-row {
  align-items: stretch;
}

.list-editor {
  display: grid;
  grid-template-rows: minmax(112px, auto) auto;
  gap: 10px;
}

.list-editor textarea {
  min-height: 112px;
}

.list-actions,
.list-actions button {
  min-width: 138px;
}

.select-col {
  width: 82px;
  min-width: 82px;
  text-align: center;
  padding-left: 0;
  padding-right: 0;
}

.name-list-grid th,
.name-list-grid td {
  vertical-align: middle;
}

.name-list-grid thead th {
  height: 36px;
  padding-top: 0;
  padding-bottom: 0;
  line-height: 1;
  vertical-align: middle;
}

.name-list-grid tbody td {
  padding-top: 0.28rem;
  padding-bottom: 0.28rem;
}

.name-list-grid th.select-col {
  padding-top: 0;
  padding-bottom: 0;
  text-align: center;
  vertical-align: middle;
}

.name-list-grid td.select-col {
  padding-top: 0.28rem;
  padding-bottom: 0.28rem;
  text-align: center;
  vertical-align: middle;
}

.list-grid th:nth-child(2),
.list-grid td:nth-child(2) {
  width: 42%;
  padding-left: 12px;
}

.list-grid th:nth-child(3),
.list-grid td:nth-child(3) {
  width: auto;
  padding-left: 12px;
}

.list-grid tbody td:nth-child(3) {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 26px;
}

.list-grid tbody td:nth-child(3) button {
  min-height: 24px;
  height: auto;
  padding: 4px 0.42rem;
  font-size: 0.76rem;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.list-grid tbody td:nth-child(3) button + button {
  margin-left: 0;
}

.name-list-grid tbody td:nth-child(3) {
  display: table-cell;
  vertical-align: middle;
  min-height: 0;
}

.name-list-grid tbody td:nth-child(3) button {
  min-height: 24px;
  height: auto;
  padding: 4px 0.42rem;
  font-size: 0.76rem;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.name-list-grid tbody td:nth-child(3) button + button {
  margin-left: 0;
}

#whiteBody td:last-child,
#blackBody td:last-child {
  display: table-cell;
  vertical-align: middle;
  min-height: 0;
}

#whiteBody td:last-child button,
#blackBody td:last-child button {
  min-height: 30px;
  height: auto;
  padding: 5px 9px;
  font-size: 1rem;
  line-height: 1.15;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#whiteBody td:last-child button + button,
#blackBody td:last-child button + button {
  margin-left: 6px;
}

.name-row-button {
  min-height: 30px !important;
  padding: 5px 9px !important;
  font-size: 1rem !important;
  line-height: 1.15 !important;
}

.select-col input {
  width: 14px;
  height: 14px;
  display: block;
  padding: 0;
  margin: 0 auto;
}

.table-select-all {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  min-width: 16px;
  height: 16px;
  line-height: 1;
  margin: 0 auto;
}

.form-row textarea {
  flex: 1 1 auto;
  min-height: 114px;
}

.form-row .stack {
  width: 138px;
  flex: 0 0 138px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

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

.actions-field {
  min-width: 180px;
}

.chart-shell {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0)), #10151d;
}

#historyChart {
  display: block;
  width: 100%;
  height: 260px;
}

.motd-editor {
  min-height: 240px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.45;
}

.log-filter {
  width: 260px;
  max-width: 100%;
}

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 10px;
  z-index: 20;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 260px;
  max-width: 360px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(18, 22, 29, 0.96);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: grid;
  gap: 4px;
}

.toast strong {
  font-size: 0.92rem;
}

.toast span {
  color: var(--muted);
  font-size: 0.86rem;
}

.toast.good {
  border-color: rgba(74, 222, 128, 0.35);
}

.toast.bad {
  border-color: rgba(248, 113, 113, 0.35);
}

.toast.warn {
  border-color: rgba(245, 158, 11, 0.35);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .metric-grid,
  .grid-form,
  .grid-form.compact,
  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .public-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .join-hero {
    grid-template-columns: 1fr;
  }

  .content,
  .sidebar {
    padding: 14px;
  }

  .panel,
  .mini-panel,
  .status-card {
    padding: 14px;
  }

  .metric-grid,
  .grid-form,
  .grid-form.compact,
  .status-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .status-head,
  .mini-head,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .toast-host {
    left: 14px;
    right: 14px;
  }

  .form-row {
    flex-direction: column;
  }

  .form-row .stack {
    width: 100%;
    flex-basis: auto;
  }

  .list-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap table {
    min-width: 560px;
  }
}
