/* ═══════════════════════════════════════════════════════════
 * 設備佈建 devices.html — 2026-05 大改版
 *
 * 範圍鎖在 #page-devices 內;載入順序在 style.css 之後。
 * 舊 .device-card / .layer-toggle 規則保留(其他 partial 還沒升版會碰到)。
 * ═══════════════════════════════════════════════════════════ */

/* 舊版 KPI 卡 / .layer-toggle 仍保留(legacy support)*/
.layer-toggle {
  padding: 5px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.layer-toggle:hover { color: var(--ink); border-color: var(--ink); }
.layer-toggle.active { background: var(--ink); color: var(--ink-inverse); border-color: var(--ink); }

.device-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: border-color 0.15s;
}
.device-card:hover { border-color: var(--ink); }
.device-card.selected {
  border: 2px solid var(--accent-blue);
  padding: 13px 15px;
}

/* ═══════════════════════════════════════════════════════════
 * 2026-05 大改版 — 4-cell KPI strip / 覆蓋分析 / 設備規格 / 變更時間軸
 * ═══════════════════════════════════════════════════════════ */

#page-devices .dev-kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
@media (max-width: 767px) {
  #page-devices .dev-kpi-row { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}
#page-devices .dev-kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--card-shadow);
}
#page-devices .dev-kpi-title {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#page-devices .dev-kpi-value {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}
#page-devices .dev-kpi-unit {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}
#page-devices .dev-kpi-sub {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
}
#page-devices .dev-kpi-pip {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  margin-right: 2px;
}
#page-devices .dev-kpi-pip.offline {
  background: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red);
}

/* ── 訊號覆蓋分析 stage ── */
#page-devices .dev-coverage-stage {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
  isolation: isolate;
}
[data-theme="dark"] #page-devices .dev-coverage-stage {
  background: var(--bg);
}
#page-devices .dev-coverage-stage .flow-canvas-body {
  margin: 0;
  position: relative;
}
#page-devices .dev-coverage-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}
#page-devices .dev-cov-circle {
  fill: rgba(255, 184, 0, 0.10);
  stroke: rgba(255, 184, 0, 0.55);
  stroke-width: 0.4;
  stroke-dasharray: 1, 0.6;
}
#page-devices .dev-cov-circle.core {
  fill: rgba(34, 197, 94, 0.14);
  stroke: rgba(34, 197, 94, 0.65);
}
#page-devices .dev-cov-circle.edge {
  fill: rgba(245, 158, 11, 0.10);
  stroke: rgba(245, 158, 11, 0.55);
}
#page-devices .dev-cov-circle.blind {
  fill: none;
  stroke: rgba(239, 68, 68, 0.55);
  stroke-dasharray: 0.8, 0.8;
}
#page-devices .dev-cov-box-marker {
  fill: var(--accent-blue);
  stroke: var(--surface);
  stroke-width: 0.6;
}
#page-devices .dev-cov-label {
  font-size: 14px;
  fill: var(--muted);
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
}
#page-devices .dev-cov-box-label {
  font-size: 14px;
  font-weight: 800;
  fill: var(--accent-blue);
  font-family: 'JetBrains Mono', monospace;
}

/* 距離 vs 精度 legend(浮在 stage 左下角)*/
#page-devices .dev-coverage-legend {
  position: relative;
  margin-top: -68px;
  margin-left: 14px;
  width: max-content;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--ink-2);
  box-shadow: 0 6px 16px -8px rgba(0,0,0,0.18);
  z-index: 3;
}
#page-devices .dev-coverage-legend-title {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}
#page-devices .dev-coverage-legend-row {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-right: 10px;
}
#page-devices .dev-coverage-legend-row:last-child { margin-right: 0; }

#page-devices .dev-cov-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
#page-devices .dev-cov-dot.dev-cov-core   { background: var(--accent-green); }
#page-devices .dev-cov-dot.dev-cov-edge   { background: var(--accent-amber); }
#page-devices .dev-cov-dot.dev-cov-blind  { background: var(--accent-red); }

/* ── 已部署設備 cards ── */
#page-devices .dev-deployed-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#page-devices .dev-deployed-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  #page-devices .dev-deployed-card { grid-template-columns: 1fr; gap: 16px; }
}
#page-devices .dev-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  grid-column: 1 / -1;
}
#page-devices .dev-card-head-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
#page-devices .dev-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-blue);
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}
[data-theme="dark"] #page-devices .dev-card-icon { background: var(--accent-blue); }
#page-devices .dev-card-name {
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
}
#page-devices .dev-card-sublocation {
  font-size: 14px;
  color: var(--muted);
  margin-top: 2px;
}
#page-devices .dev-card-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(34,197,94,0.14);
  color: var(--accent-green);
  font-size: 14px;
  font-weight: 700;
}
#page-devices .dev-card-status-pill::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-green);
}
#page-devices .dev-card-status-pill.offline {
  background: rgba(239,68,68,0.14);
  color: var(--accent-red);
}
#page-devices .dev-card-status-pill.offline::before {
  background: var(--accent-red);
}

#page-devices .dev-spec-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
#page-devices .dev-spec-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
#page-devices .dev-spec-row:first-child { border-top: 0; padding-top: 0; }
#page-devices .dev-spec-row .dev-spec-label {
  color: var(--muted);
  font-weight: 600;
}
#page-devices .dev-spec-row .dev-spec-value {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
  word-break: break-all;
}
#page-devices .dev-spec-row .dev-spec-value.mono {
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.02em;
}
#page-devices .dev-spec-value.fresh { color: var(--accent-green); font-weight: 700; }

/* 健康指標(packets/min)右側區塊 */
#page-devices .dev-health-block {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 14px 16px;
}
[data-theme="dark"] #page-devices .dev-health-block { background: var(--bg); }
#page-devices .dev-health-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
}
#page-devices .dev-health-row + .dev-health-row {
  border-top: 1px solid var(--line);
}
#page-devices .dev-health-label {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}
#page-devices .dev-health-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
#page-devices .dev-health-sub {
  font-size: 14px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  margin-top: 2px;
  display: block;
}

/* ── 斷線歷史(<details> 收摺,預設收起)── */
#page-devices .dev-offline-history {
  margin-top: 12px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}
#page-devices .dev-offline-history > summary {
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  user-select: none;
}
#page-devices .dev-offline-history > summary::-webkit-details-marker { display: none; }
#page-devices .dev-offline-history > summary::before {
  content: '▸';
  font-size: 14px;
  transition: transform 0.15s ease;
  display: inline-block;
}
#page-devices .dev-offline-history[open] > summary::before {
  transform: rotate(90deg);
}
#page-devices .dev-offline-history > summary:hover { color: var(--ink); }

#page-devices .dev-offline-empty {
  margin-top: 12px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
  font-size: 14px;
  color: var(--muted);
}

#page-devices .dev-offline-list {
  list-style: none;
  padding: 6px 0 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#page-devices .dev-offline-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 14px;
}
[data-theme="dark"] #page-devices .dev-offline-item { background: var(--bg); }
#page-devices .dev-offline-range {
  color: var(--ink);
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
}
#page-devices .dev-offline-dur {
  margin-left: auto;
  color: var(--muted);
  font-weight: 600;
}
#page-devices .dev-offline-tag {
  font-size: 14px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}
#page-devices .dev-offline-tag.dev-offline-ongoing {
  background: rgba(224, 82, 82, 0.14);
  color: #e05252;
}

/* ── 覆蓋分析建議 card(藍底)── */
#page-devices .dev-recommend-card {
  background: linear-gradient(180deg, rgba(59,130,246,0.06) 0%, rgba(59,130,246,0.02) 100%);
  border: 1px solid rgba(59,130,246,0.20);
  border-radius: 14px;
  padding: 18px 20px;
}
[data-theme="dark"] #page-devices .dev-recommend-card {
  background: linear-gradient(180deg, rgba(59,157,255,0.08) 0%, rgba(59,157,255,0.03) 100%);
  border-color: rgba(59,157,255,0.25);
}
#page-devices .dev-recommend-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-blue);
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
#page-devices .dev-recommend-icon {
  font-size: 14px;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(59,130,246,0.18);
}
#page-devices .dev-recommend-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-2);
  font-weight: 500;
  margin-bottom: 14px;
}
#page-devices .dev-recommend-text b { color: var(--ink); font-weight: 700; }
#page-devices .dev-recommend-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 600px) {
  #page-devices .dev-recommend-stats { grid-template-columns: 1fr; }
}
#page-devices .dev-recommend-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
}
#page-devices .dev-recommend-stat-label {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}
#page-devices .dev-recommend-stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

/* ── 變更時間軸(沿用舊 .timeline 規則,加 padding) ── */
.timeline {
  position: relative;
  padding-left: 26px;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--line);
}
.timeline-item {
  position: relative;
  padding-bottom: 18px;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
  content: '';
  position: absolute;
  left: -23px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--ink);
}
.timeline-item:first-child::before {
  background: var(--ink);
  box-shadow: 0 0 0 3px rgba(20,20,20,0.1);
}
.timeline-date {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
  font-family: 'JetBrains Mono', monospace;
}
.timeline-body {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 14px;
}
[data-theme="dark"] .timeline-body { background: var(--bg); }
