/* =============================================================================
   styles.css —— 管理机运行信息 · 手机监控 PWA（深色 / 移动端）
   负责人：ui-visual
   约束：仅使用 CONTRACT.md 第 2 节设计令牌；无任何外部字体/图片/CDN 依赖。
   ============================================================================= */

/* ---------------------------------------------------------------- 设计令牌 */
:root {
  --bg: #0f1419;
  --panel: #171e26;
  --panel-2: #1b232d;
  --line: #232c37;
  --text: #e9eef6;
  --muted: #8b95a7;
  --dim: #5d6879;
  --green: #2fd06a;
  --amber: #f5b83d;
  --red: #ff5a5f;
  --blue: #4fb6f7;
  --radius: 14px;

  --font: -apple-system, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --tabbar-h: 64px;
}

/* ------------------------------------------------------------------- 基础 */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 520px at 50% -12%, rgba(79, 182, 247, 0.10), transparent 62%),
    radial-gradient(900px 460px at 108% 8%, rgba(47, 208, 106, 0.055), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button,
input,
textarea,
select { font-family: inherit; }

[hidden] { display: none !important; }

svg { display: block; }

/* 数字等宽（全站） */
.num,
input[type="number"] { font-variant-numeric: tabular-nums; }

/* 语义色工具类（数值 / 状态文字复用） */
.is-ok { color: var(--green); }
.is-warn { color: var(--amber); }
.is-err { color: var(--red); }
.is-info { color: var(--blue); }
.is-none { color: var(--dim); }

/* 应用外框 */
.mqx {
  position: relative;
  width: 100%;
  max-width: 560px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
}

/* --------------------------------------------------------------- 顶部栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(180deg, rgba(15, 20, 25, 0.96) 0%, rgba(15, 20, 25, 0.9) 72%, rgba(15, 20, 25, 0.78) 100%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(1.1);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
}

.topbar-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  flex: 1 1 auto;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.brand-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--blue);
  background: rgba(79, 182, 247, 0.12);
  border: 1px solid rgba(79, 182, 247, 0.26);
}

.chip.is-dim {
  color: var(--dim);
  background: rgba(139, 149, 167, 0.09);
  border-color: rgba(139, 149, 167, 0.2);
}

.chip-origin {
  color: var(--amber);
  background: rgba(245, 184, 61, 0.12);
  border-color: rgba(245, 184, 61, 0.3);
}

/* 状态胶囊 */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
  background: rgba(139, 149, 167, 0.1);
  border: 1px solid rgba(139, 149, 167, 0.22);
}

.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
  flex: 0 0 auto;
}

.pill.is-ok {
  color: var(--green);
  background: rgba(47, 208, 106, 0.12);
  border-color: rgba(47, 208, 106, 0.3);
}

.pill.is-warn {
  color: var(--amber);
  background: rgba(245, 184, 61, 0.12);
  border-color: rgba(245, 184, 61, 0.3);
}

.pill.is-err {
  color: var(--red);
  background: rgba(255, 90, 95, 0.13);
  border-color: rgba(255, 90, 95, 0.34);
}

.pill.is-demo {
  color: var(--blue);
  background: rgba(79, 182, 247, 0.12);
  border-color: rgba(79, 182, 247, 0.3);
}

.pill.is-idle {
  color: var(--muted);
  background: rgba(139, 149, 167, 0.1);
  border-color: rgba(139, 149, 167, 0.22);
}

.pill.is-pulse .dot { animation: dotPulse 1.2s ease-in-out infinite; }

@keyframes dotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.72); }
}

/* --------------------------------------------------------------- 报警横幅 */
.alarm-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  color: #ffd9da;
  background: rgba(255, 90, 95, 0.14);
  border: 1px solid rgba(255, 90, 95, 0.42);
  box-shadow: 0 0 0 1px rgba(255, 90, 95, 0.06) inset;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: alarmIn 0.22s ease;
}

.alarm-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  color: var(--red);
}

.alarm-ico svg,
.tab svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes alarmIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ----------------------------------------------------------------- 页面体 */
.pages {
  padding: 12px 16px;
  /* 底部 Tab 栏预留（含 iOS / HarmonyOS 安全区） */
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.page {
  display: none;
  flex-direction: column;
  gap: 10px;
  animation: pageIn 0.16s ease;
}

.page.active { display: flex; }

@keyframes pageIn {
  from { opacity: 0.55; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------------- 卡片 */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
  white-space: nowrap;
}

.card-sub {
  margin-left: 6px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--dim);
  letter-spacing: 0.01em;
}

/* --------------------------------------------------------------- 数据新鲜度 */
.fresh {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fresh-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--muted);
  min-width: 0;
}

.fresh-main {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fresh-main b {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.fresh-ago {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
  white-space: nowrap;
}

.fresh-ago.is-warn { color: var(--amber); }
.fresh-ago.is-err { color: var(--red); }
.fresh-ago.is-ok { color: var(--green); }

.fresh-track {
  position: relative;
  height: 4px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.fresh-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), #6ee8a0);
  box-shadow: 0 0 10px rgba(47, 208, 106, 0.45);
  transition: width 0.9s linear, background 0.3s ease, box-shadow 0.3s ease;
}

.fresh.is-stale .fresh-fill {
  background: linear-gradient(90deg, var(--amber), #ffd27a);
  box-shadow: 0 0 10px rgba(245, 184, 61, 0.4);
}

.fresh.is-offline .fresh-fill {
  background: linear-gradient(90deg, var(--red), #ff9a9d);
  box-shadow: 0 0 10px rgba(255, 90, 95, 0.35);
}

.fresh.is-idle .fresh-fill { width: 0% !important; }

.fresh-hint {
  font-size: 11.5px;
  color: var(--dim);
  min-height: 16px;
  line-height: 1.35;
}

.fresh-hint.is-warn { color: var(--amber); }
.fresh-hint.is-err { color: var(--red); }

/* --------------------------------------------------------------- 双环仪表 */
.gauges {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.gauge-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 10px;
  min-width: 0;
}

.gauge-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 6px;
  padding: 0 2px;
}

.gauge-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}

.gauge-state {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.ring-wrap {
  position: relative;
  width: 100%;
  max-width: 172px;
  aspect-ratio: 1 / 1;
  min-width: 0;
}

.ring-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding-top: 2px;
  pointer-events: none;
}

.ring-value {
  font-size: clamp(26px, 8vw, 33px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.ring-unit {
  align-self: center;
  margin-top: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--dim);
}

.gauge-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  gap: 2px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.gauge-meta > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 0;
}

.gauge-meta .k {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--dim);
}

.gauge-meta .v {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.gauge-card.is-empty .ring-value { animation: breathe 2.4s ease-in-out infinite; }

@keyframes breathe {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ----------------------------------------------------------------- 趋势图 */
.trend-card { padding-bottom: 10px; }

.trend-legend {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.lg {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.lg-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.lg-cpu { background: var(--blue); box-shadow: 0 0 6px rgba(79, 182, 247, 0.7); }
.lg-mem { background: var(--green); box-shadow: 0 0 6px rgba(47, 208, 106, 0.6); }

.trend-wrap {
  position: relative;
  width: 100%;
  height: 134px;
}

.trend-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.trend-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 26px;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--dim);
  pointer-events: none;
  text-shadow: 0 1px 8px rgba(15, 20, 25, 0.85);
}

/* --------------------------------------------------------------- 指标网格 */
.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric-k {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-v {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-v.is-text {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
}

/* ------------------------------------------------------------- 服务状态 */
.services-card .card-head {
  margin-bottom: 2px;
}

.service-count {
  flex: 0 0 auto;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.service-list {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.service-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.service-group + .service-group { margin-top: 2px; }

.service-group-title {
  padding: 8px 0 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--dim);
  line-height: 1.4;
}

.service-group:first-child .service-group-title { padding-top: 2px; }

.service-group-rows {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.service-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.service-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.service-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--dim);
}

.service-dot.on {
  background: var(--green);
  box-shadow: 0 0 8px rgba(47, 208, 106, 0.55);
}

.service-dot.off {
  background: var(--red);
  box-shadow: 0 0 8px rgba(255, 90, 95, 0.4);
}

.service-name {
  flex: 0 0 auto;
  min-width: 0;
  max-width: 58%;
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.service-detail {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.service-row.is-offline .service-name {
  color: var(--muted);
  font-weight: 600;
}

.service-row.is-offline .service-detail {
  color: var(--dim);
}

/* ------------------------------------------------------------- 远程操作 */
.remote-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.remote-flag {
  flex: 0 0 auto;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--dim);
  white-space: nowrap;
}

.remote-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
  min-width: 0;
}

.remote-meta > span {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remote-meta .remote-topic {
  flex: 0 1 auto;
  font-size: 11.5px;
  color: var(--dim);
}

.remote-msg {
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--muted);
  word-break: break-word;
}

.remote-msg.is-warn {
  color: var(--amber);
  background: rgba(245, 184, 61, 0.08);
  border-color: rgba(245, 184, 61, 0.32);
}

.remote-msg.is-ok {
  color: var(--green);
  background: rgba(47, 208, 106, 0.08);
  border-color: rgba(47, 208, 106, 0.32);
}

.remote-msg.is-err {
  color: var(--red);
  background: rgba(255, 90, 95, 0.09);
  border-color: rgba(255, 90, 95, 0.36);
}

.remote-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.remote-hint {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--amber);
}

.btn-danger-solid {
  color: #2a0708;
  background: linear-gradient(180deg, #ff7074, var(--red));
  box-shadow: 0 4px 16px rgba(255, 90, 95, 0.3);
}

/* --------------------------------------------------------- 二次确认弹层 */
body.modal-open { overflow: hidden; }

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  background: rgba(6, 9, 12, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: maskIn 0.18s ease;
}

.modal {
  width: 100%;
  max-width: 350px;
  padding: 20px 18px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.62);
  animation: modalIn 0.2s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.modal-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 12px;
  border-radius: 50%;
  color: var(--red);
  background: rgba(255, 90, 95, 0.12);
  border: 1px solid rgba(255, 90, 95, 0.35);
}

.modal-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  color: var(--text);
}

.modal-body {
  margin-top: 8px;
  font-size: 12.5px;
  line-height: 1.6;
  text-align: center;
  color: var(--muted);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

/* 通用列表弹层（报警明细 / 遥控记录） */
.sheet-modal {
  max-width: 360px;
  padding: 18px 18px 14px;
}

.sheet-title {
  font-size: 15px;
  text-align: left;
}

.sheet-body {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}

.sheet-list {
  margin-top: 8px;
  max-height: min(56vh, 420px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}

.sheet-section {
  padding: 10px 2px 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--dim);
}

.sheet-section:first-child { padding-top: 2px; }

.sheet-empty {
  padding: 6px 2px 10px;
  font-size: 12px;
  color: var(--dim);
}

.sheet-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.sheet-device {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sheet-device:active { background: rgba(255, 255, 255, 0.04); }

.sheet-item-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-item-sub {
  font-size: 11.5px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-log {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  font-size: 12px;
}

.sheet-log-time {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.sheet-log-info {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-log-status {
  flex: 0 0 auto;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.sheet-log-ok .sheet-log-status { color: var(--green); }
.sheet-log-fail .sheet-log-status,
.sheet-log-timeout .sheet-log-status { color: var(--red); }
.sheet-log-pending .sheet-log-status { color: var(--amber); }

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.sheet-actions .btn { flex: 1 1 0; }

/* 下拉刷新指示器 */
.pull-indicator {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(23, 30, 38, 0.96);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.42);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -140%);
  transition: transform 0.18s ease;
}

.pull-indicator.is-visible { transform: translate(-50%, 0); }

@keyframes maskIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* 设置页说明文字 */
.field-note {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--dim);
}

/* ---------------------------------------------------------------- 设备页 */
.dev-sum {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dev-sum-top {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.dev-sum-k {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.dev-sum-num {
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.dev-sum-sep {
  font-size: 15px;
  font-weight: 600;
  color: var(--dim);
}

.dev-sum-total {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dev-sum-fresh {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.dev-sum-sub {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--dim);
}

.dev-search {
  position: relative;
  min-width: 0;
}

.input.dev-search-input {
  padding-left: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b95a7' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.2'/%3E%3Cpath d='m15.2 15.2 4.4 4.4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 13px center;
  background-size: 16px 16px;
}

.dev-search-input::-webkit-search-cancel-button,
.dev-search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.dev-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.dev-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.dev-chip b {
  font-weight: 700;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.dev-chip.active {
  color: var(--blue);
  border-color: rgba(79, 182, 247, 0.42);
  background: rgba(79, 182, 247, 0.12);
}

.dev-chip.active b { color: var(--blue); }

.dev-list-card { padding: 4px 14px; }

.device-list {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.device-row {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  min-height: 44px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  transition: opacity 0.2s ease;
}

.device-row:last-child { border-bottom: 0; }

.device-row.is-offline { opacity: 0.55; }

.device-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  line-height: 18px;
}

.device-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--dim);
}

.device-dot.on {
  background: var(--green);
  box-shadow: 0 0 8px rgba(47, 208, 106, 0.55);
}

.device-dot.off {
  background: var(--red);
  box-shadow: 0 0 8px rgba(255, 90, 95, 0.4);
}

.device-name {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 55%;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-meta {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-sub {
  padding-left: 16px;
  min-width: 0;
  font-size: 12px;
  line-height: 14px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-row.is-offline .device-name { color: var(--muted); }

/* 设备行可点击（打开详情） */
.device-row { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.device-row:active { background: rgba(255, 255, 255, 0.03); }

/* ------------------------------------------------------------ 设备详情覆盖层 */
body.detail-open { overflow: hidden; }

.detail-view {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: detailIn 0.18s ease;
}

@keyframes detailIn {
  from { opacity: 0.4; transform: translateX(14px); }
  to { opacity: 1; transform: translateX(0); }
}

.detail-topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 20, 25, 0.98);
}

.detail-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.detail-back:active { transform: scale(0.96); background: var(--panel-2); }

.detail-back svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.detail-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding-top: 1px;
}

.detail-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.25;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 11.5px;
  color: var(--muted);
}

.detail-sub span {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--dim);
}

.detail-dot.on { background: var(--green); box-shadow: 0 0 8px rgba(47, 208, 106, 0.55); }
.detail-dot.off { background: var(--red); box-shadow: 0 0 8px rgba(255, 90, 95, 0.4); }

.detail-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.detail-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 0 2px;
  font-size: 12px;
  color: var(--muted);
}

.detail-summary-main {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  flex: 1 1 auto;
}

.detail-summary-k {
  min-width: 0;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-sum-note {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

/* 概要行下方的计数说明（遥控 / 去重 / 模板外点位） */
.detail-count-note {
  padding: 0 2px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}

/* 设备详情：遥控卡片 */
.control-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
}

.control-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.control-item + .control-item {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.control-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}

.control-feedback {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
  word-break: break-word;
}

.control-quality.is-err {
  color: var(--red);
  font-weight: 600;
}

.control-actions {
  display: flex;
  gap: 10px;
  margin-top: 2px;
}

.control-actions .control-btn {
  flex: 1 1 0;
  height: 34px;
  font-size: 12.5px;
}

.control-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  font-size: 12px;
  color: var(--muted);
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.control-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.control-error-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--red);
  word-break: break-word;
}

.control-send {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.control-send.is-ok { color: var(--green); }
.control-send.is-warn { color: var(--amber); }
.control-send.is-err { color: var(--red); }

.control-footnote {
  font-size: 11px;
  line-height: 1.45;
  color: var(--dim);
}

/* 模板态：模板名独占一行，第二行放变量/映射/时间，避免时间挤掉关键数字 */
.detail-summary.is-stack {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 2px;
}

.detail-summary.is-stack .detail-summary-k {
  flex: 0 1 auto;
  font-size: 13px;
  font-weight: 650;
  color: var(--text);
}

.detail-summary.is-stack .detail-fresh {
  flex: 0 0 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--dim);
  white-space: nowrap;
}

.detail-fresh {
  flex: 0 0 auto;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.detail-search { flex: 0 0 auto; }

.detail-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
}

.detail-toggle {
  height: 28px;
  padding: 0 11px;
  font-size: 11.5px;
}

.detail-notice {
  flex: 0 0 auto;
  padding: 8px 10px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.4;
}

.detail-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 18px 16px;
}

.spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(79, 182, 247, 0.2);
  border-top-color: var(--blue);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.detail-loading-text {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.detail-skeleton {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.detail-skeleton i {
  display: block;
  height: 38px;
  border-radius: 9px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.04));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -80% 0; }
}

.detail-error {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-color: rgba(255, 90, 95, 0.38);
  background: rgba(255, 90, 95, 0.07);
}

.detail-error-text {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.55;
  color: var(--red);
  word-break: break-word;
}

.detail-list-card { padding: 4px 14px; }

.tag-list {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.tag-row:last-child { border-bottom: 0; }

.tag-row.is-invalid { opacity: 0.5; }

/* 模板变量未映射到设备点位 */
.tag-row.is-unmapped { opacity: 0.55; }
.tag-row.is-unmapped .tag-name { color: var(--muted); }

/* 「其它点位」折叠区（模板外设备点位） */
.tag-extra {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.tag-extra-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tag-extra-toggle .chev {
  width: 12px;
  height: 12px;
  margin-left: auto;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.2s ease;
}

.tag-extra-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }

.tag-extra-list {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tag-extra-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  padding: 7px 0;
  border-top: 1px solid rgba(35, 44, 55, 0.7);
  font-size: 12px;
}

.tag-extra-name {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-weight: 600;
}

.tag-extra-meta {
  flex: 0 0 auto;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tag-extra-val {
  flex: 0 0 auto;
  min-width: 44px;
  text-align: right;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tag-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}

.tag-name-line {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
}

.tag-extra-mark {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.tag-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 18px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.tag-sub {
  font-size: 11.5px;
  line-height: 14px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag-right {
  display: flex;
  align-items: baseline;
  gap: 3px;
  flex: 0 0 auto;
  max-width: 55%;
  min-width: 0;
}

.tag-value {
  font-size: 16px;
  font-weight: 700;
  line-height: 20px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

.tag-unit {
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
  white-space: nowrap;
}

.tag-warn {
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-left: 2px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid rgba(139, 149, 167, 0.55);
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
  font-weight: 700;
  line-height: 1;
}

/* ---------------------------------------------------------------- 端口页 */
.sum-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sum-top {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
}

.sum-num {
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.sum-sep {
  font-size: 16px;
  font-weight: 600;
  color: var(--dim);
}

.sum-total {
  font-size: 16px;
  font-weight: 600;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.sum-label {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.sum-bar {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}

.sum-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), #8ed4ff);
  box-shadow: 0 0 10px rgba(79, 182, 247, 0.4);
  transition: width 0.45s ease;
}

.sum-fill.full {
  background: linear-gradient(90deg, var(--green), #6ee8a0);
  box-shadow: 0 0 10px rgba(47, 208, 106, 0.45);
}

.sum-meta {
  font-size: 11.5px;
  color: var(--dim);
  line-height: 1.4;
  min-height: 16px;
}

/* 端口列表 */
.port-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.port-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px 12px 11px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: opacity 0.2s ease;
  min-width: 0;
}

.port-row.is-offline { opacity: 0.46; }

.port-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.port-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--dim);
}

.port-dot.on {
  background: var(--green);
  box-shadow: 0 0 8px rgba(47, 208, 106, 0.6);
}

.port-dot.off {
  background: var(--red);
  box-shadow: 0 0 8px rgba(255, 90, 95, 0.4);
}

.port-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14.5px;
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.port-type {
  flex: 0 0 auto;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel-2);
}

.port-usage {
  flex: 0 0 auto;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.port-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 11.5px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
}

.port-status {
  font-size: 11.5px;
  font-weight: 600;
  flex: 0 0 auto;
}

.port-status.on { color: var(--green); }
.port-status.off { color: var(--red); }

.port-meta { flex: 0 0 auto; }

.port-meta b {
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.usage-track {
  position: relative;
  height: 5px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}

.usage-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), #6ee8a0);
  transition: width 0.45s ease, background 0.3s ease;
}

.usage-fill.is-warn { background: linear-gradient(90deg, var(--amber), #ffd27a); }
.usage-fill.is-err { background: linear-gradient(90deg, var(--red), #ff9a9d); }

/* 离线端口：默认收起，展开后为紧凑单行（自动优化显示，避免离线占满屏） */
.offline-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.offline-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 11px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.16s ease, color 0.16s ease;
}

.offline-toggle:active { border-color: rgba(255, 90, 95, 0.35); }

.offline-mark {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 7px rgba(255, 90, 95, 0.45);
}

.offline-toggle .chev {
  width: 13px;
  height: 13px;
  margin-left: auto;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.2s ease;
}

.offline-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }

.port-list-compact {
  gap: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.port-row.compact {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-height: 0;
  padding: 11px 12px;
  background: transparent;
  border: 0;
  border-radius: 0;
  opacity: 0.72;
}

.port-row.compact + .port-row.compact {
  border-top: 1px solid var(--line);
}

.port-row.compact .port-dot { width: 7px; height: 7px; }

.port-row.compact .port-name {
  font-size: 13px;
  font-weight: 600;
}

.port-row.compact .port-type { font-size: 9px; }

.port-row.compact .port-status { font-size: 11px; }

.compact-dev {
  margin-left: auto;
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 500;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.port-row.compact .port-status { margin-left: 2px; }

/* ---------------------------------------------------------------- 设置页 */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  min-width: 0;
}

.field:first-of-type { margin-top: 0; }

.field-k {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid2 .field { margin-top: 10px; }

.input {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 9px 12px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  line-height: 1.3;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
  font-variant-numeric: tabular-nums;
}

.input::placeholder { color: var(--dim); opacity: 1; }

.input:focus {
  border-color: rgba(79, 182, 247, 0.55);
  box-shadow: 0 0 0 3px rgba(79, 182, 247, 0.13);
}

.input.mono {
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: -0.01em;
}

.input.textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.5;
  font-size: 13px;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.btn-row {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 43px;
  min-width: 0;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s ease, filter 0.16s ease, opacity 0.16s ease;
  white-space: nowrap;
}

.btn:active { transform: scale(0.977); filter: brightness(0.94); }
.btn:focus { outline: none; }
.btn:focus-visible { outline: 2px solid rgba(79, 182, 247, 0.65); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-primary {
  color: #06141d;
  background: linear-gradient(180deg, #6cc7fb, var(--blue));
  box-shadow: 0 4px 16px rgba(79, 182, 247, 0.24);
}

.btn-ghost {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--line);
}

.btn-danger {
  color: var(--red);
  background: rgba(255, 90, 95, 0.09);
  border-color: rgba(255, 90, 95, 0.32);
}

.btn-sm {
  height: 36px;
  font-size: 12.5px;
  padding: 0 14px;
}

.btn-block {
  width: 100%;
  margin-top: 10px;
}

/* 演示开关 */
.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 12px;
  padding: 10px 12px;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.switch-track {
  position: relative;
  width: 44px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #2a3442;
  border: 1px solid var(--line);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.switch-track i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s ease, background 0.2s ease;
}

.switch[aria-checked="true"] .switch-track {
  background: rgba(47, 208, 106, 0.22);
  border-color: rgba(47, 208, 106, 0.5);
}

.switch[aria-checked="true"] .switch-track i {
  transform: translateX(18px);
  background: var(--green);
  box-shadow: 0 0 10px rgba(47, 208, 106, 0.7);
}

.switch-txt {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.switch-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview {
  margin: 10px 0 0;
  padding: 10px 12px;
  max-height: 220px;
  overflow: auto;
  background: #10161d;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.55;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}

/* 关于 */
.about-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 0;
  border-bottom: 1px dashed rgba(35, 44, 55, 0.85);
  font-size: 12px;
  color: var(--muted);
}

.about-row:last-child { border-bottom: 0; padding-bottom: 0; }

.about-row b {
  font-weight: 600;
  color: var(--text);
  text-align: right;
  min-width: 0;
  word-break: break-word;
}

/* ---------------------------------------------------------------- 空状态 */
.empty-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 18px 20px;
  text-align: center;
}

.empty-ico {
  position: relative;
  width: 46px;
  height: 46px;
  margin-bottom: 2px;
  border-radius: 50%;
  border: 1px solid rgba(79, 182, 247, 0.3);
  background: radial-gradient(circle at 50% 50%, rgba(79, 182, 247, 0.14), transparent 70%);
}

.empty-ico::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1px solid rgba(79, 182, 247, 0.4);
  animation: radar 2.2s ease-out infinite;
}

.empty-ico i {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 12px rgba(79, 182, 247, 0.8);
}

@keyframes radar {
  0% { transform: scale(0.85); opacity: 0.85; }
  70% { transform: scale(1.5); opacity: 0; }
  100% { transform: scale(1.5); opacity: 0; }
}

.empty-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.empty-sub {
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--dim);
  max-width: 300px;
}

.empty-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

/* ---------------------------------------------------------------- 底部 Tab */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: stretch;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  box-sizing: content-box;
  max-width: 560px;
  margin: 0 auto;
  background: rgba(15, 20, 25, 0.88);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(1.15);
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
}

.tab {
  position: relative;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--tabbar-h);
  padding: 0;
  border: 0;
  background: none;
  color: var(--dim);
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.16s ease;
}

.tab svg {
  width: 21px;
  height: 21px;
  stroke-width: 1.75;
}

.tab.active { color: var(--blue); }

.tab.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 26px;
  height: 2px;
  transform: translateX(-50%);
  border-radius: 0 0 2px 2px;
  background: var(--blue);
  box-shadow: 0 0 10px rgba(79, 182, 247, 0.75);
}

/* ---------------------------------------------------------------- Toast */
.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}

.toast {
  max-width: min(92vw, 420px);
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(23, 30, 38, 0.97);
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.show { opacity: 1; transform: translateY(0); }

.toast-ok {
  color: #c4f7d7;
  border-color: rgba(47, 208, 106, 0.42);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48), 0 0 0 1px rgba(47, 208, 106, 0.08) inset;
}

.toast-warn {
  color: #ffe8b8;
  border-color: rgba(245, 184, 61, 0.42);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48), 0 0 0 1px rgba(245, 184, 61, 0.08) inset;
}

.toast-err {
  color: #ffc9cb;
  border-color: rgba(255, 90, 95, 0.5);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48), 0 0 0 1px rgba(255, 90, 95, 0.1) inset;
}

/* ------------------------------------------------------------ 窄屏 / 横屏 */
@media (max-width: 359px) {
  .pages { padding-left: 12px; padding-right: 12px; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .gauges { gap: 8px; }
  .metrics { gap: 8px; }
  .metric { padding: 9px 10px; }
  .metric-v { font-size: 17px; }
  .port-usage { font-size: 11.5px; }
  .grid2 { grid-template-columns: 1fr; }
  .btn-row { grid-template-columns: 1fr; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .ring-wrap { max-width: 132px; }
  .trend-wrap { height: 108px; }
  .tabbar { height: 56px; }
  .pages { padding-bottom: calc(56px + env(safe-area-inset-bottom) + 6px); }
}

/* 减少动态效果 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ------------------------------------------------------- 语义色工具类（置底）
   放在组件之后，确保 .is-* 能覆盖组件默认文字色（同等特异性、后者生效）。 */
.is-ok { color: var(--green); }
.is-warn { color: var(--amber); }
.is-err { color: var(--red); }
.is-info { color: var(--blue); }
.is-none { color: var(--dim); }

/* =============================================================================
   浅色主题（data-theme="light"；户外强光下保证对比度）
   ============================================================================= */
[data-theme="light"] {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-2: #f4f7fb;
  --line: #d7e0ea;
  --text: #17222f;
  --muted: #4f5f72;
  --dim: #78889b;
  --green: #0d9b52;
  --amber: #b56a00;
  --red: #d72f3a;
  --blue: #0f6fc4;
}

html[data-theme="light"] body {
  background:
    radial-gradient(1200px 520px at 50% -12%, rgba(15, 111, 196, 0.07), transparent 62%),
    radial-gradient(900px 460px at 108% 8%, rgba(13, 155, 82, 0.05), transparent 60%),
    var(--bg);
}

html[data-theme="light"] .topbar {
  background: linear-gradient(180deg, rgba(238, 242, 247, 0.97) 0%, rgba(238, 242, 247, 0.92) 72%, rgba(238, 242, 247, 0.76) 100%);
}

html[data-theme="light"] .detail-topbar { background: rgba(238, 242, 247, 0.98); }
html[data-theme="light"] .tabbar { background: rgba(248, 250, 253, 0.94); }

html[data-theme="light"] .pull-indicator {
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 8px 24px rgba(16, 32, 48, 0.16);
}

html[data-theme="light"] .toast {
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 12px 32px rgba(16, 32, 48, 0.18);
}

html[data-theme="light"] .modal { box-shadow: 0 24px 60px rgba(16, 32, 48, 0.22); }

html[data-theme="light"] .card {
  box-shadow: 0 1px 2px rgba(16, 32, 48, 0.05), 0 8px 20px rgba(16, 32, 48, 0.05);
}

html[data-theme="light"] .device-row:active,
html[data-theme="light"] .sheet-device:active { background: rgba(15, 32, 48, 0.05); }

html[data-theme="light"] .trend-empty { text-shadow: none; }

html[data-theme="light"] .detail-skeleton i {
  background: linear-gradient(90deg, rgba(15, 32, 48, 0.05), rgba(15, 32, 48, 0.10), rgba(15, 32, 48, 0.05));
}

html[data-theme="light"] .alarm-banner {
  color: #9d1c24;
  background: rgba(215, 47, 58, 0.09);
  border-color: rgba(215, 47, 58, 0.32);
}

html[data-theme="light"] .theme-chip.active { box-shadow: 0 1px 3px rgba(16, 32, 48, 0.14); }

/* -------------------------------------------------------- 主题选择（设置页） */
.theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0 12px;
}

.theme-k {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.theme-chips {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.theme-chip {
  padding: 5px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.theme-chip.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

/* ------------------------------------------------- 概览右栏端口摘要（平板） */
.ov-ports-card { display: none; }

.ov-ports-count {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ov-ports-list {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ov-port {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  min-width: 0;
}

.ov-port:last-child { border-bottom: 0; }
.ov-port.is-empty { font-size: 12px; color: var(--dim); border-bottom: 0; }

.ov-port-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dim);
}

.ov-port-dot.on { background: var(--green); box-shadow: 0 0 6px rgba(47, 208, 106, 0.45); }
.ov-port-dot.off { background: var(--red); }

.ov-port-name {
  min-width: 0;
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ov-port-meta {
  flex: 0 0 auto;
  margin-left: auto;
  color: var(--dim);
  font-size: 11px;
  white-space: nowrap;
}

/* =============================================================================
   平板 / 大屏两栏布局（断点：min-width 900px）
   手机端（< 900px）完全保持原布局
   ============================================================================= */
@media (min-width: 900px) {
  .mqx { max-width: 1200px; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  .pages { padding: 18px 24px calc(64px + env(safe-area-inset-bottom)); }
  .tabbar { max-width: 1200px; }
  .modal, .sheet-modal { max-width: 560px; }

  /* ---------------- 概览：左「状态+指标+趋势」，右「端口+服务」 ---------------- */
  .page[data-page="overview"].active {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
    grid-template-areas:
      "fresh services"
      "gauges services"
      "metrics ports"
      "trend remote";
    gap: 12px;
    align-items: start;
  }

  .page[data-page="overview"] > .fresh { grid-area: fresh; }
  .page[data-page="overview"] > .gauges { grid-area: gauges; }
  .page[data-page="overview"] > .metrics { grid-area: metrics; }
  .page[data-page="overview"] > .trend-card { grid-area: trend; }
  .page[data-page="overview"] > .services-card { grid-area: services; }
  .page[data-page="overview"] > .ov-ports-card { grid-area: ports; display: flex; flex-direction: column; gap: 10px; }
  .page[data-page="overview"] > .remote-card { grid-area: remote; }
  .page[data-page="overview"] > .empty-card { grid-column: 1 / -1; }

  .page[data-page="overview"] .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  /* ---------------- 端口页：端口卡片两栏 ---------------- */
  .page[data-page="ports"] .port-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: start;
  }

  /* ---------------- 设备页：搜索/筛选横排，列表两栏 ---------------- */
  .page[data-page="devices"].active {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "sum sum"
      "search chips"
      "list list"
      "empty empty";
    gap: 12px;
    align-items: start;
  }

  .page[data-page="devices"] > .dev-sum { grid-area: sum; }
  .page[data-page="devices"] > .dev-search { grid-area: search; }
  .page[data-page="devices"] > .dev-chips { grid-area: chips; align-self: center; margin: 0; flex-wrap: nowrap; }
  .page[data-page="devices"] > #devListCard { grid-area: list; }
  .page[data-page="devices"] > #devicesEmpty { grid-area: empty; }
  .page[data-page="devices"] .device-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20px; }

  /* ---------------- 设备详情：左点位、右遥控卡 ---------------- */
  .detail-topbar {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding-left: 24px;
    padding-right: 24px;
  }

  .detail-body {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
    grid-template-areas:
      "summary summary"
      "note note"
      "search control"
      "toggle control"
      "notice control"
      "list control"
      "empty control";
    gap: 12px;
    align-items: start;
  }

  .detail-body > #detailSummaryRow { grid-area: summary; }
  .detail-body > #detailCountNote { grid-area: note; }
  .detail-body > .detail-search { grid-area: search; }
  .detail-body > #detailToggleRow { grid-area: toggle; }
  .detail-body > #detailNotice { grid-area: notice; }
  .detail-body > #detailListCard { grid-area: list; }
  .detail-body > #detailEmpty { grid-area: empty; }
  .detail-body > #controlCard { grid-area: control; position: sticky; top: 84px; }
  .detail-body > #detailLoading,
  .detail-body > #detailError { grid-column: 1 / -1; }
}

/* =============================================================================
   v8：设备三态徽标 / 端口新卡片（device_list 快照）
   ============================================================================= */
.device-dot.disabled {
  background: var(--dim);
  box-shadow: none;
}

.device-badge {
  flex: 0 0 auto;
  font-size: 10.5px;
  line-height: 14px;
  font-weight: 600;
  padding: 0 6px;
  border-radius: 999px;
  white-space: nowrap;
}

.device-badge.is-ok { color: var(--green); background: rgba(47, 208, 106, 0.12); }
.device-badge.is-err { color: var(--red); background: rgba(255, 90, 95, 0.12); }
.device-badge.is-dim { color: var(--dim); background: rgba(139, 149, 167, 0.12); }

.device-row.is-disabled { opacity: 0.6; }
.device-row.is-disabled .device-name { color: var(--muted); }
.device-row.is-disabled .device-badge { opacity: 1; }

.port-proto {
  flex: 0 0 auto;
  font-size: 10.5px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.port-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
}

.port-badge {
  flex: 0 0 auto;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 10px;
  line-height: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.port-badge.is-ok { color: var(--green); background: rgba(47, 208, 106, 0.12); }
.port-badge.is-err { color: var(--red); background: rgba(255, 90, 95, 0.13); }
.port-badge.is-warn { color: var(--amber); background: rgba(245, 184, 61, 0.14); }
.port-badge.is-dim { color: var(--dim); background: rgba(139, 149, 167, 0.13); }

.port-stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  min-width: 0;
  font-size: 11.5px;
  color: var(--dim);
}

.port-stat { flex: 0 0 auto; white-space: nowrap; }

.port-stat b {
  color: var(--muted);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.port-error {
  min-width: 0;
  font-size: 10.5px;
  line-height: 14px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.port-row.is-disabled { opacity: 0.6; }

.port-row.compact .port-badge { font-size: 10px; }
.port-row.compact .port-badge.is-dim { color: var(--dim); }

/* =============================================================================
   强调色（data-accent；green 不写属性，即默认绿色方案）
   ============================================================================= */
[data-accent="blue"] { --green: #4fb6f7; --blue: #7cc4ff; }
[data-accent="cyan"] { --green: #22d3ee; --blue: #5eead4; }
[data-accent="orange"] { --green: #ff9f43; --blue: #ffc36b; }
[data-accent="purple"] { --green: #a78bfa; --blue: #c4b5fd; }

/* 浅色主题下用更深一档，保证白底对比度 */
html[data-theme="light"][data-accent="blue"] { --green: #0f6fc4; --blue: #2f86d6; }
html[data-theme="light"][data-accent="cyan"] { --green: #0e7490; --blue: #1497b0; }
html[data-theme="light"][data-accent="orange"] { --green: #b45309; --blue: #c2740f; }
html[data-theme="light"][data-accent="purple"] { --green: #6d28d9; --blue: #7c4ddb; }

/* 强调色选择器 */
.accent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 0 12px;
}

.accent-chips {
  display: flex;
  align-items: center;
  gap: 8px;
}

.accent-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--panel-2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.accent-chip.active {
  border-color: var(--text);
  transform: scale(1.06);
}

.accent-swatch {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.sw-green { background: #2fd06a; }
.sw-blue { background: #4fb6f7; }
.sw-cyan { background: #22d3ee; }
.sw-orange { background: #ff9f43; }
.sw-purple { background: #a78bfa; }

/* 主色语义组件跟随强调色（圆点光晕 / 徽标底色 / 进度条 / 主按钮） */
.device-dot.on,
.port-dot.on,
.detail-dot.on {
  box-shadow: 0 0 8px color-mix(in srgb, var(--green) 55%, transparent);
}

.ov-port-dot.on,
.lg-mem {
  box-shadow: 0 0 6px color-mix(in srgb, var(--green) 52%, transparent);
}

.device-badge.is-ok,
.port-badge.is-ok {
  background: color-mix(in srgb, var(--green) 14%, transparent);
}

.pill.is-ok {
  background: color-mix(in srgb, var(--green) 12%, transparent);
  border-color: color-mix(in srgb, var(--green) 32%, transparent);
}

.fresh-fill,
.sum-fill,
.usage-fill {
  background: linear-gradient(90deg, var(--green), color-mix(in srgb, var(--green) 62%, #fff));
}

.btn-primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--blue) 70%, #fff), var(--blue));
  box-shadow: 0 4px 16px color-mix(in srgb, var(--blue) 30%, transparent);
}

/* =============================================================================
   平板竖屏中间断点（768–899px）：轻量两栏，避免与 900px+ 完整两栏互相影响
   ============================================================================= */
@media (min-width: 768px) and (max-width: 899px) {
  .mqx { max-width: 900px; }
  .topbar { padding-left: 20px; padding-right: 20px; }
  .pages { padding: 16px 20px calc(64px + env(safe-area-inset-bottom)); }
  .tabbar { max-width: 900px; }
  .modal, .sheet-modal { max-width: 560px; }

  /* 概览：左主区 + 右窄栏（右栏最小 300px） */
  .page[data-page="overview"].active {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(300px, 1fr);
    grid-template-areas:
      "fresh services"
      "gauges services"
      "metrics ports"
      "trend remote";
    gap: 12px;
    align-items: start;
  }

  .page[data-page="overview"] > .fresh { grid-area: fresh; }
  .page[data-page="overview"] > .gauges { grid-area: gauges; }
  .page[data-page="overview"] > .metrics { grid-area: metrics; }
  .page[data-page="overview"] > .trend-card { grid-area: trend; }
  .page[data-page="overview"] > .services-card { grid-area: services; min-width: 0; }
  .page[data-page="overview"] > .ov-ports-card { grid-area: ports; display: flex; flex-direction: column; gap: 10px; }
  .page[data-page="overview"] > .remote-card { grid-area: remote; }
  .page[data-page="overview"] > .empty-card { grid-column: 1 / -1; }

  /* 设备页：搜索/筛选横排 + 列表两列（每列约 360px） */
  .page[data-page="devices"].active {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "sum sum"
      "search chips"
      "list list"
      "empty empty";
    gap: 12px;
    align-items: start;
  }

  .page[data-page="devices"] > .dev-sum { grid-area: sum; }
  .page[data-page="devices"] > .dev-search { grid-area: search; }
  .page[data-page="devices"] > .dev-chips { grid-area: chips; align-self: center; margin: 0; flex-wrap: nowrap; }
  .page[data-page="devices"] > #devListCard { grid-area: list; }
  .page[data-page="devices"] > #devicesEmpty { grid-area: empty; }
  .page[data-page="devices"] .device-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 18px; }

  /* 端口页：卡片两列 */
  .page[data-page="ports"] .port-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: start;
  }

  /* 设备详情：保持单栏（不套用 900px 的 grid 两栏） */
}

/* =============================================================================
   v13：变量统计卡（概览「指标」之后）
   ============================================================================= */
.ov-vars { display: flex; flex-direction: column; gap: 10px; }

.var-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px 10px;
  min-width: 0;
}

.var-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.var-k {
  font-size: 11px;
  line-height: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.var-v {
  font-size: 16px;
  line-height: 20px;
  font-weight: 650;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.var-v.is-none { color: var(--dim); }

/* 768+ 一行 5 项；同时把概览 grid 增加 vars 行（覆盖前面的 areas 定义） */
@media (min-width: 768px) {
  .var-stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (min-width: 768px) and (max-width: 899px) {
  .page[data-page="overview"].active {
    grid-template-areas:
      "fresh services"
      "gauges services"
      "metrics ports"
      "vars ports"
      "trend remote";
  }
  .page[data-page="overview"] > .ov-vars { grid-area: vars; }
}

@media (min-width: 900px) {
  .page[data-page="overview"].active {
    grid-template-areas:
      "fresh services"
      "gauges services"
      "metrics ports"
      "vars ports"
      "trend remote";
  }
  .page[data-page="overview"] > .ov-vars { grid-area: vars; }
}

/* =============================================================================
   v14：遥控行（模板遥控变量进入点位列表）
   ============================================================================= */
.tag-ctrl {
  flex: 0 0 auto;
  margin-left: 1px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 10px;
  line-height: 15px;
  font-weight: 600;
  color: var(--blue);
  background: color-mix(in srgb, var(--blue) 13%, transparent);
  white-space: nowrap;
}

.tag-row.is-control-row .tag-value {
  font-variant-numeric: normal;
}

.tag-row.is-control-row .tag-sub {
  color: var(--dim);
}

/* =============================================================================
   v16：设置页默认只读（点「修改」后可编辑）
   ============================================================================= */
.settings-edit-btn {
  margin-left: auto;
  height: 28px;
  padding: 0 12px;
  font-size: 12px;
  flex: 0 0 auto;
}

.settings-ro-hint {
  padding: 0 0 10px;
  margin-top: -2px;
}

.settings-form .input:disabled {
  cursor: not-allowed;
  opacity: 1;
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
  background: color-mix(in srgb, var(--panel-2) 62%, var(--bg));
  border-color: var(--line);
}

html[data-theme="light"] .settings-form .input:disabled {
  background: #eef2f7;
  color: #6b7a8c;
  -webkit-text-fill-color: #6b7a8c;
}

.settings-form .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  filter: grayscale(0.35);
}

.settings-form.is-readonly .field-k {
  color: var(--muted);
}
