/* 实验室安全题库查询系统 */
:root {
  --bg: #f3f5f9;
  --bg-soft: #e8edf5;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;
  --correct: #047857;
  --correct-bg: #ecfdf5;
  --correct-line: #10b981;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --danger: #be123c;
  --danger-bg: #fff1f2;
  --purple: #6d28d9;
  --purple-bg: #f3e8ff;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #dbeafe 0%, transparent 55%),
    radial-gradient(900px 420px at 95% 0%, #d1fae5 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

/* ===== Top bar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand-mark {
  width: 58px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.04em;
  background: linear-gradient(145deg, #0b3d91, #1d4ed8);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.28);
}

/* 失效提醒 */
.expiry-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 8px 16px;
  background: linear-gradient(90deg, #fff7ed, #ffedd5 50%, #fef3c7);
  border-bottom: 1px solid #fdba74;
  color: #9a3412;
  font-size: 13px;
  font-weight: 600;
}

.expiry-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #ea580c;
  box-shadow: 0 0 0 4px rgba(234, 88, 12, 0.18);
  animation: pulse 1.6s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.expiry-count {
  font-variant-numeric: tabular-nums;
  background: #fff;
  border: 1px solid #fdba74;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  color: #c2410c;
}

/* 过期后展示 */
.expired-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 50% -10%, #dbeafe 0%, transparent 55%),
    var(--bg);
}

.expired-gate[hidden],
#appRoot[hidden] {
  display: none !important;
}

.expired-card {
  width: min(480px, 100%);
  text-align: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 40px 28px;
  box-shadow: var(--shadow);
}

.expired-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  background: linear-gradient(145deg, #0b3d91, #1d4ed8);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  margin-bottom: 18px;
}

.expired-card h1 {
  margin: 0 0 12px;
  font-size: 28px;
  color: var(--ink);
}

.expired-card p {
  margin: 0 0 8px;
  color: var(--ink-2);
  line-height: 1.7;
}

.expired-sub {
  color: var(--muted) !important;
  font-size: 13px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-icon {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

#searchInput {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 100px 0 42px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}

#searchInput:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.16);
}

.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
}

.search-wrap .ghost-btn {
  position: absolute;
  right: 8px;
}

.stats {
  display: flex;
  gap: 10px;
}

.stat {
  min-width: 92px;
  padding: 8px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  text-align: center;
}

.stat-num {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
}

.stat-cache {
  min-width: 128px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
}

.cache-status {
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 8px;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cache-local {
  background: var(--correct-bg);
  color: var(--correct);
}

.cache-network {
  background: var(--accent-soft);
  color: var(--accent);
}

.cache-loading {
  background: var(--warn-bg);
  color: var(--warn);
}

.cache-refresh {
  padding: 3px 8px;
  font-size: 11px;
  line-height: 1.2;
}

/* ===== Layout ===== */
.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 22px 24px 40px;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: start;
}

.filters {
  position: sticky;
  top: 86px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.filter-block + .filter-block { margin-top: 18px; }

.filter-block h2 {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 12px;
  transition: all .15s ease;
}

.chip:hover { border-color: #93c5fd; color: var(--accent); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  margin: 8px 0;
  cursor: pointer;
}

.reset-btn {
  width: 100%;
  margin-top: 18px;
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  color: var(--muted);
  border-radius: 12px;
  padding: 10px;
  font-size: 13px;
}

.reset-btn:hover {
  color: var(--danger);
  border-color: #fda4af;
  background: var(--danger-bg);
}

/* ===== Content ===== */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.result-hint {
  font-size: 13px;
  color: var(--muted);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-label {
  font-size: 12px;
  color: var(--muted);
}

#sortSelect {
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  padding: 0 10px;
}

.question-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.q-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  transition: transform .16s ease, box-shadow .16s ease;
}

.q-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

.q-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}

.badge-source {
  background: var(--accent-soft);
  color: var(--accent);
}
.badge-kind {
  background: #eef2ff;
  color: #4338ca;
}
.badge-degree-easy {
  background: var(--correct-bg);
  color: var(--correct);
}
.badge-degree-mid {
  background: var(--warn-bg);
  color: var(--warn);
}
.badge-degree-hard {
  background: var(--danger-bg);
  color: var(--danger);
}
.badge-degree-media {
  background: var(--purple-bg);
  color: var(--purple);
}
.badge-media {
  background: #f1f5f9;
  color: var(--muted);
}

.q-stem {
  margin: 0 0 14px;
  font-size: 16px;
  line-height: 1.75;
  color: var(--ink);
  font-weight: 600;
}

.options {
  display: grid;
  gap: 8px;
}

.opt {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  background: #fafbfc;
  transition: all .15s ease;
}

.opt-letter {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  background: #e2e8f0;
  color: var(--ink-2);
}

.opt-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-2);
  padding-top: 2px;
}

.opt-flag {
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
  margin-top: 2px;
  opacity: 0;
}

/* 正确答案强调 */
.opt.is-correct {
  background: var(--correct-bg);
  border-color: var(--correct-line);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.25);
}

.opt.is-correct .opt-letter {
  background: var(--correct-line);
  color: #fff;
}

.opt.is-correct .opt-text {
  color: #064e3b;
  font-weight: 600;
}

.opt.is-correct .opt-flag {
  opacity: 1;
  background: var(--correct);
  color: #fff;
}

.answer-bar {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: linear-gradient(90deg, #ecfdf5, #f0fdfa 55%, #eff6ff);
  border: 1px solid #a7f3d0;
}

.answer-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.answer-letters {
  display: flex;
  gap: 6px;
}

.answer-letter {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--correct);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: 0 6px 14px rgba(4, 120, 87, 0.25);
}

.answer-text {
  flex: 1;
  min-width: 220px;
  font-size: 14px;
  color: #065f46;
  font-weight: 600;
  line-height: 1.65;
}

.q-id {
  margin-top: 10px;
  font-size: 11px;
  color: #94a3b8;
  letter-spacing: 0.02em;
}

/* answer-only mode */
.q-card.answer-only .options { display: none; }
.q-card.hide-options .options { display: none; }

.empty-state {
  text-align: center;
  padding: 56px 20px;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
}

.empty-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
  font-size: 22px;
  color: var(--muted);
}

.empty-state h3 {
  margin: 0 0 8px;
  color: var(--ink-2);
}

.empty-state p {
  margin: 0;
  font-size: 14px;
}

/* 分页 */
.pagination {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  bottom: 12px;
  z-index: 5;
}

.page-btn {
  min-width: 72px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink-2);
  font-size: 13px;
  padding: 0 12px;
}

.page-btn:hover:not(:disabled) {
  border-color: #93c5fd;
  color: var(--accent);
  background: #eff6ff;
}

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

.page-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.page-size,
.page-jump-input {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink-2);
  padding: 0 10px;
  font-size: 13px;
}

.page-jump-input {
  width: 88px;
}

.page-jump {
  min-width: 64px;
}

.footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: 8px 24px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

/* Loading */
.loading-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #cbd5e1;
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
  animation: spin .8s linear infinite;
}

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

@media (max-width: 980px) {
  .topbar-inner {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .stats { width: 100%; }
  .stat { flex: 1; }
  .layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }
  .filters {
    position: static;
  }
  .toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}
