/* ============================================================
   財報圖片檢視器 (report-viewer) — 深色簡潔介面
   重點：圖片縮放靠 #report-img 的 CSS transform，
   不是整頁縮放；原圖原始解析度顯示，不重繪、不壓縮。
   ============================================================ */

:root {
  color-scheme: dark;
  --bg: #0e0e12;
  --panel: rgba(20, 20, 27, 0.84);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #e8e8ee;
  --text-dim: #9a9aa6;
  --accent: #7aa2ff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* hidden 屬性要真的隱藏：
   #loader / #error-box 用 display:flex，會蓋掉 hidden 的 display:none →
   加 !important 確保 JS 設 hidden=true 時 overlay 一定消失。 */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  overscroll-behavior: none; /* 防止 iOS 橡皮筋滾動干擾拖曳 */
  font-family: system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
}

/* ---------- 舞台：全螢幕固定層 ---------- */
#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  /* 核心設定：touch-action:none 讓所有觸控事件交給 JS 處理
     （iPhone Safari 雙指縮放/拖曳的正常關鍵） */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- 財報原圖 ---------- */
#report-img {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(0, 0) scale(1);
  transform-origin: 0 0;
  will-change: transform;
  max-width: none;          /* 不要讓瀏覽器把原圖縮小 */
  max-height: none;
  pointer-events: none;     /* 事件統一交給 #stage */
  -webkit-user-drag: none;
  -webkit-touch-callout: none; /* iOS 長按不彈出圖示選單 */
}

/* ---------- 載入中 ---------- */
#loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 16px;
  pointer-events: none;
  z-index: 10;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: rv-spin 0.9s linear infinite;
}

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

/* ---------- 載入失敗 ---------- */
#error-box {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text);
  font-size: 18px;
  text-align: center;
  padding: 0 24px;
  z-index: 10;
}

.error-icon { font-size: 44px; }

/* ---------- 工具列 ---------- */
#toolbar {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 20;
  max-width: calc(100vw - 16px);
}

#toolbar button {
  min-width: 42px;
  height: 42px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation; /* 消除 iOS 雙擊延遲、避免按鈕觸發頁面縮放 */
  transition: background 0.15s;
}

#toolbar button:hover { background: rgba(255, 255, 255, 0.12); }
#toolbar button:active { background: rgba(122, 162, 255, 0.35); }

#zoom-label {
  min-width: 54px;
  text-align: center;
  color: var(--text);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* 桌面端：工具列移到右上角，不擋手機財報 */
@media (min-width: 900px) and (hover: hover) {
  #toolbar {
    left: auto;
    right: 14px;
    top: 14px;
    bottom: auto;
    transform: none;
  }
}

/* ---------- 類全螢幕模式 ----------
   iOS Safari 沒有真正的 Fullscreen API → 隱藏 UI、
   用整個可用畫面，並用 toast 明確告知這是「類全螢幕」。 */
body.pseudo-fs #toolbar { opacity: 0.18; transition: opacity 0.25s; }
body.pseudo-fs #toolbar:hover,
body.pseudo-fs #toolbar:active { opacity: 1; }

#btn-fs-exit {
  display: none;
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  z-index: 25;
  touch-action: manipulation;
}

body.pseudo-fs #btn-fs-exit { display: flex; align-items: center; justify-content: center; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  z-index: 30;
  pointer-events: none;
  max-width: calc(100vw - 24px);
  text-align: center;
}
