* { box-sizing: border-box; }

/* 角色靠 /api/me 异步确认,确认前先藏住角色专属元素,避免代理端闪现管理员菜单 */
body:not(.role-known) .admin-only,
body:not(.role-known) .agent-only { display: none; }

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e3e8f0;
  --border-strong: #d5dce8;
  --text: #172033;
  --muted: #667085;
  --sidebar: #111827;
  --sidebar-soft: #1f2937;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --warning: #d97706;
  --danger: #dc2626;
  --success: #15803d;
  --shadow: 0 18px 45px rgba(20, 30, 48, .08);
  --shadow-soft: 0 8px 22px rgba(20, 30, 48, .06);
}

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

a { color: inherit; text-decoration: none; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #111827 0%, #172033 48%, #233044 100%);
}

.login-card {
  width: min(390px, calc(100vw - 32px));
  padding: 36px;
  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(255, 255, 255, .62);
  border-radius: 8px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .26);
}

.login-card h1 { margin: 0 0 8px; font-size: 28px; color: #111827; }
.login-card p { margin: 0 0 24px; color: var(--muted); }
.login-form { display: grid; gap: 14px; }

.login-form input,
.input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--text);
  font: inherit;
  background: #fff;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.login-form input:focus,
.input:focus {
  border-color: rgba(37, 99, 235, .72);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

textarea.input { min-height: 86px; resize: vertical; }
.form-error { min-height: 22px; margin-top: 14px; color: var(--danger); font-size: 14px; }

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  color: #cbd5e1;
  background: var(--sidebar);
  border-right: 1px solid rgba(255, 255, 255, .08);
}

.brand {
  height: 72px;
  display: flex;
  align-items: center;
  padding: 0 22px;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

.nav { display: grid; gap: 6px; padding: 10px 10px; }

.nav-item {
  display: flex;
  align-items: center;
  min-height: 38px;
  width: 100%;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #b8c3d5;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, border-color .16s ease;
}

.nav-item:hover { background: var(--sidebar-soft); color: #fff; }
.nav-item.active { background: #fff; border-color: rgba(255, 255, 255, .18); color: #121826; }

.main { min-width: 0; }

.page-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 24px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(20, 30, 48, .02);
}

.page-title h1 { margin: 0; font-size: 24px; color: #111827; }

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.current-user {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  max-width: 260px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel {
  margin: 18px 24px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.toolbar { display: flex; gap: 12px; margin-bottom: 18px; }
.toolbar .input { max-width: 340px; }
.filter-panel,
.card-list-toolbar {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}
.filters { display: grid; grid-template-columns: repeat(5, minmax(132px, 1fr)); gap: 8px; }
.cards-filters { grid-template-columns: 132px 150px 150px minmax(220px, 1fr); }
.bulk-card-query { min-height: 88px; line-height: 1.45; }
.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.filter-actions .btn { min-height: 32px; }
.inline-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.btn {
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 12px;
  background: #eef2f7;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease, border-color .14s ease;
}

.btn:hover { box-shadow: 0 6px 14px rgba(20, 30, 48, .08); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-strong); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { border-color: var(--border-strong); background: #fff; color: #344054; }

.data-table {
  width: 100%;
  min-width: 1060px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.table-scroll .data-table {
  border: 0;
  border-radius: 0;
}

.data-table th,
.data-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 8px 8px;
  text-align: center;
  vertical-align: middle;
  color: #566074;
  font-size: 13px;
  line-height: 1.35;
  word-break: break-word;
}

.data-table th:last-child,
.data-table td:last-child { border-right: 0; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table th { background: #f7f9fc; color: #344054; font-size: 13px; font-weight: 800; }
.data-table tr:hover td { background: #f9fbff; }

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

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.badge-blue { color: #1d4ed8; background: #dbeafe; }
.badge-gray { color: #667085; background: #eef2f6; }
.badge-green { color: var(--success); background: #dcfce7; }
.badge-orange { color: #b45309; background: #fef3c7; }
.badge-red { color: var(--danger); background: #fee2e2; }

.stats {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 12px;
  padding: 8px 0;
  overflow-x: auto;
  color: #4b5563;
  font-size: 12px;
}

.stats span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  white-space: nowrap;
}

.stats strong { color: var(--primary); }
.batch-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 12px;
  flex-wrap: wrap;
}

.card-actions-bar {
  justify-content: space-between;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.selection-actions,
.extract-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.selected-count {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 13px;
  font-weight: 700;
}

.extract-control {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 13px;
  font-weight: 700;
}

.extract-control .input {
  width: 72px;
  min-height: 28px;
  padding: 4px 8px;
}

.query-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 180px;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.query-box {
  display: grid;
  gap: 8px;
  color: #4b5563;
  font-weight: 700;
}

.query-actions {
  display: grid;
  gap: 10px;
}

.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.page-size-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.page-size-control .input { width: 92px; min-height: 34px; padding: 6px 10px; }

.modal {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 30px 90px rgba(15, 23, 42, .28);
}

.modal::backdrop { background: rgba(15, 23, 42, .48); }
.modal-body { display: grid; gap: 14px; padding: 26px; }
.modal-body h2 { margin: 0 0 4px; color: #111827; }
.modal-body label { display: grid; gap: 6px; color: #4b5563; font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.copy-result-hint { margin: 0; color: #6b7280; font-size: 13px; }
.copy-result-text {
  width: 100%; min-height: 160px; max-height: 45vh; resize: vertical;
  font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 13px; line-height: 1.7;
  border: 1px solid #d1d5db; border-radius: 6px; padding: 10px 12px; color: #111827; background: #f9fafb;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, .48);
}
.modal-overlay .modal {
  width: min(520px, calc(100vw - 32px));
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 30px 90px rgba(15, 23, 42, .28);
  overflow: hidden;
}
.modal-overlay .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 26px;
  border-bottom: 1px solid var(--border);
}
.modal-overlay .modal-header h2 { margin: 0; font-size: 18px; color: #111827; }
.modal-overlay .modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.modal-overlay .modal-close:hover { color: var(--text); }
.modal-overlay .modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 26px;
  border-top: 1px solid var(--border);
}
.modal-overlay .form-group { display: grid; gap: 6px; }
.modal-overlay .form-group label { color: #4b5563; font-weight: 700; font-size: 13px; }

.btn-sm { padding: 4px 10px; font-size: 12px; min-height: 28px; }
.btn-danger { color: #fff; background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.action-cell { white-space: nowrap; display: flex; gap: 6px; }

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  padding: 12px 16px;
  border-radius: 8px;
  color: #fff;
  background: #111827;
  box-shadow: 0 18px 44px rgba(0, 0, 0, .22);
}

.toast.error { background: var(--danger); }
.toast.success { background: #16a34a; }

.card-key {
  display: inline-block;
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
  color: #1f2937;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0;
  white-space: nowrap;
}

/* 卡密 19 位定长，列锁宽避免 fixed 布局把它压到换行 */
.card-table .col-card-key { width: 196px; }
.data-table.card-table { min-width: 1180px; }

.type-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  flex-wrap: wrap;
}

.type-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 5px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #4b5563;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, box-shadow .16s ease;
}

.type-tab:hover { background: #eef2f7; }

.type-tab.active {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--primary-strong);
  box-shadow: 0 2px 6px rgba(20, 30, 48, .08);
}

.type-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  min-height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #e3e8f0;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
}

.type-tab.active .type-tab-count { background: #dbeafe; color: var(--primary-strong); }

.type-tabs-hint {
  margin-left: auto;
  padding-right: 8px;
  color: var(--muted);
  font-size: 12px;
}

.row-destroyed td { background: #fbfbfc; color: #98a2b3; }
.row-destroyed .card-key { color: #98a2b3; text-decoration: line-through; }
.stat-destroyed { color: var(--danger); }

.card-detail-modal { width: min(560px, calc(100vw - 32px)); }

.detail-grid {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px 14px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.detail-grid dt { color: var(--muted); font-size: 13px; font-weight: 700; line-height: 26px; }
.detail-grid dd { margin: 0; color: var(--text); font-size: 13px; line-height: 26px; word-break: break-all; }

.detail-danger-zone {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff7f7;
}

.detail-danger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.detail-danger-row + .detail-danger-row { border-top: 1px solid #fee2e2; padding-top: 10px; }

.detail-danger-text { display: grid; gap: 2px; }
.detail-danger-text strong { color: #991b1b; font-size: 13px; }
.detail-danger-text span { color: #a16565; font-size: 12px; line-height: 1.4; }

.detail-danger-row .btn-danger { flex-shrink: 0; min-width: 112px; }

.btn-armed { background: #991b1b; animation: armed-pulse 1s ease-in-out infinite; }

@keyframes armed-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .35); }
  50% { box-shadow: 0 0 0 5px rgba(220, 38, 38, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .btn-armed { animation: none; }
}

.stats-range-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.stats-quick-ranges { display: flex; gap: 8px; flex-wrap: wrap; }

.stats-custom-range {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stats-custom-range label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stats-custom-range .input { width: 205px; }

.stats-range-note { margin: 4px 0 14px; color: var(--muted); font-size: 12px; }

.data-table.stats-table { min-width: 0; }
.stats-table td, .stats-table th { font-size: 14px; padding: 12px 10px; }
.stats-total-row td { background: #f7f9fc; color: #172033; font-weight: 800; }

@media (max-width: 980px) {
  body { padding-bottom: 76px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 15;
    height: auto;
    border-top: 1px solid rgba(255, 255, 255, .10);
    border-right: 0;
    box-shadow: 0 -10px 28px rgba(15, 23, 42, .18);
  }
  .brand { display: none; }
  .nav {
    display: flex;
    gap: 4px;
    justify-content: space-around;
    padding: 8px;
    overflow-x: auto;
  }
  .nav-item {
    justify-content: center;
    width: auto;
    min-width: 78px;
    min-height: 50px;
    padding: 0 10px;
    text-align: center;
    font-size: 12px;
  }
  .page-header { align-items: flex-start; min-height: auto; padding: 18px; flex-direction: column; }
  .page-title h1 { font-size: 26px; }
  .header-actions { width: 100%; justify-content: flex-start; }
  .current-user { max-width: 100%; }
  .panel { margin: 12px; padding: 12px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar .input { max-width: none; }
  .filters,
  .cards-filters { grid-template-columns: 1fr; }
  .filter-actions,
  .inline-actions { justify-content: stretch; }
  .filter-actions .btn,
  .inline-actions .btn { flex: 1 1 0; }
  .query-layout { grid-template-columns: 1fr; }
  .query-actions { grid-template-columns: 1fr 1fr; }
  .type-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .type-tabs-hint { display: none; }
  .detail-danger-row { flex-direction: column; align-items: stretch; }
  .detail-danger-row .btn-danger { min-width: 0; }
  .stats-range-bar { flex-direction: column; align-items: stretch; }
  .stats-custom-range label { flex: 1 1 auto; }
  .stats-custom-range .input { width: 100%; min-width: 0; flex: 1; }
}

@media (max-width: 720px) {
  .stats { padding-bottom: 4px; }
  .selection-actions,
  .extract-actions { width: 100%; }
  .batch-actions .btn,
  .selected-count,
  .extract-control { flex: 1 1 auto; justify-content: center; }
  .data-table { min-width: 960px; }
  .data-table.card-table { min-width: 1180px; }
  .data-table.stats-table { min-width: 0; }
}
