:root {
  --bg: #f0f4f2;
  --panel: #ffffff;
  --border: #e2eae6;
  --primary: #2c5e4f;
  --primary-light: #e8f2ee;
  --text-main: #1a2620;
  --text-muted: #7a8278;
  --up: #d83a3a;
  --down: #2c8055;
  --gold: #d68a2c;
  --shadow-sm: 0 2px 8px rgba(34, 56, 47, 0.05);
  --shadow: 0 8px 24px rgba(34, 56, 47, 0.08);
  --r: 16px;
}

[data-theme="dark"] {
  --bg: #0f1315;
  --panel: #181d1f;
  --border: #283236;
  --primary: #4fb395;
  --primary-light: #2a5a48;
  --text-main: #f0f5f2;
  --text-muted: #a3b3aa;
  --up: #f05a5a;
  --down: #46b880;
  --gold: #f2ae4b;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans CJK TC", sans-serif;
  background: var(--bg);
  color: var(--text-main);
  font-size: 16px; /* 後台全局字體 16px */
  min-height: 100vh;
}

/* ── Header ── */
.admin-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Layout ── */
.admin-body {
  display: flex;
  min-height: calc(100vh - 60px);
}

.sidebar {
  width: 200px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px; /* 後台 nav-item 字體 16px */
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.15s;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-badge {
  margin-left: auto;
  background: var(--up);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

.content {
  flex: 1;
  padding: 24px;
  overflow-x: auto;
}

/* ── Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 15px; /* 後台 stat-label 字體 15px */
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-main);
}

.stat-value.pending {
  color: var(--gold);
}

.stat-value.active {
  color: var(--down);
}

.stat-value.warning {
  color: var(--gold);
}

.stat-value.suspended,
.stat-value.inactive {
  color: var(--up);
}

.stats-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0 20px;
}

.stats-grid--online {
  margin-bottom: 20px;
}

.stats-period-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.period-tab {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--panel);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.period-tab:hover {
  background: var(--panel-2, #f4f7f7);
  color: var(--text-main);
}

.period-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Section ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.section-title {
  font-size: 20px; /* 後台 section-title 字體 20px */
  font-weight: 700;
}

/* ── Table ── */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow-x: auto;
  max-height: calc(100vh - 220px);
  /* 讓長表格可內部滾動 */
  box-shadow: var(--shadow-sm);
}

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

th {
  background: var(--bg);
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

tr:hover td {
  background: var(--bg);
}

.username {
  font-weight: 600;
  color: var(--text-main);
}

.email {
  color: var(--text-muted);
  font-size: 12px;
}

/* ── Status Badge ── */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

.badge-pending {
  background: #fef3c7;
  color: #92400e;
}

.badge-active {
  background: #d1fae5;
  color: #065f46;
}

.badge-suspended {
  background: #fee2e2;
  color: #991b1b;
}

.badge-inactive {
  background: #f3f4f6;
  color: #6b7280;
}

.badge-warning {
  background: #fef3c7;
  color: #b45309;
}

.badge-admin {
  background: var(--primary-light);
  color: var(--primary);
}

/* ── Buttons ── */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn:active {
  transform: scale(0.92);
}

.btn:hover {
  opacity: 0.85;
}

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

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

.btn-success {
  background: var(--down);
  color: #fff;
}

.btn-danger {
  background: var(--up);
  color: #fff;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.btn-warning {
  background: var(--gold);
  color: #fff;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 14px;
}

/* ── Controls ── */
.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.search-input,
.filter-select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  outline: none;
  background: #fff;
  color: var(--text-main);
  transition: border-color 0.2s;
}

.search-input:focus,
.filter-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* 防呆：表單輸入錯誤時的視覺提示 (搭配 HTML required 等屬性) */
.search-input:invalid,
.filter-select:invalid {
  border-color: var(--up);
  box-shadow: 0 0 0 3px rgba(216, 58, 58, 0.15);
}

.search-input {
  width: 200px;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
}

.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}

.page-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.page-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text-main);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 1000;
  box-shadow: var(--shadow);
  transform: translateY(0);
  transition: opacity 0.3s;
}

.toast.success {
  background: var(--down);
}

.toast.error {
  background: var(--up);
}

.toast.warning {
  background: var(--gold);
}

.toast.hidden {
  display: none;
}

/* ── Empty state ── */
.empty {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

/* ── 表格載入中的旋轉動畫 ── */
.empty.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 40px;
}

.empty.loading .spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.empty.loading span:last-child {
  color: var(--text-main);
}

/* .warning-banner 已確認無任何 HTML/JS 使用，移除以消除死碼 */

.hidden {
  display: none !important;
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }

  .search-input {
    width: 140px;
  }

  .content {
    padding: 16px 16px 40px;
  }

  .admin-header {
    padding: 0 16px;
  }

  .header-right {
    gap: 8px;
    font-size: 12px;
  }
}

/* ── Info Modal (stat-help) ── */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}

.modal-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.modal-box {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  width: 90%;
  max-width: 420px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  border-radius: var(--r) var(--r) 0 0;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: 70vh;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-icon:hover {
  background: var(--border);
  color: var(--text-main);
}

/* ── 自訂 Modal 彈窗 ── */
.admin-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.admin-modal.show {
  opacity: 1;
  pointer-events: auto;
}

.admin-modal-box {
  background: var(--panel, #1a1a1a);
  padding: 24px;
  border-radius: 12px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  transform: translateY(-20px);
  transition: transform 0.2s;
  border: 1px solid var(--border-strong, #333);
}

.admin-modal.show .admin-modal-box {
  transform: translateY(0);
}

.admin-modal h3 {
  margin: 0 0 12px 0;
  font-size: 20px;
  color: var(--text-main, #fff);
  font-weight: 700;
}

.admin-modal p {
  margin: 0 0 20px 0;
  font-size: 17px;
  color: var(--text-muted, #aaa);
  line-height: 1.5;
  white-space: pre-wrap;
}

.admin-modal input {
  width: 100%;
  padding: 12px;
  margin-bottom: 20px;
  border: 1px solid var(--border-strong, #444);
  border-radius: 6px;
  box-sizing: border-box;
  background: var(--bg, #2a2a2a);
  color: var(--text-main, #fff);
  font-size: 17px;
}

.admin-modal input:focus {
  outline: 2px solid var(--primary, #4fb395);
  border-color: transparent;
}

.admin-modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

.admin-modal .btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  transition: all 0.2s;
}

.admin-modal .btn-cancel {
  background: transparent;
  color: var(--text-main, #fff);
  border: 1px solid var(--border-strong, #555);
}

.admin-modal .btn-cancel:hover {
  background: var(--border-strong, #444);
}

.admin-modal .btn-confirm {
  background: var(--primary, #4fb395);
  color: #fff;
}

.admin-modal .btn-danger {
  background: var(--up, #f05a5a);
  color: #fff;
}

/* ── 重新整理旋轉動畫 ── */
@keyframes spin-refresh {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.spin {
  animation: spin-refresh 1s linear infinite;
}
