/* ============================================
   Linux Kernel Docs — 公共样式
   支持亮色/暗色（Dracula）主题切换
   ============================================ */

/* ---- 亮色主题（默认） ---- */
:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --border: #d0d7de;
  --accent: #0969da;
  --accent2: #1a7f37;
  --accent3: #8250df;
  --accent4: #bc4c00;
  --text: #1f2328;
  --text-dim: #656d76;
  --code-bg: #f6f8fa;
  --highlight: #ddf4ff;
  --hero-bg: linear-gradient(135deg, #f6f8fa 0%, #e8ecf0 50%, #f6f8fa 100%);
  --hero-before: radial-gradient(circle at 30% 50%, rgba(9,105,218,0.06) 0%, transparent 50%),
                 radial-gradient(circle at 70% 50%, rgba(130,80,223,0.04) 0%, transparent 50%);
  --nav-bg: rgba(240,242,245,0.92);
}

/* ---- 暗色主题 (Dracula) ---- */
[data-theme="dark"] {
  --bg: #282a36;
  --card: #282a36;
  --border: #44475a;
  --accent: #8be9fd;
  --accent2: #50fa7b;
  --accent3: #bd93f9;
  --accent4: #ffb86c;
  --text: #f8f8f2;
  --text-dim: #6272a4;
  --code-bg: #21222c;
  --highlight: #44475a;
  --hero-bg: linear-gradient(135deg, #282a36 0%, #343746 50%, #282a36 100%);
  --hero-before: radial-gradient(circle at 30% 50%, rgba(139,233,253,0.06) 0%, transparent 50%),
                 radial-gradient(circle at 70% 50%, rgba(189,147,249,0.04) 0%, transparent 50%);
  --nav-bg: rgba(40,42,54,0.92);
}

/* ---- 基础 ---- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background 0.3s, color 0.3s;
}
body:has(.doc-sidebar) { margin-left: 260px; }
@media (max-width: 768px) { body:has(.doc-sidebar) { margin-left: 0; } }

/* ---- 主题切换按钮 ---- */
.theme-toggle {
  position: fixed; top: 12px; right: 20px; z-index: 200;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--card);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: background 0.3s, border-color 0.3s;
  font-size: 1.1em;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ---- Hero ---- */
.hero { background: var(--hero-bg); border-bottom: 1px solid var(--border); padding: 60px 20px 50px; text-align: center; position: relative; overflow: hidden; transition: background 0.3s; }
.hero::before { content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; background: var(--hero-before); animation: drift 20s ease-in-out infinite; }
@keyframes drift { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-2%, 1%); } }
.hero h1 { font-size: 2.6em; font-weight: 700; background: linear-gradient(135deg, #0969da, #8250df); -webkit-background-clip: text; -webkit-text-fill-color: transparent; position: relative; margin-bottom: 12px; }
.hero .subtitle { font-size: 1.15em; color: var(--text-dim); position: relative; }
.hero .version { display: inline-block; margin-top: 16px; padding: 4px 14px; background: rgba(9,105,218,0.08); border: 1px solid rgba(9,105,218,0.25); border-radius: 20px; font-size: 0.85em; color: var(--accent); position: relative; }
[data-theme="dark"] .hero .version { background: rgba(139,233,253,0.1); border-color: rgba(139,233,253,0.3); color: var(--accent); }

/* ---- Header (导航页专用) ---- */
.header { background: var(--hero-bg); border-bottom: 1px solid var(--border); padding: 48px 20px 36px; text-align: center; position: relative; overflow: hidden; transition: background 0.3s; }
.header::before { content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; background: var(--hero-before); }
.header h1 { font-size: 2.2em; font-weight: 700; background: linear-gradient(135deg, #0969da, #8250df); -webkit-background-clip: text; -webkit-text-fill-color: transparent; position: relative; margin-bottom: 8px; }
.header .subtitle { color: var(--text-dim); font-size: 1em; position: relative; }
.header .stats { display: flex; justify-content: center; gap: 24px; margin-top: 18px; position: relative; }
.header .stat { display: flex; flex-direction: column; align-items: center; }
.header .stat-num { font-size: 1.5em; font-weight: 700; color: var(--accent); }
.header .stat-label { font-size: 0.78em; color: var(--text-dim); }

/* ---- TOC: 右侧停靠目录 ---- */
nav.toc { display: none; }
@media (min-width: 1600px) {
  nav.toc { display: block; position: fixed; top: 0; right: 0; bottom: 0; width: 230px; overflow-y: auto; z-index: 90; background: var(--bg); border-left: 1px solid var(--border); }
  nav.toc::before { content: "目录"; display: block; padding: 100px 20px 10px; font-size: 0.78em; font-weight: 600; color: var(--text-dim); letter-spacing: 0.04em; text-transform: uppercase; border-bottom: 1px solid var(--border); margin: 0 16px 6px; }
  nav.toc ul { display: flex; flex-direction: column; list-style: none; margin: 0; padding: 0; }
  nav.toc li { margin: 0; }
  nav.toc a { display: block; padding: 5px 20px 5px 24px; color: var(--text-dim); text-decoration: none; font-size: 0.8em; white-space: normal; border-left: 2px solid transparent; transition: all 0.15s; }
  nav.toc a:hover { color: var(--text); background: var(--code-bg); }
  nav.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 500; }
}

/* ---- Layout ---- */
.container { max-width: 1100px; margin: 0 auto; padding: 40px 24px; }
section { margin-bottom: 60px; }

/* ---- Typography ---- */
h2 { font-size: 1.8em; font-weight: 700; color: var(--text); margin-bottom: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
h2 .num { color: var(--accent); font-size: 0.7em; font-weight: 400; opacity: 0.7; }
h3 { font-size: 1.25em; color: var(--accent3); margin: 28px 0 12px; }
p { margin-bottom: 14px; }
ul, ol { margin: 8px 0 14px 24px; }
li { margin-bottom: 4px; }

/* ---- Cards ---- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 24px; margin: 18px 0; transition: background 0.3s, border-color 0.3s; }
.card-title { font-weight: 600; color: var(--accent); margin-bottom: 10px; font-size: 1.05em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---- Code ---- */
pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 18px; overflow-x: auto; font-size: 0.88em; line-height: 1.6; margin: 12px 0; }
code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }
:not(pre) > code { background: var(--code-bg); padding: 2px 7px; border-radius: 4px; font-size: 0.88em; color: #bc4c00; border: 1px solid var(--border); }
[data-theme="dark"] :not(pre) > code { color: var(--accent4); }
.kw { color: #cf222e; }
.ty { color: #0550ae; }
.fn { color: #8250df; }
.cm { color: #656d76; }
.st { color: #0a3069; }
.num { color: #0550ae; }
[data-theme="dark"] .kw { color: #ff6b6b; }
[data-theme="dark"] .ty { color: #8be9fd; }
[data-theme="dark"] .fn { color: #bd93f9; }
[data-theme="dark"] .cm { color: #6272a4; }
[data-theme="dark"] .st { color: #f1fa8c; }
[data-theme="dark"] .num { color: #bd93f9; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 0.92em; }
th, td { padding: 10px 14px; border: 1px solid var(--border); text-align: left; }
th { background: var(--highlight); color: var(--accent); font-weight: 600; }
tr:nth-child(even) { background: rgba(127,127,127,0.05); }
[data-theme="dark"] th { background: #343746; }

/* ---- Diagrams ---- */
.diagram { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 30px; margin: 20px 0; text-align: center; overflow-x: auto; }
.flow-box { display: inline-block; background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 18px; margin: 4px; font-size: 0.88em; font-family: monospace; color: var(--accent); white-space: nowrap; }
.flow-box.active { border-color: var(--accent2); color: var(--accent2); background: rgba(26,127,55,0.06); }
.flow-box.warn { border-color: var(--accent4); color: var(--accent4); background: rgba(188,76,0,0.06); }
.flow-box.danger { border-color: #cf222e; color: #cf222e; background: rgba(207,34,46,0.06); }
.flow-box.purple { border-color: var(--accent3); color: var(--accent3); background: rgba(130,80,223,0.06); }
.flow-arrow { display: inline-block; color: var(--text-dim); font-size: 1.2em; vertical-align: middle; margin: 0 2px; }
.flow-down { display: block; text-align: center; color: var(--text-dim); font-size: 1.1em; margin: 8px 0; }

/* ---- ASCII Diagram (跨文档复用) ---- */
.ascii-diagram { background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 24px; margin: 20px 0; overflow-x: auto; }
.ascii-diagram pre { background: none; border: none; padding: 0; margin: 0; font-size: 0.82em; line-height: 1.5; color: var(--text); white-space: pre; }
[data-theme="dark"] .flow-box.active { background: rgba(80,250,123,0.1); }
[data-theme="dark"] .flow-box.warn { background: rgba(255,184,108,0.1); }
[data-theme="dark"] .flow-box.danger { background: rgba(255,85,85,0.1); }
[data-theme="dark"] .flow-box.purple { background: rgba(189,147,249,0.1); }

/* ---- Tags ---- */
.tag { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 0.78em; font-weight: 500; margin: 2px 3px; }
.tag-blue { background: rgba(9,105,218,0.08); color: #0969da; border: 1px solid rgba(9,105,218,0.2); }
.tag-green { background: rgba(26,127,55,0.08); color: #1a7f37; border: 1px solid rgba(26,127,55,0.2); }
.tag-purple { background: rgba(130,80,223,0.08); color: #8250df; border: 1px solid rgba(130,80,223,0.2); }
.tag-orange { background: rgba(188,76,0,0.08); color: #bc4c00; border: 1px solid rgba(188,76,0,0.2); }
.tag-red { background: rgba(207,34,46,0.08); color: #cf222e; border: 1px solid rgba(207,34,46,0.2); }
[data-theme="dark"] .tag-blue { background: rgba(139,233,253,0.1); color: #8be9fd; border-color: rgba(139,233,253,0.3); }
[data-theme="dark"] .tag-green { background: rgba(80,250,123,0.1); color: #50fa7b; border-color: rgba(80,250,123,0.3); }
[data-theme="dark"] .tag-purple { background: rgba(189,147,249,0.1); color: #bd93f9; border-color: rgba(189,147,249,0.3); }
[data-theme="dark"] .tag-orange { background: rgba(255,184,108,0.1); color: #ffb86c; border-color: rgba(255,184,108,0.3); }
[data-theme="dark"] .tag-red { background: rgba(255,85,85,0.1); color: #ff5555; border-color: rgba(255,85,85,0.3); }

/* ---- Callouts ---- */
.callout { border-left: 3px solid var(--accent); background: rgba(9,105,218,0.04); padding: 14px 18px; border-radius: 0 8px 8px 0; margin: 16px 0; font-size: 0.93em; }
.callout.warn { border-left-color: var(--accent4); background: rgba(188,76,0,0.04); }
.callout.tip { border-left-color: var(--accent2); background: rgba(26,127,55,0.04); }
.callout.danger { border-left-color: #cf222e; background: rgba(207,34,46,0.04); }
[data-theme="dark"] .callout { background: rgba(139,233,253,0.05); }
[data-theme="dark"] .callout.warn { background: rgba(255,184,108,0.05); }
[data-theme="dark"] .callout.tip { background: rgba(80,250,123,0.05); }
[data-theme="dark"] .callout.danger { background: rgba(255,85,85,0.05); }

/* ---- File tree ---- */
.file-tree { font-family: "Noto Sans Mono CJK SC", "Source Han Mono SC", "Microsoft YaHei Mono", "Consolas", "Liberation Mono", "Courier New", monospace; font-size: 0.9em; line-height: 1.8; color: var(--text-dim); padding: 18px; background: var(--code-bg); border-radius: 8px; border: 1px solid var(--border); letter-spacing: 0; font-variant-east-asian: full-width; -webkit-font-feature-settings: "halt"; }
.file-tree .dir { color: #0969da; }
.file-tree .file { color: #1a7f37; }
.file-tree .cmt { color: #656d76; font-style: italic; }
[data-theme="dark"] .file-tree .dir { color: #8be9fd; }
[data-theme="dark"] .file-tree .file { color: #50fa7b; }
[data-theme="dark"] .file-tree .cmt { color: #6272a4; }

/* ---- Utilities ---- */
.ref { color: var(--text-dim); font-size: 0.85em; font-style: italic; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 40px 0; }
[data-theme="dark"] footer { background: var(--bg); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .grid-2 { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.8em; }
}

/* ---- Doc Sidebar ---- */
.doc-sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 260px; background: var(--card); border-right: 1px solid var(--border); z-index: 150; display: flex; flex-direction: column; overflow-y: auto; transition: width 0.25s ease; box-shadow: 1px 0 8px rgba(0,0,0,0.04); }
.doc-sidebar.collapsed { width: 0; border-right: none; overflow: hidden; }
.doc-sidebar-hdr { padding: 14px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 6px; min-height: 46px; background: var(--code-bg); }
.doc-sidebar-hdr .back { font-size: 0.82em; color: var(--accent); text-decoration: none; display: flex; align-items: center; gap: 4px; white-space: nowrap; font-weight: 500; }
.doc-sidebar-hdr .back:hover { text-decoration: underline; opacity: 0.8; }
.doc-sidebar-hdr .btns { display: flex; gap: 4px; margin-left: auto; flex-shrink: 0; }
.doc-sidebar-hdr .hdr-btn { background: none; border: 1px solid var(--border); border-radius: 4px; width: 26px; height: 26px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 0.75em; transition: background 0.15s; }
.doc-sidebar-hdr .hdr-btn:hover { background: var(--code-bg); color: var(--text); }
.doc-sidebar-nav { flex: 1; overflow-y: auto; padding: 0; }
.doc-sidebar .sidebar-search { padding: 12px 16px 8px; position: relative; border-bottom: 1px solid var(--border); }
.doc-sidebar .sidebar-search input { width: 100%; padding: 8px 12px 8px 32px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.85em; background: var(--code-bg); color: var(--text); outline: none; }
.doc-sidebar .sidebar-search input:focus { border-color: var(--accent); }
.doc-sidebar .sidebar-search svg { position: absolute; left: 26px; top: 50%; transform: translateY(-50%); color: var(--text-dim); pointer-events: none; }
.doc-sidebar .sidebar-cat { border-bottom: 1px solid var(--border); }
.doc-sidebar .sidebar-cat-header { display: flex; align-items: center; gap: 8px; padding: 10px 16px; cursor: pointer; user-select: none; transition: background 0.15s; border-left: 2px solid transparent; position: sticky; top: 0; z-index: 2; background: var(--card); box-shadow: 0 -1px 0 var(--card), 0 1px 0 var(--border); }
.doc-sidebar .sidebar-cat-header:hover { background: var(--code-bg); border-left-color: var(--accent); }
.doc-sidebar .sidebar-cat-header .arrow { transition: transform 0.2s; font-size: 0.7em; color: var(--text-dim); }
.doc-sidebar .sidebar-cat-header.collapsed .arrow { transform: rotate(-90deg); }
.doc-sidebar .sidebar-cat-title { font-size: 0.85em; font-weight: 600; color: var(--text); flex: 1; }
.doc-sidebar .sidebar-cat-count { font-size: 0.7em; color: var(--text-dim); background: var(--code-bg); padding: 1px 6px; border-radius: 8px; }
.doc-sidebar .sidebar-cat-icon { width: 20px; height: 20px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 0.7em; flex-shrink: 0; }
.doc-sidebar .sidebar-cat-items { overflow: hidden; transition: max-height 0.3s ease; }
.doc-sidebar .sidebar-cat-items.collapsed { max-height: 0 !important; }
.doc-sidebar .sidebar-item { display: block; padding: 6px 16px 6px 44px; font-size: 0.82em; color: var(--text-dim); text-decoration: none; transition: all 0.15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 2px solid transparent; }
.doc-sidebar .sidebar-item:hover { background: var(--code-bg); color: var(--text); border-left-color: var(--border); }
.doc-sidebar .sidebar-item.current { color: var(--accent); font-weight: 500; background: rgba(9,105,218,0.06); border-left-color: var(--accent); }
/* 拖拽手柄 */
.doc-sidebar-resize { position: absolute; top: 0; right: -3px; width: 6px; height: 100%; cursor: col-resize; z-index: 1; }
.doc-sidebar-resize:hover, .doc-sidebar-resize.active { background: var(--accent); opacity: 0.25; }
/* 展开按钮（折叠后显示） */
.doc-sidebar-expand { position: fixed; top: 14px; left: 0; z-index: 160; width: 28px; height: 26px; border-radius: 0 5px 5px 0; border: 1px solid var(--border); border-left: none; background: var(--card); cursor: pointer; display: none; align-items: center; justify-content: center; box-shadow: 2px 0 6px rgba(0,0,0,0.08); font-size: 0.8em; color: var(--text-dim); }
.doc-sidebar-expand:hover { background: var(--code-bg); color: var(--text); }
body:has(.doc-sidebar:not(.collapsed)) .doc-sidebar-expand { display: none; }
body:not(:has(.doc-sidebar:not(.collapsed))) .doc-sidebar-expand { display: flex; }
/* 移动端 */
.doc-sidebar-btn { position: fixed; bottom: 20px; left: 20px; z-index: 160; width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); cursor: pointer; display: none; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1); font-size: 1.1em; }
.doc-sidebar-btn:hover { background: var(--highlight); }
.doc-sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 140; }
.doc-sidebar-overlay.visible { display: block; }
@media (max-width: 768px) {
  .doc-sidebar { transform: translateX(-100%); width: 280px; border-right: 1px solid var(--border); transition: transform 0.3s; }
  .doc-sidebar.open { transform: translateX(0); }
  .doc-sidebar.collapsed { width: 280px; transform: translateX(-100%); }
  .doc-sidebar-expand, .doc-sidebar-resize { display: none !important; }
  .doc-sidebar-btn { display: flex; }
  body:has(.doc-sidebar) { margin-left: 0; }
}
[data-theme="dark"] .doc-sidebar { background: #282a36; border-right-color: #44475a; }
[data-theme="dark"] .doc-sidebar-item { color: #6272a4; }
[data-theme="dark"] .doc-sidebar-item:hover { background: #343746; color: #f8f8f2; }
[data-theme="dark"] .doc-sidebar-item.current { color: #8be9fd; border-left-color: #8be9fd; background: rgba(139,233,253,0.08); }
[data-theme="dark"] .doc-sidebar .sidebar-item:hover { border-left-color: #6272a4; }
[data-theme="dark"] .doc-sidebar .sidebar-cat-header:hover { border-left-color: #8be9fd; }
[data-theme="dark"] .doc-sidebar-btn { background: #282a36; border-color: #44475a; }
[data-theme="dark"] .doc-sidebar-overlay { background: rgba(0,0,0,0.5); }

/* Prism 复制按钮 */
.copy-to-clipboard-button {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  background: var(--card);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.copy-to-clipboard-button:hover {
  background: var(--highlight);
  border-color: var(--accent);
}
.copy-to-clipboard-button[data-copy-state="copy-success"] {
  border-color: #2da44e;
  background: #dafbe1;
}
[data-theme="dark"] .copy-to-clipboard-button[data-copy-state="copy-success"] {
  border-color: #3fb950;
  background: rgba(63,185,80,0.15);
}

/* Prism 工具栏位置 */
pre[class*="language-"] { position: relative; }
div.code-toolbar > .toolbar { position: absolute; top: 6px; right: 8px; opacity: 0.6; transition: opacity 0.2s; }
div.code-toolbar:hover > .toolbar { opacity: 1; }

/* 文档内嵌图片 */
.chart-figure {
  margin: 1.5em 0;
  text-align: center;
}
.chart-figure img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.chart-figure figcaption {
  margin-top: 0.5em;
  font-size: 0.9em;
  color: var(--text-dim);
}
/* 代码+图表的flex布局 */
.chart-row {
  display: flex;
  gap: 1.5em;
  align-items: flex-start;
  margin: 1.5em 0;
}
.chart-row .chart-figure {
  flex: 0 0 auto;
  margin: 0;
  max-width: 55%;
}
.chart-row .chart-code {
  flex: 1;
  min-width: 0;
}
.chart-row .chart-code pre {
  margin: 0;
}
@media (max-width: 800px) {
  .chart-row { flex-direction: column; }
  .chart-row .chart-figure { max-width: 100%; }
}
