/* Tushare docs reader — tokens named by role, light/dark adapt via system preference. */
:root {
  color-scheme: light;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --bg: #ffffff;
  --surface: #f5f5f7;
  --surface-2: #ebebef;
  --text: #1d1d1f;
  --text-2: #515154;
  --text-3: #636366;
  --separator: rgba(0, 0, 0, 0.10);
  --separator-strong: rgba(0, 0, 0, 0.16);
  --accent: #0066cc;
  --accent-soft: rgba(0, 102, 204, 0.09);
  --code-bg: #f5f5f7;
  --row-alt: #fbfbfd;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.10);
  --toolbar-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #1d1d1f;
    --surface: #2c2c2e;
    --surface-2: #3a3a3c;
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #a8a8ad;
    --separator: rgba(255, 255, 255, 0.12);
    --separator-strong: rgba(255, 255, 255, 0.20);
    --accent: #2997ff;
    --accent-soft: rgba(41, 151, 255, 0.16);
    --code-bg: #2c2c2e;
    --row-alt: #232325;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.skip-link {
  position: fixed; left: 12px; top: -60px; z-index: 100;
  padding: 10px 14px; border-radius: 10px;
  background: var(--accent); color: #fff;
  transition: top .15s ease;
}
.skip-link:focus { top: 10px; text-decoration: none; }

/* Toolbar — actions on the current view, search at the trailing side. */
.toolbar {
  height: var(--toolbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  border-bottom: 1px solid var(--separator);
  background: var(--bg);
  position: relative; z-index: 20;
}
.toolbar-spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--text); color: var(--bg);
  font: 600 16px/1 var(--font-sans);
  flex: none;
}
.brand-text { min-width: 0; }
.brand-title { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  width: 32px; height: 32px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text-2);
  display: none; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.drawer-btn { display: none; }

.search-wrap {
  position: relative;
  width: min(360px, 36vw);
  display: flex; align-items: center;
}
.search-icon { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
#search {
  width: 100%; height: 32px;
  padding: 0 64px 0 32px;
  border: 1px solid transparent; border-radius: 8px;
  background: var(--surface); color: var(--text);
  font-size: 13px;
  appearance: none;
}
#search::placeholder { color: var(--text-3); }
#search:focus { outline: none; border-color: var(--accent); background: var(--bg); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-kbd {
  position: absolute; right: 9px;
  font: 11px/1 var(--font-sans); color: var(--text-3);
  border: 1px solid var(--separator-strong); border-radius: 4px;
  padding: 3px 4px; pointer-events: none;
}
.clear-btn {
  position: absolute; right: 6px;
  width: 22px; height: 22px; border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2);
  display: grid; place-items: center;
}
.clear-btn svg { width: 12px; height: 12px; stroke-width: 2; }
#search:not(:placeholder-shown) + .search-kbd { display: none; }
.source-link { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.source-link:hover { color: var(--accent); }

/* Three-pane layout. nav-shell uses display:contents so its children join the grid. */
.layout {
  display: grid;
  grid-template-columns: 232px minmax(260px, 320px) minmax(0, 1fr);
  height: calc(100dvh - var(--toolbar-h));
}
.nav-shell { display: contents; }

.sidebar, .list-pane {
  min-height: 0;
  border-right: 1px solid var(--separator);
  background: var(--surface);
}
.sidebar { padding: 14px 10px; overflow-y: auto; }
.sidebar-head {
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  color: var(--text-3); text-transform: uppercase;
  padding: 0 10px 8px;
}
.nav-item {
  width: 100%; min-height: 32px;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--text);
  text-align: left; font-size: 13px;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.nav-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); flex: none; }
.nav-item[aria-current="true"] .nav-dot { background: var(--accent); }
.subgroup { display: none; padding-left: 12px; }
.subgroup .nav-item { font-size: 12px; color: var(--text-2); }
.subgroup .nav-item[aria-current="true"] { color: var(--accent); }

.list-pane { display: flex; flex-direction: column; }
.list-head {
  height: 44px; flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 14px; border-bottom: 1px solid var(--separator);
}
.list-title { font-size: 12px; font-weight: 600; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-count { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; flex: none; }
.list-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.group-label {
  padding: 12px 8px 4px; font-size: 11px; font-weight: 600;
  color: var(--text-3); letter-spacing: .02em;
}
.list-item {
  width: 100%; min-height: 36px;
  display: flex; flex-direction: column; justify-content: center; gap: 1px;
  padding: 6px 9px;
  border: 0; border-radius: 7px; background: transparent;
  text-align: left; color: var(--text);
}
.list-item:hover { background: var(--surface-2); }
.list-item[aria-selected="true"] { background: var(--bg); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.list-item[aria-selected="true"] .li-title { color: var(--accent); font-weight: 600; }
.li-title { font-size: 13px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-meta { font-size: 11px; color: var(--text-3); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-crumb { font-size: 10px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-note { padding: 24px 12px; color: var(--text-3); font-size: 13px; text-align: center; }

/* Article — single readable column, independent scroll pane. */
.article-pane { min-width: 0; min-height: 0; overflow-y: auto; scroll-behavior: smooth; background: var(--bg); }
.article { max-width: 820px; margin: 0 auto; padding: 44px 52px 96px; }
.article:focus { outline: none; }
.breadcrumb { font-size: 12px; color: var(--text-3); margin-bottom: 10px; }
.breadcrumb span + span::before { content: " / "; color: var(--text-3); opacity: .6; }
.article h1 { font-size: 30px; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 18px; font-weight: 650; }

.api-card {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; margin: 0 0 22px;
  background: var(--surface); border-radius: 12px;
}
.api-card-label { font-size: 11px; color: var(--text-3); letter-spacing: .04em; }
.api-name {
  font: 600 17px/1.2 var(--font-mono); letter-spacing: -0.01em;
  color: var(--accent); overflow-wrap: anywhere;
}
.copy-btn {
  margin-left: auto; min-width: 28px; min-height: 28px;
  border: 1px solid var(--separator-strong); border-radius: 7px;
  background: var(--bg); color: var(--text-2);
  padding: 4px 9px; font-size: 12px;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }

.doc-meta {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  padding-bottom: 18px; margin-bottom: 24px;
  border-bottom: 1px solid var(--separator);
  font-size: 12px; color: var(--text-3);
}

.article h2, .article h3, .article h4, .article h5, .article h6 {
  line-height: 1.3; font-weight: 600; letter-spacing: -0.01em;
  margin: 32px 0 12px; color: var(--text);
}
.article h2 { font-size: 21px; }
.article h3 { font-size: 18px; }
.article h4 { font-size: 16px; }
.article h5, .article h6 { font-size: 14px; color: var(--text-2); }
.article p { margin: 0 0 14px; color: var(--text); font-size: 15px; line-height: 1.75; }
.article strong { font-weight: 600; }
.article hr { border: 0; border-top: 1px solid var(--separator); margin: 22px 0; }
.article ul, .article ol { padding-left: 22px; margin: 0 0 16px; }
.article li { margin: 4px 0; }
.article a { text-decoration: underline; text-underline-offset: 3px; }

.table-wrap { width: 100%; overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--separator); border-radius: 10px; }
.article table { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 13px; }
.article th, .article td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--separator); }
.article th { background: var(--surface); font-weight: 600; color: var(--text-2); white-space: nowrap; position: sticky; top: 0; }
.article tbody tr:nth-child(even) { background: var(--row-alt); }
.article tbody tr:last-child td { border-bottom: 0; }
.article td code { font-family: var(--font-mono); font-size: 12px; }

.code-wrap { position: relative; margin: 0 0 20px; }
.article pre {
  margin: 0; padding: 15px 16px;
  background: var(--code-bg); border-radius: 10px;
  overflow-x: auto; font: 12.5px/1.65 var(--font-mono);
  tab-size: 4;
}
.article pre code { font: inherit; background: none; padding: 0; }
.article :not(pre) > code {
  font-family: var(--font-mono); font-size: 12.5px;
  background: var(--surface); padding: 2px 5px; border-radius: 4px;
}
.code-copy {
  position: absolute; top: 8px; right: 8px;
  min-width: 28px; min-height: 28px;
  border: 1px solid var(--separator-strong); border-radius: 7px;
  background: var(--bg); color: var(--text-2);
  font-size: 11px; padding: 3px 8px;
  opacity: 0; transition: opacity .12s ease;
}
.code-wrap:hover .code-copy, .code-copy:focus-visible { opacity: 1; }

.child-links { margin: 34px 0 4px; padding-top: 22px; border-top: 1px solid var(--separator); }
.child-links h3 { margin: 0 0 12px; font-size: 15px; }
.child-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.child-card {
  display: block; padding: 11px 13px;
  border: 1px solid var(--separator); border-radius: 10px;
  color: var(--text); background: var(--bg);
}
.child-card:hover { border-color: var(--accent); text-decoration: none; }
.child-card .cc-title { font-size: 13px; font-weight: 600; }
.child-card .cc-api { font: 11px/1.5 var(--font-mono); color: var(--text-3); }

.scrim { position: fixed; inset: var(--toolbar-h) 0 0; background: rgba(0,0,0,.32); z-index: 28; }
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 12px);
  padding: 9px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg);
  font-size: 12px; opacity: 0; pointer-events: none;
  transition: opacity .15s ease, transform .15s ease; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Regular width: sidebar keeps two levels; deeper levels live in the article's child list. */
@media (max-width: 1199px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr); }
  .list-pane { display: none; }
  .subgroup { display: block; }
  .article { padding: 36px 36px 80px; }
}

/* Compact width: navigation becomes a drawer, article takes the full width. */
@media (max-width: 820px) {
  .toolbar { gap: 10px; padding: 0 12px; }
  .drawer-btn { display: inline-flex; }
  .source-link { display: none; }
  .search-wrap { width: min(300px, 42vw); }
  #search { padding-right: 12px; }
  #search:not(:placeholder-shown) { padding-right: 48px; }
  .search-kbd { display: none; }
  .brand-sub { display: none; }
  .layout { display: block; }
  .nav-shell {
    display: flex; flex-direction: column;
    position: fixed; left: 0; top: var(--toolbar-h); bottom: 0;
    width: min(88vw, 340px); z-index: 30;
    background: var(--surface);
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  body.drawer-open .nav-shell { transform: translateX(0); }
  .sidebar { flex: 0 0 42%; border-right: 0; border-bottom: 1px solid var(--separator); }
  .subgroup { display: none; }
  .list-pane { display: flex; flex: 1; min-height: 0; border-right: 0; }
  .article { padding: 28px 20px 72px; }
  .article h1 { font-size: 25px; }
  .nav-item { min-height: 44px; }
  .list-item { min-height: 44px; }
  .icon-btn, .clear-btn { width: 44px; height: 44px; }
}

@media (max-width: 520px) {
  .brand-title { font-size: 13px; }
  .brand-mark { display: none; }
  .search-wrap { width: 44vw; }
  .article { padding: 24px 16px 64px; }
  .api-card { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
