/* ============================================================
   MQTT5 物联网网关 · 技术文档
   Espressif 风格文档站样式（浅色主题）
   ============================================================ */

:root {
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-border: #bfdbfe;
  --text: #1f2937;
  --text-strong: #111827;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --bg: #ffffff;
  --bg-sidebar: #f7f8fa;
  --bg-code: #f6f8fa;
  --bg-code-header: #eef1f4;
  --note-bg: #eff6ff;
  --note-border: #bfdbfe;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --tip-bg: #f0fdf4;
  --tip-border: #bbf7d0;
  --header-h: 60px;
  --sidebar-w: 284px;
  --mono: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.75;
  font-size: 15.5px;
  -webkit-font-smoothing: antialiased;
}

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

/* ============ 顶栏 ============ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  z-index: 50;
}
.topbar .brand {
  display: flex; align-items: center; gap: 11px;
  font-weight: 700; color: var(--text-strong);
  font-size: 16px;
  white-space: nowrap;
}
.topbar .brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 15px; flex: none;
}
.topbar .brand small {
  font-weight: 400; color: var(--text-muted); font-size: 13px;
}
.topbar .spacer { flex: 1; }
.topbar .badge {
  font-size: 12px; color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  padding: 3px 10px; border-radius: 999px; font-weight: 600;
  white-space: nowrap;
}
.topbar .toplink {
  font-size: 13.5px; color: var(--text-muted);
  padding: 6px 12px; border-radius: 8px;
}
.topbar .toplink:hover { color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.topbar .toplink.primary {
  color: #fff; background: var(--accent); font-weight: 600;
}
.topbar .toplink.primary:hover { background: var(--accent-strong); }
.menu-toggle {
  display: none;
  width: 38px; height: 38px; border: 1px solid var(--border);
  background: var(--bg); border-radius: 8px; cursor: pointer;
  font-size: 18px; color: var(--text); line-height: 1;
}

/* ============ 布局骨架 ============ */
.layout {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

/* ============ 左侧导航 ============ */
.sidebar {
  position: fixed;
  top: var(--header-h); bottom: 0; left: 0;
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 18px 12px 40px;
}
.sidebar .nav-group {
  margin-bottom: 6px;
}
.sidebar .nav-group-title {
  font-size: 12px; font-weight: 700; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .5px;
  padding: 10px 12px 6px;
}
.sidebar a.nav-link {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 12px; border-radius: 8px;
  color: var(--text); font-size: 14px;
  line-height: 1.4;
}
.sidebar a.nav-link:hover { background: #eceef2; text-decoration: none; color: var(--text-strong); }
.sidebar a.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}
.sidebar a.nav-link.active::before {
  content: ""; width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent); flex: none;
}
.sidebar .nav-note {
  margin: 16px 8px 0; padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; font-size: 12.5px; color: var(--text-muted);
}
.sidebar .nav-note strong { color: var(--text-strong); }

/* ============ 正文区 ============ */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  padding: 34px 46px 80px;
}
.article { max-width: 860px; }

.breadcrumb {
  font-size: 13px; color: var(--text-faint); margin-bottom: 8px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .sep { margin: 0 6px; color: var(--border-strong); }

h1.page-title {
  font-size: 30px; line-height: 1.25; color: var(--text-strong);
  margin: 4px 0 10px; letter-spacing: -.01em;
}
.lead {
  font-size: 16.5px; color: var(--text-muted);
  margin: 0 0 26px; max-width: 720px;
}

h2 {
  font-size: 22px; color: var(--text-strong);
  margin: 40px 0 14px; padding-top: 10px;
  scroll-margin-top: 80px;
}
h3 {
  font-size: 17.5px; color: var(--text-strong);
  margin: 28px 0 10px; scroll-margin-top: 80px;
}
h4 { font-size: 15.5px; color: var(--text-strong); margin: 22px 0 8px; scroll-margin-top: 80px; }
p { margin: 12px 0; }
strong { color: var(--text-strong); }
ul, ol { margin: 12px 0; padding-left: 26px; }
li { margin: 5px 0; }
li::marker { color: var(--accent); }

/* 标题锚点 */
h2 .anchor, h3 .anchor, h4 .anchor {
  opacity: 0; margin-left: 6px; color: var(--text-faint);
  transition: opacity .15s;
}
h2:hover .anchor, h3:hover .anchor, h4:hover .anchor { opacity: 1; text-decoration: none; }

/* ============ 代码块 ============ */
pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  overflow-x: auto;
  margin: 16px 0;
  line-height: 1.6;
}
pre code {
  font-family: var(--mono);
  font-size: 13px; color: #24292f;
}
code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  padding: 1.5px 6px; border-radius: 5px;
  color: #c62828;
}
pre code { background: none; border: none; padding: 0; color: #24292f; }
pre code .c { color: #6a737d; font-style: italic; }
pre code .s { color: #0a3069; }
pre code .k { color: #a626a4; }

.code-title {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-code-header); border: 1px solid var(--border);
  border-bottom: none; border-radius: 10px 10px 0 0;
  padding: 8px 14px; font-size: 12.5px; color: var(--text-muted);
  font-family: var(--mono);
}
.code-title + pre { border-radius: 0 0 10px 10px; margin-top: 0; }

/* ============ CRLF 结束符标记 ============ */
.crlf {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
  color: #b91c1c;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 4px;
  padding: 0 5px;
  margin: 0 1px;
  letter-spacing: .3px;
  vertical-align: 1px;
  white-space: nowrap;
}
pre code .crlf, code .crlf, .admonition .crlf { font-style: normal; }

/* ============ AT 帧示例卡片（发送 / HEX / 响应） ============ */
.at-frame {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 14px 0 18px;
  overflow: hidden;
  background: #fff;
}
.at-frame .af-row { display: flex; border-top: 1px solid var(--border); }
.at-frame .af-row:first-child { border-top: none; }
.at-frame .af-tag {
  flex: 0 0 66px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 9px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
}
.at-frame .af-body {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: #24292f;
  overflow-x: auto;
  white-space: pre;
}
.at-frame .af-body.hex { color: #0a3069; }
.at-frame .af-body .c { color: #6a737d; font-style: italic; }
.at-frame .af-row.resp .af-body { color: #0a3069; }
.at-frame .af-row.err .af-body { color: #b91c1c; }
@media (max-width: 640px) {
  .at-frame .af-row { flex-direction: column; }
  .at-frame .af-tag {
    flex: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 6px 12px;
  }
}

/* ============ 逐字节 HEX 对照表 ============ */
table.byte-tbl { font-family: var(--mono); }
table.byte-tbl th, table.byte-tbl td {
  text-align: center;
  white-space: nowrap;
  padding: 7px 9px;
  font-size: 12.5px;
}
table.byte-tbl th:first-child, table.byte-tbl td:first-child {
  text-align: left;
  font-family: var(--sans);
  white-space: normal;
}
table.byte-tbl td.crlf-cell {
  font-weight: 700;
  color: #b91c1c;
  background: #fef2f2;
}
table.byte-tbl td.hexcell {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.75;
  text-align: left;
  white-space: normal;
  word-break: break-all;
  color: #0a3069;
}

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; margin: 16px 0; }
table {
  border-collapse: collapse; width: 100%;
  font-size: 14px; margin: 0;
}
th, td {
  border: 1px solid var(--border);
  padding: 9px 13px; text-align: left; vertical-align: top;
}
th {
  background: var(--bg-sidebar);
  font-weight: 600; color: var(--text-strong);
  white-space: nowrap;
}
tbody tr:nth-child(even) { background: #fafbfc; }
td code { font-size: 12.5px; }

/* ============ 提示框 ============ */
.admonition {
  border: 1px solid var(--note-border);
  background: var(--note-bg);
  border-radius: 10px;
  padding: 14px 18px;
  margin: 18px 0;
  font-size: 14.5px;
}
.admonition .ad-title {
  font-weight: 700; margin-bottom: 4px; color: var(--text-strong);
  display: flex; align-items: center; gap: 7px;
}
.admonition.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.admonition.warn .ad-title { color: #92400e; }
.admonition.danger { background: var(--danger-bg); border-color: var(--danger-border); }
.admonition.danger .ad-title { color: #b91c1c; }
.admonition.tip { background: var(--tip-bg); border-color: var(--tip-border); }
.admonition.tip .ad-title { color: #166534; }
.admonition p:last-child { margin-bottom: 0; }
.admonition code { background: rgba(0,0,0,.04); }

/* ============ 特性卡片 ============ */
.card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px; margin: 20px 0;
}
.feature-card {
  border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px;
  background: var(--bg);
  transition: border-color .15s, box-shadow .15s;
}
.feature-card:hover {
  border-color: var(--accent-border);
  box-shadow: 0 4px 16px rgba(37,99,235,.08);
  text-decoration: none;
}
.feature-card .fc-icon { font-size: 22px; margin-bottom: 8px; }
.feature-card .fc-title { font-weight: 700; color: var(--text-strong); margin-bottom: 4px; font-size: 15px; }
.feature-card .fc-desc { color: var(--text-muted); font-size: 13.5px; line-height: 1.55; }

/* ============ 上/下一页导航 ============ */
.pager {
  display: flex; justify-content: space-between; gap: 14px;
  margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border);
}
.pager a {
  flex: 1; display: block; border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 18px;
  color: var(--text); transition: border-color .15s, background .15s;
}
.pager a:hover { border-color: var(--accent-border); background: var(--accent-soft); text-decoration: none; }
.pager .dir { font-size: 12px; color: var(--text-faint); margin-bottom: 3px; }
.pager .lbl { font-weight: 600; color: var(--text-strong); font-size: 14.5px; }
.pager a.next { text-align: right; }
.pager a.prev { text-align: left; }

/* ============ 右侧本页目录 ============ */
.toc {
  position: fixed; top: calc(var(--header-h) + 30px); right: 20px;
  width: 240px; max-height: calc(100vh - var(--header-h) - 60px);
  overflow-y: auto; font-size: 13px;
  border-left: 1px solid var(--border); padding-left: 16px;
  display: none;
}
.toc .toc-title {
  font-size: 12px; font-weight: 700; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px;
}
.toc a {
  display: block; color: var(--text-muted); padding: 3px 0;
  border-left: 2px solid transparent; padding-left: 10px; margin-left: -10px;
}
.toc a:hover { color: var(--accent); text-decoration: none; }
.toc a.lvl2 { font-weight: 600; color: var(--text); }
.toc a.active { border-left-color: var(--accent); color: var(--accent); }

/* ============ 核心亮点（图文） ============ */
.hl-lead-img {
  border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden;
  box-shadow: 0 18px 46px rgba(15,23,42,.10);
  background: #0b1220; margin: 22px 0 6px;
}
.hl-lead-img img { width: 100%; display: block; }
.hl-lead-img figcaption {
  padding: 12px 16px; font-size: 13px; color: var(--text-muted);
  background: #fff; border-top: 1px solid var(--border);
}

.dive {
  display: grid; grid-template-columns: 1fr 1.1fr; gap: 34px; align-items: center;
  margin: 30px 0; padding: 26px; border: 1px solid var(--border);
  border-radius: 16px; background: var(--bg);
}
.dive.reverse { grid-template-columns: 1.1fr 1fr; }
.dive.reverse .dive-text { order: 2; }
.dive.reverse .dive-shot { order: 1; }
.dive-text h3 { margin: 0 0 10px; font-size: 20px; }
.dive-text p { color: var(--text-muted); font-size: 14.5px; margin: 0 0 12px; }
.dive-text ul { margin: 0; padding-left: 20px; }
.dive-text li { margin: 6px 0; color: var(--text-muted); font-size: 14px; line-height: 1.65; }
.dive-text li strong { color: var(--text-strong); }
.dive-shot {
  border-radius: 12px; overflow: hidden; border: 1px solid var(--border);
  background: #0b1220; box-shadow: 0 14px 36px rgba(15,23,42,.10);
}
.dive-shot img { width: 100%; display: block; }

.gallery-doc {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; margin: 20px 0;
}
.gdoc { margin: 0; background: #fff; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.gdoc .gdoc-shot { background: #0b1220; border-bottom: 1px solid var(--border); }
.gdoc .gdoc-shot img { width: 100%; display: block; }
.gdoc figcaption { padding: 12px 14px 14px; }
.gdoc figcaption h4 { margin: 0 0 4px; font-size: 14.5px; }
.gdoc figcaption p { margin: 0; font-size: 13px; color: var(--text-muted); }

.toc a.toc-h2 { font-weight: 600; color: var(--text); }
.toc a.toc-h3 { padding-left: 16px; }

/* ============ 快速上手（两条路线） ============ */
/* 路线标签 */
.route-tag {
  display: inline-block; font-size: 12.5px; font-weight: 700;
  padding: 2px 10px; border-radius: 999px; margin-right: 8px;
  vertical-align: 3px; letter-spacing: .3px;
}
.route-tag.a { color: var(--text-muted); background: #f3f4f6; border: 1px solid var(--border); }
.route-tag.b { color: #fff; background: var(--accent); }

/* 步骤截图：单图限宽，避免整幅截图撑满破坏版式节奏 */
.qs-fig { margin: 18px 0 22px; }
.qs-fig > .qs-shot {
  border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
  background: #0b1220;
  box-shadow: 0 12px 30px rgba(15,23,42,.10);
  max-width: 680px;
}
.qs-fig > .qs-shot img { width: 100%; display: block; }
.qs-fig figcaption {
  margin-top: 8px; max-width: 680px;
  font-size: 13px; color: var(--text-muted); line-height: 1.6;
}
.qs-pair {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin: 18px 0 22px;
}
.qs-pair .qs-fig { margin: 0; }
.qs-pair .qs-fig > .qs-shot,
.qs-pair .qs-fig figcaption { max-width: none; }
.qs-pair .qs-fig figcaption { font-size: 12.5px; }

/* 侧栏二级链接 */
.sidebar a.nav-link.sub {
  padding-left: 28px; font-size: 13.2px; color: var(--text-muted);
}

@media (max-width: 900px) {
  .qs-pair { grid-template-columns: 1fr; gap: 14px; }
}

/* ============ 页脚 ============ */
.doc-footer {
  margin-top: 56px; padding-top: 22px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-faint);
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.doc-footer a { color: var(--text-muted); }

/* ============ 响应式 ============ */
@media (min-width: 1360px) {
  .toc { display: block; }
  .article { max-width: 820px; }
}

@media (max-width: 900px) {
  .dive, .dive.reverse { grid-template-columns: 1fr; gap: 16px; padding: 18px; }
  .dive.reverse .dive-text { order: 0; }
  .dive.reverse .dive-shot { order: 0; }
  .gallery-doc { grid-template-columns: 1fr; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: none;
    z-index: 40;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .main { margin-left: 0; padding: 24px 20px 64px; }
  .menu-toggle { display: block; }
  .topbar .toplink { display: none; }
  .topbar .badge { display: none; }
  h1.page-title { font-size: 25px; }
}

.sidebar-backdrop {
  display: none; position: fixed; inset: var(--header-h) 0 0 0;
  background: rgba(0,0,0,.32); z-index: 39;
}
.sidebar-backdrop.show { display: block; }
