:root {
  --bg: #f5f7fb;
  --panel: #fff;
  --ink: #17202e;
  --muted: #66758a;
  --line: #e1e6ef;
  --brand: #2f75d6;
  --brand-dark: #1d5ed8;
  --danger: #c9473d;
  --ok: #18805b;
  --info: #1468b2;
  --shadow: 0 10px 24px rgba(23, 32, 46, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  background: var(--bg);
}

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

button {
  border: 0;
  cursor: pointer;
}

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

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 34px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.admin-header h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.admin-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
}

.header-actions a,
.header-actions button {
  color: var(--brand-dark);
  font-size: 14px;
  text-decoration: none;
  background: transparent;
}

.admin-shell {
  width: min(1440px, calc(100vw - 36px));
  margin: 22px auto 48px;
}

.notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #bcd7ff;
  border-radius: 8px;
  color: #1e4d85;
  background: #eef6ff;
}

.tabbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.tabbar button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  background: transparent;
}

.tabbar button.active {
  color: var(--brand-dark);
  border-bottom-color: var(--brand);
  font-weight: 700;
}

.tab-panel {
  display: none;
}

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

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.metric-grid article,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-grid article {
  min-height: 104px;
  padding: 16px;
}

.metric-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.panel {
  overflow: hidden;
}

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

.panel-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.filters input,
.filters select {
  height: 36px;
  min-width: 190px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
}

.filters button,
.row-actions button,
.dialog-actions button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  color: #fff;
  background: var(--brand);
}

.filters button:hover,
.row-actions button:hover,
.dialog-actions button:hover {
  background: var(--brand-dark);
}

.row-actions button.secondary,
.dialog-actions button.secondary {
  color: var(--ink);
  background: #edf1f6;
}

.row-actions button.secondary:hover,
.dialog-actions button.secondary:hover {
  background: #dfe5ee;
}

.row-actions button.danger {
  background: var(--danger);
}

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

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  color: var(--muted);
  font-weight: 600;
  background: #fafbfe;
}

td.title-cell {
  max-width: 420px;
  white-space: normal;
}

td.note-cell,
td.error-cell {
  max-width: 300px;
  white-space: normal;
}

td.error-cell {
  color: var(--danger);
}

.amount.positive {
  color: var(--ok);
  font-weight: 700;
}

.amount.negative {
  color: var(--danger);
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: #5c6678;
  background: #eef1f6;
}

.badge.admin,
.badge.completed,
.badge.active,
.badge.paid,
.badge.free,
.badge.charged,
.badge.ok {
  color: var(--ok);
  background: #e7f5ee;
}

.badge.failed,
.badge.disabled,
.badge.refunded,
.badge.bad {
  color: var(--danger);
  background: #fdecea;
}

.badge.running,
.badge.queued,
.badge.waiting_dependency,
.badge.pending,
.badge.reserved,
.badge.generate_order_consume,
.badge.generate_order_refund,
.badge.admin_grant,
.badge.admin_deduct {
  color: var(--info);
  background: #e8f2ff;
}

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

.system-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
}

.system-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.system-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.kv {
  display: grid;
  grid-template-columns: minmax(88px, 0.8fr) minmax(0, 1.2fr);
  gap: 8px 12px;
  color: var(--muted);
  font-size: 13px;
}

.kv strong {
  color: var(--ink);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.account-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(23, 32, 46, 0.22);
}

.user-detail-dialog {
  width: min(860px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(23, 32, 46, 0.22);
}

.user-detail-dialog::backdrop {
  background: rgba(20, 29, 42, 0.35);
}

.user-detail-dialog form {
  display: grid;
  gap: 16px;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.detail-head h2 {
  margin: 0;
  font-size: 19px;
}

.detail-head p {
  margin: 5px 0 0;
  color: var(--muted);
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.detail-summary article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfe;
}

.detail-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail-summary strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
}

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

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

.detail-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 150px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.detail-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail-row em {
  color: var(--muted);
  font-style: normal;
  text-align: right;
}

.detail-empty {
  margin: 0;
  color: var(--muted);
}

.account-dialog::backdrop {
  background: rgba(20, 29, 42, 0.35);
}

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

.account-dialog h2 {
  margin: 0;
  font-size: 18px;
}

.account-dialog p {
  margin: 0;
  color: var(--muted);
}

.account-dialog label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.account-dialog input,
.account-dialog textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  resize: vertical;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 1100px) {
  .metric-grid,
  .system-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .admin-header,
  .panel-head,
  .filters {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .metric-grid,
  .system-grid,
  .detail-summary {
    grid-template-columns: 1fr;
  }

  .detail-row {
    grid-template-columns: 1fr;
  }

  .detail-row em {
    text-align: left;
  }

  .filters {
    justify-content: flex-start;
  }

  .filters input,
  .filters select {
    min-width: 100%;
  }
}
