:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --primary: #1677ff;
  --primary-hover: #0958d9;
  --success: #52c41a;
  --warning: #faad14;
  --danger: #ff4d4f;
  --text: #1f1f1f;
  --text-secondary: #8c8c8c;
  --border: #f0f0f0;
  --sidebar: #001529;
  --sidebar-text: rgba(255,255,255,.75);
  --shadow: 0 2px 8px rgba(0,0,0,.06);
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1677ff 0%, #003a8c 100%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 8px;
  text-align: center;
}

.login-card .sub {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.form-group { margin-bottom: 20px; }

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(22,119,255,.15);
}

.form-group textarea { min-height: 100px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-default { background: #fff; color: var(--text); border: 1px solid #d9d9d9; }
.btn-default:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }

.btn-danger { background: #fff; color: var(--danger); border: 1px solid #ffa39e; }
.btn-danger:hover:not(:disabled) { background: #fff1f0; }

.btn-sm { padding: 5px 12px; font-size: 13px; }

.btn-block { width: 100%; padding: 12px; font-size: 15px; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand h2 {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
}

.sidebar-brand span {
  font-size: 12px;
  opacity: .6;
}

.sidebar-nav { padding: 16px 12px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--sidebar-text);
  transition: all .2s;
  margin-bottom: 4px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.main {
  flex: 1;
  margin-left: 220px;
  padding: 24px;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 { font-size: 22px; font-weight: 600; }

.page-header .time { color: var(--text-secondary); font-size: 13px; }

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}

.stat-card .num {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.stat-card .label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.stat-card.success .num { color: var(--success); }
.stat-card.warning .num { color: var(--warning); }
.stat-card.danger .num { color: var(--danger); }

/* Table */
.table-wrap { overflow-x: auto; }

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

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

th {
  background: #fafafa;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

tr:hover td { background: #fafafa; }

.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.tag-green { background: #f6ffed; color: #389e0d; border: 1px solid #b7eb8f; }
.tag-blue { background: #e6f4ff; color: #0958d9; border: 1px solid #91caff; }
.tag-orange { background: #fff7e6; color: #d46b08; border: 1px solid #ffd591; }
.tag-red { background: #fff2f0; color: #cf1322; border: 1px solid #ffccc7; }
.tag-gray { background: #fafafa; color: #8c8c8c; border: 1px solid #d9d9d9; }

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.pagination span { font-size: 13px; color: var(--text-secondary); }

.page { display: none; }
.page.active { display: block; }

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

.filter-bar { display: flex; gap: 8px; align-items: center; }

/* Toast */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  animation: slideIn .3s ease;
  max-width: 360px;
}

.toast-success { background: #f6ffed; border: 1px solid #b7eb8f; color: #389e0d; }
.toast-error { background: #fff2f0; border: 1px solid #ffccc7; color: #cf1322; }
.toast-info { background: #e6f4ff; border: 1px solid #91caff; color: #0958d9; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}

.loading-overlay.show { display: flex; }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid #e8e8e8;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.config-item {
  padding: 16px;
  background: #fafafa;
  border-radius: 8px;
}

.config-item .key { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.config-item .val { font-size: 15px; font-weight: 500; word-break: break-all; }

.msg-cell {
  display: inline-block;
  max-width: 320px;
  font-size: 12px;
  line-height: 1.45;
  color: #595959;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: help;
}

.msg-cell.clickable {
  cursor: pointer;
  color: var(--primary);
  text-decoration: underline;
}

.fail-code {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: #fff1f0;
  color: #cf1322;
  border: 1px solid #ffa39e;
  margin-right: 4px;
}

.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: 10px;
  width: min(760px, 96vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; }
.order-detail-text {
  margin: 0;
  padding: 16px 18px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.55;
  color: #333;
  flex: 1;
}

.oauth-modal { width: min(480px, 96vw); }
.oauth-hint {
  padding: 12px 18px 0;
  font-size: 14px;
  color: #666;
  line-height: 1.6;
}
.oauth-qr-wrap {
  display: flex;
  justify-content: center;
  padding: 16px 18px 8px;
}
.oauth-link-label {
  padding: 0 18px;
  font-size: 13px;
  color: #888;
}
.oauth-link-row {
  display: flex;
  gap: 8px;
  padding: 8px 18px 12px;
}
.oauth-url-input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  font-size: 12px;
}
.oauth-status {
  padding: 0 18px 16px;
  font-size: 13px;
  color: var(--primary);
}

.config-hint {
  font-size: 13px;
  color: #888;
  margin-bottom: 16px;
  line-height: 1.6;
}
.field-hint {
  font-size: 12px;
  color: #52c41a;
  font-weight: normal;
}
.form-row { margin-bottom: 12px; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
.form-row-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.config-status {
  font-size: 13px;
  color: #666;
  margin-left: 8px;
}

@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .sidebar-brand h2, .sidebar-brand span, .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 14px; }
  .main { margin-left: 64px; padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
