/* ============ 全局 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --text: #1f2937;
  --text-muted: #6b7280;
  --bg: #f9fafb;
  --border: #e5e7eb;
  --card-bg: #ffffff;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.06);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.6;
}

/* ============ 前台页面 ============ */
.user-page {
  background: linear-gradient(135deg, #eef2ff 0%, #f0f9ff 50%, #ecfdf5 100%);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}
.bg-decoration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(79,70,229,0.12) 0%, transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(16,185,129,0.10) 0%, transparent 40%);
}
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px;
  position: relative;
  z-index: 1;
}
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.hero { text-align: center; }
.hero h1 {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--primary), #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 36px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 36px 28px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  animation: fadeIn 0.4s ease;
}
@keyframes fadeIn { from { opacity:0; transform: translateY(12px);} to {opacity:1; transform:none;} }

.card-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}
.card-text { font-size: 17px; font-weight: 600; margin-bottom: 14px; }
.card-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px 28px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(79,70,229,0.3); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

/* 卡密输入 */
.card-input-row {
  display: flex;
  gap: 10px;
  max-width: 460px;
  margin: 0 auto 4px;
}
.card-input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: border-color 0.2s;
}
.card-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}
.inline-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  margin-bottom: 2px;
}

/* 结果卡片 */
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-gray { background: #f3f4f6; color: #4b5563; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }

.expire-text { font-size: 13px; color: var(--warning); font-weight: 500; }
.expire-text.expired { color: var(--danger); }

.account-info { text-align: left; }
.info-row { margin-bottom: 16px; }
.info-row label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.info-value {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  gap: 10px;
}
.info-value span {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 14px;
  word-break: break-all;
  flex: 1;
}
.copy-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.copy-btn:hover { background: var(--primary-dark); }

.twofa-value { background: #ecfdf5; border-color: #a7f3d0; }
.totp-code {
  font-size: 22px !important;
  font-weight: 700;
  letter-spacing: 4px;
  color: #065f46;
}
.btn-refresh {
  background: transparent;
  border: none;
  color: var(--success);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: all 0.2s;
}
.btn-refresh:hover { background: #d1fae5; }
.twofa-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* 2FA 锁定状态 */
.twofa-locked { text-align: center; }
.btn-view-2fa {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px dashed var(--primary);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-view-2fa:hover {
  background: var(--primary);
  color: #fff;
  border-style: solid;
}
.remaining-count {
  font-weight: 700;
  color: var(--primary);
}
.remaining-count.exhausted {
  color: var(--danger);
}
.btn-refresh:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 确认弹窗 */
.confirm-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.6;
}

.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
  flex-wrap: wrap;
}
.tip-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 16px;
  text-align: center;
}

.error-icon { font-size: 40px; margin-bottom: 12px; }
.error-card p { color: var(--danger); margin-bottom: 16px; font-weight: 500; }

.site-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 40px;
}
.hidden { display: none !important; }

/* ============ 登录页 ============ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #eef2ff, #f0f9ff);
}
.login-box {
  background: #fff;
  padding: 40px 36px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}
.login-box h1 { font-size: 22px; margin-bottom: 6px; }
.login-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.login-form { text-align: left; }
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s;
  font-family: inherit;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}
.btn-block { width: 100%; justify-content: center; margin-top: 8px; }
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert-error { background: #fee2e2; color: #991b1b; }
.back-home {
  display: inline-block;
  margin-top: 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
}
.back-home:hover { color: var(--primary); }

/* ============ 后台 ============ */
.admin-page { background: var(--bg); }
.admin-layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: #111827;
  color: #fff;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 24px;
  font-size: 16px;
  font-weight: 700;
  border-bottom: 1px solid #1f2937;
}
.sidebar-nav {
  flex: 1;
  padding: 16px 0;
}
.nav-link {
  display: block;
  padding: 12px 20px;
  color: #9ca3af;
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: #1f2937; color: #fff; }
.nav-link.active {
  background: #1f2937;
  color: #fff;
  border-left-color: var(--primary);
}
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid #1f2937;
}
.sidebar-footer a {
  display: block;
  padding: 8px 0;
  color: #9ca3af;
  text-decoration: none;
  font-size: 13px;
}
.sidebar-footer a:hover { color: #fff; }

.admin-main {
  flex: 1;
  margin-left: 220px;
  padding: 28px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.stat-blue { background: #dbeafe; }
.stat-green { background: #d1fae5; }
.stat-orange { background: #fed7aa; }
.stat-purple { background: #e9d5ff; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 13px; color: var(--text-muted); }

.panel {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.panel-header h2 { font-size: 17px; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  text-align: left;
  padding: 14px 16px;
  background: #f9fafb;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:hover td { background: #f9fafb; }
.email-cell { font-family: monospace; font-size: 13px; }
.pwd-cell {
  background: #f3f4f6;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}
.qr-link {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  color: var(--primary);
  text-decoration: none;
  padding: 1px 6px;
  border: 1px solid var(--primary);
  border-radius: 4px;
}
.qr-link:hover { background: var(--primary); color: #fff; }
.action-cell { white-space: nowrap; }
.btn-link {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 4px;
  margin-right: 4px;
}
.btn-edit { color: var(--primary); }
.btn-edit:hover { background: var(--primary-light); }
.btn-del { color: var(--danger); }
.btn-del:hover { background: #fee2e2; }
.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px;
}

.settings-form { padding: 24px; max-width: 640px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* 卡密管理 */
.gen-row { display: flex; align-items: center; gap: 8px; }
.gen-count {
  width: 80px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.gen-count:focus { outline: none; border-color: var(--primary); }
.gen-result {
  padding: 16px 24px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
}
.gen-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.gen-keys {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 15px;
  letter-spacing: 1px;
  white-space: pre-wrap;
  color: var(--text);
  margin: 0;
}
.card-key { letter-spacing: 1px; }

/* 弹窗 */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.show { display: flex; }
.modal-content {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.25s ease;
}
@keyframes modalIn { from {opacity:0; transform:scale(0.95);} to {opacity:1; transform:scale(1);} }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; }
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
#accountForm { padding: 20px 24px; }
#confirmForm { padding: 20px 24px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Toast */
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #111827;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s;
  z-index: 200;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* 响应式 */
@media (max-width: 768px) {
  /* 前台 */
  .container { padding: 20px 14px; }
  .site-header { margin-bottom: 24px; }
  .hero h1 { font-size: 24px; }
  .subtitle { font-size: 13px; margin-bottom: 24px; }
  .card { padding: 24px 16px; }
  .card-icon { width: 52px; height: 52px; border-radius: 13px; }
  .totp-code { font-size: 17px !important; letter-spacing: 2px; }
  .btn-view-2fa { padding: 11px 14px; font-size: 13px; }

  /* 后台：侧边栏改为顶部横向导航 */
  .admin-layout { display: block; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 10px 8px;
    overflow-x: auto;
  }
  .sidebar-logo { padding: 0 10px; border-bottom: none; white-space: nowrap; flex-shrink: 0; }
  .sidebar-nav { display: flex; flex: 1; padding: 0; }
  .nav-link {
    padding: 10px 12px;
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
  }
  .nav-link.active { border-left: none; border-bottom-color: var(--primary); }
  .sidebar-footer { padding: 0 10px; border-top: none; display: flex; flex-shrink: 0; }
  .admin-main { margin-left: 0; padding: 16px 12px; }

  /* 后台内容 */
  .stats-row { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-icon { width: 40px; height: 40px; font-size: 18px; }
  .stat-value { font-size: 20px; }
  .panel-header { padding: 14px 16px; flex-wrap: wrap; gap: 8px; }
  .panel-header h2 { font-size: 15px; }
  .settings-form { max-width: 100%; padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  #accountForm, #confirmForm { padding: 16px; }
}

@media (max-width: 420px) {
  .hero h1 { font-size: 21px; }
  .card-input-row { flex-direction: column; }
  .card-input-row .btn-primary { justify-content: center; }
  .totp-code { font-size: 15px !important; }
  .stats-row { grid-template-columns: 1fr; }
}
