:root {
  --ink: #1f2933;
  --muted: #65717d;
  --line: #d9e0e5;
  --line-strong: #c3ccd4;
  --paper: #f7f9fa;
  --panel: #ffffff;
  --navy: #243746;
  --navy-soft: #e9eff3;
  --teal: #237a78;
  --teal-soft: #e3f1ef;
  --amber: #9a6500;
  --amber-soft: #fff3d5;
  --red: #a14343;
  --red-soft: #fbeaea;
  --shadow: 0 10px 30px rgba(31, 41, 51, 0.07);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  line-height: 1.6;
}

button, input, select { font: inherit; }

a { color: inherit; }

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

.skip-link {
  position: fixed;
  left: 1rem;
  top: -4rem;
  z-index: 10;
  padding: 0.6rem 0.9rem;
  background: var(--navy);
  color: #fff;
  text-decoration: none;
}

.skip-link:focus { top: 1rem; }

.section-kicker {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  font-weight: 700;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 1rem 0.5rem 0.25rem;
  padding: 0.52rem 0.65rem;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}

.search-box:focus-within { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(35, 122, 120, 0.12); }
.search-icon { color: #778690; font-size: 1.2rem; line-height: 1; }
.search-box input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 0.8rem; }
.search-box input::placeholder { color: #84919a; }
.search-box kbd { color: #778690; font-size: 0.7rem; border: 1px solid var(--line-strong); padding: 0 0.3rem; border-radius: 3px; }

.source-link { display: inline-block; margin: 0.85rem 0.5rem 0; color: var(--teal); white-space: nowrap; font-size: 0.76rem; text-underline-offset: 3px; }
.source-link:hover { color: var(--navy); }

.app-shell {
  display: grid;
  grid-template-columns: minmax(15rem, 18rem) minmax(0, 1fr);
  max-width: 1440px;
  min-height: 100vh;
  margin: 0 auto;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: calc(100vh - 0px);
  padding: 1.5rem 1rem 1.25rem;
  background: #eef2f4;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.sidebar-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 0.75rem; padding: 0 0.5rem 1rem; border-bottom: 1px solid var(--line); }
.sidebar-heading h1 { margin: 0.15rem 0 0; font-size: 1.08rem; }
.sidebar .section-kicker { color: var(--teal); }
.count-badge { display: inline-grid; place-items: center; min-width: 2rem; height: 1.55rem; padding: 0 0.35rem; background: #fff; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 0.76rem; }

.sidebar-filters { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 0.5rem; padding: 1rem 0.5rem 0.75rem; color: var(--muted); font-size: 0.78rem; }
.sidebar-filters select { width: 100%; padding: 0.35rem 0.45rem; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 3px; }

.command-nav { display: grid; gap: 0.6rem; }
.nav-group { border: 1px solid transparent; }
.nav-group[open] { border-color: var(--line); background: rgba(255,255,255,0.55); }
.nav-group summary { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.55rem 0.6rem; cursor: pointer; list-style: none; color: var(--navy); font-weight: 700; font-size: 0.86rem; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::before { content: "+"; display: inline-grid; place-items: center; width: 1rem; height: 1rem; color: var(--teal); font-size: 1rem; }
.nav-group[open] summary::before { content: "−"; }
.nav-count { margin-left: auto; color: var(--muted); font-size: 0.72rem; font-weight: 500; }
.nav-items { display: grid; gap: 0.15rem; padding: 0 0.35rem 0.45rem 1.65rem; }
.nav-item { display: grid; gap: 0.08rem; min-width: 0; padding: 0.48rem 0.5rem; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; overflow-wrap: anywhere; }
.nav-item:hover { background: #fff; color: var(--navy); }
.nav-item.active { border-left-color: var(--teal); background: var(--teal-soft); color: var(--teal); font-weight: 700; }
.nav-item.hidden { display: none; }
.nav-label { color: var(--navy); font-size: 0.82rem; line-height: 1.45; }
.nav-command { padding: 0; background: transparent; color: #7c8993; font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace; font-size: 0.64rem; font-weight: 500; line-height: 1.35; }
.nav-item:hover .nav-command, .nav-item.active .nav-command { color: inherit; }

.sidebar-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.55rem; margin: 1.5rem 0.5rem 0; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.72rem; }
.legend-dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; }
.dot-condition { background: #547eae; }
.dot-action { background: var(--teal); }
.dot-flow { background: var(--amber); }

.content-area { min-width: 0; padding: 2.3rem clamp(1.25rem, 4vw, 4.5rem) 5rem; }
.content-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; max-width: 62rem; margin: 0 auto 1rem; }
.content-toolbar .section-kicker { color: var(--teal); }
.result-summary { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.83rem; }
.icon-button { display: inline-grid; place-items: center; width: 2.2rem; height: 2.2rem; border: 1px solid var(--line-strong); border-radius: 4px; background: #fff; color: var(--navy); cursor: pointer; }
.icon-button:hover { border-color: var(--teal); color: var(--teal); }

.detail-view { max-width: 62rem; margin: 0 auto; }
.empty-state { padding: 4rem 2rem; border: 1px dashed var(--line-strong); background: rgba(255,255,255,0.6); text-align: center; color: var(--muted); }
.empty-state h2 { margin: 0 0 0.5rem; color: var(--navy); font-size: 1.2rem; }

.command-header { padding-bottom: 1.5rem; border-bottom: 1px solid var(--line-strong); }
.command-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; margin-bottom: 0.75rem; }
.type-badge, .meta-chip, .status-badge { display: inline-flex; align-items: center; min-height: 1.6rem; padding: 0.15rem 0.55rem; border-radius: 3px; font-size: 0.72rem; font-weight: 700; }
.type-badge { background: var(--navy-soft); color: var(--navy); }
.type-badge.condition { background: #e8eef8; color: #416991; }
.type-badge.action { background: var(--teal-soft); color: var(--teal); }
.type-badge.flow { background: var(--amber-soft); color: var(--amber); }
.type-badge.metadata, .type-badge.database { background: #eeeaf6; color: #69528c; }
.meta-chip { background: #f0f3f5; color: var(--muted); font-weight: 500; }
.status-badge { background: var(--amber-soft); color: var(--amber); }
.status-badge.native, .status-badge.reviewed { background: var(--teal-soft); color: var(--teal); }
.status-badge.implemented { background: #e8eef8; color: #416991; }
.status-badge.unavailable { background: var(--red-soft); color: var(--red); }
.command-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.75rem; margin: 0; color: var(--navy); font-size: clamp(1.45rem, 3vw, 2.1rem); line-height: 1.25; }
.command-title code { color: var(--ink); font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace; font-size: 0.8em; }
.command-title span { color: var(--muted); font-size: 0.62em; font-weight: 500; }
.summary { max-width: 55rem; margin: 0.75rem 0 0; color: #40505d; font-size: 1rem; }

.detail-section { border-bottom: 1px solid var(--line); }
.detail-section:last-child { border-bottom: 0; }
.detail-section h2 { margin: 0 0 0.8rem; color: var(--navy); font-size: 1.05rem; }
.detail-section h2::before { content: ""; display: inline-block; width: 0.28rem; height: 1rem; margin-right: 0.5rem; background: var(--teal); vertical-align: -0.1rem; }
.syntax-list { display: grid; gap: 0.5rem; }
pre { margin: 0; padding: 1rem 1.15rem; border: 1px solid #dce5e9; border-left: 3px solid var(--teal); background: #f1f5f6; color: #243746; overflow-x: auto; }
pre code { font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace; font-size: 0.82rem; line-height: 1.7; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 32rem; background: #fff; }
th, td { padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f1f4f5; color: var(--navy); font-size: 0.8rem; white-space: nowrap; }
td { color: #40505d; font-size: 0.88rem; }
tr:last-child td { border-bottom: 0; }
td code, .inline-code { padding: 0.12rem 0.3rem; background: #edf2f4; color: var(--navy); font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace; font-size: 0.82em; }
.notes { display: grid; gap: 0.55rem; margin: 0; padding-left: 1.1rem; color: #40505d; }
.notes li::marker { color: var(--teal); }
.examples { display: grid; gap: 1rem; }
.example-title { margin: 0 0 0.35rem; color: var(--muted); font-size: 0.8rem; font-weight: 700; }
.related-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.related-list a { padding: 0.35rem 0.55rem; border: 1px solid var(--line-strong); background: #fff; color: var(--teal); text-decoration: none; font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace; font-size: 0.76rem; }
.related-list a:hover { border-color: var(--teal); background: var(--teal-soft); }
.no-data { color: var(--muted); font-size: 0.86rem; }
.variable-group + .variable-group { margin-top: 1.25rem; }
.variable-group h3 { margin: 0 0 0.55rem; color: var(--navy); font-size: 0.9rem; }
.variable-table th:first-child, .variable-table td:first-child { width: 15rem; white-space: nowrap; }

.toast { position: fixed; right: 1.25rem; bottom: 1.25rem; max-width: 20rem; padding: 0.7rem 0.9rem; background: var(--navy); color: #fff; box-shadow: var(--shadow); opacity: 0; transform: translateY(0.5rem); pointer-events: none; transition: opacity 160ms ease, transform 160ms ease; font-size: 0.82rem; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 850px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 1rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .command-nav { max-height: 18rem; overflow-y: auto; }
  .sidebar-footer { display: none; }
  .content-area { padding: 1.6rem 1rem 3rem; }
}

@media (max-width: 520px) {
  .content-toolbar { align-items: flex-start; }
  .command-title { flex-direction: column; gap: 0.25rem; }
  table { min-width: 0; }
  th, td { padding: 0.6rem; }
  th:nth-child(2), td:nth-child(2) { width: 5rem; }
  .variable-table th:first-child, .variable-table td:first-child { width: auto; white-space: normal; overflow-wrap: anywhere; }
  pre { padding: 0.8rem; }
  pre code { font-size: 0.76rem; }
}
