* { box-sizing: border-box; }

:root {
  /* Dark theme (default) */
  --bg: #0f1115;
  --panel: #161a22;
  --line: #232a36;
  --text: #e6e8ec;
  --muted: #8a93a3;
  --accent: #6ea8ff;
  --accent-fg: #0b1220;
  --user-bubble: #2a3447;
  --ai-bubble: #1c2230;
  --strong: #ffffff;
  --code-bg: rgba(255,255,255,0.08);
  --pre-bg: rgba(0,0,0,0.3);
  --hover: rgba(255,255,255,0.04);
  --cite-bg: rgba(110, 168, 255, 0.07);
  --danger: #e06c75;
  --ok: #98c379;
  --warn: #e5c07b;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

[data-theme="light"] {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #e1e5ee;
  --text: #1a1f2c;
  --muted: #5f6877;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --user-bubble: #dbeafe;
  --ai-bubble: #f3f4f6;
  --strong: #0a0f1a;
  --code-bg: rgba(0,0,0,0.06);
  --pre-bg: #eef0f4;
  --hover: rgba(0,0,0,0.04);
  --cite-bg: rgba(37, 99, 235, 0.06);
  --danger: #b91c1c;
  --ok: #15803d;
  --warn: #b45309;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
}

html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; transition: background 0.18s, color 0.18s; }

/* ==== Admin stats dashboard ==== */
.stats-panel .stats-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 18px; }
.stats-section-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--muted);
  text-transform: uppercase;
  margin: 24px 0 10px;
}

/* Hero card — live online count */
.stat-hero {
  position: relative;
  background: linear-gradient(135deg, rgba(46, 204, 113, 0.10) 0%, rgba(110, 168, 255, 0.08) 60%, transparent 100%);
  border: 1px solid rgba(46, 204, 113, 0.25);
  border-radius: 16px;
  padding: 28px 32px;
  display: flex;
  align-items: center;
  gap: 28px;
  overflow: hidden;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.stat-hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(46, 204, 113, 0.4), transparent);
}

/* Concentric pulse rings around the live indicator */
.hero-pulse {
  position: relative;
  width: 64px; height: 64px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hero-pulse::after {
  content: '';
  width: 14px; height: 14px;
  background: #2ecc71;
  border-radius: 50%;
  box-shadow: 0 0 16px #2ecc71, 0 0 4px rgba(46, 204, 113, 0.8);
  z-index: 4;
  animation: pulseDot 2s ease-in-out infinite;
}
.hero-pulse span {
  position: absolute;
  top: 50%; left: 50%;
  width: 14px; height: 14px;
  border: 2px solid #2ecc71;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(1);
  opacity: 0.7;
  animation: heroRing 2.4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
.hero-pulse span:nth-child(2) { animation-delay: 0.8s; }
.hero-pulse span:nth-child(3) { animation-delay: 1.6s; }
@keyframes heroRing {
  0%   { transform: translate(-50%, -50%) scale(1); opacity: 0.7; }
  100% { transform: translate(-50%, -50%) scale(4.5); opacity: 0; }
}
@keyframes pulseDot {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.18); }
}

.hero-content { flex: 1; min-width: 0; }
.hero-num {
  font-size: 64px;
  font-weight: 800;
  color: var(--strong);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.hero-unit {
  font-size: 22px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 1px;
}
.hero-label {
  font-size: 15px;
  color: #b8c5d8;
  margin-top: 6px;
  font-weight: 500;
}

/* Smaller cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  transition: border-color 0.2s, transform 0.2s, background 0.2s;
  position: relative;
  overflow: hidden;
}
.stat-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.stat-card.today { border-color: rgba(110, 168, 255, 0.25); background: linear-gradient(135deg, rgba(110, 168, 255, 0.05), transparent 70%); }
.stat-card.today .stat-num { color: var(--accent); }

.stat-num {
  font-size: 32px;
  font-weight: 700;
  color: var(--strong);
  line-height: 1.1;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}
.stat-label { font-size: 13px; color: var(--muted); }

/* Brief flash when a number changes */
.stat-card.just-changed,
.stat-hero.just-changed {
  animation: flashHighlight 1.2s ease-out;
}
@keyframes flashHighlight {
  0%   { box-shadow: 0 0 0 0 rgba(110, 168, 255, 0.45); }
  30%  { box-shadow: 0 0 0 8px rgba(110, 168, 255, 0.15); }
  100% { box-shadow: 0 0 0 0 rgba(110, 168, 255, 0); }
}

@media (max-width: 600px) {
  .stat-hero { padding: 22px 20px; gap: 18px; }
  .hero-pulse { width: 48px; height: 48px; }
  .hero-num { font-size: 48px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-num { font-size: 26px; }
}

/* ==== Related reading card ==== */
.related-read { margin-top: 28px; }
.related-head {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.related-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.18s, transform 0.18s, background 0.18s;
}
.related-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  background: var(--hover);
  text-decoration: none;
}
.related-icon {
  font-size: 28px;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(110, 168, 255, 0.15), rgba(46, 204, 113, 0.1));
  border-radius: 12px;
}
.related-body { flex: 1; min-width: 0; }
.related-title { font-size: 15px; font-weight: 600; color: var(--strong); margin-bottom: 4px; }
.related-desc { font-size: 13px; color: var(--muted); line-height: 1.5; }
.related-arrow {
  font-size: 20px;
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 0.2s, color 0.2s;
}
.related-card:hover .related-arrow {
  color: var(--accent);
  transform: translate(2px, -2px);
}

@media (max-width: 600px) {
  .related-card { padding: 14px 16px; gap: 12px; }
  .related-icon { width: 40px; height: 40px; font-size: 24px; }
  .related-title { font-size: 14px; }
  .related-desc { font-size: 12px; }
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.error { background: rgba(224, 108, 117, 0.12); color: var(--danger); padding: 8px 12px; border-radius: 6px; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 600; color: var(--text); font-size: 16px; }
.topbar nav { margin-left: auto; display: flex; gap: 10px; align-items: center; }

/* Pill-style nav tabs for /chat and /mindmap (more prominent than plain text links) */
.nav-tab {
  padding: 8px 18px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s;
}
.nav-tab:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.nav-tab.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}

#theme-toggle {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  width: 36px; height: 36px; padding: 0; border-radius: 50%;
  font-size: 16px; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-weight: 400;
}
#theme-toggle:hover { border-color: var(--accent); }

main { max-width: 960px; margin: 24px auto; padding: 0 16px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px 24px; margin-bottom: 20px; }
.panel h1 { margin-top: 0; font-size: 20px; }
.panel h2 { font-size: 16px; margin: 0 0 12px; }

.auth-box { max-width: 380px; margin: 80px auto; }
.auth-box form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.auth-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.auth-box input { background: var(--bg); border: 1px solid var(--line); color: var(--text); padding: 10px 12px; border-radius: 6px; font-size: 14px; }
button { background: var(--accent); color: var(--accent-fg); border: 0; padding: 9px 16px; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 14px; }
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); font-weight: 400; }
button.ghost:hover { color: var(--text); border-color: var(--accent); }
button.link { background: transparent; color: var(--muted); padding: 2px 6px; font-weight: 400; }
button.link:hover { color: var(--text); }
button.danger { color: var(--danger); }

.upload { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.upload input[type=file] { color: var(--muted); }

.docs { width: 100%; border-collapse: collapse; font-size: 14px; }
.docs th, .docs td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.docs th { color: var(--muted); font-weight: 500; font-size: 12px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; }
.badge.ready { background: rgba(152, 195, 121, 0.15); color: var(--ok); }
.badge.processing, .badge.pending { background: rgba(229, 192, 123, 0.15); color: var(--warn); }
.badge.failed { background: rgba(224, 108, 117, 0.15); color: var(--danger); }
.err { font-size: 11px; color: var(--danger); margin-top: 2px; }
.cta { display: inline-block; margin-top: 8px; }

.chat-panel { display: flex; flex-direction: column; min-height: 70vh; }
.chat-head { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.chat-head h1 { margin: 0; font-size: 18px; }
.messages { flex: 1; overflow-y: auto; padding: 8px 0; max-height: 60vh; }
.msg { margin: 12px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bubble); padding: 10px 14px; border-radius: 12px 12px 2px 12px; max-width: 78%; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--ai-bubble); padding: 12px 16px; border-radius: 12px 12px 12px 2px; border: 1px solid var(--line); }
.msg.assistant .bubble p { margin: 0 0 8px; }
.msg.assistant .bubble p:last-child { margin-bottom: 0; }
.msg.assistant .bubble ul, .msg.assistant .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.msg.assistant .bubble li { margin: 2px 0; }
.msg.assistant .bubble strong { color: var(--strong); font-weight: 600; }
.msg.assistant .bubble code { background: var(--code-bg); padding: 1px 6px; border-radius: 4px; font-size: 13px; }
.msg.assistant .bubble pre { background: var(--pre-bg); padding: 10px 12px; border-radius: 6px; overflow-x: auto; }
.msg.assistant .bubble pre code { background: none; padding: 0; }
.msg.assistant .bubble h1, .msg.assistant .bubble h2, .msg.assistant .bubble h3 { margin: 12px 0 6px; font-size: 15px; }
.msg.assistant .bubble blockquote { border-left: 2px solid var(--line); padding-left: 10px; color: var(--muted); margin: 6px 0; }
.cites-fold { margin-top: 6px; }
.cites-fold > summary { cursor: pointer; color: var(--muted); font-size: 12px; list-style: none; padding: 4px 8px; border-radius: 6px; display: inline-block; }
.cites-fold > summary:hover { background: var(--hover); color: var(--text); }
.cites-fold > summary::-webkit-details-marker { display: none; }
.cites-fold[open] > summary { color: var(--text); }

/* markmap theme-aware overrides */
.markmap-foreign { color: var(--text); }
.markmap-foreign a { color: var(--accent); }
.markmap-foreign code { background: var(--code-bg); padding: 0 4px; border-radius: 3px; }
.markmap g circle { stroke-width: 1.5px; }
.mm-wrap { position: relative; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; overflow: hidden; }
.mm-canvas { position: relative; width: 100%; height: 78vh; overflow: hidden; }
.mm-canvas svg { width: 100%; height: 100%; display: block; }

/* Mobile: don't let mm.fit() shrink text to a 360px viewport — give the
   canvas a generous min-width and let users pan the tree horizontally. */
@media (max-width: 700px) {
  .mm-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .mm-canvas { min-width: 900px; height: 70vh; }
}
.mm-toolbar { position: absolute; bottom: 12px; right: 12px; z-index: 2; }
.mm-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.mm-tab { background: var(--panel); color: var(--muted); border: 1px solid var(--line); padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 400; cursor: pointer; }
.mm-tab:hover { color: var(--text); border-color: var(--accent); }
.mm-tab.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.mm-toolbar .mm-toolbar-item { background: var(--panel) !important; border: 1px solid var(--line) !important; color: var(--text) !important; }
.citations { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.cite { background: var(--cite-bg); border-left: 2px solid var(--accent); padding: 8px 12px; border-radius: 0 6px 6px 0; font-size: 13px; }
.cite-text { color: var(--muted); margin-top: 4px; font-size: 12px; line-height: 1.5; max-height: 4.5em; overflow: hidden; white-space: pre-wrap; }

.ask { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; }
.ask textarea { flex: 1; background: var(--bg); border: 1px solid var(--line); color: var(--text); padding: 10px 12px; border-radius: 8px; resize: vertical; font: inherit; }
.ask button { height: 40px; }

.site-footer {
  max-width: 960px; margin: 24px auto 32px; padding: 20px 16px 0;
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 12px;
  font-size: 12px; color: var(--muted);
}
.site-footer .disclaimer { font-size: 11.5px; line-height: 1.6; color: var(--muted); margin: 0; }
.site-footer .footer-row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; align-items: center; }
.xhs-credit {
  display: inline-flex; align-items: center; gap: 6px;
  position: relative; cursor: default; outline: none;
}
.xhs-credit .xhs-logo {
  display: inline-block; background: #ff2442; color: #fff;
  font-size: 9px; font-weight: 700; padding: 2px 5px;
  border-radius: 4px; letter-spacing: 0.3px; line-height: 1;
}
.xhs-credit .xhs-name { color: var(--text); }
.xhs-credit .xhs-card-pop {
  position: absolute; bottom: calc(100% + 10px); left: 0;
  width: 220px; border-radius: 14px; overflow: hidden; background: #fff;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  opacity: 0; visibility: hidden;
  transform: translateY(8px) scale(0.96); transform-origin: bottom left;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
  pointer-events: none; z-index: 999;
}
.xhs-credit .xhs-card-pop img { width: 100%; display: block; }
.xhs-credit:hover .xhs-card-pop,
.xhs-credit:focus-within .xhs-card-pop,
.xhs-credit:focus .xhs-card-pop {
  opacity: 1; visibility: visible; transform: translateY(0) scale(1);
}
