/* projects/show 頁專用 CSS（從 inline <style> 抽出，方便 browser cache） */
/* ⚠ z-index: 0 是必要的，不是裝飾。position: relative 讓這個 ℹ️ 變成定位元素，
   z-index: auto 時會照 DOM 順序疊在 sticky 表頭**上面**——列表往下捲時，
   被表頭蓋住那一列的 ℹ️ 會浮在「備註」兩個字中間。 */
.note-tip { position: relative; z-index: 0; }
/* ⚠ 不能用 .note-tip:hover::after —— 這些表格都在 `overflow-x: auto` 的容器裡，
   而 overflow-x 不是 visible 時 overflow-y 會被算成 auto，**兩個方向都裁**：
   第一列的 tooltip 往上彈會被切掉，手機上容器只有 320px 更是怎麼放都露不全。
   改成掛在 body 上的 position: fixed（shared/_note_tooltip.html.erb 定位）。

   ⚠ white-space 不能用 nowrap：備註最長 280 字，12px 中文會拉成約 3000px 寬。
   pre-wrap 是因為備註裡的條列（「1.…2.…」）本來就帶換行。 */
.note-tip-pop {
  position: fixed; display: none; z-index: 3000;
  /* max-width 預設算的是 content box，不加這行實際會寬出左右 padding 共 20px */
  box-sizing: border-box;
  background: #333; color: #fff;
  padding: 6px 10px; border-radius: 4px;
  font-size: 12px; line-height: 1.55; text-align: left; font-weight: 400;
  white-space: pre-wrap; width: max-content;
  max-width: min(320px, calc(100vw - 24px));
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  pointer-events: none;
}

/* Card 容器（對齊 area 頁 .area-card 視覺） */
.project-card { background: white; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); border: 1px solid #e5e7eb; padding: 24px; margin-bottom: 20px; transition: box-shadow 0.2s; }
.project-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.project-card > h2 { margin: 0 0 16px 0; font-size: 17px; color: #1f2937; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.project-card > h2::before { content: ''; display: inline-block; width: 3px; height: 18px; background: #2563eb; border-radius: 2px; flex-shrink: 0; }

.tab-container { margin-bottom: 20px; }
.tab-buttons { display: flex; gap: 10px; margin-bottom: 15px; }
.tab-btn {
  padding: 10px 20px;
  border: none;
  background: #e5e7eb;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.tab-btn.active { background: #2563eb; color: white; }
.tab-content { display: none; }
.tab-content.active { display: block; }
.txn-table-scroll { overflow: auto; }
/* sticky 掛在 th 不掛在 tr：Safari 不支援 <tr> 當 sticky（Chrome 才支援）。
   底色也要跟著搬過來，不然 th 透明會讓下面的列透出來。 */
.txn-table thead th { background: #333; color: white; position: sticky; top: 0; z-index: 2; }
.sales-matrix-scroll { overflow: auto; }
.sales-matrix table { border-collapse: collapse; min-width: 100%; }
.sales-matrix th, .sales-matrix td {
  border: 1px solid #ddd;
  padding: 8px 12px;
  text-align: center;
  min-width: 80px;
  font-size: 12px;
}
/* ⚠ 這四條 z-index 少一條表頭就會被蓋掉。
   tbody 的格子為了放「特」標記帶 position: relative，樓層欄為了橫向釘住帶 position: sticky
   ——都是**定位元素**。定位元素在 z-index: auto 時照 DOM 順序疊，tbody 在 thead 後面，
   所以表頭雖然有黏住（box 量得到停在捲動容器頂端），卻整條被下面的格子蓋在底下看不見，
   只從 border-collapse 的 1px 接縫漏出 #333，就是那條「壞掉的黑色影」。
   修法是明確把層級排出來：角落 > 表頭 > 樓層欄 > 內容格。 */
.sales-matrix th { background: #333; color: white; position: sticky; top: 0; z-index: 2; }
.sales-matrix .floor-header { background: #f3f4f6; font-weight: bold; position: sticky; left: 0; z-index: 1; }
/* 左上角那格同時是表頭與樓層欄，兩軸都要釘，不然橫向捲動時「樓層」會跟樓層欄脫隊 */
.sales-matrix thead th:first-child { left: 0; z-index: 3; }
/* 樓層欄只放「25F」，不需要跟戶別欄等寬。
   table 有 min-width:100%，auto layout 會把多出來的寬度平均分給每一欄，
   欄數少時樓層欄會被撐到 200px 以上，所以這裡單獨壓窄，多餘寬度留給戶別欄。 */
.sales-matrix th:first-child,
.sales-matrix .floor-header {
  width: 64px;
  min-width: 64px;
  padding-left: 6px;
  padding-right: 6px;
}
.sales-matrix .sold { transition: filter 0.15s; }
.sales-matrix .sold:hover { filter: brightness(0.9); }
.sales-matrix .empty { background: #f9fafb; color: #9ca3af; }
/* 特殊交易標記。判定與交易列表、彈出視窗同一條規則（Transaction#special_relation_transaction?）。
   格子底色是熱力圖，從綠到紅都有，所以用實心色塊白字而不是彩色文字，任何底色上都讀得到。
   絕對定位在右上角，不動原本四行數字的排版。圖例在 .heatmap-legend 裡共用同一個 class，
   所以樣式不掛在 .sales-matrix 底下，只有定位那一條掛。

   ⚠ 底色不能用 amber-500 (#f59e0b)：配白字只有 2.15:1，WCAG AA 普通文字要 4.5:1，
   連大字的 3:1 都不到，而這是 9px。amber-700 (#b45309) 文字過關(5.02)但**色塊本身**
   對紅色熱力格只有 2.9:1，低於非文字元素的 3:1。要同時過兩關才行：
     #92400e  白字 7.09:1｜對綠 5.31 / 黃 5.83 / 紅 4.09（最差 4.09）
   熱力格底色是 hsl(0~120, 65%, 80%)，紅端最深，所以拿紅色格當最壞情況驗。 */
.matrix-special {
  display: inline-block;
  font-size: 9px; line-height: 1; font-weight: 700;
  color: #fff; background: #92400e;
  border-radius: 3px; padding: 2px 3px;
}
.sales-matrix .txn-cell { position: relative; z-index: 0; }
.sales-matrix .txn-cell .matrix-special { position: absolute; top: 2px; right: 2px; }
/* 空白樓層列與有資料列等高（td height 作用如 min-height），避免無交易的樓層變扁 */
.sales-matrix td { height: 68px; }
/* 樓層用途（建照／使照的使用類組）。用途字串可能很長（一層列到四種用途），
   所以樓層那欄固定寬、用途那欄自己換行，不做水平捲動。 */
/* 樓層用途：預設收合，summary 維持跟其他區塊標題一樣的樣子（icon + 標題 + 底線） */
.floor-usage { margin: 18px 0 8px; }
.floor-usage > summary {
  display: flex; align-items: center; gap: 8px;
  padding-bottom: 4px; border-bottom: 2px solid #d1d5db;
  cursor: pointer; user-select: none;
  /* 兩個都要：list-style 管新版瀏覽器，::-webkit-details-marker 管舊 Safari，
     少一個就會多出一個預設三角形跟自己的 chevron 打架 */
  list-style: none;
}
.floor-usage > summary::-webkit-details-marker { display: none; }
.floor-usage-title { font-weight: 600; color: #374151; white-space: nowrap; }
/* 窄螢幕時來源標註縮成省略號，不要把標題擠成兩行 */
.floor-usage-hint {
  color: #6b7280; font-size: 12px;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.floor-usage-chevron { margin-left: auto; color: #9ca3af; flex-shrink: 0; transition: transform 0.15s ease; }
.floor-usage[open] > summary .floor-usage-chevron { transform: rotate(180deg); }
.floor-usage-body { padding-top: 8px; }
.floor-usage-source { color: #6b7280; font-size: 12px; margin-bottom: 6px; }
.floor-usage-list { display: grid; grid-template-columns: 84px 1fr; font-size: 13px; line-height: 1.5; }
.floor-usage-list > div { border-bottom: 1px solid #eee; padding: 6px 0; }
.floor-usage-level { color: #374151; font-weight: 600; }
.floor-usage-value { color: #4b5563; }
.floor-usage-units { color: #4b5563; font-size: 13px; margin-top: 8px; line-height: 1.6; }
.floor-usage-units .floor-usage-tag { color: #374151; font-weight: 600; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); column-gap: 28px; row-gap: 3px; }
.info-item { display: flex; border-bottom: 1px solid #eee; padding: 7px 0; font-size: 14px; line-height: 1.45; }
.info-label { color: #666; min-width: 96px; }
.info-value { font-weight: 500; }
.stat-card {
  background: white;
  padding: 16px;
  border-radius: 8px;
  text-align: center;
  border: 1px solid #e5e7eb;
}
.stat-card .stat-value { font-size: 24px; font-weight: bold; }
.stat-card .stat-label { color: #666; font-size: 12px; margin-top: 4px; }
.stat-card .stat-sublabel { color: #9ca3af; font-size: 11px; margin-top: 2px; }
.stat-card .stat-sub { color: #999; font-size: 11px; margin-top: 2px; }
.progress-bar-bg {
  background: #e5e7eb;
  border-radius: 4px;
  height: 8px;
  margin-top: 8px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}
.ping-filter-btn {
  padding: 6px 14px;
  border: 1px solid #d1d5db;
  background: white;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.ping-filter-btn:hover { border-color: #2563eb; color: #2563eb; }
.ping-filter-btn.active { background: #2563eb; color: white; border-color: #2563eb; }

/* 圖片 lightbox（shared/_image_lightbox.html.erb，設計圖與建照平面圖共用）
   一律用 class，不用 id——同一頁有多個圖庫，各自 id 前綴不同，
   以前寫死 #urban-prev 的 RWD 規則平面圖就吃不到。
   display 由 JS 以 inline style 控制，這裡不宣告。 */
/* 用 padding 幫控制項留位子，圖片再吃滿剩下的空間。
   原本圖片是 max-height 90%，上下各只留 5%——視窗高度低於 1000px 時
   放不下頂端工具列（top 20 + 高 30），+ − 1:1 就會蓋在圖上（1440x900 實測 129x5）；
   低於 740px 時底部頁碼也會蓋到。上 56 = 工具列 50 再加點餘裕，
   下 44 = 頁碼 37 同理，左右 72 讓 ‹ › 不會壓到寬圖。 */
.lb { position: fixed; top: 0; left: 0; width: 100%; height: 100%; box-sizing: border-box; padding: 56px 72px 44px; background: rgba(0,0,0,0.9); z-index: 2000; justify-content: center; align-items: center; }
.lb-close { position: absolute; top: 20px; right: 20px; background: none; border: none; color: white; font-size: 36px; cursor: pointer; z-index: 2001; }
/* 桌機：整組鋪滿，子元素維持各自的絕對定位；不吃點擊，背景點擊關閉才不會失效 */
.lb-bar { position: absolute; inset: 0; z-index: 2001; pointer-events: none; }
.lb-bar > * { pointer-events: auto; }
.lb-zoombar { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
.lb-zoom { background: rgba(255,255,255,0.2); border: none; color: white; font-size: 22px; cursor: pointer; padding: 4px 12px; border-radius: 4px; line-height: 1; }
.lb-zoom-reset { font-size: 14px; padding: 4px 10px; line-height: normal; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,0.2); border: none; color: white; font-size: 36px; cursor: pointer; padding: 10px 15px; border-radius: 4px; }
.lb-prev { left: 20px; }
.lb-next { right: 20px; }
.lb-counter { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); color: white; font-size: 14px; }
/* 100% 是「.lb 扣掉 padding 之後」的空間，控制項的位子已經留好了 */
.urban-lightbox-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; transition: transform 0.15s; cursor: grab; }

/* 手機版 RWD */
@media (max-width: 640px) {
  .project-main { padding: 14px 10px !important; }
  .project-card { padding: 14px !important; margin-bottom: 16px !important; }
  .project-card > h2 { font-size: 16px !important; margin-bottom: 12px !important; }
  .project-main > h1 { font-size: 20px !important; padding-bottom: 8px !important; }
  .project-main > h1 .developer-name { display: block; margin-left: 0 !important; margin-top: 4px; font-size: 13px !important; }

  /* 統計卡片 */
  .project-stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  .stat-card { padding: 12px !important; }
  .stat-card .stat-value { font-size: 20px !important; }

  /* 基本資料 */
  .project-info-section { padding: 14px !important; }
  .info-grid { grid-template-columns: 1fr !important; }
  .info-label { min-width: 90px !important; font-size: 13px; }

  /* 地圖街景 */
  .map-street-grid { grid-template-columns: 1fr !important; }
  .map-street-grid > div { height: 250px !important; }

  /* Tab 按鈕 */
  .tab-buttons { flex-wrap: wrap; gap: 6px !important; }
  .tab-btn { padding: 8px 14px !important; font-size: 13px !important; }

  /* 實價登錄表格 */
  .txn-table-wrap { padding: 10px !important; }
  .txn-table { min-width: 800px; }
  .txn-table th, .txn-table td { padding: 8px 6px !important; }

  /* 坪數篩選 */
  .ping-filter-btn { padding: 5px 10px !important; font-size: 12px !important; }

  /* 價格分析圖表 */
  .analysis-grid { grid-template-columns: 1fr !important; }

  /* 設計圖 */
  .urban-plan-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)) !important; gap: 6px !important; }
  .urban-plan-thumb { height: 70px !important; }

  /* 銷控表 */
  .sales-matrix { padding: 10px !important; }

  /* 圖表高度縮減 */
  .chart-container { height: 220px !important; }
  .analysis-grid > div { padding: 14px !important; }
  .analysis-grid h3 { font-size: 14px !important; }

  /* 頁面標題 */
  .project-main > h1 { font-size: 22px !important; }

  /* 基本資料子區塊間距 */
  .project-info-section .info-item { padding: 6px 0 !important; }

  /* 銷控表 cell 更緊湊 */
  .sales-matrix th, .sales-matrix td { padding: 6px 8px !important; min-width: 65px !important; font-size: 11px !important; }
  .sales-matrix td { height: 60px !important; }
  .sales-matrix th:first-child,
  .sales-matrix .floor-header { width: 46px !important; min-width: 46px !important; padding-left: 4px !important; padding-right: 4px !important; }

  /* 熱力圖圖例 */
  .heatmap-legend { flex-wrap: wrap; font-size: 11px; gap: 6px !important; }

  /* 交易表格 body cell nowrap 關鍵欄位 */
  .txn-table td { white-space: nowrap; }

  /* footer 間距 */
  .project-main > footer { padding: 12px 0 !important; }

  /* 圖片 lightbox：控制項全部退到上下兩端，不再壓在圖片上。
     原本 ‹ › 是左右垂直置中、z-index 蓋在圖上，正好落在想拖曳或縮放時
     手指最自然的落點（實測 390x844 下與圖片重疊 23px），一碰就換頁。 */
  .lb { padding: 72px 0 calc(62px + env(safe-area-inset-bottom)); }
  /* 圖片拿回滿寬：原本的 max-width 80% 只是為了閃避左右箭頭 */
  .urban-lightbox-img { border-radius: 0; }
  /* 單指拖曳平移目前會被瀏覽器判成頁面捲動搶走（pointercancel 中斷），
     所以只交出單指；兩指仍走瀏覽器原生 pinch——這次不自己寫 pinch handler，
     用 touch-action: none 會把手機上唯一的縮放手段一起關掉。 */
  .urban-lightbox-img { touch-action: pinch-zoom; }

  /* 底部一列：‹  5 / 18  ›   +  −  1:1  （窄螢幕放不下就換行） */
  .lb-bar { inset: auto 0 0 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .lb-bar > * { position: static; transform: none; }
  .lb-prev { order: 1; }
  .lb-counter { order: 2; min-width: 56px; text-align: center; }
  .lb-next { order: 3; }
  .lb-zoombar { order: 4; margin-left: 8px; gap: 4px; }
  .lb-nav { font-size: 26px; padding: 0 12px; min-width: 44px; min-height: 44px; background: rgba(255,255,255,0.22); }
  /* +/− 一定要留著。原生 pinch 縮放的是瀏覽器 visual viewport，跟 JS 的 scale
     是兩套不相通的狀態：1:1 只重設 JS scale，對 pinch 出來的放大完全無效；
     而拖曳平移的條件是 scale > 1，沒有 +/− 就永遠進不去。 */
  .lb-zoom { min-width: 44px; min-height: 44px; font-size: 20px; padding: 0 8px; }
  .lb-zoom-reset { font-size: 13px; }
  .lb-close { min-width: 44px; min-height: 44px; }
}

/* 交易詳情 modal */
#txn-modal {
  display: none; position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(4px);
  z-index: 1000; justify-content: center; align-items: center;
  opacity: 0; transition: opacity 0.2s ease-out;
}
#txn-modal.show { opacity: 1; }
#txn-modal .modal-card {
  background: #fff; border-radius: 16px;
  max-width: 420px; width: 92%; max-height: 85vh;
  overflow-y: auto; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  transform: translateY(12px) scale(0.97);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
#txn-modal.show .modal-card { transform: translateY(0) scale(1); }
#txn-modal .modal-header {
  padding: 20px 24px 16px; display: flex;
  justify-content: space-between; align-items: flex-start;
}
#txn-modal .modal-close {
  background: none; border: none; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #9ca3af; font-size: 20px; line-height: 1;
  transition: background 0.15s, color 0.15s; flex-shrink: 0;
}
#txn-modal .modal-close:hover { background: #f3f4f6; color: #374151; }
#txn-modal .modal-hero {
  margin: 0 24px 16px; padding: 16px 20px;
  background: linear-gradient(135deg, #f8fafc, #f1f5f9);
  border-radius: 12px; display: flex;
  justify-content: space-around; text-align: center;
}
#txn-modal .modal-hero .hero-item { flex: 1; }
#txn-modal .modal-hero .hero-label {
  font-size: 11px; color: #94a3b8; margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
#txn-modal .modal-hero .hero-value {
  font-size: 20px; font-weight: 700; color: #0f172a;
}
#txn-modal .modal-hero .hero-unit {
  font-size: 12px; color: #64748b; font-weight: 400;
}
#txn-modal .modal-hero .hero-divider {
  width: 1px; background: #e2e8f0; margin: 0 4px;
}
#txn-modal .modal-body { padding: 0 24px 20px; }
#txn-modal .modal-row {
  display: flex; justify-content: space-between;
  align-items: center; padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}
#txn-modal .modal-row:last-child { border-bottom: none; }
#txn-modal .modal-label { font-size: 13px; color: #94a3b8; }
#txn-modal .modal-value { font-size: 14px; color: #1e293b; font-weight: 500; text-align: right; }
#txn-modal .modal-badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  border-radius: 6px; padding: 2px 8px; letter-spacing: 0.3px;
}
/* 特殊交易／配偶交易。白底(.modal-card)上的純文字，11px 不粗體＝WCAG AA 普通文字，
   要 4.5:1。原本的 amber-500 (#f59e0b) 只有 2.15:1；#92400e 是 7.09:1，
   與銷控表格子上的 .matrix-special 同色。 */
#txn-modal .modal-special {
  font-size: 11px; color: #92400e; margin-left: 6px;
}
