/* AI复盘助手 文档站样式 —— 单文件、无外部依赖（CSP: style-src 'self'） */

:root {
  --c-bg: #ffffff;
  --c-bg-soft: #f8fafc;
  --c-bg-code: #f1f5f9;
  --c-border: #e2e8f0;
  --c-border-strong: #cbd5e1;
  --c-text: #1e293b;
  --c-text-soft: #475569;
  --c-muted: #64748b;
  --c-accent: #2563eb;
  --c-accent-soft: #eff6ff;
  --c-up: #dc2626;
  --c-down: #16a34a;
  --topbar-h: 56px;
  --sidebar-w: 264px;
  --toc-w: 216px;
  --font-sans: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 16px); }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- 顶栏 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--c-border);
}

.brand {
  font-size: 16px;
  font-weight: 600;
  color: var(--c-text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--c-accent); }

.icon-btn {
  display: none;
  border: 1px solid var(--c-border);
  background: #fff;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  color: var(--c-text-soft);
}

.search { position: relative; flex: 1 1 auto; max-width: 420px; }

.search input {
  width: 100%;
  height: 34px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg-soft);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  outline: none;
}
.search input:focus { border-color: var(--c-accent); background: #fff; }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .12);
  padding: 6px;
}

.search-item {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--c-text);
}
.search-item:hover,
.search-item.is-active { background: var(--c-accent-soft); text-decoration: none; }
.search-item-title { font-weight: 600; font-size: 14px; }
.search-item-sub { font-size: 12px; color: var(--c-muted); }
.search-item mark { background: #fde68a; color: inherit; padding: 0 1px; border-radius: 2px; }
.search-empty { padding: 10px; font-size: 13px; color: var(--c-muted); }

.app-link {
  margin-left: auto;
  font-size: 14px;
  white-space: nowrap;
  padding: 6px 12px;
  border: 1px solid var(--c-border);
  border-radius: 8px;
}
.app-link:hover { text-decoration: none; border-color: var(--c-accent); background: var(--c-accent-soft); }

/* ---------------------------------------------------------------- 布局 */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 40px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 20px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 24px 4px 40px 0;
  font-size: 14px;
}

.nav-section { margin-bottom: 6px; }
.nav-section > summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--c-muted);
  text-transform: none;
  user-select: none;
}
.nav-section > summary::-webkit-details-marker { display: none; }
.nav-section > summary::before {
  content: "▾";
  display: inline-block;
  width: 12px;
  margin-right: 2px;
  font-size: 10px;
  transition: transform .15s;
}
.nav-section:not([open]) > summary::before { transform: rotate(-90deg); }

.nav-section ul { list-style: none; margin: 0 0 10px; padding: 0; }

.nav-link {
  display: block;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--c-text-soft);
  border-left: 2px solid transparent;
}
.nav-link:hover { background: var(--c-bg-soft); color: var(--c-text); text-decoration: none; }
.nav-link.is-active {
  background: var(--c-accent-soft);
  color: var(--c-accent);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: 24px;
  padding: 12px 10px 0;
  border-top: 1px solid var(--c-border);
  font-size: 12px;
  color: var(--c-muted);
  line-height: 1.6;
}

.content { min-width: 0; padding: 28px 0 80px; }

.breadcrumb { font-size: 13px; color: var(--c-muted); margin-bottom: 8px; }
.crumb-sep { margin: 0 6px; }
.crumb-current { color: var(--c-text-soft); }

/* ---------------------------------------------------------------- 正文 */

.markdown > h1 {
  font-size: 30px;
  line-height: 1.35;
  margin: 0 0 8px;
  letter-spacing: -.01em;
}

.markdown h2 {
  font-size: 21px;
  margin: 40px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--c-border);
  scroll-margin-top: calc(var(--topbar-h) + 12px);
}

.markdown h3 {
  font-size: 17px;
  margin: 28px 0 10px;
  scroll-margin-top: calc(var(--topbar-h) + 12px);
}

.markdown h4 { font-size: 15px; margin: 20px 0 8px; color: var(--c-text-soft); }

.markdown h2 .anchor,
.markdown h3 .anchor {
  margin-left: 8px;
  font-size: .8em;
  color: var(--c-border-strong);
  opacity: 0;
  transition: opacity .15s;
}
.markdown h2:hover .anchor,
.markdown h3:hover .anchor { opacity: 1; }

.markdown p { margin: 12px 0; }
.markdown ul, .markdown ol { padding-left: 22px; margin: 12px 0; }
.markdown li { margin: 5px 0; }
.markdown li > ul, .markdown li > ol { margin: 5px 0; }

.markdown strong { font-weight: 600; }

.markdown blockquote {
  margin: 16px 0;
  padding: 10px 16px;
  background: var(--c-bg-soft);
  border-left: 3px solid var(--c-accent);
  border-radius: 0 8px 8px 0;
  color: var(--c-text-soft);
}
.markdown blockquote p { margin: 6px 0; }

.markdown code {
  font-family: var(--font-mono);
  font-size: .88em;
  background: var(--c-bg-code);
  padding: 2px 5px;
  border-radius: 4px;
}

.markdown pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 10px;
  overflow-x: auto;
  line-height: 1.6;
}
.markdown pre code { background: none; color: inherit; padding: 0; font-size: 13px; }

.table-wrap { overflow-x: auto; margin: 16px 0; }

.markdown table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}
.markdown th, .markdown td {
  border: 1px solid var(--c-border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.markdown th { background: var(--c-bg-soft); font-weight: 600; white-space: nowrap; }
.markdown tbody tr:nth-child(even) { background: #fcfdfe; }

.markdown hr { border: none; border-top: 1px solid var(--c-border); margin: 32px 0; }

/* 截图：图存在时是圆角卡片；图还没放进来时 alt 文字会以浅灰占位显示 */
.markdown img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 18px 0;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, .07);
  color: var(--c-muted);
  font-size: 13px;
  line-height: 1.5;
  padding: 6px;
  background: var(--c-bg-soft);
}

/* 正文里的状态点：涨用红、跌用绿，与 A 股习惯一致 */
.up { color: var(--c-up); }
.down { color: var(--c-down); }

/* ---------------------------------------------------------------- 本页目录 */

.toc {
  position: sticky;
  top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 28px 0 40px;
  font-size: 13px;
}
.toc-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--c-muted);
  margin-bottom: 8px;
}
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--c-border); }
.toc a {
  display: block;
  padding: 4px 0 4px 12px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--c-muted);
  line-height: 1.5;
}
.toc a:hover { color: var(--c-text); text-decoration: none; }
.toc a.is-active { color: var(--c-accent); border-left-color: var(--c-accent); font-weight: 600; }
.toc-l3 a { padding-left: 24px; font-size: 12.5px; }

/* ---------------------------------------------------------------- 翻页 */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--c-border);
}
.pager-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 16px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  color: var(--c-text);
}
.pager-link:hover { border-color: var(--c-accent); background: var(--c-accent-soft); text-decoration: none; }
.pager-next { text-align: right; }
.pager-empty { border: none; }
.pager-dir { font-size: 12px; color: var(--c-muted); }
.pager-title { font-weight: 600; font-size: 14px; }

/* ---------------------------------------------------------------- 移动端 */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 45;
}

@media (max-width: 1180px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: 280px;
    max-height: none;
    background: #fff;
    border-right: 1px solid var(--c-border);
    padding: 16px 12px 40px;
    z-index: 50;
    transform: translateX(-102%);
    transition: transform .2s ease;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim { display: block; }

  .brand { font-size: 15px; }
  .app-link { padding: 6px 10px; font-size: 13px; }
  .markdown > h1 { font-size: 24px; }
  .markdown h2 { font-size: 19px; }
}

@media (max-width: 620px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .brand { display: none; }
  .app-link { display: none; }
  .search { max-width: none; }
  .pager { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- 独立页（404） */

.standalone {
  max-width: 560px;
  margin: 15vh auto;
  padding: 0 20px;
  text-align: center;
}
.standalone h1 { font-size: 26px; margin-bottom: 8px; }
.standalone p { color: var(--c-muted); }
