/* ============================================
   SJR3 电机软启动器 - 说明书样式表
   移动端优先 · 工业简洁风格
   ============================================ */

/* --- CSS 变量 --- */
:root {
  --primary: #1a73e8;
  --primary-dark: #1558b0;
  --accent: #f0f4ff;
  --bg: #f8f9fb;
  --card: #ffffff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --border: #e0e4ea;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffdf5;
  --info: #0891b2;
  --info-bg: #f0f9fb;
  --radius: 6px;
  --font-size-base: 16px;
  --font-size-h2: 1.2rem;
  --font-size-h3: 1.05rem;
  --line-height: 1.6;
  --topbar-h: 52px;
  --drawer-w: 280px;
  --transition: 0.2s ease;
}

/* 暗色模式 */
[data-theme="dark"] {
  --bg: #111827;
  --card: #1a2332;
  --text: #e5e7eb;
  --text-secondary: #9ca3af;
  --border: #2d3748;
  --accent: #1a2744;
  --primary: #60a5fa;
  --primary-dark: #3b82f6;
  --danger-bg: #3b1515;
  --warning-bg: #2d2408;
  --info-bg: #0c2830;
}

/* 字体档位 */
[data-font="large"] {
  --font-size-base: 19px;
  --font-size-h2: 1.4rem;
  --font-size-h3: 1.2rem;
}
[data-font="xlarge"] {
  --font-size-base: 22px;
  --font-size-h2: 1.6rem;
  --font-size-h3: 1.35rem;
  --line-height: 1.75;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: var(--font-size-base);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: var(--line-height);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
ul, ol { padding-left: 1.3em; }
li { margin: 0.15em 0; }
p { margin: 0.5em 0; }

kbd {
  background: var(--border); color: var(--text);
  border-radius: 3px; padding: 1px 6px; font-size: 0.9em;
  font-family: inherit; border: 1px solid #ccc;
}

/* --- 顶部导航栏 --- */
.top-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--topbar-h);
  background: #1e2a3a; color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.top-bar-title {
  font-size: 0.95rem; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; flex: 1; text-align: center;
  margin: 0 8px;
}
.top-bar-actions { display: flex; gap: 0; }
.icon-btn {
  width: 38px; height: 38px; border: none; background: transparent;
  color: #fff; cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; transition: background var(--transition);
}
.icon-btn:hover { background: rgba(255,255,255,0.12); }
.icon-btn svg { display: block; }

/* --- 阅读进度条 --- */
.progress-bar {
  position: fixed; top: var(--topbar-h); left: 0; height: 2px; z-index: 999;
  background: var(--primary); width: 0%; transition: width 0.15s;
  pointer-events: none;
}

/* --- 搜索面板 --- */
.search-overlay {
  position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,0.4);
  display: none; align-items: flex-start; justify-content: center; padding-top: 18vh;
}
.search-overlay.active { display: flex; }
.search-panel {
  background: var(--card); border-radius: var(--radius); width: 94%; max-width: 480px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18); overflow: hidden;
  animation: slideDown 0.15s ease-out;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
.search-header {
  display: flex; align-items: center; border-bottom: 1px solid var(--border);
  padding: 6px 10px;
}
.search-input {
  flex: 1; border: none; outline: none; font-size: 1rem;
  background: transparent; color: var(--text); padding: 6px;
}
.search-input::placeholder { color: var(--text-secondary); }
.search-close {
  width: 32px; height: 32px; border: none; background: transparent;
  font-size: 1.2rem; cursor: pointer; color: var(--text-secondary);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.search-results { max-height: 55vh; overflow-y: auto; }
.search-hint { text-align: center; color: var(--text-secondary); padding: 20px; font-size: 0.92rem; }
.search-result-item {
  padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.search-result-item:hover { background: var(--accent); }
.search-result-item .highlight { background: #fde68a; color: #92400e; border-radius: 2px; padding: 0 2px; }
.search-result-item .result-chapter { font-size: 0.78rem; color: var(--primary); font-weight: 600; }
.search-result-item .result-text { font-size: 0.9rem; margin-top: 2px; }
.search-no-result { text-align: center; padding: 16px; color: var(--text-secondary); }

/* --- 字体/语言面板 --- */
.font-panel, .lang-panel {
  position: fixed; top: var(--topbar-h); z-index: 1500;
  background: var(--card); border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12); padding: 12px 14px;
  display: none; animation: fadeIn 0.12s ease-out;
}
.font-panel { right: 76px; }
.lang-panel { right: 8px; }
.font-panel.active, .lang-panel.active { display: block; }
.font-panel-title, .lang-panel-title {
  font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 6px;
}
.font-options, .lang-options { display: flex; gap: 6px; }
.font-option, .lang-option {
  padding: 6px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: transparent; color: var(--text); cursor: pointer; font-size: 0.9rem;
  transition: all var(--transition);
}
.font-option.active, .lang-option.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}

/* --- 侧边目录 --- */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 900;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.drawer-mask.active { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 950;
  width: var(--drawer-w); max-width: 85vw;
  background: var(--card); box-shadow: 2px 0 16px rgba(0,0,0,0.1);
  transform: translateX(-100%); transition: transform 0.25s ease;
  display: flex; flex-direction: column;
}
.drawer.active { transform: translateX(0); }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: #1e2a3a; color: #fff;
}
.drawer-header h2 { font-size: 1.05rem; font-weight: 600; }
.drawer-close {
  width: 30px; height: 30px; border: none; background: rgba(255,255,255,0.12);
  color: #fff; font-size: 1.1rem; border-radius: 50%; cursor: pointer;
}
.toc { list-style: none; padding: 4px 0; overflow-y: auto; flex: 1; }
.toc li { margin: 0; border-bottom: 1px solid var(--border); }
.toc a {
  display: block; padding: 11px 16px; color: var(--text); font-size: 0.94rem;
  transition: background var(--transition);
}
.toc a:hover, .toc a.active { background: var(--accent); color: var(--primary); text-decoration: none; }

/* --- 主内容区 --- */
.content {
  margin-top: var(--topbar-h);
  padding: 0 0 48px 0;
  max-width: 800px;
  margin-left: auto; margin-right: auto;
}

/* --- 快速目录导航 --- */
.quick-nav {
  padding: 20px 12px 28px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.quick-nav-header {
  text-align: center; padding: 0 0 18px;
}
.quick-nav-header .nav-title {
  font-size: 1.15rem; font-weight: 700; color: var(--text);
  margin-bottom: 3px;
}
.quick-nav-header .nav-subtitle {
  font-size: 0.78rem; color: var(--text-secondary);
}
.nav-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 500px;
  margin: 0 auto;
}
.nav-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 10px 16px;
  display: flex; flex-direction: column; align-items: center;
  text-decoration: none; color: var(--text);
  transition: all 0.12s ease;
  min-height: 92px;
  justify-content: center; gap: 6px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative; overflow: hidden;
}
.nav-card:active {
  background: var(--accent);
  border-color: var(--primary);
  transform: scale(0.96);
}
.nav-card .nav-icon { font-size: 1.6rem; line-height: 1; }
.nav-card .nav-label {
  font-size: 0.88rem; font-weight: 600; line-height: 1.2;
  text-align: center;
}
/* 最后一个卡片（奇数总数时）居中 */
.nav-grid .nav-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  max-width: calc(50% - 5px);
  justify-self: center;
}

@media (min-width: 500px) {
  .nav-grid { grid-template-columns: repeat(3, 1fr); }
  .nav-card { min-height: 88px; padding: 16px 10px 14px; }
  .nav-grid .nav-card:last-child:nth-child(odd) {
    grid-column: span 1;
    max-width: none;
    justify-self: auto;
  }
  /* 3列时最后一个奇数项也要处理 */
  .nav-grid .nav-card:nth-child(9):nth-last-child(1) {
    grid-column: 2;
  }
}

/* --- 章节 --- */
.chapter { padding: 12px 14px; }
.chapter-header {
  padding: 12px 0 10px; margin-bottom: 12px;
  border-bottom: 2px solid var(--primary);
}
.chapter-header.warning-header { border-bottom-color: var(--danger); }
.chapter-number { font-size: 0.78rem; color: var(--text-secondary); display: block; margin-bottom: 2px; }
.chapter-title { font-size: var(--font-size-h2); font-weight: 700; color: var(--text); }

/* --- 卡片 --- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px;
  border: 1px solid var(--border);
}
.card h3, .section-title {
  font-size: var(--font-size-h3); font-weight: 600; color: var(--text);
  margin-bottom: 8px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.section-title .sec-num {
  color: var(--primary); font-weight: 700; margin-right: 4px;
}

/* --- 警告框 --- */
.warning-box {
  display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--radius);
  margin-bottom: 8px; align-items: flex-start;
}
.warning-box.danger { background: var(--danger-bg); border: 1px solid var(--danger); }
.warning-box.warning { background: var(--warning-bg); border: 1px solid var(--warning); }
.warning-box.info { background: var(--info-bg); border: 1px solid var(--info); }
.warning-icon { font-size: 1.2rem; flex-shrink: 0; line-height: 1.3; }
.warning-body strong { display: block; margin-bottom: 2px; }
.warning-box.danger .warning-body strong { color: var(--danger); }
.warning-box.warning .warning-body strong { color: var(--warning); }
.warning-box.info .warning-body strong { color: var(--info); }
.warning-body p { font-size: 0.92rem; line-height: 1.55; }

/* --- 特性列表 --- */
.feature-list { list-style: none; padding: 0; }
.feature-list li { padding: 2px 0; font-size: 0.94rem; }

/* --- 型号图解 --- */
.model-diagram {
  background: var(--accent); border-radius: var(--radius);
  padding: 12px; text-align: center; margin: 6px 0;
}
.model-diagram code {
  font-size: 1.1rem; font-weight: 700; color: var(--primary);
  letter-spacing: 1px; background: transparent; border: none;
}
.model-legend { margin-top: 8px; text-align: left; font-size: 0.88rem; }
.model-legend p { margin: 2px 0; }

/* --- 步骤列表 --- */
.step { display: flex; gap: 10px; padding: 10px 0; }
.step:not(:last-child) { border-bottom: 1px solid var(--border); }
.step-num {
  width: 28px; height: 28px; flex-shrink: 0;
  background: var(--primary); color: #fff; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; margin-top: 2px;
}
.step-content strong { display: block; margin-bottom: 2px; }
.step-content p { font-size: 0.9rem; color: var(--text-secondary); }

/* --- 表格 --- */
.table-scroll {
  margin: 4px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.spec-table {
  width: 100%; border-collapse: collapse; font-size: 0.82rem;
  table-layout: auto;
}
.spec-table td, .spec-table th {
  word-break: break-word; overflow-wrap: break-word;
}
/* 参数表 — 代码/数值列不换行 */
.spec-table.param-table th:nth-child(1),
.spec-table.param-table td:nth-child(1),
.spec-table.param-table th:nth-child(3),
.spec-table.param-table td:nth-child(3),
.spec-table.param-table th:nth-child(4),
.spec-table.param-table td:nth-child(4) {
  white-space: nowrap;
  word-break: normal;
}
/* 参数说明列允许换行 */
.spec-table.param-table th:nth-child(5),
.spec-table.param-table td:nth-child(5) {
  word-break: break-word;
}
/* 紧凑表格 — 多列型号规格表 */
.spec-table.compact {
  font-size: 0.72rem;
}
.spec-table.compact th {
  font-size: 0.68rem;
  padding: 5px 4px;
}
.spec-table.compact td {
  padding: 5px 4px;
  white-space: nowrap;
  word-break: normal;
}
.spec-table.compact td:first-child {
  white-space: nowrap;
}
.spec-table th {
  background: #1e2a3a; color: #fff; padding: 7px 8px;
  text-align: left; font-weight: 500; font-size: 0.8rem;
}
.spec-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.spec-table tr:nth-child(even) td { background: #f9fafb; }
[data-theme="dark"] .spec-table tr:nth-child(even) td { background: rgba(255,255,255,0.03); }

/* --- 检查清单 --- */
.checklist { list-style: none; padding: 0; }
.checklist li { padding: 2px 0; font-size: 0.93rem; }

/* --- 按键说明 --- */
.key-list { display: flex; flex-direction: column; gap: 4px; }
.key-item { font-size: 0.92rem; display: flex; align-items: center; gap: 8px; }
.key-item kbd { min-width: 48px; text-align: center; }

/* --- 故障列表 --- */
.fault-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.fault-item {
  display: flex; gap: 10px; background: var(--card); border-radius: var(--radius);
  padding: 10px 12px; border: 1px solid var(--border); align-items: flex-start;
}
.fault-code {
  background: var(--danger); color: #fff; border-radius: 4px;
  padding: 3px 8px; font-weight: 700; font-size: 0.85rem;
  white-space: nowrap; flex-shrink: 0;
}
.fault-detail strong { display: block; font-size: 0.94rem; margin-bottom: 2px; }
.fault-detail p { font-size: 0.88rem; color: var(--text-secondary); }

/* --- 联系信息 --- */
.contact-list { list-style: none; padding: 0; }
.contact-list li { padding: 3px 0; font-size: 0.93rem; }

/* --- 备注 --- */
.note {
  background: var(--warning-bg); border-left: 3px solid var(--warning);
  padding: 8px 12px; border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem; margin-top: 8px;
}

/* --- URL 显示 --- */
.url-display {
  background: var(--accent); border: 1px solid var(--primary);
  border-radius: var(--radius); padding: 8px 12px; font-family: monospace;
  font-size: 0.9rem; color: var(--primary); text-align: center;
  margin: 8px 0; word-break: break-all;
}

/* --- 底栏 --- */
.footer {
  text-align: center; padding: 20px 16px 16px; font-size: 0.82rem;
  color: var(--text-secondary); border-top: 1px solid var(--border);
  margin-top: 8px;
}
.footer-links { margin-top: 6px; text-align: center; font-size: 0.85rem; color: var(--primary); font-weight: 500; }

/* --- 回到顶部 --- */
.back-to-top {
  position: fixed; bottom: 20px; right: 16px; z-index: 800;
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 1.1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2); cursor: pointer;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: all 0.2s; display: flex; align-items: center; justify-content: center;
}
.back-to-top.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }

/* --- PWA 安装提示 --- */
.pwa-install {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1200;
  background: var(--card); border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
  padding: 10px 14px; display: none; align-items: center; gap: 8px;
  animation: slideUp 0.2s ease-out;
}
.pwa-install.active { display: flex; }
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.pwa-install p { flex: 1; font-size: 0.88rem; }
.pwa-btn {
  background: var(--primary); color: #fff; border: none; border-radius: var(--radius);
  padding: 7px 14px; font-size: 0.85rem; cursor: pointer; white-space: nowrap;
}
.pwa-close {
  width: 28px; height: 28px; border: none; background: transparent;
  font-size: 1rem; cursor: pointer; color: var(--text-secondary);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
}

/* --- 编号列表 --- */
.numbered-list { padding-left: 1.3em; }
.numbered-list li { padding: 2px 0; font-size: 0.94rem; }

/* --- 图框（Figure Box） --- */
.figure-box {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); margin: 12px 0; overflow: hidden;
}
.figure-box .figure-img {
  display: flex; align-items: center; justify-content: center;
  padding: 12px; background: #fcfcfd;
}
[data-theme="dark"] .figure-box .figure-img { background: #0f1724; }
.figure-box .figure-img img {
  max-width: 100%; height: auto; border-radius: 2px; display: block;
}
.figure-box .figure-caption {
  padding: 8px 12px; border-top: 1px solid var(--border);
  font-size: 0.82rem; color: var(--text-secondary); text-align: center;
  background: var(--bg);
}
.figure-box .figure-caption .fig-num {
  font-weight: 700; color: var(--primary); margin-right: 4px;
}
/* 并排图框 */
.figure-row {
  display: flex; gap: 10px; margin: 12px 0; flex-wrap: wrap;
}
.figure-row .figure-box { flex: 1 1 48%; min-width: 160px; margin: 0; }
.figure-box.size-sm .figure-img { padding: 10px 16px; }
.figure-box.size-sm .figure-img img { max-width: 260px; }
.figure-box.size-xs .figure-img { padding: 10px 16px; }
.figure-box.size-xs .figure-img img { max-width: 180px; }

/* --- 打印 --- */
@media print {
  .top-bar, .progress-bar, .back-to-top, .pwa-install,
  .search-overlay, .font-panel, .lang-panel, .drawer, .drawer-mask { display: none !important; }
  .content { margin-top: 0; }
  .card { border: 1px solid #ddd; break-inside: avoid; }
  .quick-nav { padding: 12px; }
  body { background: #fff; color: #000; }
}

/* --- 大屏 --- */
@media (min-width: 768px) {
  .content { padding: 0 20px 48px; }
  .chapter { padding: 16px 20px; }
  .card { padding: 14px 18px; }
  .nav-grid { max-width: 560px; }
}

/* --- 参数表 — 小屏转换为卡片布局 --- */
@media (max-width: 600px) {
  .param-table,
  .param-table tbody,
  .param-table tr,
  .param-table td {
    display: block;
  }
  .param-table thead { display: none; }
  .param-table tr {
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg, #fff);
    padding: 10px 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  }
  .param-table td {
    padding: 3px 0;
    border-bottom: none;
    text-align: left;
    white-space: normal;
    word-break: break-word;
  }
  /* 代码 + 名称并排 */
  .param-table td:nth-child(1) {
    display: inline-block;
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--primary);
    margin-right: 8px;
  }
  .param-table td:nth-child(2) {
    display: inline;
    font-size: 0.85rem;
    color: var(--text);
  }
  .param-table td:nth-child(2)::after {
    content: '';
    display: block;
  }
  /* 范围 + 出厂值 inline 标签 */
  .param-table td:nth-child(3),
  .param-table td:nth-child(4) {
    display: inline-block;
    font-size: 0.76rem;
    color: #666;
    margin-top: 4px;
    margin-right: 16px;
  }
  .param-table td:nth-child(3)::before { content: '设定范围: '; font-weight: 500; color: #999; }
  .param-table td:nth-child(4)::before { content: '出厂值: ';   font-weight: 500; color: #999; }
  /* 说明列 — 全宽可读 */
  .param-table td:nth-child(5) {
    border-top: 1px dashed var(--border);
    margin-top: 6px;
    padding-top: 6px;
    font-size: 0.82rem;
    line-height: 1.6;
    color: #555;
  }
  /* 偶行背景改为卡片内统一 */
  .param-table tr:nth-child(even) td {
    background: transparent;
  }
}

/* --- 小屏表格紧凑 --- */
@media (max-width: 420px) {
  .spec-table.compact {
    font-size: 0.66rem;
  }
  .spec-table.compact th {
    font-size: 0.63rem;
    padding: 4px 3px;
  }
  .spec-table.compact td {
    padding: 4px 3px;
  }
}
