/* ═══════════════════════════════════════════════════════════
 * 停留分析 dwell.html — 2026-05 大改版
 *
 * 載入順序在 style.css 之後;範圍鎖在 #page-dwell 內。
 * ═══════════════════════════════════════════════════════════ */

/* ── 分析對象 filter bar ── */
#page-dwell .dwell-filter-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
}
#page-dwell .dwell-filter-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
#page-dwell .dwell-filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
#page-dwell .dwell-filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font: inherit;
  font-size: 14px;
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
#page-dwell .dwell-filter-pill:hover {
  border-color: var(--ink-2);
  color: var(--ink);
}
#page-dwell .dwell-filter-pill.active {
  background: rgba(59,130,246,0.12);
  border-color: rgba(59,130,246,0.40);
  color: var(--accent-blue);
  font-weight: 700;
}
#page-dwell .dwell-filter-pill.muted {
  opacity: 0.55;
}
#page-dwell .filter-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
#page-dwell .filter-name { font-weight: 600; }
#page-dwell .filter-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  color: var(--muted);
}
#page-dwell .dwell-filter-pill.active .filter-count {
  color: var(--accent-blue);
}
#page-dwell .dwell-filter-hint {
  margin-left: auto;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}

/* ── 3-cell KPI strip ── */
#page-dwell .dwell-kpi-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
#page-dwell .dwell-kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--card-shadow);
}
#page-dwell .dwell-kpi-title {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}
#page-dwell .dwell-kpi-value {
  font-size: 32px;
  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-dwell .dwell-kpi-unit {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}
#page-dwell .dwell-kpi-sub {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
}

@media (max-width: 767px) {
  #page-dwell .dwell-kpi-row { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  #page-dwell .dwell-kpi-card { padding: 12px 12px; }
  #page-dwell .dwell-kpi-value { font-size: 24px; }
}

/* ── donut + bucket list ── */
#page-dwell .dwell-donut-wrap {
  width: 200px;
  height: 200px;
  flex-shrink: 0;
  position: relative;
}
#page-dwell .dwell-donut {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);  /* 12 點開始 */
}
#page-dwell .dwell-donut-track {
  stroke: var(--line);
  fill: none;
  stroke-width: 18;
}
#page-dwell .dwell-donut-slice {
  fill: none;
  stroke-width: 18;
  transition: stroke-dasharray 0.6s ease;
}
#page-dwell .slice-b1 { stroke: var(--mint-l1); }
#page-dwell .slice-b2 { stroke: var(--mint-l2); }
#page-dwell .slice-b3 { stroke: var(--mint-l3); }
#page-dwell .slice-b4 { stroke: var(--mint-l4); }
#page-dwell .dwell-donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

#page-dwell .dwell-bucket-label { font-weight: 600; }
#page-dwell .dwell-bucket-bar {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  margin-top: 4px;
}
#page-dwell .dwell-bucket-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  transition: width 0.5s ease;
}

/* ── 停留摘要(右卡)── */
#page-dwell .dwell-summary-row {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
#page-dwell .dwell-summary-row[hidden] { display: none; }
#page-dwell .dwell-summary-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#page-dwell .dwell-summary-count {
  font-size: 14px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}
#page-dwell .dwell-summary-avg {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 停留摘要的 row 加色塊背景:同學藍 / 工作人員洋紅 / 機器灰 */
#page-dwell #dwellSummaryMid   { background: rgba(59,130,246,0.06); }
#page-dwell #dwellSummaryShort { background: rgba(59,130,246,0.06); }   /* 走廊主桶也是藍 */
#page-dwell .dwell-summary-row[data-bucket="mid"] .dwell-summary-avg,
#page-dwell .dwell-summary-row[data-bucket="short"] .dwell-summary-avg { color: var(--accent-blue); }

/* ── scatter chart dot legend ── */
#page-dwell .scatter-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── 停留洞察 card ── */
#page-dwell .dwell-insight-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-dwell .dwell-insight-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-dwell .dwell-insight-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-dwell .dwell-insight-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-dwell .dwell-insight-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-2);
  font-weight: 500;
}
#page-dwell .dwell-insight-text b { color: var(--ink); font-weight: 700; }
#page-dwell .dwell-insight-cta {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
#page-dwell .dwell-cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
#page-dwell .dwell-cta-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--surface-2);
}
#page-dwell .dwell-cta-btn.primary {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}
#page-dwell .dwell-cta-btn.primary:hover {
  background: var(--accent-blue);
  filter: brightness(1.06);
  color: #fff;
}
#page-dwell .dwell-cta-btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

/* ── 調整判定門檻 popup ── */
#page-dwell .dwell-thresh-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.32);
  display: grid;
  place-items: center;
  animation: dwellThreshFade 0.18s ease;
}
@keyframes dwellThreshFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
#page-dwell .dwell-thresh-popup {
  width: min(420px, 92vw);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px -12px rgba(0,0,0,0.32);
}
#page-dwell .dwell-thresh-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
#page-dwell .dwell-thresh-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  display: grid;
  place-items: center;
}
#page-dwell .dwell-thresh-close:hover { border-color: var(--ink); color: var(--ink); }
#page-dwell .dwell-thresh-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#page-dwell .dwell-thresh-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
#page-dwell .dwell-thresh-label {
  font-size: 14px;
  color: var(--ink-2);
  font-weight: 600;
}
#page-dwell .dwell-thresh-select {
  font: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  min-width: 160px;
}
#page-dwell .dwell-thresh-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 14px;
}
[data-theme="dark"] #page-dwell .dwell-thresh-select { color-scheme: dark; }
