/* ════════════════════════════════════════════════════════════
   票價趨勢圖 — 樣式（設計 token 移植自 docs/uiux/001-price-trend-design.html）
   對照：docs/development/票價趨勢圖.md §7
   ════════════════════════════════════════════════════════════ */

/* ── 設計 Token ── */
:root {
  --accent: #1a73e8;  --accent-hover: #1557b0;  --accent-light: rgba(26,115,232,0.12);
  --success: #188038; --success-light: #e6f4ea; --success-border: #a8dab5;
  --danger: #c5221f;  --danger-light: #fce8e6;  --danger-border: #f5c6c2;
  --warning: #e37400; --warning-light: #fff4e5;
  --bg: #ffffff; --surface: #ffffff; --surface-2: #f6f7f9; --surface-3: #eef0f3;
  --border: #e3e6ea; --text: #374151; --muted: #9ca3af;
  --shadow: 0 2px 12px rgba(0,0,0,0.08); --shadow-lg: 0 12px 32px rgba(0,0,0,0.16);
  --h: 36px; --h-mobile: 44px;
  --radius: 10px; --radius-sm: 6px; --transition: 0.2s ease;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11191f; --surface: #181e25; --surface-2: #1e2530; --surface-3: #232c38;
    --border: #262e38; --text: #c7c9ce; --muted: #7d8590;
    --shadow: 0 2px 16px rgba(0,0,0,0.45); --shadow-lg: 0 12px 36px rgba(0,0,0,0.6);
  }
}

* { box-sizing: border-box; }
/* 防止作者樣式（display:flex 等）覆蓋 [hidden] 屬性的 UA 樣式（display:none） */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--text);
  transition: background var(--transition), color var(--transition);
}
.page { max-width: 1120px; margin: 0 auto; padding: 0 1rem 3rem; }
.ico { width: 18px; height: 18px; flex-shrink: 0; }

/* ── 頁首 ── */
.ph { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.2rem 0; flex-wrap: wrap; }
.ph-title { margin: 0; font-size: 1.35rem; }
.ph-sub { color: var(--muted); font-size: 0.82rem; margin: 0.25rem 0 0; }
.ph-right { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.badge-upd { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.75rem; color: var(--success); background: var(--success-light); border: 1px solid var(--success-border); border-radius: 20px; padding: 0.3rem 0.7rem; white-space: nowrap; }
.badge-upd .dotg { width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.alertbar { display: flex; align-items: center; gap: 0.45rem; font-size: 0.78rem; color: var(--warning); background: var(--warning-light); border: 1px solid rgba(227,116,0,0.35); border-radius: 8px; padding: 0.45rem 0.8rem; }
.alertbar .ico { width: 15px; height: 15px; color: var(--warning); }

/* ── 航線 tab ── */
.route-tabs { display: flex; gap: 0.35rem; border-bottom: 1px solid var(--border); }

/* ═══ PWA 更新橫幅（§7：新版本可用）═══ */
.update-bar {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  font-size: 0.82rem; color: var(--accent);
  background: var(--accent-light); border: 1px solid rgba(26,115,232,0.35);
  border-radius: 8px; padding: 0.55rem 0.85rem; margin: 0.55rem 0 0.15rem;
  animation: slideDown 0.3s ease;
}
.update-bar .ico { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }
.update-bar span { flex: 1; }
.update-bar .btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 20px; padding: 0.35rem 0.85rem;
  font-size: 0.78rem; font-weight: 600; cursor: pointer;
  transition: background var(--transition);
}
.update-bar .btn:hover { background: var(--accent-hover); }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.rtab { display: inline-flex; align-items: center; gap: 0.45rem; height: var(--h); padding: 0 1.05rem; border: 1px solid transparent; border-radius: var(--radius-sm) var(--radius-sm) 0 0; background: none; color: var(--muted); font-size: 0.875rem; cursor: pointer; font-weight: 500; transition: all var(--transition); position: relative; }  /* position:relative 為 E2 提示錨點 */
.rtab:hover { color: var(--text); background: var(--surface-2); }
.rtab:focus-visible { outline: 3px solid var(--accent-light); outline-offset: -2px; }
.rtab.active { background: var(--surface); border-color: var(--border); border-bottom-color: var(--bg); color: var(--accent); font-weight: 700; box-shadow: inset 0 2px 0 var(--accent); }
.rtab .code { font-family: var(--mono); font-size: 0.7rem; color: var(--muted); }
.rtab.active .code { color: var(--accent); }

/* ── 工具列 ── */
.chart-toolbar { display: flex; align-items: center; gap: 1rem; padding: 0.8rem 0; flex-wrap: wrap; }
.tb-label { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.sel { height: var(--h); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: 0.875rem; padding: 0 0.5rem; cursor: pointer; }
.sel:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); outline: none; }
.sel:disabled, .seg-chart:disabled button { opacity: 0.5; cursor: not-allowed; }
.seg-chart { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; gap: 2px; }
.seg-chart button { border: none; background: none; color: var(--muted); font-size: 0.75rem; padding: 0.3rem 0.65rem; border-radius: 6px; cursor: pointer; transition: all var(--transition); }
.seg-chart button:hover { color: var(--text); }
.seg-chart button.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); font-weight: 600; }
.legend-row { display: flex; align-items: center; gap: 0.9rem; margin-left: auto; flex-wrap: wrap; }
.lg { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.72rem; color: var(--muted); }
.lg .sw { width: 16px; height: 3px; border-radius: 2px; background: var(--accent); flex-shrink: 0; }
.lg .sw.avg { background: none; border-top: 2px dashed var(--warning); height: 0; }
.lg .sw.min { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.lg .sw.pk { width: 12px; height: 12px; border-radius: 3px; background: rgba(197,34,31,0.15); border: 1px solid rgba(197,34,31,0.35); }
.progress-text { font-size: 0.75rem; color: var(--muted); font-family: var(--mono); margin-left: auto; }

/* ── 錯誤卡 / 空狀態 / 骨架 ── */
.errbox { display: flex; align-items: center; gap: 0.7rem; font-size: 0.82rem; color: var(--danger); background: var(--danger-light); border: 1px solid var(--danger-border); border-radius: 10px; padding: 0.7rem 1rem; margin: 0.8rem 0; }
.errbox .ico { width: 18px; height: 18px; color: var(--danger); }
.err-body { flex: 1; line-height: 1.5; }
.err-detail { font-size: 0.72rem; font-family: var(--mono); color: var(--danger); opacity: 0.85; }
.btn { height: var(--h); display: inline-flex; align-items: center; gap: 0.4rem; padding: 0 0.9rem; border-radius: var(--radius-sm); font-size: 0.875rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.emptybox { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; color: var(--muted); font-size: 0.85rem; padding: 2.5rem 1rem; border: 1px dashed var(--border); border-radius: 10px; text-align: center; margin: 0.8rem 0; }
.emptybox .ico { width: 30px; height: 30px; color: var(--muted); }
.skeleton { height: 300px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; position: relative; overflow: hidden; }
.skeleton::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(128,128,128,0.18), transparent); animation: shim 1.2s infinite; }
@keyframes shim { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ── 圖表 ── */
.chart-wrap { position: relative; padding: 0.6rem 0; }
.chart-title { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.chart-title b { color: var(--text); }
.chart-wrap svg { width: 100%; height: auto; display: block; }

.grid-major { stroke: var(--border); stroke-width: 1; }
.tick-label { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.axis-caption { fill: var(--muted); font-size: 10px; }
.peak-rect { fill: rgba(197,34,31,0.07); stroke: rgba(197,34,31,0.30); stroke-width: 1; }
.peak-label { fill: var(--danger); font-size: 11px; font-weight: 700; }
.price-line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.avg-line { fill: none; stroke: var(--warning); stroke-width: 1.6; stroke-dasharray: 6 4; }
.avg-label { fill: var(--warning); font-size: 11px; font-weight: 700; }
.dot { fill: var(--accent); cursor: pointer; transition: r 0.15s ease; }
.dot:hover, .dot:focus { fill: var(--accent); stroke: var(--surface); stroke-width: 2.5; outline: none; }
.dot.min { fill: var(--danger); stroke: var(--surface); stroke-width: 2; }
.min-label { fill: var(--danger); font-size: 11.5px; font-weight: 700; }
.gap-dot { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 3 2; }
.sold-out-label { fill: var(--muted); font-size: 10px; }

/* ── 漲跌 badge（chart dot ring） ── */
.dot.up { fill: var(--danger); }
.dot.down { fill: var(--success); }
.change-badge { font-size: 9px; font-weight: 700; font-family: var(--mono); pointer-events: none; }
.change-badge.up { fill: var(--danger); }
.change-badge.down { fill: var(--success); }
.change-badge.flat { fill: var(--muted); }

/* ── Tooltip ── */
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 0.55rem 0.75rem; font-size: 0.75rem; line-height: 1.6; opacity: 0; transition: opacity 0.15s ease; z-index: 5; min-width: 168px; }
.tip.show { opacity: 1; }
.tip .t-date { color: var(--muted); font-size: 0.7rem; }
.tip .t-price { font-size: 0.95rem; font-weight: 700; color: var(--accent); margin: 0.1rem 0; }
.tip .t-low { color: var(--success); font-weight: 600; }
.tip .t-high { color: var(--danger); font-weight: 600; }
.tip .t-fl { font-family: var(--mono); font-size: 0.7rem; color: var(--muted); }
.tip .t-none { color: var(--muted); }

/* ── Summary ── */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem; padding: 0.8rem 0 0.5rem; }
.scard { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 0.65rem 0.85rem; }
.scard .s-k { font-size: 0.68rem; color: var(--muted); }
.scard .s-v { font-size: 1.02rem; font-weight: 700; margin-top: 0.15rem; line-height: 1.35; }
.scard .s-s { font-size: 0.72rem; color: var(--muted); margin-top: 0.1rem; }
.scard.cheap .s-v { color: var(--success); }
.scard.peak .s-v { color: var(--danger); }
.scard.avg .s-v { color: var(--warning); }

/* ═══ 離線狀態層（§7：離線橫幅 / 手動更新 disabled / tab 提示 / 同步狀態）═══ */
.offbar {
  display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap;
  font-size: 0.8rem; color: var(--danger);
  background: var(--danger-light); border: 1px solid var(--danger-border);
  border-radius: 8px; padding: 0.5rem 0.85rem; margin: 0.55rem 0 0.15rem;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); border-color: var(--border); }
.rtab .hint {
  position: absolute; top: -0.45rem; right: 0.4rem;
  font-size: 0.62rem; color: var(--danger);
  background: var(--danger-light); border: 1px solid var(--danger-border);
  border-radius: 4px; padding: 0.08rem 0.35rem; white-space: nowrap;
  opacity: 1; transition: opacity 0.3s ease; pointer-events: none; z-index: 2;
}
.rtab .hint.fade { opacity: 0; }            /* ~3s 後加 fade 再移除（E2） */
.sync-status { font-size: 0.72rem; font-weight: 600; color: var(--success); }
.sync-status.warn { color: var(--warning); }

/* ═══ PWA（§7）：動作列 / 安裝按鈕 / iOS 提示 / 訂閱（Phase 2 預留）═══ */
.pwa-actions {
  display: flex; align-items: center; gap: 0.6rem;
  flex-wrap: wrap; padding: 0.2rem 0 0.6rem;
}
.install-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--accent); color: #fff;
  border: none; border-radius: 20px; padding: 0.42rem 1rem;
  font-size: 0.8rem; font-weight: 600; cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.install-btn:hover { background: var(--accent-hover); }
.install-btn:focus-visible { outline: 3px solid var(--accent-light); outline-offset: 2px; }
.install-btn .ico { width: 15px; height: 15px; }

.ios-hint {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-size: 0.78rem; color: var(--accent);
  background: var(--accent-light); border: 1px solid rgba(26,115,232,0.3);
  border-radius: 8px; padding: 0.45rem 0.8rem;
}
.ios-hint .ico { width: 15px; height: 15px; color: var(--accent); }

/* ═══ 訂閱 toggle（.sub-toggle；三態，Phase 2 / T9 預留）═══ */
.sub-toggle { border-radius: 20px; font-size: 0.8rem; font-weight: 600; }
.sub-toggle.subscribed {
  background: var(--success-light); color: var(--success);
  border: 1px solid var(--success-border);
}
.sub-toggle:disabled { opacity: 0.55; cursor: not-allowed; }   /* E3 停用 */
/* 流程中 loading：點擊後立即回饋（不等 async 1~2s）；spinner + 不淡化（disabled 時仍清晰） */
.sub-toggle.loading { opacity: 1; cursor: progress; }
.sub-toggle.loading::before {
  content: ''; display: inline-block; width: 0.85em; height: 0.85em;
  margin-right: 0.4rem; vertical-align: -0.12em;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: sub-spin 0.7s linear infinite;
}
@keyframes sub-spin { to { transform: rotate(360deg); } }

/* ═══ 訂閱狀態提示（.sub-status；Phase 2 / T9 預留）═══ */
.sub-status {
  font-size: 0.74rem; font-weight: 600; color: var(--success);
  background: var(--success-light); border: 1px solid var(--success-border);
  border-radius: 8px; padding: 0.35rem 0.7rem;
}
.sub-status.warn {                      /* denied / error：拒絕引導、訂閱失敗（E1/E2） */
  color: var(--danger); background: var(--danger-light); border-color: var(--danger-border);
}
.sub-status.unavailable {               /* E3：提醒功能暫時不可用 */
  color: var(--warning); background: var(--warning-light);
  border-color: rgba(227,116,0,0.35);
}

/* ═══ 每週漲跌卡片（scrape-vs-scrape 變動）═══ */
.change-cards-wrap {
  margin: 0.8rem 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.change-cards-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  padding: 0.55rem 0.85rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.change-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px;
}
.ccard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  cursor: default;
  transition: box-shadow var(--transition), transform var(--transition);
  position: relative;
}
.ccard:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.ccard:focus-visible {
  outline: 3px solid var(--accent-light);
  outline-offset: 2px;
}
.ccard-date {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ccard-date svg { width: 12px; height: 12px; flex-shrink: 0; }
.ccard-price {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--mono);
  line-height: 1.3;
}
.ccard-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: var(--mono);
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 20px;
}
.ccard-change.drop {
  color: var(--success);
  background: var(--success-light);
}
.ccard-change.rise {
  color: var(--danger);
  background: var(--danger-light);
}
.ccard-change.flat {
  color: var(--muted);
  background: var(--surface-2);
}
.ccard-change svg { width: 14px; height: 14px; }
.ccard-prev {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 6px;
  font-family: var(--mono);
}
.ccard-prev s { text-decoration: line-through; opacity: 0.7; }

/* ── RWD ── */
@media (max-width: 1023px) {
  .chart-toolbar { gap: 0.7rem; }
  .change-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 767px) {
  .route-tabs { flex-direction: column; align-items: stretch; }
  .rtab { height: var(--h-mobile); justify-content: center; border-radius: var(--radius-sm); border: 1px solid var(--border); }
  .rtab.active { box-shadow: none; border-color: var(--accent); border-bottom-color: var(--accent); }
  .chart-toolbar { flex-direction: column; align-items: stretch; gap: 0.6rem; }
  .sel { height: var(--h-mobile); width: 100%; }
  .seg-chart { justify-content: stretch; }
  .seg-chart button { flex: 1; padding: 0.55rem 0.5rem; }
  .legend-row { margin-left: 0; justify-content: space-between; }
  .chart-wrap { overflow-x: auto; }
  .chart-wrap svg { min-width: 640px; }
  .summary { grid-template-columns: 1fr; }
  .change-cards { grid-template-columns: 1fr; }
  .tip { position: fixed; }
  .progress-text { margin-left: 0; }
}

/* ── 無障礙與動畫 ── */
:focus-visible { outline: 3px solid var(--accent-light); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
