:root {
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #19222d;
  --muted: #566170;
  --line: #dde3ea;
  --accent: #0b7a86;
  --accent-ink: #ffffff;
  --accent-soft: #dcf2f4;
  --green: #23894f;
  --green-soft: #def4e6;
  --yellow: #94700a;
  --yellow-soft: #fbf0cc;
  --red: #b5322a;
  --red-soft: #fbe1de;
  --code-bg: #eef1f5;
  --shadow: 0 1px 2px rgba(20, 30, 45, 0.06), 0 6px 18px rgba(20, 30, 45, 0.05);
  --radius: 12px;
  --header-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1319;
    --surface: #151c25;
    --surface-2: #1b2430;
    --text: #e5eaf0;
    --muted: #9aa6b5;
    --line: #263140;
    --accent: #3fb8c3;
    --accent-ink: #06161a;
    --accent-soft: #0f2c31;
    --green: #4cc380;
    --green-soft: #12301f;
    --yellow: #e0b93c;
    --yellow-soft: #33290a;
    --red: #f0746b;
    --red-soft: #381614;
    --code-bg: #1b2430;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #0e1319;
  --surface: #151c25;
  --surface-2: #1b2430;
  --text: #e5eaf0;
  --muted: #9aa6b5;
  --line: #263140;
  --accent: #3fb8c3;
  --accent-ink: #06161a;
  --accent-soft: #0f2c31;
  --green: #4cc380;
  --green-soft: #12301f;
  --yellow: #e0b93c;
  --yellow-soft: #33290a;
  --red: #f0746b;
  --red-soft: #381614;
  --code-bg: #1b2430;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip-link {
  position: absolute; left: -999px; top: 8px;
  background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: 8px; z-index: 100;
}
.skip-link:focus { left: 8px; }

/* header */
.site-header {
  position: sticky; top: 0; z-index: 50; height: var(--header-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 20px; font-weight: 800; line-height: 1;
}
.brand small { color: var(--muted); font-weight: 500; }
.header-spacer { flex: 1; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 18px;
  display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); }
.lang-switch { font-size: 13px; font-weight: 700; text-decoration: none; letter-spacing: .02em; }
.menu-btn { display: none; }

.search { position: relative; width: min(340px, 100%); }
.search input {
  width: 100%; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); padding: 0 12px; font: inherit; font-size: 15px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-results {
  position: absolute; top: 46px; left: 0; right: 0; max-height: 60vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); display: none;
}
.search-results.open { display: block; }
.search-results a { display: block; padding: 10px 14px; color: var(--text); border-bottom: 1px solid var(--line); }
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover { background: var(--surface-2); text-decoration: none; }
.search-results .sr-title { font-weight: 600; }
.search-results .sr-page { color: var(--muted); font-size: 13px; }
.search-results .sr-empty { padding: 12px 14px; color: var(--muted); }

/* layout */
.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr) 220px; gap: 28px; max-width: 1380px; margin: 0 auto; padding: 24px 16px 64px; }

.sidebar { position: sticky; top: calc(var(--header-h) + 16px); align-self: start; max-height: calc(100vh - var(--header-h) - 32px); overflow: auto; }
.sidebar nav a {
  display: block; padding: 8px 12px; border-radius: 8px; color: var(--text); font-size: 15px;
}
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar .group { margin: 14px 12px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }

.toc { position: sticky; top: calc(var(--header-h) + 16px); align-self: start; max-height: calc(100vh - var(--header-h) - 32px); overflow: auto; font-size: 14px; }
.toc h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.toc a { display: block; padding: 4px 0 4px 10px; color: var(--muted); border-left: 2px solid var(--line); }
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.sub { padding-left: 22px; font-size: 13px; }
.toc a.current { color: var(--accent); border-left-color: var(--accent); }

main { min-width: 0; }
.content {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(18px, 4vw, 40px); box-shadow: var(--shadow);
}
.content > :first-child { margin-top: 0; }

h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); line-height: 1.2; margin: 0 0 12px; letter-spacing: -0.01em; }
h2 { font-size: 1.5rem; margin: 2.2em 0 0.6em; padding-top: 0.4em; border-top: 1px solid var(--line); line-height: 1.3; }
h2:first-of-type { border-top: 0; }
h3 { font-size: 1.15rem; margin: 1.6em 0 0.4em; }
p, ul, ol { margin: 0.8em 0; }
li { margin: 0.25em 0; }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 70ch; }

code { font-family: var(--mono); font-size: 0.9em; background: var(--code-bg); padding: 0.12em 0.4em; border-radius: 6px; }
pre {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
  overflow: auto; font-size: 0.88rem; line-height: 1.55; position: relative;
}
pre code { background: none; padding: 0; font-size: inherit; }
.copy-btn {
  position: absolute; top: 8px; right: 8px; font: inherit; font-size: 12px; padding: 4px 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 6px;
}
.copy-btn:hover { color: var(--text); }

.table-wrap { overflow-x: auto; margin: 1em 0; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
th, td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td code, th code { white-space: nowrap; }

.callout { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 12px 16px; border-radius: 8px; margin: 1.2em 0; }
.callout.warn { border-color: var(--yellow); background: var(--yellow-soft); }
.callout.danger { border-color: var(--red); background: var(--red-soft); }
.callout p:first-child { margin-top: 0; }
.callout p:last-child { margin-bottom: 0; }
.callout strong.title { display: block; margin-bottom: 2px; }

.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; letter-spacing: 0.02em; white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.neutral { background: var(--surface-2); color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin: 1.2em 0; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 16px; background: var(--surface); }
.card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.93rem; }
a.card { color: inherit; display: block; }
a.card:hover { text-decoration: none; border-color: var(--accent); box-shadow: var(--shadow); }

.hero { padding: clamp(8px, 2vw, 18px) 0 8px; }
.hero .cta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.btn {
  display: inline-block; padding: 10px 18px; border-radius: 10px; font-weight: 600; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); cursor: pointer; font: inherit; font-weight: 600;
}
.btn:hover { text-decoration: none; filter: brightness(1.06); }
.btn.secondary { background: transparent; color: var(--accent); }

/* disease catalog */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 1em 0; }
.filters input[type="search"] {
  flex: 1 1 220px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 0 12px; font: inherit;
}
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 14px; cursor: pointer; font: inherit; font-size: 14px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.disease-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.disease { border: 1px solid var(--line); border-radius: 12px; padding: 16px; background: var(--surface); border-top: 4px solid var(--line); }
.disease.green { border-top-color: var(--green); }
.disease.yellow { border-top-color: var(--yellow); }
.disease.red { border-top-color: var(--red); }
.disease h3 { margin: 0 0 4px; font-size: 1.1rem; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.disease dl { margin: 10px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 0.9rem; }
.disease dt { color: var(--muted); }
.disease dd { margin: 0; }
.disease[hidden] { display: none; }
.result-count { color: var(--muted); font-size: 14px; margin-left: auto; }

.steps { counter-reset: step; list-style: none; padding: 0; }
.steps > li { counter-increment: step; position: relative; padding: 4px 0 4px 46px; margin: 12px 0; }
.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 2px; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center;
}

.page-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.page-nav a { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--surface); color: var(--text); }
.page-nav a:hover { border-color: var(--accent); text-decoration: none; }
.page-nav small { display: block; color: var(--muted); }

footer.site-footer { text-align: center; color: var(--muted); font-size: 14px; padding: 8px 16px 40px; }

.scrim { display: none; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding-top: 16px; }
  .menu-btn { display: inline-grid; }
  .brand small { display: none; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0; width: min(300px, 86vw); max-height: none;
    background: var(--surface); border-right: 1px solid var(--line); padding: 12px; z-index: 60;
    transform: translateX(-102%); transition: transform 0.2s ease;
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--header-h) 0 0 0; background: rgba(0, 0, 0, 0.45); z-index: 55; }
  .search { width: auto; flex: 1; }
  .header-spacer { display: none; }
}

@media (max-width: 560px) {
  .brand > span:last-child { display: none; }
  .search { min-width: 0; }
  .site-header { gap: 8px; padding: 0 10px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .sidebar { transition: none; }
}

@media print {
  .site-header, .sidebar, .toc, .page-nav, .copy-btn, .scrim, .filters { display: none !important; }
  .layout { display: block; padding: 0; }
  .content { border: 0; box-shadow: none; padding: 0; }
  body { background: #fff; color: #000; }
}
