:root {
  color-scheme: light dark;
  --accent: #315eea;
  --accent-soft: #edf2ff;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #e1e6ef;
  --code: #162033;
  --shadow: 0 7px 24px rgba(27, 39, 72, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: padding-left 0.2s ease;
}

body.overlay-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tools {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 10px 12px;
  background: rgba(245, 247, 251, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.tools-inner {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 10px;
  align-items: center;
  width: min(100%, 1040px);
  margin: 0 auto;
}

.menu-button,
.ai-button {
  width: 44px;
  height: 44px;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(27, 39, 72, 0.04);
}

.menu-button {
  color: var(--text);
  font-size: 23px;
  line-height: 1;
}

.ai-button {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.search-box {
  position: relative;
  display: block;
  min-width: 0;
  height: 44px;
}

.search-box input {
  display: block;
  width: 100%;
  height: 44px;
  padding: 0 44px 0 14px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  font-size: 15px;
}

.search-box input::-webkit-search-cancel-button {
  display: none;
  -webkit-appearance: none;
  appearance: none;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(49, 94, 234, 0.12);
}

.clear-button {
  position: absolute;
  top: 50%;
  right: 5px;
  display: none;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  transform: translateY(-50%);
}

.clear-button.visible {
  display: block;
}

.clear-button::before,
.clear-button::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 17px;
  height: 1.6px;
  content: "";
  background: currentColor;
  border-radius: 2px;
  transform-origin: center;
}

.clear-button::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.clear-button::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.content {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 20px 16px 52px;
}

.section-head {
  display: flex;
  gap: 18px;
  align-items: flex-end;
  justify-content: space-between;
  margin: 2px 2px 14px;
}

.section-head p {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.section-head h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.35;
  letter-spacing: -0.02em;
}

.section-head > span {
  color: var(--muted);
  text-align: right;
  font-size: 13px;
}

.function-card {
  margin-bottom: 14px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: var(--shadow);
  scroll-margin-top: 78px;
}

.function-head {
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.function-title {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.function-title h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.4;
}

.call {
  display: block;
  margin-top: 11px;
  padding: 11px 12px;
  overflow-x: auto;
  color: #e8efff;
  background: var(--code);
  border-radius: 8px;
  font: 13px/1.55 Consolas, "SFMono-Regular", monospace;
  white-space: nowrap;
  -webkit-user-select: text;
  user-select: text;
}

.function-body {
  padding: 15px 18px 18px;
}

.description {
  margin: 0 0 15px;
  color: var(--text);
  white-space: pre-line;
  font-size: 15px;
  line-height: 1.75;
}

.table-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 15px 0 7px;
  font-size: 15px;
  font-weight: 700;
}

.table-title small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 14px;
}

th,
td {
  overflow-wrap: anywhere;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

th:last-child,
td:last-child {
  border-right: 0;
}

tr:last-child td {
  border-bottom: 0;
}

th {
  height: 34px;
  padding: 6px;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  background: var(--accent-soft);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  vertical-align: middle;
}

td {
  padding: 10px 9px;
  text-align: left;
  line-height: 1.65;
  vertical-align: top;
}

.index-col {
  width: 54px;
  text-align: center;
}

.name-col {
  width: 128px;
}

.type-col {
  width: 72px;
  text-align: center;
}

.result-list {
  margin: 7px 0 0;
  padding-left: 19px;
  color: var(--muted);
}

.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  display: flex;
  width: min(70vw, 280px);
  flex-direction: column;
  background: var(--card);
  box-shadow: 12px 0 35px rgba(20, 29, 52, 0.2);
  transform: translateX(-102%);
  transition: transform 0.2s ease;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 66px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-head strong {
  font-size: 16px;
}

.drawer-head span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.drawer-close,
.ai-dialog-close {
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--text);
  background: var(--bg);
  border: 0;
  border-radius: 8px;
  font-size: 21px;
  line-height: 1;
}

.drawer-close {
  display: inline-flex;
  min-width: 54px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.drawer-nav {
  overflow-y: auto;
  padding: 9px 11px 28px;
}

.drawer-group {
  margin: 5px 0;
}

.drawer-group summary {
  padding: 10px 9px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  list-style: none;
}

.drawer-group summary::-webkit-details-marker {
  display: none;
}

.drawer-group summary::after {
  float: right;
  color: var(--muted);
  content: "›";
  transform: rotate(90deg);
}

.drawer-group:not([open]) summary::after {
  transform: rotate(0);
}

.category-link {
  display: flex;
  width: 100%;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px 9px 18px;
  color: var(--muted);
  border-radius: 8px;
  font-size: 14px;
}

.category-link.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

.category-link em {
  font-size: 12px;
  font-style: normal;
  opacity: 0.8;
}

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

.scrim.open {
  display: block;
}

.search-panel {
  position: fixed;
  top: 70px;
  left: 50%;
  z-index: 45;
  width: min(calc(100% - 24px), 950px);
  max-height: min(72vh, 680px);
  padding: 10px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 55px rgba(15, 23, 42, 0.2);
  transform: translateX(-50%);
}

.search-panel[hidden] {
  display: none;
}

.search-message {
  margin: 0;
  padding: 22px 14px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.search-result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 7px 10px;
  color: var(--muted);
  font-size: 12px;
}

.search-result {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border-top: 1px solid var(--line);
  border-radius: 8px;
}

.search-result:hover {
  background: var(--accent-soft);
}

.search-result strong {
  color: var(--text);
  font-size: 15px;
}

.search-result code {
  overflow: hidden;
  color: var(--accent);
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 12px Consolas, "SFMono-Regular", monospace;
}

.search-result small {
  color: var(--muted);
  font-size: 11px;
}

.ai-dialog-wrap {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.5);
}

.ai-dialog-wrap.open {
  display: flex;
}

.ai-dialog {
  width: min(100%, 540px);
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 55px rgba(15, 23, 42, 0.28);
}

.ai-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 11px;
}

.ai-dialog-head h2 {
  margin: 0;
  font-size: 19px;
}

.ai-dialog-body {
  padding: 0 16px 16px;
}

.ai-intro {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.ai-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  background: var(--bg);
  border-radius: 11px;
}

.ai-mode {
  height: 42px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
}

.ai-mode.active {
  color: var(--accent);
  background: var(--card);
  box-shadow: 0 2px 8px rgba(24, 35, 65, 0.1);
}

.ai-mode-detail {
  min-height: 68px;
  margin: 14px 2px 11px;
  color: var(--text);
  font-size: 14px;
}

.ai-mode-detail small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.ai-actions {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.ai-actions > .ai-copy,
.ai-actions > .ai-view {
  display: inline-flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 40px;
  margin: 0;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.ai-copy {
  color: #ffffff;
  background: var(--accent);
  border: 0;
}

.ai-view {
  color: var(--accent);
  background: var(--card);
  border: 1px solid var(--line);
  text-align: center;
  text-decoration: none;
}

.ai-copy:disabled,
.ai-view[aria-disabled="true"] {
  opacity: 0.6;
}

.ai-status {
  min-height: 20px;
  margin: 7px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

/* 桌面端将分类导航固定在左侧，只有较小屏幕使用覆盖式抽屉。 */
@media (min-width: 1024px) {
  :root {
    --docs-sidebar-width: 280px;
  }

  body {
    padding-left: var(--docs-sidebar-width);
  }

  .drawer {
    width: var(--docs-sidebar-width);
    border-right: 1px solid var(--line);
    box-shadow: none;
    transform: translateX(0);
  }

  .menu-button {
    display: none;
  }

  .tools-inner {
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .scrim.open {
    display: none;
  }

  .search-panel {
    left: calc((100% + var(--docs-sidebar-width)) / 2);
    width: min(calc(100% - var(--docs-sidebar-width) - 24px), 950px);
  }

  body.sidebar-collapsed {
    padding-left: 0;
  }

  body.sidebar-collapsed .drawer {
    transform: translateX(-102%);
  }

  body.sidebar-collapsed .menu-button {
    display: block;
  }

  body.sidebar-collapsed .tools-inner {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }

  body.sidebar-collapsed .search-panel {
    left: 50%;
    width: min(calc(100% - 24px), 950px);
  }
}

@media (max-width: 520px) {
  .tools {
    padding: 8px 9px;
  }

  .tools-inner {
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    gap: 8px;
  }

  .menu-button,
  .ai-button,
  .search-box,
  .search-box input {
    height: 42px;
  }

  .menu-button,
  .ai-button {
    width: 42px;
  }

  .content {
    padding: 14px 9px 38px;
  }

  .section-head {
    margin-inline: 3px;
  }

  .section-head h1 {
    font-size: 22px;
  }

  .section-head > span {
    max-width: 135px;
    font-size: 12px;
  }

  .function-head,
  .function-body {
    padding-right: 12px;
    padding-left: 12px;
  }

  .function-title h2 {
    font-size: 17px;
  }

  .description {
    font-size: 14px;
  }

  table {
    min-width: 590px;
    font-size: 13px;
  }

  th {
    font-size: 12px;
  }

  .search-panel {
    top: 64px;
    width: calc(100% - 18px);
  }

  .drawer {
    width: min(76vw, 280px);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #86a2ff;
    --accent-soft: #243154;
    --bg: #10141c;
    --card: #191f2a;
    --text: #f1f4fa;
    --muted: #a8b2c4;
    --line: #2d3543;
    --code: #0e131c;
    --shadow: none;
  }

  .tools {
    background: rgba(16, 20, 28, 0.95);
  }

  .page-direction.disabled {
    color: #6f7888;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .drawer {
    transition: none;
  }
}
