/* OD-LAYOUT-PRIMITIVES v1 — structure only: display, flex/grid, overflow, wrapping, ratio, geometry.
   Put this @layer first; product CSS outside the layer wins ordinary layout rules.
   Native hidden and closed-dialog states take precedence over component display rules. */
@layer od-layout {
  [hidden]:not([hidden="until-found" i]) { display: none !important; }
  dialog:not([open]) { display: none !important; }

  :where(.od-stack,.od-row,.od-row-top,.od-cluster,.od-grid,.od-field,.od-stat,.od-cell,.od-tile) > :where(*) { min-width: 0; }

  .od-stack   { display: flex; flex-direction: column; gap: var(--od-gap, 8px); }
  .od-row     { display: flex; align-items: center; gap: var(--od-gap, 8px); }
  .od-row-top { display: flex; align-items: flex-start; gap: var(--od-gap, 8px); }
  .od-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--od-gap, 8px); }
  .od-fill    { flex: 1 1 0; min-width: 0; }
  .od-fixed   { flex: none; }
  .od-grid    { display: grid; gap: var(--od-gap, 12px); grid-template-columns: repeat(var(--od-cols, 3), minmax(0, 1fr)); }

  .od-stat, .od-field, .od-cell { display: grid; gap: var(--od-gap, 2px); }
  :where(.od-stat,.od-field,.od-cell) > :where(*) { display: block; }
  .od-tile { display: grid; grid-template-rows: auto 1fr; }
  :where(.od-tile) > :where(*) { display: block; }

  .od-media { display: block; width: 100%; height: auto; aspect-ratio: var(--od-ratio, auto); }
  .od-media-cover { object-fit: cover; }

  .od-icon { display: inline-block; inline-size: var(--od-icon-size, 1em); block-size: var(--od-icon-size, 1em); flex: none; }

  .od-truncate { display: block; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .od-clamp-2, .od-clamp-3 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
  .od-clamp-2 { -webkit-line-clamp: 2; }
  .od-clamp-3 { -webkit-line-clamp: 3; }
  .od-lines-2 { min-height: calc(2 * 1.4em); }
  .od-nowrap  { white-space: nowrap; }
  .od-keep    { word-break: keep-all; overflow-wrap: anywhere; }

  .od-screen { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
  .od-scroll { overflow-y: auto; overscroll-behavior: contain; min-height: 0; }

  .od-rail { display: flex; gap: var(--od-gap, 8px); overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none;
             padding-inline: var(--od-rail-pad, 16px); scroll-padding-inline: var(--od-rail-pad, 16px); }
  .od-rail::-webkit-scrollbar { display: none; }
  :where(.od-rail) > :where(*) { flex: none; scroll-snap-align: start; }
  :where(.od-rail) > :where(:last-child) { margin-inline-end: var(--od-rail-pad, 16px); }

  .od-spacer { flex: none; visibility: hidden; pointer-events: none; }
  .od-touch  { min-width: 44px; min-height: 44px; }
}
:root [hidden]:where(:not([hidden="until-found" i])) { display: none; }
/* /OD-LAYOUT-PRIMITIVES v1 */

/* ───────── 设计令牌：精密工业测控台（日光浅色默认） ───────── */
:root {
  color-scheme: light;
  --bg: #EEF2F6;
  --surface: #FFFFFF;
  --surface-2: #F6F8FB;
  --surface-3: #E6ECF2;
  --line: #D7E0EA;
  --line-strong: #B6C3D1;

  --text: #0F172A;
  --text-2: #475569;
  --text-3: #64748B;

  --accent: #0B5FD4;
  --accent-hover: #094CAD;
  --accent-soft: #E8F1FD;
  --accent-line: #B5D2FA;

  --ok: #0F7B4D;
  --ok-soft: #E5F6EE;
  --ok-line: #8FD4B4;
  --warn: #9A5B00;
  --warn-soft: #FEF4DF;
  --warn-line: #E6BD6A;
  --bad: #C02624;
  --bad-soft: #FCEAEA;
  --bad-line: #EEABA9;

  --dirty: #FFF9E6;
  --dirty-line: #D48A00;
  --dirty-text: #6D4200;

  --nav-bg: #0E1726;
  --nav-surface: #162235;
  --nav-border: #203048;
  --nav-text: #D7E0EC;
  --nav-muted: #8698AF;
  --nav-active-bg: rgba(59, 130, 246, 0.16);
  --nav-active-fg: #FFFFFF;
  --nav-accent: #60A5FA;

  --log-bg: #0B121D;
  --log-fg: #D5E0EC;
  --log-border: #1C293D;

  --font-ui: "Segoe UI Variable Text", "Segoe UI", "PingFang SC", "Microsoft YaHei UI", "Noto Sans SC", sans-serif;
  --font-title: "Segoe UI Variable Display", "PingFang SC", "Microsoft YaHei UI", "Noto Sans SC", sans-serif;
  --font-mono: "Cascadia Mono", "JetBrains Mono", Consolas, "Microsoft YaHei UI", monospace;

  --fs-xs: 12.5px;
  --fs-sm: 13.5px;
  --fs-md: 15px;
  --fs-lg: 19px;
  --fs-xl: 26px;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 12px 30px rgba(15, 23, 42, 0.14);
  --shadow-lg: 0 22px 54px rgba(15, 23, 42, 0.24);
  --sticky-shadow: 3px 0 8px -3px rgba(15, 23, 42, 0.12);

  --focus: 0 0 0 3px rgba(11, 95, 212, 0.25);
  --t-fast: 140ms;
  --t-mid: 210ms;
}

/* ───────── 夜间机房模式令牌 ───────── */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090F19;
  --surface: #111A29;
  --surface-2: #172235;
  --surface-3: #1E2C42;
  --line: #25344B;
  --line-strong: #374A67;

  --text: #EEF3F9;
  --text-2: #A6B4C8;
  --text-3: #7A8CA5;

  --accent: #3B82F6;
  --accent-hover: #2563EB;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --accent-line: rgba(96, 165, 250, 0.42);

  --ok: #34D399;
  --ok-soft: rgba(16, 185, 129, 0.16);
  --ok-line: rgba(52, 211, 153, 0.42);
  --warn: #FBBF24;
  --warn-soft: rgba(245, 158, 11, 0.16);
  --warn-line: rgba(251, 191, 36, 0.42);
  --bad: #F87171;
  --bad-soft: rgba(239, 68, 68, 0.16);
  --bad-line: rgba(248, 113, 113, 0.45);

  --dirty: rgba(245, 158, 11, 0.13);
  --dirty-line: #F59E0B;
  --dirty-text: #FCD34D;

  --nav-bg: #070C15;
  --nav-surface: #0F1828;
  --nav-border: #1C2A40;
  --nav-text: #D7E0EC;
  --nav-muted: #7F92AA;
  --nav-active-bg: rgba(59, 130, 246, 0.2);
  --nav-active-fg: #FFFFFF;
  --nav-accent: #60A5FA;

  --log-bg: #060A12;
  --log-fg: #D5E0EC;
  --log-border: #1C293D;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-sm: 0 3px 10px rgba(0, 0, 0, 0.32);
  --shadow-md: 0 14px 36px rgba(0, 0, 0, 0.46);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.62);
  --sticky-shadow: 4px 0 10px -2px rgba(0, 0, 0, 0.45);
  --focus: 0 0 0 3px rgba(59, 130, 246, 0.38);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
h1, h2, h3, h4 { margin: 0; font-family: var(--font-title); font-weight: 600; line-height: 1.28; letter-spacing: -0.01em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, select, input, label { touch-action: manipulation; -webkit-tap-highlight-color: rgba(11, 95, 212, 0.14); }
body.drawer-open { overflow: hidden; }
code, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.small { font-size: var(--fs-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ───────── 主框架布局 ───────── */
.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "nav top" "nav main";
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ───────── 侧边栏导航 ───────── */
.sidebar {
  grid-area: nav;
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--nav-border);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.03);
}
.brand {
  padding: var(--s-4) var(--s-4) 14px;
  border-bottom: 1px solid var(--nav-border);
}
.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}
.brand-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #1D4ED8 0%, #0EA5E9 100%);
  color: #FFFFFF;
  flex: none;
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  --od-icon-size: 18px;
}
.brand-text { min-width: 0; }
.brand-title {
  font-family: var(--font-title);
  font-size: 16.5px;
  font-weight: 700;
  color: #FFFFFF;
  line-height: 1.2;
}

.nav-drawer-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--nav-border);
  border-radius: var(--radius-sm);
  background: var(--nav-surface);
  color: var(--nav-text);
  cursor: pointer;
  --od-icon-size: 18px;
  flex: none;
}
.nav-drawer-close:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--nav-accent); }
.nav-backdrop, .conn-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 13, 23, 0.56);
  backdrop-filter: blur(2px);
}
.nav-backdrop { z-index: 40; }
.conn-backdrop { z-index: 28; }

.mobile-bar { display: none; }
.mobile-menu-btn { position: relative; padding: 4px 8px; }
.drawer-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #F59E0B;
  color: #1B1200;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}
.mobile-brand { display: flex; align-items: center; gap: 7px; min-width: 0; flex: 1 1 auto; }
.mobile-title {
  font-family: var(--font-title);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mobile-actions { display: flex; align-items: center; gap: 6px; flex: none; }

.nav {
  padding: 10px 10px 14px;
  overflow-y: auto;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-group-label {
  padding: 12px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--nav-muted);
  opacity: 0.85;
  user-select: none;
}
.nav-group-label:first-child { padding-top: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 39px;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--nav-text);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  --od-icon-size: 18px;
  position: relative;
  transition: background var(--t-fast) ease, color var(--t-fast) ease, border-color var(--t-fast) ease;
}
.nav-item .od-icon { color: var(--nav-muted); transition: color var(--t-fast) ease; }
.nav-item[aria-current="page"] {
  background: var(--nav-active-bg);
  border-color: rgba(96, 165, 250, 0.26);
  color: var(--nav-active-fg);
  font-weight: 600;
}
.nav-item[aria-current="page"] .od-icon { color: var(--nav-accent); }
.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--nav-accent);
  box-shadow: 0 0 10px rgba(96, 165, 250, 0.65);
}
.nav-item:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--nav-accent); }
.nav-badge {
  margin-left: auto;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #F59E0B;
  color: #1A1100;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  line-height: 19px;
}

.sidebar-bottom {
  border-top: 1px solid var(--nav-border);
  background: rgba(0, 0, 0, 0.16);
}
.sidebar-tools {
  padding: 10px 12px 0;
}
.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--nav-border);
  border-radius: var(--radius-sm);
  background: var(--nav-surface);
  color: var(--nav-text);
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  --od-icon-size: 15px;
  transition: background var(--t-fast) ease, border-color var(--t-fast) ease, color var(--t-fast) ease;
}
.theme-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--nav-accent); }
.sidebar-foot {
  padding: 10px 14px 12px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--nav-muted);
}

@media (hover: hover) {
  .nav-item:hover { background: var(--nav-surface); color: #FFFFFF; }
  .nav-item:hover .od-icon { color: #CBD5E1; }
  .theme-btn:hover { background: #1E2E47; border-color: #364B6C; color: #FFFFFF; }
}

/* ───────── 顶部指挥栏 ───────── */
.topbar {
  grid-area: top;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px 18px;
  padding: 10px var(--s-5);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
  z-index: 10;
}
.conn {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 10px;
  min-width: 0;
}
.conn .field { min-width: 0; gap: 3px; }
.conn .field > label { font-size: 11.5px; font-weight: 600; color: var(--text-3); letter-spacing: 0.01em; }
.conn .field-port { flex: 1 1 200px; max-width: 310px; }
.conn .field-short { width: 78px; flex: 0 0 78px; }
.conn .field-mid { width: 108px; flex: 0 0 108px; }
.conn-actions { display: flex; align-items: flex-end; gap: 6px; flex: none; }
.link-state { display: flex; align-items: center; min-height: 36px; white-space: nowrap; }

.save-zone {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
  margin-top: 18px;
  padding: 4px 0;
}
.save-zone.has-dirty {
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--dirty);
  border: 1px solid var(--dirty-line);
}
.save-progress { font-size: var(--fs-sm); color: var(--text-2); max-width: 280px; }

/* ───────── 主区与页面容器 ───────── */
.main {
  grid-area: main;
  overflow-y: auto;
  min-height: 0;
  scroll-behavior: smooth;
}
.page {
  padding: var(--s-5);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-4);
  align-content: start;
  max-width: 1580px;
  margin-inline: auto;
}
.page > * { min-width: 0; }
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-3);
}
.page-head h1 { font-size: var(--fs-xl); color: var(--text); }
.page-head p { color: var(--text-2); font-size: var(--fs-sm); margin-top: 3px; }
.page-tools { display: flex; flex-wrap: wrap; gap: var(--s-2); }

.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  overflow: clip;
}
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2) var(--s-3);
  min-height: 52px;
  padding: 10px var(--s-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.section-head h2 { font-size: 16.5px; font-weight: 600; color: var(--text); }
.section-head .hint { font-size: var(--fs-sm); color: var(--text-2); }
.section-head .btn.small { min-height: 29px; padding-block: 3px; }
.section-body { padding: var(--s-4); }
.section-body.flush { padding: 0; }

.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); align-items: stretch; }
.cols-2 > .section { margin-bottom: 0; display: flex; flex-direction: column; }
.cols-2 > .section > .section-body { flex: 1 1 auto; }
.stack-gap { display: grid; gap: var(--s-4); margin-bottom: var(--s-4); }

/* ───────── KPI 仪表卡片 ───────── */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s-3);
}
.kpi {
  position: relative;
  padding: 14px var(--s-4);
  display: grid;
  gap: 4px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}
.kpi::before {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  top: 0;
  height: 2px;
  border-radius: 0 0 2px 2px;
  background: linear-gradient(90deg, var(--accent) 0%, transparent 100%);
  opacity: 0.45;
}
.kpi-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-2);
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: clamp(20px, 1.8vw, 24px);
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-foot {
  font-size: var(--fs-xs);
  color: var(--text-3);
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ───────── 定义列表 Facts ───────── */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: 0 var(--s-5); margin: 0; }
.fact {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s-3);
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
  min-width: 0;
}
.fact:last-child { border-bottom: 0; }
.fact dt { color: var(--text-2); font-size: var(--fs-sm); flex: none; }
.fact dd {
  margin: 0;
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text);
  min-width: 0;
  overflow-wrap: anywhere;
}
.fact dd.has-copy { display: inline-flex; align-items: center; gap: 4px; justify-content: flex-end; min-width: 0; }
.fact dd.has-copy .fact-val { min-width: 0; overflow-wrap: anywhere; }

/* ───────── 状态胶囊（颜色 + 形状 + 文字） ───────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text-2);
  font-family: var(--font-ui);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.pill.ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.pill.ok::before { box-shadow: 0 0 6px currentColor; }
.pill.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.pill.warn::before { border-radius: 1px; transform: rotate(45deg); }
.pill.bad { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }
.pill.bad::before {
  border-radius: 1px;
  width: 8px;
  height: 8px;
  clip-path: polygon(20% 0, 50% 30%, 80% 0, 100% 20%, 70% 50%, 100% 80%, 80% 100%, 50% 70%, 20% 100%, 0 80%, 30% 50%, 0 20%);
}
.pill.idle { background: var(--surface-2); border-color: var(--line); color: var(--text-2); }
.pill.idle::before { background: transparent; border: 2px solid currentColor; }
.pill.busy { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.pill.busy::before { border: 2px solid currentColor; border-right-color: transparent; background: transparent; animation: spin 900ms linear infinite; }

/* ───────── 表单与控件 ───────── */
.field { display: grid; gap: 4px; min-width: 0; align-content: start; }
.field > label, .field > .label {
  font-size: var(--fs-sm);
  color: var(--text-2);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field .req { color: var(--bad); margin-left: 2px; }
.field .help { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.45; }
.field .error { font-size: var(--fs-xs); color: var(--bad); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s-4); align-items: start; }
.form-grid .wide { grid-column: 1 / -1; }

.input, .select {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-md);
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease, background var(--t-fast) ease;
}
.input.mono, .select.mono { font-family: var(--font-mono); }
.input:focus-visible, .select:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input:disabled, .select:disabled { background: var(--surface-2); border-color: var(--line); color: var(--text-3); cursor: not-allowed; opacity: 0.78; }
.input[readonly] { background: var(--surface-2); color: var(--text-2); }
.is-dirty {
  background: var(--dirty) !important;
  border-color: var(--dirty-line) !important;
  box-shadow: inset 3px 0 0 var(--dirty-line);
}
.is-invalid { border-color: var(--bad) !important; box-shadow: 0 0 0 2px rgba(192, 38, 36, 0.2); }

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}

.check { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; min-height: 36px; font-size: var(--fs-sm); }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }
.check.is-dirty { background: var(--dirty); outline: 1px solid var(--dirty-line); border-radius: var(--radius-sm); padding: 0 var(--s-2); }

.switch { position: relative; display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; min-height: 36px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: var(--line-strong);
  position: relative;
  transition: background var(--t-fast) ease-out;
  flex: none;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.14);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform var(--t-fast) ease-out;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }
.switch.is-dirty .switch-track { outline: 2px solid var(--dirty-line); outline-offset: 2px; }

.range-row { display: flex; align-items: center; gap: var(--s-3); }
.range-row input[type="range"] { flex: 1 1 auto; accent-color: var(--accent); min-width: 0; cursor: pointer; }
.range-row .input { width: 88px; flex: none; }

/* ───────── 按钮 ───────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast) ease, border-color var(--t-fast) ease, color var(--t-fast) ease, transform var(--t-fast) ease;
  --od-icon-size: 16px;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #FFFFFF; box-shadow: 0 1px 2px rgba(11, 95, 212, 0.25); }
.btn.danger { background: var(--surface); border-color: var(--bad-line); color: var(--bad); }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #FFFFFF; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--surface-2); border-color: var(--line); color: var(--text-3); box-shadow: none; cursor: not-allowed; }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: var(--fs-xs); --od-icon-size: 14px; }
.btn.icon-only { padding-inline: 8px; }
.btn .spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 800ms linear infinite; }
@media (hover: hover) {
  .btn:not(:disabled):hover { background: var(--surface-2); border-color: var(--text-3); }
  .btn.primary:not(:disabled):hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #FFFFFF; }
  .btn.danger:not(:disabled):hover { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
  .btn.danger-solid:not(:disabled):hover { filter: brightness(0.92); color: #FFFFFF; }
  .btn.ghost:not(:disabled):hover { background: var(--accent-soft); color: var(--accent-hover); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── 表格与首列冻结 ───────── */
.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; position: relative; }
.table-scroll-hint {
  display: none;
  position: sticky;
  left: 0;
  padding: 5px 12px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-line);
}
#hj-instruments .input { min-width: 8ch; }
#hj-instruments [data-field$=".serial"] { min-width: 26ch; }
#hj-instruments [type="datetime-local"] { min-width: 21ch; }

table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.grid.sticky-col thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--surface-2);
  box-shadow: var(--sticky-shadow), 1px 0 0 var(--line);
}
table.grid.sticky-col tbody :is(th, td):first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: var(--sticky-shadow), 1px 0 0 var(--line);
}
table.grid.sticky-col tbody tr.off :is(th, td):first-child { background: var(--surface); }
table.grid.sticky-col tbody tr.dragging :is(th, td):first-child { background: var(--accent-soft); }

table.grid td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}
table.grid tbody tr:last-child td,
table.grid tbody tr:last-child th { border-bottom: 0; }
@media (hover: hover) {
  table.grid tbody tr:not(.dragging):hover td,
  table.grid tbody tr:not(.dragging):hover th { background: var(--surface-2); }
  table.grid.sticky-col tbody tr:not(.dragging):hover :is(th, td):first-child { background: var(--surface-2); }
}
table.grid tbody th { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; font-weight: 600; white-space: nowrap; }
table.grid td.mono, table.grid td .mono { font-family: var(--font-mono); }
table.grid td.r, table.grid th.r { text-align: right; }
table.grid tbody tr.off td { color: var(--text-3); }
table.grid .input, table.grid .select { min-height: 32px; padding: 4px 8px; font-size: 14px; }
table.grid .select { padding-right: 26px; }
table.grid .w-xs { width: 64px; }
table.grid .w-sm { width: 88px; }
table.grid .w-md { width: 112px; }
table.grid .w-lg { width: 140px; }
table.grid .error { display: block; margin-top: 2px; font-size: var(--fs-xs); color: var(--bad); font-weight: 600; white-space: normal; }
table.grid .io-state { white-space: nowrap; }
table.grid .check { min-height: 32px; }
table.grid td .cell-error { max-width: 190px; line-height: 1.3; }
.scroll-y { max-height: 540px; overflow: auto; }

/* ───────── IO 指示灯 ───────── */
.lamp {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: transparent;
  flex: none;
  transition: background var(--t-fast) ease, border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}
.lamp.on {
  background: var(--ok);
  border-color: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}
.io-state { display: flex; align-items: center; gap: var(--s-2); font-weight: 600; }

/* ───────── 空状态引导工作台 ───────── */
.empty {
  display: grid;
  gap: var(--s-4);
  max-width: 900px;
  padding: var(--s-5) var(--s-6);
  margin: var(--s-5) auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.empty-hero {
  display: flex;
  align-items: flex-start;
  gap: var(--s-4);
}
.empty-hero-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  flex: none;
  --od-icon-size: 26px;
}
.empty-hero-copy { display: grid; gap: 4px; min-width: 0; }
.empty-kicker {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.empty h1 { font-size: 22px; }
.empty p { color: var(--text-2); max-width: 68ch; }
.empty-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-3);
}
.empty-steps li {
  counter-increment: step;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  line-height: 1.6;
  color: var(--text);
}
.empty-steps li::before {
  content: "0" counter(step);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-xs);
  width: fit-content;
  padding: 1px 7px;
}
.empty-actions-panel {
  display: grid;
  gap: var(--s-3);
  padding: var(--s-4);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.empty-actions-notes { display: grid; gap: 4px; }
.empty-progress { display: flex; align-items: center; gap: var(--s-2); color: var(--accent); font-weight: 600; }
.empty .banner { width: 100%; }

/* ───────── 提示条 Banner ───────── */
.banner {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  padding: 12px var(--s-4);
  border-radius: var(--radius);
  border: 1px solid;
  --od-icon-size: 19px;
}
.banner.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.banner.bad { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }
.banner.info { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.banner .od-icon { margin-top: 2px; }
.banner a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.banner a:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; border-radius: 2px; }
.banner ul { margin: 4px 0 0; padding-left: 18px; }
.errors-list { list-style: none; padding: 0 !important; display: grid; gap: 4px; }
.errors-list button { width: 100%; justify-content: flex-start; text-align: left; white-space: normal; }

/* ───────── 固件升级 ───────── */
.dropzone {
  display: grid;
  justify-items: center;
  gap: var(--s-2);
  padding: var(--s-5);
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
  background: var(--surface-2);
  cursor: pointer;
  --od-icon-size: 28px;
  transition: border-color var(--t-fast) ease, background var(--t-fast) ease;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-visible { outline: none; box-shadow: var(--focus); }
.progress { height: 10px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; border: 1px solid var(--line); }
.progress-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, #38BDF8 100%);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform var(--t-mid) ease-out;
}
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); }
.steps li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: var(--fs-sm);
  color: var(--text-3);
  --od-icon-size: 18px;
}
.steps li.active { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); font-weight: 600; }
.steps li.done { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-line); }
.steps li.failed { color: var(--bad); background: var(--bad-soft); border-color: var(--bad-line); font-weight: 600; }

/* ───────── 收发报文终端 ───────── */
.log {
  font-family: var(--font-mono);
  font-size: 13px;
  max-height: 440px;
  overflow: auto;
  background: var(--log-bg);
  color: var(--log-fg);
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 6px 0;
  -webkit-overflow-scrolling: touch;
}
.log-row {
  display: grid;
  grid-template-columns: 98px 46px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--s-2) var(--s-3);
  padding: 4px var(--s-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.log-row .t { color: #7C8FA6; white-space: nowrap; }
.log-row .d-tx { color: #60A5FA; font-weight: 700; white-space: nowrap; }
.log-row .d-rx { color: #34D399; font-weight: 700; white-space: nowrap; }
.log-row .d-err { color: #F87171; font-weight: 700; white-space: nowrap; }
.log-row .b { overflow-wrap: anywhere; min-width: 0; }
.log-row .n { color: #9FB1C8; }
.log-empty { padding: var(--s-4); color: #9FB1C8; font-family: var(--font-ui); }
.log-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px var(--s-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.log-filter .select.small { width: auto; min-height: 32px; font-size: var(--fs-xs); }
.log-filter .input.small { flex: 1 1 200px; min-height: 32px; font-size: var(--fs-xs); }
.log-row .log-copy {
  flex: none;
  margin-left: auto;
  opacity: 0.65;
  color: #9FB1C8;
  padding: 2px 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
}
.log-row:hover .log-copy, .log-row .log-copy:focus-visible { opacity: 1; border-color: #354760; color: #F1F5F9; }

/* ───────── 弹窗与 Toast ───────── */
dialog.modal {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  background: var(--surface);
}
dialog.modal::backdrop { background: rgba(7, 12, 21, 0.58); backdrop-filter: blur(2px); }
dialog.modal[open] { display: flex; flex-direction: column; animation: dialog-in var(--t-mid) ease-out; }
.modal.wide { width: min(760px, calc(100vw - 32px)); }
.modal-head { flex: none; padding: var(--s-4) var(--s-5) 10px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: var(--fs-lg); }
.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--s-4) var(--s-5);
  color: var(--text-2);
  display: grid;
  gap: var(--s-3);
  align-content: start;
}
.modal-body ul { margin: 0; padding-left: 20px; max-height: 260px; overflow: auto; }
.modal-foot {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: 12px var(--s-5) var(--s-4);
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
#dlg-hj-board section { border-top: 1px solid var(--line); padding-top: var(--s-3); }
.hj-board-value {
  display: block;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }

.toasts { position: fixed; right: var(--s-5); bottom: var(--s-5); display: grid; gap: var(--s-2); z-index: 55; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto;
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  padding: 12px var(--s-4);
  border-radius: var(--radius);
  background: #0F172A;
  border: 1px solid #263449;
  color: #F1F5F9;
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  animation: toast-in var(--t-mid) ease-out;
  --od-icon-size: 18px;
}
.toast.ok .od-icon { color: #34D399; }
.toast.bad .od-icon { color: #F87171; }
.toast.warn .od-icon { color: #FBBF24; }
.toast.info .od-icon { color: #60A5FA; }
.toast.leaving { animation: toast-out 150ms ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* ───────── 拖拽排序 ───────── */
.slot { display: flex; align-items: center; gap: var(--s-2); }
.slot-text { display: grid; line-height: 1.3; }
.moved-note { font-size: 11.5px; color: var(--warn); font-weight: 600; white-space: nowrap; }
.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 28px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-3);
  cursor: grab;
  touch-action: none;
  --od-icon-size: 18px;
}
.drag-handle:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--focus); color: var(--accent); }
@media (hover: hover) {
  .drag-handle:hover { background: var(--surface-3); color: var(--text); }
}
body.is-sorting, body.is-sorting * { cursor: grabbing !important; user-select: none; }
table.grid tr.dragging td { background: var(--accent-soft); }
table.grid tr.dragging .drag-handle { color: var(--accent); }
table.grid tr.drop-before td { box-shadow: inset 0 3px 0 var(--accent); }
table.grid tr.drop-after td { box-shadow: inset 0 -3px 0 var(--accent); }

/* ───────── 批量添加轮询 & 探测 ───────── */
#dlg-batch { width: min(640px, calc(100vw - 32px)); }
#dlg-batch .form-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--s-3); }
#pb-preview { color: var(--text); line-height: 1.7; }
.pb-error { color: var(--bad); font-weight: 600; }

#dlg-probe { width: min(560px, calc(100vw - 32px)); }
#dlg-probe .form-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--s-3); }
.probe-hit {
  padding: var(--s-3);
  border: 1px solid var(--ok-line);
  border-radius: var(--radius);
  background: var(--ok-soft);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

/* ───────── 轮询合并标记 & 寄存器占用图 ───────── */
table.grid td.merge-cell { white-space: nowrap; }
.merge-cell { font-size: var(--fs-sm); }
.merge-tag {
  display: inline-block;
  padding: 0 6px;
  margin-right: 6px;
  border-radius: var(--radius-xs);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
  line-height: 20px;
}
.merge-meta { color: var(--text-2); }
.merge-single { color: var(--text-3); }

.poll-map-wrap {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  display: grid;
  gap: 8px;
  font-size: var(--fs-xs);
}
.poll-map-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; color: var(--text-2); }
.poll-map-track {
  position: relative;
  height: 24px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.poll-map-seg {
  position: absolute;
  top: 2px;
  bottom: 2px;
  border-radius: 3px;
  background: var(--accent);
  opacity: 0.9;
  color: #FFFFFF;
  font-size: 10px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  padding: 0 3px;
  cursor: pointer;
}
.poll-map-seg:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; z-index: 3; }
.poll-map-seg.alt { background: #0284C7; }
.poll-map-seg.gnss { background: var(--ok); }
.poll-map-seg.conflict { background: var(--bad); opacity: 0.95; z-index: 2; }
.poll-map-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-3);
  line-height: 1;
}
.poll-map-legend { display: flex; flex-wrap: wrap; gap: 12px; color: var(--text-2); }
.poll-map-dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

.row-actions { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.row-actions .btn.small { min-height: 28px; padding: 2px 8px; font-size: 12px; }
.addr-hint { display: block; margin-top: 2px; font-size: 11px; color: var(--text-2); white-space: nowrap; }
.addr-hint.warn { color: var(--warn); font-weight: 600; }
.progress-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: var(--fs-sm); }

/* ───────── 刷新控制、一键复制、离线编辑与 Diff ───────── */
.poll-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 6px 2px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  min-height: 36px;
}
.poll-bar[hidden] { display: none; }
.poll-bar .select.small { min-height: 28px; padding: 2px 24px 2px 8px; width: auto; font-size: var(--fs-xs); }
.poll-bar .btn.small { min-height: 28px; padding: 2px 7px; }

.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  vertical-align: middle;
  margin-left: 4px;
  padding: 3px 5px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  --od-icon-size: 13px;
}
.copy-btn:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--focus); color: var(--accent); }
@media (hover: hover) {
  .copy-btn:hover { background: var(--surface-3); border-color: var(--line); color: var(--accent); }
}

.offline-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: 10px var(--s-5);
  border-bottom: 1px solid var(--warn-line);
  background: var(--warn-soft);
  font-size: var(--fs-sm);
}
.offline-bar[hidden] { display: none; }
.offline-bar-info { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }

.diff-wrap {
  max-height: 310px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: var(--s-2) 0;
  background: var(--surface);
}
.diff-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.diff-table th, .diff-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.diff-table th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-2); font-weight: 600; white-space: nowrap; }
.diff-table tr:last-child td { border-bottom: 0; }
.diff-old { color: var(--bad); text-decoration: line-through; opacity: 0.85; word-break: break-all; }
.diff-new { color: var(--ok); font-weight: 600; word-break: break-all; }
.diff-arrow { color: var(--text-3); padding: 0 5px; }

/* ───────── 交付状态辅助 ───────── */
.skip-link {
  position: absolute;
  left: var(--s-2);
  top: -48px;
  z-index: 100;
  padding: var(--s-2) var(--s-3);
  background: var(--accent);
  color: #FFFFFF;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: var(--s-2); outline: 2px solid #FFFFFF; outline-offset: 2px; }

.spinner {
  display: inline-block;
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
.btn[aria-busy="true"] { pointer-events: none; }
.btn[aria-busy="true"] > .od-icon { display: none; }
.btn[aria-busy="true"]::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
  flex: none;
}
.btn:not(:disabled):active { transform: translateY(1px); }

.table-empty { padding: var(--s-4); color: var(--text-2); font-size: var(--fs-sm); }
#ov-sub.stale { color: var(--warn); font-weight: 600; }

/* ───────── 多端响应式适配：桌面 / 平板 / 手机 / 横屏 / 触控 ───────── */

/* 1. 桌面宽屏（>= 1440px）：舒适留白与 5 列 KPI 平铺 */
@media (min-width: 1440px) {
  .page { padding: var(--s-5) var(--s-6); }
  .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* 2. 中等桌面（<= 1240px）：侧栏略窄，两栏内容更宽裕 */
@media (max-width: 1240px) {
  .app { grid-template-columns: 228px minmax(0, 1fr); }
  .topbar { padding: 10px var(--s-4); }
}

/* 3. 中小屏与平板共用：两栏合并单栏 + 宽表格滑行提示 */
@media (max-width: 1180px) {
  .cols-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .table-scroll-hint { display: block; }
}

/* 4. 平板端（769px ~ 1180px 且非手机横屏）：88px 图标+文字导航轨 + 整齐双层顶栏 */
@media (max-width: 1180px) and (min-width: 769px) and (min-height: 521px) {
  .app { grid-template-columns: 88px minmax(0, 1fr); }
  .brand { padding: 12px 8px; }
  .brand-row { justify-content: center; }
  .brand-identity { justify-content: center; }
  .brand-text, .nav-group-label, .sidebar-foot { display: none; }
  .nav { padding: 8px 6px; gap: 3px; }
  .nav-item {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    min-height: 56px;
    text-align: center;
    --od-icon-size: 19px;
  }
  .nav-item[aria-current="page"]::before { left: 0; top: 10px; bottom: 10px; }
  .nav-label { font-size: 11.5px; line-height: 1.15; white-space: nowrap; }
  .nav-badge {
    position: absolute;
    top: 3px;
    right: 4px;
    margin-left: 0;
    min-width: 18px;
    line-height: 17px;
    font-size: 11px;
    padding: 0 4px;
  }
  .sidebar-tools { padding: 8px 10px 10px; }
  .theme-btn { padding: 6px; min-height: 38px; --od-icon-size: 17px; }
  .theme-label { display: none; }

  .topbar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; padding: 10px 16px; gap: 8px 12px; }
  .conn { width: 100%; gap: 6px 8px; }
  .conn .field-port { flex: 1 1 180px; max-width: none; }
  .conn .field-mid { width: 98px; flex: 0 0 98px; }
  .conn .field-short { width: 68px; flex: 0 0 68px; }
  .conn .input, .conn .select, .conn .btn, .save-zone .btn { min-height: 34px; }
  .save-zone { margin-left: auto; margin-top: 0; }

  .page { padding: var(--s-4); }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .facts { grid-template-columns: repeat(auto-fill, minmax(275px, 1fr)); }
  .form-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .empty { margin: var(--s-4); padding: var(--s-5); }
  .empty-steps { grid-template-columns: minmax(0, 1fr); }
}

/* 5. 手机竖屏 / 小平板（<= 768px）与手机横屏（max-height: 520px and max-width: 960px）：
      自然文档滚动 + 54px 粘性顶栏 + 悬浮参数面板 + 粘性快切胶囊 + 抽屉导航 + 底部悬浮保存 Dock */
@media (max-width: 768px), (max-height: 520px) and (max-width: 960px) {
  .app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  /* 顶部栏：54px 紧凑粘性栏；参数面板作为绝对定位下拉浮层展开，不推动下方快切栏 */
  .topbar {
    order: 1;
    position: sticky;
    top: 0;
    z-index: 30;
    display: block;
    padding: 0;
    padding-top: env(safe-area-inset-top);
    box-shadow: var(--shadow-xs);
  }
  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px calc(12px + env(safe-area-inset-right)) 7px calc(12px + env(safe-area-inset-left));
    min-height: 54px;
    background: var(--surface);
  }
  .mobile-brand { gap: 6px; }
  .mobile-title { font-size: 14.5px; flex: 0 1 auto; }
  .mobile-bar .pill { font-size: 11px; padding: 2px 7px; flex-shrink: 1; max-width: 116px; overflow: hidden; text-overflow: ellipsis; }
  .mobile-bar .btn.small { min-height: 36px; padding: 4px 10px; font-size: var(--fs-xs); }
  .mobile-bar .btn.icon-only { min-width: 36px; padding: 4px 8px; }
  .mobile-bar .mobile-menu-btn { padding: 4px 9px; }
  .topbar.conn-open #m-conn-toggle {
    background: var(--accent-soft);
    border-color: var(--accent-line);
    color: var(--accent);
  }

  .conn {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 31;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    align-items: end;
    padding: 12px calc(12px + env(safe-area-inset-right)) 14px calc(12px + env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line-strong);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    max-height: calc(100dvh - 64px - env(safe-area-inset-top));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .topbar.conn-open .conn { display: grid; }
  .conn .field-port, .conn .conn-actions, .conn .poll-bar { grid-column: 1 / -1; max-width: none; width: auto; }
  .conn .field-short, .conn .field-mid { width: auto; flex: none; }
  .conn .conn-actions { flex-wrap: wrap; }
  .conn .conn-actions .btn { flex: 1 1 120px; }
  .conn .link-state { display: none; }
  .conn .poll-bar { justify-content: space-between; width: 100%; }

  /* 未修改时隐藏保存区；有改动或保存中吸底悬浮，预留安全区 */
  .save-zone { display: none; }
  .save-zone.has-dirty, .save-zone.is-saving {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 32;
    margin-left: 0;
    margin-top: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding: 10px calc(12px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
    background: var(--surface);
    border-top: 1px solid var(--line-strong);
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.16);
    gap: 8px;
    justify-content: space-between;
  }
  .save-zone .save-progress { width: 100%; max-width: none; text-align: center; }
  .save-zone .btn { flex: 1 1 0; min-height: 44px; }

  /* 侧边栏默认形态：顶栏正下方横向快切胶囊导航 */
  .sidebar {
    order: 2;
    position: sticky;
    top: calc(54px + env(safe-area-inset-top));
    z-index: 20;
    flex-direction: row;
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--nav-border);
  }
  .sidebar .brand, .sidebar .nav-group-label, .sidebar .sidebar-bottom { display: none; }
  .sidebar .nav {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 5px;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    padding: 6px calc(10px + env(safe-area-inset-right)) 6px calc(10px + env(safe-area-inset-left));
  }
  .sidebar .nav::-webkit-scrollbar { display: none; }
  .sidebar .nav-item {
    flex: none;
    width: auto;
    min-height: 36px;
    min-width: 44px;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    scroll-snap-align: start;
    font-size: var(--fs-sm);
    --od-icon-size: 16px;
  }
  .sidebar .nav-badge { margin-left: 2px; min-width: 18px; line-height: 17px; font-size: 11px; padding: 0 5px; }
  .sidebar .nav-item[aria-current="page"]::before { display: none; }

  /* 侧边栏展开形态：从左侧滑出的全高抽屉 */
  .sidebar.drawer-open {
    position: fixed;
    inset: 0 auto 0 0;
    top: 0;
    width: min(296px, 85vw);
    height: 100vh;
    height: 100dvh;
    z-index: 45;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    border-right: 1px solid var(--nav-border);
    border-bottom: 0;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.drawer-open .brand { display: block; padding: 14px var(--s-4); }
  .sidebar.drawer-open .nav-drawer-close { display: inline-flex; }
  .sidebar.drawer-open .nav-group-label { display: block; }
  .sidebar.drawer-open .sidebar-bottom { display: block; }
  .sidebar.drawer-open .nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 10px;
    scroll-snap-type: none;
  }
  .sidebar.drawer-open .nav-item {
    width: 100%;
    min-height: 44px;
    padding: 8px 12px;
    gap: 10px;
    border-radius: var(--radius-sm);
    font-size: var(--fs-md);
    --od-icon-size: 18px;
  }
  .sidebar.drawer-open .nav-badge { margin-left: auto; }
  .sidebar.drawer-open .nav-item[aria-current="page"]::before {
    display: block;
    left: -1px;
    right: auto;
    top: 8px;
    bottom: 8px;
    width: 3px;
    height: auto;
  }

  /* 主内容区：页面级自然滚动 */
  .main {
    order: 3;
    overflow: visible;
    flex: 1 0 auto;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
  body.has-mobile-dock .main { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }

  .offline-bar { padding: 10px 12px; gap: 8px; }
  .offline-bar .od-cluster { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }

  .empty { margin: var(--s-3); padding: var(--s-4); gap: var(--s-3); }
  .empty-hero { gap: var(--s-3); }
  .empty-hero-badge { width: 44px; height: 44px; border-radius: 12px; --od-icon-size: 22px; }
  .empty h1 { font-size: 20px; }
  .empty-steps { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .empty-actions-panel { padding: var(--s-3); }
  .empty-actions { width: 100%; }
  .empty-actions .btn { flex: 1 1 180px; }

  .page {
    padding: var(--s-3) calc(12px + env(safe-area-inset-right)) var(--s-4) calc(12px + env(safe-area-inset-left));
    gap: var(--s-3);
  }
  .page-head { gap: var(--s-2); }
  .page-head h1 { font-size: 21px; }
  .page-tools { width: 100%; }
  .page-tools .btn { flex: 1 1 auto; }

  .section-head { padding: 10px 12px; min-height: 46px; }
  .section-head h2 { font-size: 15.5px; }
  .section-body { padding: var(--s-3); }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 18px; }
  .kpis > .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }

  .facts { grid-template-columns: minmax(0, 1fr); }
  .fact { flex-wrap: wrap; row-gap: 2px; }
  .fact dd { text-align: left; }
  .fact dd.has-copy { justify-content: flex-start; }

  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
  .field > label, .field > .label { white-space: normal; }
  .poll-map-wrap { padding: var(--s-2) var(--s-3); }
  .poll-map-track { height: 26px; }
  .poll-map-seg { line-height: 20px; font-size: 11px; }

  /* 防止 iOS Safari 聚焦输入框自动放大 */
  .input, .select, textarea, table.grid .input, table.grid .select { font-size: 16px; }

  /* 报文日志卡片化两行展示 */
  .log { max-height: 55dvh; font-size: 12.5px; }
  .log-filter { padding: var(--s-2) var(--s-3); }
  .log-filter .input.small { flex: 1 1 100%; }
  .log-row {
    grid-template-columns: auto auto 1fr;
    gap: 2px 8px;
    padding: 7px var(--s-3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  }
  .log-row .b { grid-column: 1 / -1; }
  .log-row .log-copy { grid-column: 3; grid-row: 1; justify-self: end; opacity: 0.9; padding: 2px 8px; }

  /* 弹窗全宽适配安全区 */
  dialog.modal, .modal.wide, #dlg-probe, #dlg-batch {
    width: calc(100vw - 16px);
    max-width: none;
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
  }
  .modal-head { padding: var(--s-3) var(--s-4); }
  .modal-body { padding: var(--s-3) var(--s-4); }
  .modal-foot { padding: var(--s-3) var(--s-4) calc(var(--s-3) + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1 1 auto; }

  .toasts {
    left: calc(12px + env(safe-area-inset-left));
    right: calc(12px + env(safe-area-inset-right));
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
  }
  body.has-mobile-dock .toasts { bottom: calc(78px + env(safe-area-inset-bottom)); }
}

/* 6. 窄屏手机（<= 640px）：操作配置型表格转为清晰卡片列表，零横向滚动 */
@media (max-width: 640px) {
  #m-theme-toggle { display: none; }
  .mobile-bar .m-conn-label { display: none; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .range-row { flex-wrap: wrap; }
  .range-row .input { width: 100%; }

  table.grid.mobile-cards { display: block; width: 100%; }
  table.grid.mobile-cards thead { display: none; }
  table.grid.mobile-cards tbody { display: grid; gap: 10px; padding: 10px; }
  table.grid.mobile-cards tbody:empty { display: none; }
  table.grid.mobile-cards tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
  }
  table.grid.mobile-cards tbody th,
  table.grid.mobile-cards tbody td {
    display: grid;
    gap: 4px;
    padding: 0;
    border: 0;
    white-space: normal;
    text-align: left;
    min-width: 0;
    background: transparent !important;
  }
  table.grid.mobile-cards tbody td[data-label]::before {
    content: attr(data-label);
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-3);
  }

  /* DI / 继电器卡片排布 */
  #di-grid tr, #relay-grid tr { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  #di-grid th, #relay-grid th { font-size: 15px; color: var(--text); }
  #di-grid td:nth-child(2)::before, #relay-grid td:nth-child(2)::before { display: none; }
  #di-grid td:nth-child(3), #relay-grid td:nth-child(3),
  #di-grid td:nth-child(4), #relay-grid td:nth-child(4),
  #di-grid td:nth-child(5), #relay-grid td:nth-child(5) { grid-column: 1 / -1; }
  #di-grid td:nth-child(3), #relay-grid td:nth-child(3) {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 6px;
    border-top: 1px dashed var(--line);
  }
  #relay-grid td:nth-child(4) .od-cluster { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  #relay-grid td:nth-child(4) .btn { min-height: 42px; }

  /* 串口参数卡片 */
  #port-config td:nth-child(1), #port-config td:nth-child(2) {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding-bottom: 6px;
    border-bottom: 1px dashed var(--line);
  }
  #port-config td:nth-child(1)::before, #port-config td:nth-child(2)::before { display: none; }
  #port-config td:nth-child(2) { justify-content: flex-end; color: var(--text-2); font-size: var(--fs-xs); }
  #port-config .w-xs, #port-config .w-sm, #port-config .w-md { width: 100%; }

  /* 仪表标识卡片：取消桌面 ch 最小宽度，避免窄屏撑爆 */
  #hj-instruments .input,
  #hj-instruments [data-field$=".serial"],
  #hj-instruments [type="datetime-local"] { min-width: 0; width: 100%; }
  #hj-instruments tr { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  #hj-instruments td:first-child { display: flex; align-items: center; gap: 6px; font-weight: 700; font-family: var(--font-mono); }
  #hj-instruments td:first-child::before { content: "槽位 #"; font-family: var(--font-ui); }
  #hj-instruments td:nth-child(2),
  #hj-instruments td:nth-child(3),
  #hj-instruments td:nth-child(4) { grid-column: 1 / -1; }
  #hj-instruments td:last-child { grid-column: 2; grid-row: 1; }
  #hj-instruments td:last-child::before { display: none; }

  /* 操作记录卡片 */
  #oplog tr { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  #oplog td:nth-child(1)::before, #oplog td:nth-child(4)::before { display: none; }
  #oplog td:nth-child(2), #oplog td:nth-child(3), #oplog td:nth-child(5) { grid-column: 1 / -1; }
  #oplog td:nth-child(4) { grid-column: 2; grid-row: 1; justify-self: end; }
  #oplog td:nth-child(2), #oplog td:nth-child(3) { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

  /* Diff 对比表卡片（修复原标签映射错误） */
  .diff-table thead { display: none; }
  .diff-table tbody, .diff-table tr, .diff-table td { display: block; width: 100%; }
  .diff-table tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .diff-table tr:last-child { border-bottom: 0; }
  .diff-table td { border: 0; padding: 2px 0; }
  .diff-table td:first-child { font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); }
  .diff-table td:nth-child(2) { font-weight: 600; color: var(--text); }
  .diff-table td[data-label]:nth-child(3)::before {
    content: attr(data-label) "：";
    color: var(--text-3);
    font-family: var(--font-ui);
    font-weight: 500;
    margin-right: 4px;
  }
  .diff-wrap { max-height: 45dvh; }
}

/* 7. 手机横屏细调（高度 <= 520px 且宽度 <= 960px） */
@media (max-height: 520px) and (max-width: 960px) {
  .scroll-y { max-height: none; }
  .log { max-height: 240px; }
  .conn { grid-template-columns: repeat(4, minmax(0, 1fr)); max-height: 70dvh; }
  .conn .field-port { grid-column: span 2; }
  .conn .conn-actions, .conn .poll-bar { grid-column: span 2; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis > .kpi:last-child:nth-child(odd) { grid-column: auto; }
  .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* 8. 触屏设备通用 ergonomics（手机、iPad、触屏工控本） */
@media (pointer: coarse) {
  .btn, .input, .select { min-height: 44px; font-size: 16px; }
  .btn.small { min-height: 38px; }
  table.grid .input, table.grid .select { min-height: 40px; font-size: 16px; }
  .drag-handle { width: 40px; height: 44px; }
  .check { min-height: 44px; }
  .copy-btn { min-width: 36px; min-height: 36px; padding: 4px 6px; }
  .log-row .log-copy { opacity: 0.9; padding: 3px 8px; }
  .poll-map-track { height: 28px; }
  .poll-map-seg { line-height: 22px; }
}
