
:root {
  --bg: #f8f9fb;
  --bg2: #ffffff;
  --ink: #1a1a2e;
  --muted: #6b7280;
  --rule: #e5e7eb;
  --accent: #2563eb;
  --accent2: #0ea5e9;
  --accent-bg: #eff6ff;
  --tag-bg: #f0fdf4;
  --tag-ink: #166534;
  --orange: #f59e0b;
  --orange-bg: #fffbeb;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
}

/* Header */
.header {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #0ea5e9 100%);
  color: white;
  padding: 2rem 1.5rem;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px rgba(37,99,235,0.2);
}

.header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
  letter-spacing: 0.02em;
}

.header .subtitle {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-bottom: 1rem;
}

/* Search */
.search-wrap {
  max-width: 600px;
  margin: 0 auto;
  position: relative;
}

.search-wrap input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.8rem;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  font-size: 0.95rem;
  background: rgba(255,255,255,0.15);
  color: white;
  outline: none;
  transition: all 0.3s;
  backdrop-filter: blur(10px);
}

.search-wrap input::placeholder {
  color: rgba(255,255,255,0.6);
}

.search-wrap input:focus {
  border-color: rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.2);
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  opacity: 0.7;
}

.search-result-count {
  text-align: center;
  font-size: 0.8rem;
  margin-top: 0.5rem;
  opacity: 0;
  transition: opacity 0.3s;
}

.search-result-count.show {
  opacity: 0.85;
}

/* Stats bar */
.stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--bg2);
  border-bottom: 1px solid var(--rule);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.stat-num {
  font-weight: 700;
  color: var(--accent);
  font-size: 1rem;
}

/* Layout */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* Category cards */
.categories {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.cat-card {
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.cat-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(37,99,235,0.08);
  transform: translateY(-1px);
}

.cat-card.active {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.cat-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent-bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.cat-info {
  flex: 1;
  min-width: 0;
}

.cat-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
}

.cat-count {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Section */
.faq-section {
  margin-bottom: 2rem;
  scroll-margin-top: 140px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--rule);
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
}

/* Tree list */
.tree-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.tree-sublist {
  list-style: none;
  padding-left: 1.5rem;
  margin: 0;
}

.tree-item {
  margin: 0;
  line-height: 1.6;
}

/* Branch (expandable item) */
.tree-branch-text {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  transition: all 0.15s;
}

.tree-branch-text:hover {
  background: var(--bg);
  color: var(--accent);
}

.tree-branch-link {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}

.tree-branch-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.tree-branch-link::after {
  content: " ↗";
  font-size: 0.65rem;
  opacity: 0.4;
}

.tree-arrow {
  font-size: 0.6rem;
  width: 14px;
  text-align: center;
  flex-shrink: 0;
  color: var(--muted);
  transition: transform 0.2s;
}

.tree-branch-text.collapsed .tree-arrow {
  transform: rotate(-90deg);
}

.tree-branch-text.collapsed + .tree-sublist,
.tree-branch-text.collapsed ~ .tree-sublist {
  display: none;
}

/* Leaf (link item) */
.tree-link {
  display: block;
  padding: 0.35rem 0.5rem;
  font-size: 0.88rem;
  color: var(--ink);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.15s;
}

.tree-link:hover {
  background: var(--bg);
  color: var(--accent);
}

/* Slightly different background for deeper levels to show hierarchy */
.tree-level-1 .tree-link,
.tree-level-1 .tree-branch-text {
  padding-left: 0.5rem;
}

.tree-level-2 .tree-link,
.tree-level-2 .tree-branch-text {
  padding-left: 0.5rem;
  font-size: 0.85rem;
}

.tree-level-3 .tree-link,
.tree-level-3 .tree-branch-text {
  font-size: 0.83rem;
}

/* Hidden items */
.tree-item.hidden {
  display: none;
}

.tree-item.highlight .tree-link {
  background: #fef3c7;
  color: #92400e;
  border-radius: 6px;
  animation: flashHighlight 2s ease-out;
}

@keyframes flashHighlight {
  0% { background: #fde68a; }
  100% { background: transparent; }
}

.tree-item.highlight .tree-link mark {
  background: #fde68a;
  padding: 0 2px;
  border-radius: 2px;
}

/* Smart match panel */
.smart-match {
  display: none;
  margin-bottom: 1.5rem;
  background: var(--bg2);
  border: 1px solid var(--accent);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 16px rgba(37,99,235,0.1);
}

.smart-match.show {
  display: block;
}

.smart-match-header {
  background: var(--accent-bg);
  padding: 0.75rem 1rem;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(37,99,235,0.1);
}

.smart-match-header .match-icon {
  font-size: 1.1rem;
}

.smart-match-list {
  padding: 0.5rem;
  max-height: 400px;
  overflow-y: auto;
}

.smart-match-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  color: var(--ink);
}

.smart-match-item:hover {
  background: var(--bg);
}

.smart-match-item .score-badge {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
}

.smart-match-item .score-high { background: #10b981; }
.smart-match-item .score-mid { background: var(--accent); }
.smart-match-item .score-low { background: var(--muted); }

.smart-match-item .match-info {
  flex: 1;
  min-width: 0;
}

.smart-match-item .match-title {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.4;
}

.smart-match-item .match-title mark {
  background: #fde68a;
  padding: 0 2px;
  border-radius: 2px;
  color: #92400e;
}

.smart-match-item .match-path {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.smart-match-item .match-arrow {
  flex-shrink: 0;
  opacity: 0.3;
  font-size: 0.85rem;
  transition: opacity 0.15s;
}

.smart-match-item:hover .match-arrow {
  opacity: 0.7;
}

/* No results */
.no-results {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  display: none;
}

.no-results.show {
  display: block;
}

.no-results svg {
  width: 64px;
  height: 64px;
  margin-bottom: 1rem;
  opacity: 0.3;
}

/* Footer */
.footer {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--rule);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

/* Back to top */
.back-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  box-shadow: 0 4px 12px rgba(37,99,235,0.3);
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 99;
}

.back-top.show {
  display: flex;
}

.back-top:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37,99,235,0.4);
}

/* Responsive */
@media (max-width: 640px) {
  .header { padding: 1.5rem 1rem; }
  .header h1 { font-size: 1.3rem; }
  .categories { grid-template-columns: 1fr; }
  .container { padding: 1rem 0.5rem 2rem; }
  .stats { gap: 1rem; flex-wrap: wrap; }
  .faq-section { scroll-margin-top: 120px; }
}

/* AI 智能问答 */
.ai-assistant {
  margin: 1.25rem auto 0;
  max-width: 760px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  color: #fff;
  backdrop-filter: blur(4px);
}
.ai-assistant-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.92rem;
  margin-bottom: 0.75rem;
}
.ai-badge {
  background: #fff;
  color: #4f46e5;
  font-weight: 700;
  font-size: 0.75rem;
  border-radius: 6px;
  padding: 2px 7px;
  letter-spacing: 0.5px;
}
.ai-input-row {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}
.ai-input-row textarea {
  flex: 1;
  resize: vertical;
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.92);
  color: #1f2937;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.5;
}
.ai-input-row textarea:focus { outline: 2px solid #fff; }
.ai-input-row button {
  flex: 0 0 auto;
  border: none;
  border-radius: 10px;
  background: #fff;
  color: #4f46e5;
  font-weight: 600;
  padding: 0 1.2rem;
  cursor: pointer;
  font-size: 0.95rem;
}
.ai-input-row button:disabled { opacity: 0.6; cursor: default; }
.ai-reply {
  margin-top: 0.85rem;
  background: rgba(255, 255, 255, 0.95);
  color: #1f2937;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  font-size: 0.95rem;
  line-height: 1.7;
  white-space: normal;
}
.ai-reply[hidden] { display: none; }
.ai-answer { white-space: pre-wrap; }
.ai-answer code {
  background: #eef2ff;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}
.ai-loading, .ai-error { color: #4b5563; }
.ai-error { color: #b91c1c; }
.ai-source {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: #6b7280;
  border-top: 1px dashed #e5e7eb;
  padding-top: 0.5rem;
}
.ai-hint {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.85);
}

/* FAQ 正文弹窗 */
body.modal-open { overflow: hidden; }

.faq-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.faq-modal[hidden] { display: none; }

.faq-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  animation: modalFade 0.18s ease-out;
}

.faq-modal-panel {
  position: relative;
  background: var(--bg2);
  color: var(--ink);
  width: 100%;
  max-width: 720px;
  max-height: 82vh;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalPop 0.2s ease-out;
}

@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalPop {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.faq-modal-close {
  position: absolute;
  top: 0.8rem;
  right: 0.9rem;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: all 0.15s;
}
.faq-modal-close:hover { background: #fee2e2; color: #b91c1c; }

.faq-modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  padding: 1.1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--rule);
  padding-right: 3rem;
  line-height: 1.4;
}

.faq-modal-body {
  padding: 1.1rem 1.25rem;
  overflow-y: auto;
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.8;
  color: #374151;
}

.faq-modal-empty {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

.faq-modal-foot {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--rule);
  text-align: right;
}

.faq-modal-origin {
  display: inline-block;
  background: var(--accent-bg);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  transition: all 0.15s;
}
.faq-modal-origin:hover { background: #dbeafe; }

@media (max-width: 640px) {
  .faq-modal { padding: 0.75rem; }
  .faq-modal-panel { max-height: 90vh; }
}
