/* ===== 全局 ===== */
:root {
  --primary: #4f46e5;
  --primary-light: #eef2ff;
  --primary-hover: #4338ca;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo { font-size: 1.15rem; font-weight: 700; flex: 1; display: flex; align-items: center; gap: 8px; }
.menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.stats-badge {
  font-size: .8rem;
  background: var(--primary-light);
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
  white-space: nowrap;
}

/* ===== Layout ===== */
.layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 60px);
}

/* ===== Sidebar ===== */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--card-bg);
  overflow-y: auto;
  height: calc(100vh - 60px);
  position: sticky;
  top: 60px;
  transition: transform .25s ease;
}
.sidebar-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h3 { font-size: .9rem; }

/* Tree */
.tree-container { padding: 8px 0; }
.tree-module { }
.tree-module-header {
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: .88rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background .15s;
}
.tree-module-header:hover { background: var(--primary-light); }
.tree-module-header.selected { background: var(--primary); color: #fff; border-radius: 6px; margin: 0 8px; }
.tree-module-header.selected .count { color: rgba(255,255,255,.85); }
.tree-module-header .arrow {
  transition: transform .2s;
  font-size: .7rem;
  width: 16px;
}
.tree-module-header .arrow.open { transform: rotate(90deg); }

.tree-chapter { padding-left: 8px; }
/* 默认展开，折叠时隐藏 */
.tree-module:not(.open) > .tree-chapter { display: none; }
.tree-module.open > .tree-chapter { display: block; }
.tree-chapter-header {
  padding: 6px 16px 6px 24px;
  cursor: pointer;
  font-size: .82rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background .15s;
  color: var(--text-muted);
}
.tree-chapter-header:hover {
  background: var(--primary-light);
  color: var(--text);
}
.tree-chapter-header.selected { background: var(--primary-light); color: var(--primary); font-weight: 600; border-radius: 6px; }
.tree-chapter-header .arrow { transition: transform .2s; font-size: .6rem; width: 12px; }
.tree-chapter-header .arrow.open { transform: rotate(90deg); }
.tree-topics { padding-left: 0; }
/* 默认展开，折叠时隐藏 */
.tree-chapter:not(.open) > .tree-topics { display: none; }
.tree-chapter.open > .tree-topics { display: block; }

.tree-topic {
  padding: 5px 16px 5px 36px;
  font-size: .8rem;
  cursor: pointer;
  border-radius: 0 20px 20px 0;
  transition: all .15s;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tree-topic:hover { background: var(--primary-light); color: var(--text); }
.tree-topic.active {
  background: var(--primary);
  color: #fff;
  font-weight: 500;
}
.tree-topic .count {
  margin-left: auto;
  font-size: .7rem;
  opacity: .7;
  background: rgba(255,255,255,.2);
  padding: 0 6px;
  border-radius: 8px;
}

/* ===== Main ===== */
.main {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

/* ===== Toolbar ===== */
.toolbar {
  margin-bottom: 16px;
}
.toolbar-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.toolbar-row + .toolbar-row { margin-top: 8px; }
.search-box {
  flex: 1;
  min-width: 200px;
}
.search-box input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  outline: none;
  transition: border .2s;
}
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .85rem;
  background: var(--card-bg);
  cursor: pointer;
  min-width: 100px;
}
.result-count {
  font-size: .82rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* ===== Question List ===== */
.question-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: .9rem; }

/* Question Card */
.q-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all .2s;
}
.q-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  border-color: var(--primary);
}
.q-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.q-badge {
  display: inline-block;
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 500;
}
.q-badge-topic {
  background: #dbeafe;
  color: #1d4ed8;
}
.q-badge-type {
  background: #f3e8ff;
  color: #7c3aed;
}
.q-badge-difficulty-easy { background: #dcfce7; color: #16a34a; }
.q-badge-difficulty-mid  { background: #fef9c3; color: #ca8a04; }
.q-badge-difficulty-hard { background: #fee2e2; color: #dc2626; }
.q-badge-number { background: #e0e7ff; color: #4338ca; font-size: .7rem; }
.q-badge-source { background: #fef3c7; color: #b45309; font-size: .7rem; }

.q-card-content {
  font-size: .93rem;
  line-height: 1.7;
  margin-bottom: 8px;
}
.q-card-options {
  margin: 6px 0 8px 0;
  padding-left: 4px;
}
.q-card-option {
  font-size: .88rem;
  line-height: 1.6;
  padding: 2px 0;
  color: var(--text);
}
.q-card-answer {
  font-size: .82rem;
  margin-top: 4px;
}
.q-card-answer .hidden-answer {
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  font-size: .85rem;
}
.q-card-answer-show {
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
}
.q-answer-line {
  font-size: .85rem;
  line-height: 1.6;
  color: var(--success);
  font-weight: 500;
}
.answer-toggle-btm {
  margin-top: 8px;
  font-size: .8rem;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-block;
  padding: 2px 10px;
  border-radius: 6px;
  transition: all .15s;
}
.answer-toggle-btm:hover {
  background: #f1f5f9;
  color: var(--primary);
}
.q-solution-line {
  font-size: .83rem;
  line-height: 1.6;
  color: var(--text);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #e2e8f0;
}
.q-label {
  font-weight: 600;
  color: var(--text);
}
.q-card-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.q-card-footer button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .8rem;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
  transition: all .15s;
}
.q-card-footer button:hover { background: var(--primary-light); color: var(--primary); }
.q-card-footer .btn-del:hover { background: #fee2e2; color: var(--danger); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: none;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 700px;
  margin-top: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: modalIn .2s ease;
}
.modal-lg { max-width: 800px; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { font-size: 1.05rem; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 4px;
  color: var(--text-muted);
}
.modal-body { padding: 20px; }

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: .85rem;
  font-weight: 500;
  margin-bottom: 6px;
}
.form-group .required { color: var(--danger); }
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  outline: none;
  transition: border .2s;
  font-family: inherit;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 500;
  transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #f1f5f9; color: var(--text); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-sm { padding: 6px 14px; font-size: .82rem; }
.btn-xs { padding: 4px 10px; font-size: .75rem; background: none; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.btn-xs:hover { background: var(--primary-light); }

/* ===== Detail ===== */
.detail-section { margin-bottom: 16px; }
.detail-section h4 {
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.detail-section .detail-body {
  font-size: .95rem;
  line-height: 1.8;
}
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.detail-tags .tag {
  font-size: .78rem;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: 12px;
}
.detail-options {
  list-style: none;
  padding: 0;
}
.detail-options li {
  padding: 6px 0;
  font-size: .92rem;
}
.detail-options li.correct { color: var(--success); font-weight: 600; }

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 4px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-size-select {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  color: var(--text-muted);
}
.page-size-select select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .82rem;
  background: var(--card-bg);
  cursor: pointer;
}
.page-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-info {
  font-size: .82rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.page-nav button:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .menu-btn { display: block; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 60px;
    height: calc(100vh - 60px);
    z-index: 50;
    transform: translateX(-100%);
    width: 280px;
    box-shadow: 4px 0 20px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 12px; }
  .toolbar-row { flex-direction: column; }
  .filter-select { width: 100%; min-width: unset; }
  .modal-overlay { padding: 10px; align-items: flex-start; }
  .modal { margin-top: 10px; }
}

/* ===== KaTeX fix ===== */
.katex { font-size: 1.05em !important; }
.katex-display { margin: .5em 0 !important; overflow-x: auto; overflow-y: hidden; }
.ver-badge { font-size: .65rem; background: #6366f1; color: #fff; padding: 1px 6px; border-radius: 4px; font-weight: 500; }
.qn { display: inline; font-weight: 700; color: #4338ca; margin-right: 4px; }

/* 题目附图样式 */
.q-card-image img, .detail-image img {
  max-width: 100%;
  height: auto;
  max-height: 350px;
  object-fit: contain;
  display: block;
  margin: 8px auto;
  border-radius: 6px;
}
@media (max-width: 480px) {
  .q-card-image img, .detail-image img { max-height: 250px; }
}

/* ===== Markdown 表格 ===== */
.md-table {
  border-collapse: collapse;
  margin: 8px 0;
  width: auto;
  min-width: 50%;
  max-width: 100%;
  font-size: .85rem;
  border: 1px solid var(--border);
}
.md-table th,
.md-table td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  white-space: nowrap;
}
.md-table th {
  background: #f1f5f9;
  font-weight: 600;
}
.md-table tr:nth-child(even) td {
  background: #f8fafc;
}
