/* ===== 基础 ===== */
:root {
  --bg: #f2f4f8;
  --panel: #ffffff;
  --ink: #1c2333;
  --ink-2: #5b6478;
  --accent: #4f6ef7;
  --accent-2: #7c5cf0;
  --ok: #22b07d;
  --warn: #e8a23c;
  --err: #e05252;
  --border: #e4e8f0;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(28, 35, 51, .08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
/* hidden 属性必须永远生效：防止 .drawer/.busy-overlay 等显式 display 覆盖 */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 22px;
  background: linear-gradient(120deg, #2b3a67, #3c2e6b 55%, #4f6ef7);
  color: #fff;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.logo { font-size: 30px; }
.brand h1 { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.subtitle { font-size: 12px; opacity: .8; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25);
  padding: 4px 12px; border-radius: 999px; font-size: 12px; backdrop-filter: blur(4px);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa3b5; flex: none; }
.chip.ok .dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.chip.fail .dot { background: var(--err); box-shadow: 0 0 6px var(--err); }
.chip.unknown .dot { background: var(--warn); box-shadow: 0 0 6px var(--warn); }

/* ===== 按钮 ===== */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--ink);
  padding: 8px 16px; border-radius: 10px; cursor: pointer;
  font-size: 13px; font-weight: 600; transition: all .15s;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #3f5ce0; }
.btn.ghost { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.btn.ghost:hover:not(:disabled) { background: rgba(255,255,255,.22); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* ===== 布局 ===== */
.layout {
  display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr);
  gap: 18px; padding: 18px 22px 0;
  align-items: start;
}
.panel {
  background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 15px; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ===== 网络摄像头 ===== */
.net-cam {
  background: #f7f8fc; border-bottom: 1px solid var(--border); padding: 8px 16px;
}
.net-cam summary { cursor: pointer; font-size: 13px; font-weight: 700; color: var(--ink-2); user-select: none; }
.net-cam-row { display: flex; gap: 8px; margin-top: 8px; }
.net-cam-row input, .net-cam-row select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff; color: var(--ink); outline: none; min-width: 0;
}
.net-cam-row input:focus, .net-cam-row select:focus { border-color: var(--accent); }
.net-cam-hint { font-size: 12px; color: var(--ink-2); margin: 8px 0 2px; }
#net-preview { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ===== 视频区 ===== */
.video-wrap { position: relative; background: #0d1117; aspect-ratio: 16/9; overflow: hidden; }
#video { width: 100%; height: 100%; object-fit: cover; display: block; }
.zoom-ctrl {
  position: absolute; top: 8px; right: 8px; z-index: 5;
  display: flex; align-items: center; gap: 3px;
  background: rgba(13, 17, 23, .55); border-radius: 8px; padding: 3px;
}
.zoom-btn {
  border: none; background: rgba(255, 255, 255, .16); color: #fff;
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
  font-size: 15px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.zoom-btn:hover { background: rgba(255, 255, 255, .32); }
.zoom-label { color: #fff; font-size: 11px; min-width: 36px; text-align: center; font-variant-numeric: tabular-nums; }
.video-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; color: #8b93a7; text-align: center; padding: 20px;
}
.ph-icon { font-size: 52px; }
.ph-hint { font-size: 12px; opacity: .7; }
.scanline {
  position: absolute; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scan 2.2s ease-in-out infinite;
  box-shadow: 0 0 14px var(--accent);
}
@keyframes scan { 0% { top: 0; } 50% { top: calc(100% - 3px); } 100% { top: 0; } }
.busy-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: rgba(13,17,23,.55); color: #fff; font-size: 15px; font-weight: 600;
}
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.3); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 结果卡片 ===== */
.result-panel { min-height: 420px; }
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 80px 20px; color: #8b93a7; text-align: center;
}
.info-card { padding: 0 0 16px; animation: pop .35s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to { opacity: 1; transform: none; }
}
.card-head { padding: 14px 16px 0; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-title h3 { font-size: 19px; }
.card-tags { display: flex; gap: 8px; align-items: center; }
.tag {
  background: #eef1ff; color: var(--accent); border-radius: 999px;
  padding: 3px 12px; font-size: 12px; font-weight: 600;
}
.conf { font-size: 12px; color: var(--ink-2); }
.conf b { color: var(--ok); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab {
  border: none; background: none; padding: 8px 14px; cursor: pointer;
  font-size: 13px; color: var(--ink-2); border-bottom: 2px solid transparent;
  font-weight: 600;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-body { padding: 14px 16px; }
.tab-body h4 { font-size: 13px; color: var(--ink-2); margin: 12px 0 6px; }
.desc { color: var(--ink); }
.specs { list-style: none; }
.specs li {
  padding: 6px 10px; margin: 4px 0; background: #f7f8fc;
  border-left: 3px solid var(--accent); border-radius: 6px; font-size: 13px;
}
.tips { color: var(--ink-2); font-size: 13px; background: #fff8e8; border-radius: 8px; padding: 8px 12px; }
.ai-summary { margin-top: 6px; }
.ai-summary p { background: #f3f0ff; border-radius: 8px; padding: 8px 12px; font-size: 13px; color: #4a3f8f; }

/* 识别卡片内嵌 5 页签（栏宽较窄，页签可换行、媒体高度调低） */
.info-card .tabs { flex-wrap: wrap; gap: 2px 4px; }
.info-card .tabs .tab { padding: 6px 10px; font-size: 12px; }
.info-card .tab-body { padding: 12px 16px; }
.info-card .media-frame { height: 380px; }
.info-card .media-video { max-height: 380px; }

/* ===== 爆炸图 ===== */
.exploded-diagram { position: relative; height: 190px; margin: 8px 0 16px; }
.exploded-layer {
  position: absolute; left: 50%; transform: translateX(-50%);
  width: 62%; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 12px; font-weight: 600; color: #fff;
  border: 2px solid rgba(255,255,255,.7);
  box-shadow: 0 4px 10px rgba(0,0,0,.15);
  background: linear-gradient(135deg, hsl(calc(220 + var(--i) * 38), 70%, 58%), hsl(calc(220 + var(--i) * 38), 65%, 42%));
  top: calc(var(--i) * 44px);
  opacity: .92;
}
.exploded-layer:nth-child(even) { margin-left: 6%; }
.exploded-layer img { height: 26px; border-radius: 4px; }
.exploded-list { display: flex; flex-direction: column; gap: 6px; }
.exploded-item {
  display: flex; gap: 10px; align-items: baseline;
  padding: 8px 12px; background: #f7f8fc; border-radius: 8px;
}
.exploded-item-name { font-weight: 700; font-size: 13px; color: var(--accent); flex: none; min-width: 90px; }
.exploded-item-desc { font-size: 13px; color: var(--ink-2); }
.exploded-empty, .exploded-3d-note {
  color: var(--ink-2); font-size: 13px; text-align: center;
  padding: 24px 12px; border: 1px dashed var(--border); border-radius: 10px;
}

/* ===== 日志 ===== */
.log-panel { margin: 18px 22px 22px; }
.log-list { list-style: none; max-height: 220px; overflow-y: auto; padding: 8px 16px; }
.log-list li {
  display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px dashed var(--border);
  font-size: 13px; align-items: baseline;
}
.log-list li:last-child { border-bottom: none; }
.log-time { color: #9aa3b5; font-size: 12px; flex: none; font-variant-numeric: tabular-nums; }
.log-msg { word-break: break-all; }
.log-msg.ok { color: var(--ok); }
.log-msg.warn { color: var(--warn); }
.log-msg.err { color: var(--err); }

/* ===== 设置抽屉 ===== */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(10,14,24,.45); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 360px; max-width: 92vw;
  background: #fff; z-index: 50; box-shadow: -12px 0 32px rgba(0,0,0,.18);
  display: flex; flex-direction: column;
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: none; } }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.drawer-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.drawer-body label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.drawer-body input, .drawer-body select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  background: #fbfcfe; color: var(--ink); outline: none;
}
.drawer-body input:focus, .drawer-body select:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; }
.row select { flex: 1; }
.row input[list] { flex: 1; min-width: 0; }
.test-result { font-size: 12px; padding: 8px 10px; border-radius: 8px; display: none; }
.test-result.ok { display: block; background: #e8f9f1; color: var(--ok); }
.test-result.fail { display: block; background: #fdecec; color: var(--err); }
.drawer-foot { padding: 12px 18px; border-top: 1px solid var(--border); }

/* ===== 开关 ===== */
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; color: var(--ink-2); font-weight: 600; }
.switch input { display: none; }
.switch span::before {
  content: ""; display: inline-block; width: 34px; height: 19px; border-radius: 999px;
  background: #cfd6e4; vertical-align: middle; margin-right: 6px; transition: background .15s;
  position: relative;
}
.switch span::after {
  content: ""; position: absolute; width: 15px; height: 15px; border-radius: 50%;
  background: #fff; transition: left .15s; top: 2px; left: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch span { position: relative; }
.switch input:checked + span::before { background: var(--accent); }
.switch input:checked + span::after { left: 17px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #1c2333; color: #fff; padding: 10px 20px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow); z-index: 60; animation: pop .25s ease;
  max-width: 80vw;
}

.meta { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ===== 响应式 ===== */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
}

/* ===== 知识库管理模态框 ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 14, 24, .45); z-index: 40;
}
.kb-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 860px; max-width: 94vw; max-height: 86vh;
  background: #fff; border-radius: var(--radius); z-index: 50;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  animation: pop .25s ease;
}
.kb-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.kb-head h2 { font-size: 15px; margin-right: auto; }
.kb-head .controls { flex: none; }
.kb-body {
  display: grid; grid-template-columns: 250px 1fr;
  min-height: 0; overflow: hidden; flex: 1;
}
.kb-list { border-right: 1px solid var(--border); overflow-y: auto; padding: 8px; }
.kb-item { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-radius: 8px; }
.kb-item:hover { background: #f2f4f9; }
.kb-item.active { background: #eef1ff; }
.kb-item-main {
  flex: 1; text-align: left; background: none; border: none; cursor: pointer; padding: 0;
  display: flex; flex-direction: column; gap: 1px; font: inherit;
}
.kb-item-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.kb-item.active .kb-item-name { color: var(--accent); }
.kb-item-cat { font-size: 11px; color: var(--ink-2); }
.kb-item-del {
  border: none; background: none; cursor: pointer; font-size: 13px;
  color: #9aa3b5; padding: 2px 6px; border-radius: 6px;
}
.kb-item-del:hover { color: var(--err); background: #fdecec; }
.kb-empty { padding: 24px 12px; color: var(--ink-2); font-size: 13px; text-align: center; }
.kb-editor {
  overflow-y: auto; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.kb-field { display: flex; flex-direction: column; gap: 4px; }
.kb-field label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.kb-field input, .kb-field textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fbfcfe; color: var(--ink); outline: none;
  font-family: inherit; resize: vertical;
}
.kb-field input:focus, .kb-field textarea:focus { border-color: var(--accent); }
.kb-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.kb-foot .test-result { flex: 1; }

/* ===== 详情页 ===== */
.detail-layout { padding: 18px 22px 22px; max-width: 960px; margin: 0 auto; }
.detail-panel { min-height: 420px; }
.detail-panel .tabs { padding: 0 16px; }
.detail-panel .tab-body { padding: 16px; }

/* ===== 原理仿真 / 维保视频 ===== */
.media-frame {
  display: block; width: 100%; height: 520px;
  border: 1px solid var(--border); border-radius: 10px; background: #0d1117;
}
.media-video {
  display: block; width: 100%; max-height: 520px;
  border: 1px solid var(--border); border-radius: 10px; background: #0d1117;
}
.resource-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.resource-title { font-size: 14px; font-weight: 600; color: var(--ink); }
.resource-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 48px 20px; margin: 8px 0;
  border: 2px dashed var(--border); border-radius: 12px;
  color: var(--ink-2); text-align: center; background: #f7f8fc;
}
.resource-icon { font-size: 40px; }
.resource-empty p { font-size: 15px; font-weight: 600; color: var(--ink); }
.resource-empty small { font-size: 12px; line-height: 1.8; max-width: 560px; }
.resource-empty code { background: #eef1ff; color: var(--accent); padding: 1px 6px; border-radius: 4px; }

/* ===== 习题练习 ===== */
.quiz-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.quiz-progress { font-size: 12px; color: var(--ink-2); }
.quiz-score { font-size: 12px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.quiz-question { font-size: 15px; font-weight: 600; margin: 4px 0 14px; line-height: 1.7; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-option {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: #fbfcfe; color: var(--ink); font-size: 14px; cursor: pointer;
  transition: all .15s; font: inherit;
}
.quiz-option:hover:not(:disabled) { border-color: var(--accent); background: #f0f3ff; }
.quiz-option.selected { border-color: var(--accent); background: #eef1ff; }
.quiz-option.correct { border-color: var(--ok); background: #e8f9f1; }
.quiz-option.wrong { border-color: var(--err); background: #fdecec; }
.quiz-option:disabled { cursor: default; opacity: 1; }
.quiz-opt-key {
  flex: none; width: 24px; height: 24px; border-radius: 6px;
  background: #e4e8f0; color: var(--ink-2); display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.quiz-option.correct .quiz-opt-key { background: var(--ok); color: #fff; }
.quiz-option.wrong .quiz-opt-key { background: var(--err); color: #fff; }
.quiz-feedback { margin: 12px 0 0; padding: 10px 14px; border-radius: 10px; font-size: 13px; line-height: 1.7; }
.quiz-feedback.ok { background: #e8f9f1; color: #177a55; }
.quiz-feedback.fail { background: #fdecec; color: #b23c3c; }
.quiz-feedback b { font-size: 14px; }
.quiz-explain { display: block; margin-top: 4px; color: var(--ink-2); }
.quiz-actions { display: flex; gap: 10px; margin-top: 14px; }
.quiz-done { text-align: center; padding: 48px 20px; }
.quiz-done h3 { font-size: 20px; margin-bottom: 8px; }
.quiz-done-score { font-size: 18px; margin-bottom: 16px; }
.quiz-done-score b { color: var(--ok); font-size: 26px; }
