:root {
  color-scheme: dark;
  --bg: #0d1118;
  --panel: #151a23;
  --panel-2: #1c232f;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f4f6fa;
  --muted: #8f98a8;
  --accent: #e7b866;
  --green: #56d68a;
  --red: #ff7373;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: #101620;
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 26px;
}

.brand span {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #fff, var(--accent));
}

.brand strong {
  font-size: 17px;
}

nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.content {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar p,
.topbar h1,
.panel h2,
.modal-card h2,
.modal-card p {
  margin: 0;
}

.topbar p {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

.topbar h1 {
  font-size: 28px;
}

.token-box {
  display: flex;
  gap: 8px;
}

input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111722;
  color: var(--text);
  outline: none;
  padding: 0 12px;
}

.token-box input {
  width: 300px;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #242c39;
  color: var(--text);
  padding: 0 14px;
}

button.primary,
#saveToken,
#confirmCredit {
  border-color: transparent;
  background: var(--accent);
  color: #191713;
  font-weight: 700;
}

button.danger {
  color: var(--red);
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.stats article,
.panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.stats article {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.stats span {
  color: var(--muted);
  font-size: 13px;
}

.stats strong {
  font-size: 26px;
}

.panel {
  overflow: hidden;
}

.panel-spaced {
  margin-top: 16px;
}

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

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

.panel-tools input {
  width: 240px;
}

.panel h2 {
  font-size: 18px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

td {
  color: #dce2ec;
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.mono {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

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

.tag {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #cbd3df;
  padding: 0 9px;
  font-size: 12px;
}

.tag.paid,
.positive {
  color: var(--green);
}

.tag.pending,
.negative {
  color: var(--accent);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#userDialog,
#creditDialog,
#apiKeyDialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
}

#userDialog {
  width: min(620px, calc(100vw - 32px));
}

#userDialog::backdrop,
#creditDialog::backdrop,
#apiKeyDialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal-card {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 20px;
}

.secret-box {
  display: grid;
  gap: 10px;
  border: 1px solid rgba(231, 184, 102, 0.35);
  border-radius: 10px;
  background: rgba(231, 184, 102, 0.08);
  padding: 12px;
}

.secret-box code {
  overflow-wrap: anywhere;
  border-radius: 8px;
  background: #0b0f16;
  color: #f5d18c;
  padding: 10px;
  font-family: "SFMono-Regular", Consolas, monospace;
  line-height: 1.5;
}

.modal-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-card label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.user-detail {
  max-height: min(760px, calc(100vh - 32px));
  overflow: auto;
}

.detail-list {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 10px 14px;
  margin: 4px 0 18px;
}

.detail-list dt {
  color: var(--muted);
}

.detail-list dd {
  margin: 0;
  word-break: break-all;
}

.user-detail h3 {
  margin: 18px 0 8px;
  font-size: 15px;
}

.detail-stack {
  display: grid;
  gap: 8px;
}

.detail-stack p {
  display: flex;
  min-height: 38px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 0 10px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111722;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.36);
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(10px);
  transition: 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  nav,
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .token-box input {
    width: 100%;
  }

  .panel-head,
  .panel-tools {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-tools input {
    width: 100%;
  }
}
