/* ============================================================================
   通用 OTA 协议文档 —— 共用样式
   入口页（index.html）与子页（sub_web/*.html）共用本文件。
   路径说明：子页引用 ../assets/doc.css
   ========================================================================== */

/* ---------- 主题变量：浅色 ---------- */
:root {
  --bg:        #f5f6f8;
  --panel:     #ffffff;
  --panel-2:   #fbfcfd;
  --fg:        #1f2328;
  --fg-soft:   #3d464f;
  --muted:     #616b77;
  --line:      #e2e6ea;
  --line-soft: #eef1f4;
  --accent:    #1f6feb;
  --accent-bg: #e8f1ff;
  --code-bg:   #f4f6f8;
  --code-line: #e2e6ea;
  --ok:        #1a7f37;  --ok-bg:   #e7f5ec;
  --warn:      #9a6700;  --warn-bg: #fff6da;
  --err:       #c0392b;  --err-bg:  #fdecea;
  --info:      #0b5cad;  --info-bg: #eaf3ff;
  --shadow:    0 1px 2px rgba(16,24,40,.05), 0 10px 28px rgba(16,24,40,.05);
  --radius:    10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* ---------- 主题变量：深色 ---------- */
html[data-theme="dark"] {
  --bg:        #0d1117;
  --panel:     #161b22;
  --panel-2:   #1b2129;
  --fg:        #e6edf3;
  --fg-soft:   #c9d1d9;
  --muted:     #9198a1;
  --line:      #2b323b;
  --line-soft: #232a32;
  --accent:    #58a6ff;
  --accent-bg: #12233c;
  --code-bg:   #0f151c;
  --code-line: #2b323b;
  --ok:        #3fb950;  --ok-bg:   #12261a;
  --warn:      #d29922;  --warn-bg: #2a2313;
  --err:       #f85149;  --err-bg:  #2d1618;
  --info:      #58a6ff;  --info-bg: #12233c;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.72;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================================
   顶栏
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  background: var(--panel); /* 旧浏览器回退 */
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .tb-title { font-weight: 650; font-size: 15px; letter-spacing: .2px; }
.topbar .tb-sub   { color: var(--muted); font-size: 12.5px; }
.topbar .spacer   { flex: 1 1 auto; }

.tb-btn {
  appearance: none; cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--fg-soft);
  font: inherit; font-size: 12.5px;
  padding: 5px 11px; border-radius: 999px;
  transition: .15s;
}
.tb-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================================
   文档布局：左侧目录 + 正文
   ========================================================================== */
.doc-layout {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  gap: 30px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px 22px 80px;
}

.sidebar {
  position: sticky; top: 66px; align-self: start;
  max-height: calc(100vh - 92px);
  overflow-y: auto;
  padding-right: 4px;
  border-right: 1px solid var(--line-soft);
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.sb-head {
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); font-weight: 650; margin: 0 0 8px 2px;
}
.sb-search { position: relative; margin-bottom: 12px; }
.sb-search input {
  width: 100%; font: inherit; font-size: 13px;
  padding: 7px 10px 7px 28px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); color: var(--fg);
}
.sb-search input:focus { outline: 2px solid var(--accent-bg); border-color: var(--accent); }
.sb-search::before {
  content: "⌕"; position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 14px; pointer-events: none;
}

.toc { font-size: 13.3px; padding-bottom: 24px; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc > ul > li { margin: 1px 0; }
.toc a {
  display: flex; gap: 7px; align-items: baseline;
  color: var(--fg-soft); text-decoration: none;
  padding: 4px 8px 4px 9px;
  border-left: 2px solid transparent; border-radius: 0 6px 6px 0;
  line-height: 1.45;
}
.toc a:hover { background: var(--accent-bg); color: var(--accent); text-decoration: none; }
.toc li.active > a {
  border-left-color: var(--accent);
  background: var(--accent-bg); color: var(--accent); font-weight: 600;
}
.toc .num {
  flex: 0 0 auto; min-width: 1.9em; color: var(--muted);
  font-family: var(--mono); font-size: 11.5px; padding-top: .18em;
}
.toc li.active > a .num { color: var(--accent); }
.toc .toc-l3 { margin-left: 14px; font-size: 12.9px; }
.toc .toc-l3 a { color: var(--muted); }
.toc .toc-l3 li.active > a { color: var(--accent); }
.toc li.hidden { display: none; }
.toc-empty { color: var(--muted); font-size: 12.5px; padding: 6px 9px; }

.doc-main { min-width: 0; }
.doc-body { max-width: 1000px; }

/* ============================================================================
   文档头（标题区）
   ========================================================================== */
.doc-hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px 20px;
  margin-bottom: 26px;
}
.doc-hero h1 { margin: 0 0 6px; font-size: 25px; line-height: 1.35; letter-spacing: .2px; }
.doc-hero .lede { margin: 0 0 14px; color: var(--muted); font-size: 14px; }

.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.3px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--fg-soft);
}
.badge b { font-weight: 650; }
.badge.ok   { color: var(--ok);   background: var(--ok-bg);   border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.badge.warn { color: var(--warn); background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.badge.info { color: var(--info); background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 30%, transparent); }

/* 速查折叠块 */
details.quickref {
  margin-top: 16px; border: 1px dashed var(--line);
  border-radius: 8px; background: var(--panel-2); padding: 10px 14px;
}
details.quickref > summary {
  cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--accent);
  list-style: none;
}
details.quickref > summary::-webkit-details-marker { display: none; }
details.quickref > summary::before { content: "▸ "; }
details.quickref[open] > summary::before { content: "▾ "; }
details.quickref .qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(252px, 1fr));
  gap: 16px 28px; margin-top: 12px; font-size: 13.2px;
}
details.quickref .qr-grp { break-inside: avoid; }
details.quickref .qr-wide { grid-column: 1 / -1; }   /* 应用层 err：整行铺开，内部多列 */
details.quickref h5 { margin: 0 0 6px; font-size: 12.6px; color: var(--muted); letter-spacing: .04em; }
details.quickref ul { margin: 0; padding: 0; list-style: none; }
details.quickref li {
  margin: 2px 0; break-inside: avoid;
  display: flex; gap: 8px; align-items: baseline;   /* 一条一行，冒号位对齐 */
}
details.quickref li > .chip { flex: 0 0 auto; min-width: 2.2em; text-align: center; }
details.quickref ul.qr-idx li > .chip { min-width: 3.7em; }         /* 0x01 这类多字符码 */
details.quickref ul.qr-kv li > code:first-child { flex: 0 0 auto; min-width: 4.6em; }
details.quickref ul.qr-cols { column-count: 3; column-gap: 30px; }   /* err 0~14 分三列 */
details.quickref code { font-size: 12.4px; }

/* ============================================================================
   正文排版
   ========================================================================== */
.doc-body h2 {
  position: relative;
  margin: 44px 0 14px;
  padding: 0 0 9px;
  font-size: 20.5px;
  border-bottom: 2px solid var(--line);
  scroll-margin-top: 74px;
}
.doc-body h2::after {
  content: ""; position: absolute; left: 0; bottom: -2px; width: 68px; height: 2px;
  background: var(--accent);
}
.doc-body h3 {
  margin: 30px 0 10px;
  font-size: 16.6px;
  scroll-margin-top: 74px;
}
.doc-body h4 { margin: 22px 0 8px; font-size: 15px; color: var(--fg-soft); }
.doc-body p  { margin: 10px 0; }
.doc-body > p, .doc-body li { color: var(--fg-soft); }
.doc-body ul, .doc-body ol { margin: 10px 0; padding-left: 22px; }
.doc-body li { margin: 4px 0; }
.doc-body hr { border: 0; border-top: 1px solid var(--line); margin: 34px 0; }

.hlink {
  margin-left: 8px; font-size: 14px; color: var(--line);
  text-decoration: none; opacity: 0; transition: .15s;
}
h2:hover .hlink, h3:hover .hlink, h4:hover .hlink { opacity: 1; }

code.inline, p code, li code, td code, th code, .doc-body dd code {
  font-family: var(--mono); font-size: 12.9px;
  background: var(--code-bg); border: 1px solid var(--code-line);
  border-radius: 5px; padding: 1px 5px; color: var(--fg);
  word-break: break-word;
}
html[data-theme="dark"] code.inline,
html[data-theme="dark"] p code, html[data-theme="dark"] li code,
html[data-theme="dark"] td code { color: #a5d6ff; }

/* 表格 */
.tbl-wrap { overflow-x: auto; margin: 14px 0 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
table.tbl { border-collapse: collapse; width: 100%; font-size: 13.6px; }
table.tbl th, table.tbl td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
table.tbl thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel-2); color: var(--fg);
  font-weight: 650; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
table.tbl tbody tr:nth-child(even) td { background: var(--panel-2); background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
table.tbl tbody tr:hover td { background: var(--accent-bg); }
table.tbl td.num, table.tbl th.num { white-space: nowrap; font-family: var(--mono); font-size: 12.8px; }
table.tbl caption { caption-side: top; text-align: left; padding: 8px 12px 0; color: var(--muted); font-size: 12.6px; }

.tbl-tools { display: flex; align-items: center; gap: 10px; margin: 14px 0 -4px; }
.tbl-tools input {
  font: inherit; font-size: 12.8px; padding: 5px 10px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel); color: var(--fg); min-width: 210px;
}
.tbl-tools .cnt { color: var(--muted); font-size: 12.3px; }

/* 状态码：色片 */
.chip {
  display: inline-block; font-family: var(--mono); font-size: 12.2px; font-weight: 600;
  padding: 0 7px; border-radius: 5px; border: 1px solid transparent; white-space: nowrap;
}
.chip.ok   { color: var(--ok);   background: var(--ok-bg);   border-color: color-mix(in srgb, var(--ok) 26%, transparent); }
.chip.warn { color: var(--warn); background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 26%, transparent); }
.chip.err  { color: var(--err);  background: var(--err-bg);  border-color: color-mix(in srgb, var(--err) 26%, transparent); }
.chip.info { color: var(--info); background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 26%, transparent); }

/* 代码块 */
.code-wrap { position: relative; margin: 14px 0 18px; }
pre.code {
  margin: 0; padding: 14px 16px;
  background: var(--code-bg); border: 1px solid var(--code-line); border-radius: 8px;
  overflow-x: auto;
  font-family: var(--mono); font-size: 12.9px; line-height: 1.62;
  color: var(--fg); tab-size: 4;
}
html[data-theme="dark"] pre.code { color: #c9d1d9; }
pre.code.ascii { line-height: 1.42; font-size: 12.5px; }
pre.code.json::before {
  content: "JSON"; position: absolute; top: 8px; right: 52px;
  font-size: 10.5px; letter-spacing: .1em; color: var(--muted);
}
pre.code.c::before    { content: "C";    position: absolute; top: 8px; right: 52px; font-size: 10.5px; letter-spacing: .1em; color: var(--muted); }
pre.code.py::before   { content: "PY";   position: absolute; top: 8px; right: 52px; font-size: 10.5px; letter-spacing: .1em; color: var(--muted); }
pre.code.shell::before{ content: "SHELL";position: absolute; top: 8px; right: 52px; font-size: 10.5px; letter-spacing: .1em; color: var(--muted); }
pre.code.ini::before  { content: "INI";  position: absolute; top: 8px; right: 52px; font-size: 10.5px; letter-spacing: .1em; color: var(--muted); }

.copy-btn {
  position: absolute; top: 6px; right: 8px; z-index: 2;
  cursor: pointer; font: inherit; font-size: 11.5px;
  padding: 3px 9px; border-radius: 6px;
  border: 1px solid var(--code-line); background: var(--panel); color: var(--muted);
  opacity: 0; transition: .15s;
}
.code-wrap:hover .copy-btn, .copy-btn:focus { opacity: 1; }
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.done { color: var(--ok); border-color: var(--ok); }

/* 提示块 */
.callout {
  display: block; margin: 14px 0 18px; padding: 11px 14px 11px 15px;
  border: 1px solid var(--line); border-left: 4px solid var(--muted);
  border-radius: 6px; background: var(--panel); color: var(--fg-soft); font-size: 14px;
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child  { margin-bottom: 0; }
.callout .co-tag { font-weight: 650; margin-right: 6px; }
.callout.note   { border-left-color: var(--info); background: var(--info-bg); }
.callout.note   .co-tag { color: var(--info); }
.callout.tip    { border-left-color: var(--ok); background: var(--ok-bg); }
.callout.tip    .co-tag { color: var(--ok); }
.callout.warn   { border-left-color: var(--warn); background: var(--warn-bg); }
.callout.warn   .co-tag { color: var(--warn); }
.callout.danger { border-left-color: var(--err); background: var(--err-bg); }
.callout.danger .co-tag { color: var(--err); }

/* 流程步骤（有序列表卡片化） */
.steps { counter-reset: st; list-style: none; padding: 0; margin: 14px 0 18px; }
.steps > li {
  counter-increment: st; position: relative;
  padding: 9px 14px 9px 44px; margin: 6px 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
.steps > li::before {
  content: counter(st);
  position: absolute; left: 12px; top: 9px;
  width: 21px; height: 21px; line-height: 21px; text-align: center;
  border-radius: 50%; background: var(--accent-bg); color: var(--accent);
  font-size: 12px; font-weight: 700; font-family: var(--mono);
}

/* FAQ */
details.faq {
  margin: 10px 0; padding: 10px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  scroll-margin-top: 74px;
}
details.faq > summary {
  cursor: pointer; font-weight: 600; color: var(--fg); font-size: 14.4px;
  list-style: none;
}
details.faq > summary::-webkit-details-marker { display: none; }
details.faq > summary::before { content: "Q "; color: var(--accent); font-family: var(--mono); font-weight: 700; }
details.faq[open] > summary { margin-bottom: 6px; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
details.faq .ans { color: var(--fg-soft); font-size: 14px; }

/* 待补充占位（骨架页用） */
.todo {
  margin: 12px 0 20px; padding: 12px 14px;
  border: 1px dashed var(--line); border-radius: 8px;
  background: var(--panel-2); color: var(--muted); font-size: 13.6px;
}
.todo b { color: var(--fg-soft); }

/* 页脚 */
.doc-footer {
  max-width: 1000px; margin: 50px 0 0;
  padding-top: 14px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12.8px;
}

/* 回到顶部 */
.totop {
  position: fixed; right: 22px; bottom: 22px; z-index: 50;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  cursor: pointer; font-size: 15px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: .2s;
}
.totop.show { opacity: 1; pointer-events: auto; }
.totop:hover { color: var(--accent); border-color: var(--accent); }

/* 侧栏开合按钮（窄屏） */
.sb-toggle { display: none; }

/* ============================================================================
   入口页（portal）
   ========================================================================== */
body.portal-page { background: var(--bg); }

.portal-header {
  padding: 26px 24px 22px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(900px 220px at 12% -40%, var(--accent-bg), transparent 70%),
    var(--panel);
}
.portal-header .brand { display: flex; align-items: center; gap: 14px; max-width: 1440px; margin: 0 auto; }
.portal-header .logo {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .5px;
  box-shadow: var(--shadow);
}
.portal-header h1 { margin: 0; font-size: 22px; }
.portal-header .sub { margin: 2px 0 0; color: var(--muted); font-size: 13.4px; }
.portal-header .tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.portal-main { max-width: 1440px; margin: 0 auto; padding: 24px 24px 70px; }

.sec-title {
  display: flex; align-items: center; gap: 10px;
  margin: 6px 0 14px; font-size: 13px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); font-weight: 650;
}
.sec-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }

.card {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 18px 18px 15px;
  cursor: pointer; transition: .18s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card:focus-visible { outline: 3px solid var(--accent-bg); }
.card .c-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.card .c-ico {
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  font-family: var(--mono); font-size: 12.5px; font-weight: 700;
  background: var(--accent-bg); color: var(--accent);
}
.card h3 { margin: 0; font-size: 16.5px; }
.card .c-desc { color: var(--muted); font-size: 13.4px; margin: 2px 0 12px; flex: 1 1 auto; }
.card .c-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.card .c-actions { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line-soft); padding-top: 11px; }
.card .c-open {
  appearance: none; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: 5px 13px; border-radius: 7px;
}
.card .c-open:hover { filter: brightness(1.08); }
.card .c-new { font-size: 12.6px; color: var(--muted); }
.card.stub { background: var(--panel-2); }
.card.stub .c-ico { background: var(--warn-bg); color: var(--warn); }

.portal-note {
  margin-top: 26px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  font-size: 13.4px; color: var(--muted);
}
.portal-note h4 { margin: 0 0 8px; font-size: 13.6px; color: var(--fg-soft); }
.portal-note code { font-size: 12.5px; }
.portal-note pre.code { margin: 10px 0 0; }

/* 查看器 */
#viewer { display: flex; flex-direction: column; gap: 10px; }
#viewer[hidden] { display: none; }
.viewer-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.viewer-bar .crumb { color: var(--muted); font-size: 13px; }
.viewer-bar .crumb b { color: var(--fg); }
.viewer-bar select {
  font: inherit; font-size: 12.8px; padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel-2); color: var(--fg);
}
#docFrame {
  width: 100%; height: calc(100vh - 176px); min-height: 520px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  box-shadow: var(--shadow);
}
.load-hint { margin: 6px 0 0; color: var(--muted); font-size: 12.6px; }

/* ============================================================================
   响应式
   ========================================================================== */
@media (max-width: 900px) {
  details.quickref ul.qr-cols { column-count: 2; }
}
@media (max-width: 620px) {
  details.quickref ul.qr-cols { column-count: 1; }
}

@media (max-width: 1020px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 16px 14px 70px; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
    width: 300px; max-height: none; padding: 16px 14px;
    background: var(--panel); border-right: 1px solid var(--line);
    transform: translateX(-102%); transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  body.sb-open .sidebar { transform: none; }
  .sb-toggle { display: inline-flex; }
  .sb-backdrop {
    display: none; position: fixed; inset: 0; z-index: 55;
    background: rgba(15, 20, 28, .45);
  }
  body.sb-open .sb-backdrop { display: block; }
}
@media (min-width: 1021px) { .sb-backdrop { display: none !important; } }

@media print {
  .topbar, .sidebar, .totop, .copy-btn, .tbl-tools input, .sb-backdrop { display: none !important; }
  .doc-layout { grid-template-columns: 1fr; padding: 0; }
  body { background: #fff; font-size: 11.5pt; }
  details.faq, details.quickref { break-inside: avoid; }
  pre.code { white-space: pre-wrap; word-break: break-all; }
}
