:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e6e8ec;
  --line-strong: #d5d9e0;
  --text: #14171d;
  --text-2: #5a6272;
  --text-3: #8b93a3;
  --accent: #c8102e;
  --accent-soft: #fdeaed;
  --blue: #1f6feb;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }

.layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(145deg, #c8102e, #8c0a20);
  color: #fff; font-weight: 700; font-size: 15px;
  display: grid; place-items: center; letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: .2px; }
.brand-text span { font-size: 11px; color: var(--text-3); }
.side-search { padding: 0 14px 12px; }
.side-search input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong);
  border-radius: 8px; background: #fbfbfc; outline: none; font-size: 13px;
}
.side-search input:focus { border-color: var(--accent); background: #fff; }

.side-nav { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.side-sec { margin-bottom: 14px; }
.side-sec > h4 {
  margin: 0; padding: 6px 10px; font-size: 11px; font-weight: 600;
  color: var(--text-3); text-transform: uppercase; letter-spacing: .08em;
  display: flex; justify-content: space-between; cursor: pointer; user-select: none;
}
.side-sec > h4 .caret { transition: transform .15s; font-size: 9px; color: var(--text-3); }
.side-sec.collapsed .caret { transform: rotate(-90deg); }
.side-sec.collapsed .side-list { display: none; }
.side-list { display: flex; flex-direction: column; gap: 1px; }
.side-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 5px 10px; border-radius: 7px; font-size: 13px; color: var(--text-2);
  cursor: pointer; border: none; background: none; text-align: left; width: 100%;
}
.side-item:hover { background: #f2f4f7; color: var(--text); }
.side-item.active { background: var(--accent-soft); color: #8c0a20; font-weight: 600; }
.side-item .cnt { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.side-item.active .cnt { color: #b0576a; }
.side-foot { border-top: 1px solid var(--line); padding: 10px 14px; font-size: 11px; color: var(--text-3); }

.toggle {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  font-size: 12.5px; color: var(--text-2); cursor: pointer; border-radius: 7px;
}
.toggle:hover { background: #f2f4f7; }
.toggle input { accent-color: var(--accent); margin: 0; }

/* ---------- main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 52px; flex: 0 0 52px; display: flex; align-items: center;
  justify-content: space-between; padding: 0 22px;
  background: rgba(255,255,255,.86); backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.crumbs { font-size: 12.5px; color: var(--text-3); display: flex; gap: 6px; align-items: center; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { opacity: .5; }
.top-actions { display: flex; gap: 8px; }
.btn {
  border: 1px solid var(--line-strong); background: #fff; color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 12.5px;
}
.btn:hover { border-color: var(--text-3); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #a90d26; }
.btn.ghost { background: transparent; }

.content { flex: 1; overflow-y: auto; padding: 22px 26px 60px; }
.wrap { max-width: 1180px; margin: 0 auto; }

/* ---------- hero ---------- */
.hero {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px 24px; margin-bottom: 18px;
}
.hero h1 { margin: 0 0 6px; font-size: 20px; letter-spacing: .2px; }
.hero p { margin: 0; color: var(--text-2); font-size: 13px; max-width: 720px; }
.stats { display: flex; flex-wrap: wrap; gap: 26px; margin-top: 18px; }
.stat b { display: block; font-size: 21px; font-variant-numeric: tabular-nums; letter-spacing: -.2px; }
.stat span { font-size: 11.5px; color: var(--text-3); }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 12px;
}
.result-count { font-size: 12.5px; color: var(--text-3); margin-right: auto; }
.chip {
  border: 1px solid var(--line-strong); background: #fff; border-radius: 999px;
  padding: 4px 10px; font-size: 12px; color: var(--text-2); cursor: pointer;
}
.chip:hover { border-color: var(--text-3); color: var(--text); }
.chip.active { background: #14171d; border-color: #14171d; color: #fff; }
select.sel {
  border: 1px solid var(--line-strong); background: #fff; border-radius: 8px;
  padding: 5px 8px; font-size: 12.5px; color: var(--text-2);
}

/* ---------- device grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; gap: 12px; cursor: pointer; transition: .15s;
  min-height: 92px;
}
.card:hover { border-color: #c3c9d4; box-shadow: 0 4px 16px rgba(20,23,29,.06); transform: translateY(-1px); }
.card .thumb {
  width: 52px; height: 52px; flex: 0 0 52px; border-radius: 10px; background: #f2f4f7;
  display: grid; place-items: center; overflow: hidden;
}
.card .thumb img { width: 44px; height: 44px; object-fit: contain; }
.card .meta { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.card .name {
  font-size: 13.5px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .sub { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .tags { display: flex; gap: 4px; margin-top: auto; flex-wrap: wrap; }
.tag {
  font-size: 10.5px; padding: 1px 6px; border-radius: 5px;
  background: #f0f2f5; color: var(--text-2); white-space: nowrap;
}
.tag.spec { background: #e8f1ff; color: #1f5fbf; }
.tag.warn { background: #fff1e8; color: #a8541b; }
.tag.hide { background: #f3f3f4; color: #9aa0ac; }

.more-wrap { display: flex; justify-content: center; padding: 26px 0 0; }
.empty { text-align: center; color: var(--text-3); padding: 60px 20px; font-size: 13px; }

/* ---------- detail ---------- */
.back { font-size: 12.5px; color: var(--text-3); margin-bottom: 12px; display: inline-block; }
.back:hover { color: var(--accent); }
.detail-head {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px 22px; display: flex; gap: 18px; align-items: flex-start; margin-bottom: 16px;
}
.detail-head .big {
  width: 84px; height: 84px; flex: 0 0 84px; border-radius: 14px; background: #f2f4f7;
  display: grid; place-items: center;
}
.detail-head .big img { width: 66px; height: 66px; object-fit: contain; }
.detail-head h2 { margin: 0 0 4px; font-size: 19px; }
.detail-head .en { color: var(--text-3); font-size: 12.5px; margin-bottom: 8px; }
.kv { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--text-2); }
.kv code { font-family: var(--mono); font-size: 11.5px; background: #f4f5f7; padding: 1px 5px; border-radius: 4px; }
.detail-head .badges { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab {
  border: none; background: none; padding: 8px 12px; font-size: 13px; color: var(--text-2);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.panel-head {
  padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex;
  align-items: center; justify-content: space-between; gap: 10px;
}
.panel-head h3 { margin: 0; font-size: 13.5px; }
.panel-head .hint { font-size: 11.5px; color: var(--text-3); }
.panel-body { padding: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

/* services */
.svc { border-bottom: 1px solid var(--line); }
.svc:last-child { border-bottom: none; }
.svc-head { padding: 11px 16px; display: flex; align-items: baseline; gap: 10px; background: #fafbfc; }
.svc-head strong { font-size: 13px; }
.svc-head code { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); }
.svc-head p { margin: 0; font-size: 11.5px; color: var(--text-3); }
.svc-body { padding: 4px 0 10px; }
.svc-sub { padding: 8px 16px 2px; font-size: 11px; color: var(--text-3); letter-spacing: .04em; }

table.spec { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.spec th {
  text-align: left; font-weight: 500; color: var(--text-3); font-size: 11px;
  padding: 5px 16px; border-bottom: 1px solid var(--line); background: #fff;
  white-space: nowrap;
}
table.spec td { padding: 7px 16px; border-bottom: 1px solid #f2f3f5; vertical-align: top; }
table.spec tr:last-child td { border-bottom: none; }
table.spec td.mono, .mono { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); }
.type-pill { font-size: 10.5px; padding: 1px 6px; border-radius: 4px; background: #f0f2f5; color: #46505f; }
.rw-r { color: var(--text-3); }
.rw-w { color: #a8541b; }
.enum-chip { display: inline-block; font-size: 10.5px; background: #f6f7f9; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin: 1px 3px 1px 0; }

pre.json {
  margin: 0; padding: 14px 16px; background: #14171d; color: #d7dce5;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.6; overflow: auto; max-height: 560px;
  border-radius: 0 0 12px 12px;
}
code.inline { font-family: var(--mono); font-size: 11.5px; background: #f4f5f7; padding: 1px 5px; border-radius: 4px; }

.notice {
  padding: 12px 16px; background: #fff8e6; border: 1px solid #f3e1b0; border-radius: 10px;
  font-size: 12.5px; color: #7a5a12; margin-bottom: 16px;
}
.notice strong { color: #5e4410; }

.dl { display: grid; grid-template-columns: 96px 1fr; gap: 6px 14px; font-size: 12.5px; padding: 14px 16px; }
.dl dt { color: var(--text-3); }
.dl dd { margin: 0; color: var(--text); word-break: break-all; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(20,23,29,.42); display: grid; place-items: center; z-index: 50; padding: 24px; }
.modal[hidden] { display: none; }
.modal-box {
  background: #fff; border-radius: 14px; width: min(720px, 100%); max-height: 86vh; overflow: auto;
  padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-box h2 { margin: 0 0 8px; font-size: 17px; }
.modal-box p { color: var(--text-2); font-size: 13px; }
.modal-box textarea {
  width: 100%; min-height: 190px; font-family: var(--mono); font-size: 12px;
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 10px; resize: vertical;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal-box ul { padding-left: 18px; color: var(--text-2); font-size: 13px; }
.modal-box li { margin: 4px 0; }

.bars { display: flex; flex-direction: column; gap: 7px; padding: 14px 16px; }
.bar-row { display: grid; grid-template-columns: 84px 1fr 48px; gap: 10px; align-items: center; font-size: 12px; }
.bar-row .track { height: 7px; background: #f0f2f5; border-radius: 4px; overflow: hidden; }
.bar-row .fill { height: 100%; background: linear-gradient(90deg, #c8102e, #e8627a); border-radius: 4px; }
.bar-row .num { text-align: right; color: var(--text-3); font-variant-numeric: tabular-nums; }

.section-title { display: flex; align-items: baseline; gap: 10px; margin: 26px 0 10px; }
.section-title h2 { margin: 0; font-size: 15px; }
.section-title span { font-size: 12px; color: var(--text-3); }

/* ---------- 物模型库 / profile 表格 ---------- */
.perm {
  font-family: var(--mono); font-size: 10px; color: var(--text-3);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 3px; margin-left: 4px;
}
.spec-search {
  width: 320px; padding: 7px 10px; border: 1px solid var(--line-strong);
  border-radius: 8px; font-size: 13px; outline: none; background: #fff;
}
.spec-search:focus { border-color: var(--accent); }
.spec-table tbody tr.prow { cursor: pointer; }
.spec-table tbody tr.prow:hover { background: #fafbfc; }
.spec-table td { padding: 9px 16px; }

/* ---------- 数据源状态 ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: #f0f2f5; color: var(--text-2); border: 1px solid transparent;
  white-space: nowrap;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #9aa0ac; }
.pill.live { background: #e8f7ee; color: #1a7f45; }
.pill.live::before { background: #22a35a; }
.pill.off { background: #fff4e6; color: #a06012; }
.pill.off::before { background: #d98a1e; }


/* ---------------- 详情页双栏：左物模型 / 右 H5 ---------------- */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  gap: 18px;
  align-items: start;
}
.split-main { min-width: 0; }
.split-side { position: sticky; top: 12px; }
@media (max-width: 1240px) {
  .split { grid-template-columns: 1fr; }
  .split-side { position: static; }
}

/* ---------------- H5 控制面板 ---------------- */
.h5-panel { overflow: hidden; }
.h5-actions { display: flex; gap: 6px; margin-left: auto; }
.h5-actions .btn { padding: 3px 9px; font-size: 12px; line-height: 1.5; }
.h5-stage {
  display: flex; justify-content: center;
  padding: 14px; background: #eef0f4; overflow: auto;
}
.h5-frame {
  flex: none;
  border-radius: 22px; overflow: hidden; background: #fff;
  border: 8px solid #1c1f24;
  box-shadow: 0 8px 24px rgba(16, 20, 28, .2);
}
.h5-frame iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.h5-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--text-3);
  overflow: hidden;
}
.h5-foot code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h5-foot .hint { margin-left: auto; flex: none; }
@media (max-width: 1240px) {
  .h5-stage { padding: 10px; }
  .h5-frame { border-width: 6px; border-radius: 18px; }
}
/* ---------------- 筛选条 / 空状态 / 禁用项 ---------------- */
.fbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; }
.fchip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--text-2);
  border-radius: 999px; padding: 4px 10px 4px 12px; font-size: 12.5px;
  cursor: pointer; font-family: inherit; line-height: 1.5;
}
.fchip:hover { border-color: var(--accent); color: var(--accent); }
.fchip .x { opacity: .5; font-size: 13px; }
.fchip:hover .x { opacity: 1; }
.fclear { padding: 4px 10px; font-size: 12.5px; }

.side-item.zero { opacity: .38; cursor: not-allowed; }
.side-item.zero:hover { background: transparent; color: var(--text-2); }
.chip.zero { opacity: .38; cursor: not-allowed; }
.chip.zero:hover { border-color: var(--line-strong); color: var(--text-3); }

.empty-filter { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 52px 16px; text-align: center; }
.ef-title { font-weight: 600; font-size: 15.5px; }
.ef-sub { color: var(--text-2); font-size: 13px; max-width: 720px; line-height: 1.75; }
.ef-tip { color: var(--text-3); font-size: 12.5px; }
/* ---------------- 侧栏：手风琴 / 分页 / 组内搜索 ---------------- */
.side-entry .side-item { text-decoration: none; }
.side-cur {
  margin-left: 6px; margin-right: auto; font-weight: 600;
  color: var(--accent); font-size: 11px; letter-spacing: 0;
  text-transform: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62%;
}
.side-sec > h4 { gap: 4px; }
.side-sec > h4 .caret { margin-left: auto; }
.side-sec .side-search { padding: 2px 4px 6px; }
.side-sec .side-search input { padding: 5px 8px; font-size: 12.5px; }
.side-more {
  display: block; width: 100%; text-align: left; padding: 6px 10px;
  font-size: 12px; color: var(--blue); background: none; border: 0;
  cursor: pointer; font-family: inherit; border-radius: 7px;
}
.side-more:hover { background: #f2f4f7; text-decoration: underline; }
/* ---------------- 首页：设备类型横向筛选条 ---------------- */
.type-strip { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; min-width: 0; }
.type-q {
  flex: none; width: 130px; padding: 5px 10px; font-size: 12.5px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: #fff; font-family: inherit; color: var(--text); outline: none;
}
.type-q:focus { border-color: var(--accent); }
.type-chips {
  display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden;
  padding: 2px 2px 6px; min-width: 0; scrollbar-width: thin;
}
.type-chips .chip { flex: none; white-space: nowrap; }
.type-empty { font-size: 12.5px; color: var(--text-3); padding: 6px 2px; white-space: nowrap; }
.type-chips::-webkit-scrollbar { height: 6px; }
.type-chips::-webkit-scrollbar-thumb { background: #d5d9e0; border-radius: 3px; }
/* ---------------- 设备标签放大 ---------------- */
.tag {
  font-size: 12.5px;
  padding: 2px 8px;
  border-radius: 6px;
  line-height: 1.5;
}
.card .tags { gap: 6px; }
.card .meta { gap: 4px; }
.card .sub { font-size: 12px; }
/* ---------------- 设备卡片整体放大 ---------------- */
.grid {
  grid-template-columns: repeat(auto-fill, minmax(258px, 1fr));
  gap: 14px;
}
.card {
  padding: 16px;
  gap: 14px;
  min-height: 112px;
  border-radius: 12px;
}
.card .thumb {
  width: 64px; height: 64px; flex: 0 0 64px;
  border-radius: 12px;
}
.card .thumb img { width: 56px; height: 56px; }
.card .name { font-size: 14.5px; line-height: 1.4; }
.card .sub  { font-size: 12.5px; }
/* ---------------- 已适配 ha-oneconnect-bridge 标记 ---------------- */
.tag.adapt { background: #e8f7ee; color: #14713f; border: 1px solid #c9ebd7; }
.svc-head .tag.adapt { margin-left: 6px; }
/* ---------------- 元数据页内折叠的原始 JSON ---------------- */
.json-fold { margin-top: 16px; }
.json-fold > summary {
  cursor: pointer; user-select: none; list-style: none;
  padding: 10px 16px; font-size: 12.5px; color: var(--text-2);
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
}
.json-fold > summary::-webkit-details-marker { display: none; }
.json-fold > summary::before { content: '▸'; margin-right: 8px; color: var(--text-3); }
.json-fold[open] > summary::before { content: '▾'; }
.json-fold[open] > summary { border-radius: 10px 10px 0 0; border-bottom-color: transparent; }
.json-fold .panel { margin: 0; border-radius: 0 0 10px 10px; }
.json-fold pre.json { max-height: 420px; }