/* =============================================================================
   ui/places.css — 領域 P「地圖與掃碼」
   頁面：消費地圖（#view-merchants）
   對話框：店家詳情、掃碼中心（qr-scanner.js 全部：店家付款、掃碼領金幣、發票、集章、相機／上傳、
          結果與確認）
   規則（完整說明見 docs/DESIGN.md）：
   - 每條規則都以 #view-merchants 或本領域 class（places-…，或沿用既有的 merchant-／qr-…）開頭。
   - 顏色、陰影、圓角、字級一律用 foundation 的 token，不寫色碼；半透明一律用 color-mix()。
   - 共用元件（.panel、.status、.ui-*、帳號挑選器）直接使用，不在這裡改它們的基本外觀。
   - 不要寫 @layer：一般規則本來就會蓋過 foundation 的預設。
   ============================================================================= */

/* =============================================================================
   1. 消費地圖頁 #view-merchants
   版面：頁首「附近 N 家店可用金幣」→ 篩選卡（據點類型分段、搜尋、分類、只看有優惠、AI 精細分類、排序位置）
         → 桌機雙欄：左清單、右黏頂地圖；手機地圖在上、清單在下，可用分段切換。
   ============================================================================= */

/* ----- 頁首 ----- */
#view-merchants .ui-page-head h2 { font-variant-numeric: tabular-nums; }
#view-merchants .ui-page-head-actions > button > svg { width: 18px; height: 18px; }

/* ----- 篩選卡 ----- */
#view-merchants .merchant-filter-panel { --panel-pad: var(--sp-5); }
#view-merchants .merchant-filter-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); }
#view-merchants .merchant-tabs > button > svg { width: 17px; height: 17px; }
#view-merchants .merchant-safe-note { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-2); font-size: var(--fs-13); font-weight: 600; }
#view-merchants .merchant-safe-note > svg { width: 17px; height: 17px; color: var(--ok); }

#view-merchants .merchant-filter-form { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) auto auto; gap: var(--sp-3) var(--sp-4); align-items: end; }
#view-merchants .merchant-search-field .field-shell { display: flex; }
#view-merchants .merchant-discount-switch { align-self: end; min-height: 44px; color: var(--ink); font-size: var(--fs-15); font-weight: 600; white-space: nowrap; }
#view-merchants .merchant-filter-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
#view-merchants .merchant-filter-actions > button > svg { width: 18px; height: 18px; }

/* AI 精細分類：紫色語氣的虛線區塊，說清楚它只是輔助、不取代官方資料 */
#view-merchants .merchant-ai-filter { display: grid; gap: var(--sp-3); padding: var(--sp-4); border: 1px dashed var(--ai-line); border-radius: var(--r-lg); background: color-mix(in srgb, var(--ai-soft) 55%, var(--surface)); }
#view-merchants .merchant-ai-filter-heading { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
#view-merchants .merchant-ai-filter-heading h3 { margin: 0; color: var(--ink); font-size: var(--fs-16); }
#view-merchants .merchant-ai-filter-heading > [role="status"] { margin-left: auto; color: var(--ink-2); font-size: var(--fs-13); font-weight: 600; line-height: 1.5; }
#view-merchants .merchant-ai-filter-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3) var(--sp-4); }
#view-merchants .merchant-ai-taxonomy-counts { display: flex; flex-wrap: wrap; gap: 6px; }
#view-merchants .merchant-ai-taxonomy-counts:empty { display: none; }
#view-merchants .merchant-ai-taxonomy-count strong { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
#view-merchants .merchant-ai-filter-note { color: var(--ink-3); font-size: var(--fs-13); line-height: 1.6; }

/* 排序位置：圖示底座＋目前位置說明＋手動輸入 */
#view-merchants .merchant-location-row { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(300px, 1.2fr); gap: var(--sp-3) var(--sp-4); align-items: center; padding-top: var(--sp-4); border-top: 1px solid var(--line-2); }
#view-merchants .merchant-location-pin { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; color: var(--brand-ink); background: var(--brand-soft); }
#view-merchants .merchant-location-copy { display: grid; gap: 2px; min-width: 0; }
#view-merchants .merchant-location-copy strong { color: var(--ink); font-size: var(--fs-14); }
#view-merchants .merchant-location-copy span { color: var(--ink-3); font-size: var(--fs-13); line-height: 1.5; overflow-wrap: anywhere; }
#view-merchants .merchant-manual-location-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-2) var(--sp-2); align-items: start; }
#view-merchants .merchant-manual-location-form > label { gap: 0; }
#view-merchants .merchant-manual-location-form > small { grid-column: 1 / -1; color: var(--ink-3); font-size: var(--fs-12); line-height: 1.5; }

/* 手機才出現的「清單／地圖」切換 */
#view-merchants .merchant-view-switch { display: none; }
#view-merchants .merchant-view-switch > button > svg { width: 17px; height: 17px; }

/* ----- 雙欄：清單＋黏頂地圖 ----- */
#view-merchants .merchant-layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr); gap: var(--sp-5); align-items: start; margin-top: var(--sp-5); }
#view-merchants .merchant-results { min-width: 0; }
#view-merchants .merchant-map-panel { position: sticky; top: calc(var(--appbar-h) + var(--vitals-h) + var(--sp-4)); min-width: 0; }

/* ----- 地圖 ----- */
#view-merchants .merchant-map {
  position: relative; width: 100%; height: clamp(380px, calc(100dvh - var(--appbar-h) - var(--vitals-h) - 236px), 620px);
  overflow: hidden; border: 1px solid var(--line); border-radius: var(--r-lg);
  background-color: var(--surface-3);
  background-image: linear-gradient(var(--line-2) 1px, transparent 1px), linear-gradient(90deg, var(--line-2) 1px, transparent 1px);
  background-size: 32px 32px;
  cursor: grab; isolation: isolate; touch-action: none;
}
#view-merchants .merchant-map.dragging { cursor: grabbing; }
#view-merchants .merchant-map:focus-visible { outline-offset: 3px; }
#view-merchants .merchant-map-stage { position: absolute; inset: 0; will-change: transform; }
#view-merchants .merchant-map-tile { position: absolute; width: 256px; height: 256px; max-width: none; user-select: none; -webkit-user-drag: none; pointer-events: none; }
/* 深色「夜」：街道底圖反相成深色，數字標記不受影響 */
#view-merchants .merchant-map-tile:where(:root[data-theme="dark"] *) { filter: invert(1) hue-rotate(195deg) brightness(.82) contrast(.92) saturate(.72); }

/* 數字標記：圓頭＋小尾巴的釘子，顏色依優惠；整顆 ≥ 44px 高好點按 */
#view-merchants .merchant-marker {
  --btn-bg: transparent; --btn-line: transparent; --btn-bg-hover: transparent; --btn-line-hover: transparent; --btn-shadow: none;
  position: absolute; z-index: 5; display: grid; justify-items: center; align-content: start;
  width: 36px; min-height: 44px; padding: 0; border: 0; border-radius: var(--r-md);
  transform: translate(-50%, -100%); transition: transform var(--t-fast) var(--ease);
}
#view-merchants .merchant-marker > span {
  display: grid; place-items: center; width: 32px; height: 32px; border: 2px solid var(--surface); border-radius: 50%;
  background: var(--brand); color: var(--on-brand); box-shadow: var(--sh-2);
  font-family: var(--font-num); font-size: var(--fs-13); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums;
}
#view-merchants .merchant-marker::after { content: ""; width: 10px; height: 10px; margin-top: -5px; background: var(--brand); clip-path: polygon(0 0, 100% 0, 50% 100%); }
#view-merchants .merchant-marker.discount > span { background: var(--coin); color: var(--ink); }
#view-merchants .merchant-marker.discount::after { background: var(--coin); }
#view-merchants .merchant-marker:hover, #view-merchants .merchant-marker:focus-visible { z-index: 7; transform: translate(-50%, -100%) scale(1.1); }
#view-merchants .merchant-marker:active:not(:disabled) { transform: translate(-50%, -100%) scale(1.04); }

#view-merchants .merchant-current-location { position: absolute; z-index: 6; width: 16px; height: 16px; border: 3px solid var(--surface); border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 6px var(--brand-soft), var(--sh-1); transform: translate(-50%, -50%); }
#view-merchants .merchant-current-location::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; color: var(--brand); animation: ui-live 1.8s ease-out infinite; }

#view-merchants .merchant-map-controls { position: absolute; z-index: 8; top: var(--sp-3); right: var(--sp-3); display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--sh-2); }
#view-merchants .merchant-map-controls > button { --btn-bg: var(--surface); --btn-line: transparent; --btn-bg-hover: var(--surface-2); --btn-line-hover: transparent; width: 40px; min-width: 40px; min-height: 40px; padding: 0; border-radius: 0; }
#view-merchants .merchant-map-controls > button + button { border-top: 1px solid var(--line-2); }
#view-merchants .merchant-map-controls > button > svg { width: 18px; height: 18px; }
#view-merchants .merchant-map-message { position: absolute; z-index: 7; top: 50%; left: 50%; max-width: calc(100% - 32px); padding: 8px 14px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--ink-2); box-shadow: var(--sh-2); font-size: var(--fs-14); font-weight: 600; text-align: center; transform: translate(-50%, -50%); }
#view-merchants .merchant-map-attribution { position: absolute; z-index: 8; right: 0; bottom: 0; padding: 2px 8px; border-top-left-radius: var(--r-sm); background: color-mix(in srgb, var(--surface) 86%, transparent); color: var(--ink-3); font-size: var(--fs-12); line-height: 1.5; }
#view-merchants .merchant-map-attribution a { color: var(--ink-2); }
#view-merchants .merchant-map-legend { margin-top: var(--sp-3); }
#view-merchants .merchant-map-legend > li::before { border-radius: 50%; }
#view-merchants .merchant-map-legend > li.is-discount::before { background: var(--coin); }
#view-merchants .merchant-map-legend > li.is-current::before { background: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }

/* ----- 結果清單 ----- */
#view-merchants .merchant-result-heading h3 { font-size: var(--fs-18); }
#view-merchants .merchant-result-range { align-self: center; color: var(--ink-3); font-size: var(--fs-13); font-weight: 600; text-align: right; }
#view-merchants .merchant-card-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line-2); }
#view-merchants .merchant-card-list > li { min-width: 0; border-bottom: 1px solid var(--line-2); }
#view-merchants .merchant-card { align-items: center; gap: var(--sp-3); padding: 12px var(--sp-2); border: 0; border-radius: var(--r-md); }
#view-merchants .merchant-card:hover { background: var(--row-hover); }
#view-merchants .merchant-card-media { position: relative; display: grid; place-items: center; flex: none; width: 44px; height: 44px; overflow: hidden; border-radius: 11px; background: var(--brand-soft); color: var(--brand-ink); }
#view-merchants .merchant-card-media > img { width: 100%; height: 100%; object-fit: cover; }
#view-merchants .merchant-index { font-family: var(--font-num); font-size: var(--fs-15); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
#view-merchants .merchant-card-media.has-image .merchant-index { position: absolute; right: 0; bottom: 0; display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 7px 0 0 0; background: var(--brand); color: var(--on-brand); font-size: var(--fs-12); }
#view-merchants .merchant-card-body { gap: 3px; }
#view-merchants .merchant-card-topline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; }
#view-merchants .merchant-card-topline strong { min-width: 0; color: var(--ink); font-size: var(--fs-15); font-weight: 700; line-height: 1.4; }
#view-merchants .merchant-discount-tag > svg { width: 14px; height: 14px; }
#view-merchants .merchant-card-category { display: block; color: var(--ink-3); font-size: var(--fs-13); line-height: 1.5; overflow-wrap: anywhere; }
#view-merchants .merchant-ai-card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
#view-merchants .merchant-ai-card-tags:empty { display: none; }
#view-merchants .merchant-card-meta { display: flex; align-items: center; gap: var(--sp-2); }
#view-merchants .merchant-card-distance { display: grid; justify-items: end; gap: 1px; text-align: right; }
#view-merchants .merchant-card-distance b { font-size: var(--fs-15); white-space: nowrap; }
#view-merchants .merchant-card-distance small { white-space: nowrap; }
#view-merchants .merchant-card-go { width: 16px; height: 16px; color: var(--ink-4); }

/* AI 標籤：套用 .ui-tag，依語氣上色（也用在店家詳情） */
.merchant-ai-tag { max-width: 100%; }
.merchant-ai-tag > svg { width: 14px; height: 14px; }
.merchant-ai-tag.category { font-weight: 700; }
.merchant-ai-tag.subcategory { font-weight: 600; }
.merchant-ai-tag.review { font-weight: 700; }
.merchant-ai-pending { border-style: dashed; font-weight: 600; }

/* 載入中骨架：形狀同清單列 */
#view-merchants .merchant-skeleton-list { border-top: 1px solid var(--line-2); }
#view-merchants .merchant-skeleton { align-items: center; }
#view-merchants .merchant-skeleton-badge { width: 44px; height: 44px; flex: none; border-radius: 11px; }
#view-merchants .merchant-skeleton .ui-row-main > .ui-skeleton:last-child { width: 68%; }

/* =============================================================================
   2. 店家詳情（桌機右側面板 data-modal-layout="side"）
   ============================================================================= */
#modal:has(.modal-body .merchant-detail) { --modal-side-w: 720px; }
.merchant-detail { display: grid; gap: var(--sp-4); min-width: 0; }
.merchant-detail-hero { position: relative; display: grid; place-items: center; min-height: 150px; overflow: hidden; border-radius: var(--r-lg); background: linear-gradient(135deg, var(--brand-soft), var(--surface-2)); }
.merchant-detail-hero.has-image { min-height: 0; aspect-ratio: 16 / 7; background: var(--surface-3); }
.merchant-detail-hero > img { width: 100%; height: 100%; object-fit: cover; }
.merchant-detail-initial { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 20px; background: var(--surface); color: var(--brand-ink); box-shadow: var(--sh-2); font-size: var(--fs-32); font-weight: 800; line-height: 1; }
.merchant-detail-title { display: grid; gap: 6px; }
.merchant-detail-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.merchant-detail-tags > .ui-tag > svg { width: 14px; height: 14px; }
.merchant-detail-title h2 { color: var(--ink); font-size: var(--fs-24); font-weight: 800; line-height: 1.3; letter-spacing: -.01em; }
.merchant-detail-title p { color: var(--ink-2); font-size: var(--fs-15); line-height: 1.6; }
.merchant-detail-section { display: grid; gap: 6px; padding: var(--sp-4); border: 1px solid var(--line-2); border-radius: var(--r-lg); background: var(--surface-2); }
.merchant-detail-section h3 { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: var(--fs-15); }
.merchant-detail-section h3 > svg { width: 18px; height: 18px; color: var(--ink-3); }
.merchant-detail-section p { color: var(--ink-2); font-size: var(--fs-15); line-height: var(--lh-long); white-space: pre-line; overflow-wrap: anywhere; }
.merchant-detail-section.discount-callout { border-color: var(--coin-line); background: var(--coin-soft); }
.merchant-detail-section.discount-callout h3 > svg { color: var(--coin-deep); }
.merchant-detail-section.discount-callout p { color: var(--ink); font-weight: 600; }
.merchant-detail-ai > div { display: grid; gap: 6px; }
.merchant-detail-ai > div > p { color: var(--ink-2); font-size: var(--fs-14); line-height: 1.6; }
.merchant-ai-detail-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.merchant-detail-actions > a > svg { width: 18px; height: 18px; }
.merchant-detail-pay > div { font-size: var(--fs-15); }
.merchant-detail-disclaimer { color: var(--ink-3); font-size: var(--fs-13); line-height: 1.65; }

/* =============================================================================
   3. 掃碼中心（qr-scanner.js）
   版面：安全提示 → 1. 要做什麼（四張用途卡）→ 2. 用哪個帳號（搜尋、標籤、下拉、目前帳號卡、領獎範圍）
         → 集章活動與位置（只在集章）→ 3. 掃描或輸入（相機｜圖片／手動）→ 結果面板（空、載入、預覽、確認、結果、失敗）
   桌機置中 M（預設寬度）；手機是全高的底部抽屜。
   ============================================================================= */
.qr-scanner { display: grid; gap: var(--sp-5); min-width: 0; }
.qr-scanner .ui-section-head h3 { font-size: var(--fs-16); }
.qr-scanner.is-previewing .qr-capture-section, .qr-scanner.is-confirming .qr-type-section, .qr-scanner.is-confirming .qr-account-section, .qr-scanner.is-confirming .qr-capture-section, .qr-scanner.is-confirming .qr-stamp-fields { opacity: .72; }
.qr-scanner-intro { align-items: center; }
.qr-scanner-intro > .status { flex: none; }

/* ----- 1. 用途卡 ----- */
.qr-type-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-2); min-width: 0; padding: 0; border: 0; }
.qr-type-card {
  position: relative; display: grid; gap: 8px; min-width: 0; min-height: 44px; padding: 12px;
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); color: var(--ink); cursor: pointer;
  transition: border-color var(--t-fast), background-color var(--t-fast), box-shadow var(--t-fast);
}
.qr-type-card > input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.qr-type-card:hover { border-color: var(--ink-4); }
.qr-type-card:has(> input:checked) { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.qr-type-card:has(> input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.qr-type-card:has(> input:disabled) { cursor: not-allowed; opacity: .6; }
.qr-type-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: var(--brand-ink); background: var(--brand-soft); transition: background-color var(--t-fast), color var(--t-fast); }
.qr-type-card:has(> input:checked) .qr-type-icon { color: var(--on-brand); background: var(--brand); }
.qr-type-icon > svg { width: 20px; height: 20px; }
.qr-type-copy { display: grid; gap: 2px; min-width: 0; }
.qr-type-copy strong { color: var(--ink); font-size: var(--fs-15); line-height: 1.35; }
.qr-type-copy small { color: var(--ink-3); font-size: var(--fs-12); line-height: 1.5; }

/* ----- 2. 帳號 ----- */
.qr-account-picker { display: grid; gap: var(--sp-3); min-width: 0; }
.qr-account-search { position: relative; display: flex; align-items: center; min-width: 0; }
.qr-account-search > input { min-height: 44px; }
.qr-account-search > button { min-height: 44px; min-width: 44px; }
.qr-account-tag-filter { gap: 6px; }
.qr-account-select { color: var(--ink-2); }
.qr-account-search-count { color: var(--ink-3); font-size: var(--fs-13); }
.qr-account-search-empty { padding: 10px 12px; border: 1px dashed var(--line-strong); border-radius: var(--r-md); color: var(--ink-3); font-size: var(--fs-14); }

/* 目前帳號卡：頭像＋名稱＋四格事實＋官方到期同步狀態 */
.qr-account-expiry { min-width: 0; }
.qr-account-expiry-empty { padding: 12px 14px; border: 1px dashed var(--line-strong); border-radius: var(--r-lg); color: var(--ink-3); font-size: var(--fs-14); line-height: 1.6; }
.qr-account-expiry-card { display: grid; gap: var(--sp-3); min-width: 0; padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--card-sheen), var(--surface); }
.qr-account-expiry-card.has-expiry { border-color: var(--warn-line); }
.qr-account-expiry-card > header { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }
.qr-account-expiry-card > header > div { display: grid; gap: 1px; flex: 1; min-width: 0; }
.qr-account-expiry-card > header .eyebrow { margin: 0; }
.qr-account-expiry-card > header strong { color: var(--ink); font-size: var(--fs-16); line-height: 1.35; }
.qr-account-expiry-card > header small { color: var(--ink-3); font-size: var(--fs-13); }
.qr-account-expiry-card > header > .ui-tag { flex: none; }
.qr-account-expiry-card .ui-facts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.qr-account-expiry-card .ui-facts dd { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.qr-account-expiry-card.has-expiry .ui-facts > div:nth-child(3) dd { color: var(--warn); }
.qr-account-expiry-card > footer { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
.qr-account-expiry-card > footer button { min-height: 44px; }
.qr-account-expiry-card > .ui-field-hint { margin: 0; }
.qr-expiry-sync-status { display: inline-flex; align-items: center; gap: 7px; min-width: 0; color: var(--ink-3); font-size: var(--fs-13); font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.qr-expiry-sync-status::before { content: ""; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--ink-4); }
.qr-expiry-sync-status.loading { color: var(--brand-ink); }
.qr-expiry-sync-status.loading::before { background: var(--brand); color: var(--brand); animation: ui-live 1.8s ease-out infinite; }
.qr-expiry-sync-status.success { color: var(--ok); }
.qr-expiry-sync-status.success::before { background: var(--ok-solid); }
.qr-expiry-sync-status.error { color: var(--bad); }
.qr-expiry-sync-status.error::before { background: var(--bad-solid); }

/* 領獎帳號範圍：單一／特定／全部 */
.qr-award-scope { min-width: 0; }
.qr-award-scope-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-2); min-width: 0; padding: 0; border: 0; }
.qr-scope-option { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 10px; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--ink); cursor: pointer; transition: border-color var(--t-fast), background-color var(--t-fast); }
.qr-scope-option > input { margin-top: 2px; }
.qr-scope-option > span { display: grid; gap: 1px; min-width: 0; }
.qr-scope-option strong { color: var(--ink); font-size: var(--fs-14); }
.qr-scope-option small { color: var(--ink-3); font-size: var(--fs-12); line-height: 1.5; }
.qr-scope-option:hover { border-color: var(--ink-4); }
.qr-scope-option:has(> input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.qr-award-specific { display: grid; gap: var(--sp-3); min-width: 0; }
.qr-award-specific-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2) var(--sp-3); }
.qr-award-specific-actions > strong { color: var(--ink); font-size: var(--fs-14); }
.qr-award-specific-actions > div { display: flex; flex-wrap: wrap; gap: 6px; }
.qr-award-specific-actions button { min-height: 44px; }
.qr-award-account-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.qr-award-account-grid .check-card-body > small { font-family: var(--font-ui); font-weight: 500; }
.qr-award-account-grid .account-tag-badges, .qr-award-account-grid .account-tags-none { margin-top: 3px; }
.qr-award-selection-empty { padding: 10px 12px; border: 1px dashed var(--line-strong); border-radius: var(--r-md); color: var(--ink-3); font-size: var(--fs-14); }
.qr-award-all-note { color: var(--ink-2); }

/* ----- 集章活動與位置 ----- */
.qr-stamp-fields { min-width: 0; }
.qr-stamp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3) var(--sp-4); align-items: end; }
.qr-stamp-grid > .qr-stamp-entry-picker { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-4); padding: 8px 12px; }
.qr-stamp-entry-picker > legend { float: left; margin-right: var(--sp-2); padding: 0; }
.qr-stamp-entry-picker > label { min-height: 44px; color: var(--ink); font-size: var(--fs-14); }
.qr-location-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
.qr-location-actions > button > svg { width: 18px; height: 18px; }
.qr-location-actions > span { font-size: var(--fs-13); font-weight: 600; }

/* ----- 3. 掃描或輸入 ----- */
.qr-capture-section { min-width: 0; }
.qr-capture-section .ui-section-head > .ui-tag { flex: none; }
.qr-scanner-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-4); min-width: 0; }
.qr-capture-panel, .qr-alternative-panel { display: grid; gap: var(--sp-3); align-content: start; min-width: 0; }
.qr-viewport { position: relative; display: grid; place-items: center; aspect-ratio: 4 / 3; min-height: 200px; overflow: hidden; border-radius: var(--r-lg); color: var(--on-hero); background: var(--media-bg); isolation: isolate; }
.qr-viewport video { position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity var(--t-mid); }
.qr-viewport.active video { opacity: 1; }
.qr-camera-empty { z-index: 1; display: grid; justify-items: center; gap: 4px; padding: var(--sp-4); text-align: center; }
.qr-camera-empty > span { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 4px; border: 1px solid color-mix(in srgb, var(--on-hero) 26%, transparent); border-radius: 16px; background: color-mix(in srgb, var(--on-hero) 10%, transparent); }
.qr-camera-empty > span > svg { width: 26px; height: 26px; }
.qr-camera-empty strong { font-size: var(--fs-15); }
.qr-camera-empty small { color: color-mix(in srgb, var(--on-hero) 74%, transparent); font-size: var(--fs-12); line-height: 1.5; }
.qr-viewfinder { position: absolute; z-index: 2; width: min(62%, 240px); aspect-ratio: 1; border-radius: 18px; pointer-events: none; box-shadow: 0 0 0 999px color-mix(in srgb, var(--media-bg) 62%, transparent); opacity: 0; transition: opacity var(--t-mid); }
.qr-viewport.active .qr-viewfinder { opacity: 1; }
.qr-viewfinder::before, .qr-viewfinder::after, .qr-viewfinder span::before, .qr-viewfinder span::after { content: ""; position: absolute; width: 26px; height: 26px; border: 0 solid var(--on-hero); }
.qr-viewfinder::before { top: -2px; left: -2px; border-width: 3px 0 0 3px; border-radius: 12px 0 0 0; }
.qr-viewfinder::after { top: -2px; right: -2px; border-width: 3px 3px 0 0; border-radius: 0 12px 0 0; }
.qr-viewfinder span::before { bottom: -2px; left: -2px; border-width: 0 0 3px 3px; border-radius: 0 0 0 12px; }
.qr-viewfinder span::after { right: -2px; bottom: -2px; border-width: 0 3px 3px 0; border-radius: 0 0 12px 0; }
/* 狀態列：JS 只切換 .muted／.error-text，這裡把它畫成有圓點的一句話 */
.qr-capture-status { display: flex; align-items: flex-start; gap: 8px; margin: 0; min-height: 0; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: var(--r-md); background: var(--surface-2); color: var(--ink-2); font-size: var(--fs-14); font-weight: 600; line-height: 1.5; white-space: normal; }
.qr-capture-status::before { content: ""; width: 8px; height: 8px; flex: none; margin-top: 6px; border-radius: 50%; background: var(--ink-4); }
.qr-capture-status.error-text { border-color: var(--bad-line); background: var(--bad-soft); color: var(--bad); }
.qr-capture-status.error-text::before { background: var(--bad-solid); }
.qr-camera-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-2); }
.qr-camera-actions > button > svg { width: 18px; height: 18px; }
.qr-file-picker { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--sp-3); min-height: 72px; padding: 12px 14px; border: 1px dashed var(--line-strong); border-radius: var(--r-lg); background: var(--surface-2); color: var(--ink); cursor: pointer; transition: border-color var(--t-fast), background-color var(--t-fast); }
.qr-file-picker:hover { border-color: var(--brand); background: var(--brand-soft); }
.qr-file-picker:has(> input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.qr-file-picker:has(> input:disabled) { cursor: not-allowed; opacity: .6; }
.qr-file-picker > input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.qr-file-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; color: var(--brand-ink); background: var(--surface); box-shadow: var(--sh-1); }
.qr-file-copy { display: grid; gap: 2px; min-width: 0; }
.qr-file-copy strong { color: var(--ink); font-size: var(--fs-14); line-height: 1.4; }
.qr-file-copy small { color: var(--ink-3); font-size: var(--fs-12); line-height: 1.5; }
.qr-manual-form { display: grid; gap: var(--sp-2); min-width: 0; }
.qr-manual-form textarea { min-height: 84px; font-family: var(--font-mono); font-size: var(--fs-14); }
.qr-privacy-note { display: flex; gap: 8px; margin: 0; color: var(--ink-3); font-size: var(--fs-13); line-height: 1.6; }
.qr-privacy-note > svg { width: 16px; height: 16px; flex: none; margin-top: 3px; color: var(--ok); }

/* ----- 結果面板 ----- */
.qr-result-panel { display: grid; gap: var(--sp-4); min-width: 0; padding: var(--sp-5); border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--card-sheen), var(--surface); box-shadow: var(--sh-1); }
.qr-result-state { min-height: 150px; }
.qr-result-loading { display: grid; justify-items: center; align-content: center; gap: 6px; min-height: 150px; text-align: center; color: var(--ink-2); }
.qr-result-loading strong { color: var(--ink); font-size: var(--fs-15); }
.qr-result-loading small { color: var(--ink-3); font-size: var(--fs-13); }
.qr-result-steps { padding-bottom: var(--sp-3); border-bottom: 1px solid var(--line-2); }
.qr-result-heading { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--sp-2) var(--sp-3); min-width: 0; }
.qr-result-heading .eyebrow { margin-bottom: 2px; }
.qr-result-heading h3 { color: var(--ink); font-size: var(--fs-18); line-height: 1.35; overflow-wrap: anywhere; }
.qr-result-heading > .status { flex: none; margin-top: 2px; }
.qr-result-outcome > div > strong { display: block; }
.qr-preview-facts { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.qr-expiry { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--ink-3); font-size: var(--fs-13); font-weight: 600; }
.qr-expiry > svg { width: 15px; height: 15px; }
.qr-payment-action { flex-wrap: wrap; align-items: center; }
.qr-payment-action > div { flex: 1 1 260px; }
.qr-payment-action > button { flex: none; margin-left: auto; }
.qr-preview-only-note { margin: 0; padding: 10px 12px; border: 1px dashed var(--line-strong); border-radius: var(--r-md); color: var(--ink-2); font-size: var(--fs-14); line-height: 1.6; }
.qr-result-safety { margin: 0; padding: 8px 12px; border-left: 3px solid var(--line-strong); color: var(--ink-3); font-size: var(--fs-13); line-height: 1.65; }

/* 確認：確認碼→重新輸入→墨色「確認並執行」（動到金幣的最後一步） */
.qr-confirm-form { display: grid; gap: var(--sp-3); min-width: 0; padding-top: var(--sp-4); border-top: 1px solid var(--line-2); }
.qr-confirm-form > label { max-width: 360px; }
.qr-confirm-code { display: inline-flex; align-items: center; gap: var(--sp-3); justify-self: start; max-width: 100%; padding: 8px 14px 8px 12px; border-radius: var(--r-md); background: var(--inv); color: var(--on-inv); }
.qr-confirm-code > span { font-size: var(--fs-13); font-weight: 650; }
.qr-confirm-code > strong { font-family: var(--font-num); font-size: var(--fs-24); font-weight: 800; letter-spacing: .22em; line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.qr-confirm-note { margin: 0; color: var(--ink-2); font-size: var(--fs-14); line-height: 1.65; }
.qr-confirm-error:not([hidden]) { padding: 10px 12px; border: 1px solid var(--bad-line); border-radius: var(--r-md); background: var(--bad-soft); }
.qr-confirm-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-2) var(--sp-3); margin: 0 calc(-1 * var(--sp-5)) calc(-1 * var(--sp-5)); padding: 14px var(--sp-5); border-top: 1px solid var(--line-2); border-radius: 0 0 calc(var(--r-xl) - 1px) calc(var(--r-xl) - 1px); background: var(--surface-2); }
.qr-confirm-foot > p { flex: 1 1 240px; min-width: 0; margin: 0; color: var(--ink-2); font-size: var(--fs-14); line-height: 1.6; }
.qr-confirm-foot > p strong { color: var(--ink); }
/* 墨色按鈕前面的鎖頭：JS 會改寫按鈕文字，所以圖示畫在 ::before（遮罩只讀透明度） */
.qr-scanner button.commit::before {
  content: ""; width: 16px; height: 16px; flex: none; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4.5' y='10.5' width='15' height='10' rx='2.5'/%3E%3Cpath d='M8 10.5V8a4 4 0 0 1 8 0v2.5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4.5' y='10.5' width='15' height='10' rx='2.5'/%3E%3Cpath d='M8 10.5V8a4 4 0 0 1 8 0v2.5'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* 集章里程碑 */
.qr-stamp-awards { padding-top: var(--sp-3); border-top: 1px solid var(--line-2); }
.qr-award-list .ui-row-icon > svg { width: 18px; height: 18px; }

/* 批次領獎：預覽與逐帳號結果 */
.qr-award-batch-overview { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.qr-award-batch-overview dd { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.qr-award-batch-confirm { border-top-color: var(--line); }
.qr-award-batch-intents { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); margin: 0; padding: 0; list-style: none; }
.qr-award-batch-intents > li { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.qr-award-batch-intents .ui-row-main strong { font-size: var(--fs-14); }
.qr-award-batch-excluded { padding: 10px 12px; border: 1px solid var(--warn-line); border-radius: var(--r-md); background: var(--warn-soft); }
.qr-award-batch-excluded > summary { color: var(--warn); font-size: var(--fs-14); }
.qr-award-batch-excluded > div { display: grid; gap: 6px; padding-top: 6px; }
.qr-award-batch-excluded p { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 0; color: var(--ink-2); font-size: var(--fs-14); line-height: 1.5; }
.qr-award-batch-excluded p strong { color: var(--ink); }
.qr-award-batch-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.qr-award-result { display: grid; gap: var(--sp-2); min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.qr-award-result.unknown { border-color: var(--warn-line); background: var(--warn-soft); }
.qr-award-result > header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 6px 10px; }
.qr-award-result > header > div { display: grid; gap: 1px; min-width: 0; }
.qr-award-result > header strong { color: var(--ink); font-size: var(--fs-15); }
.qr-award-result > header small { color: var(--ink-3); font-size: var(--fs-12); }
.qr-award-result .ui-facts { grid-template-columns: minmax(0, 1fr); border: 0; background: transparent; }
.qr-award-result .ui-facts > div { padding: 6px 0; box-shadow: 0 1px 0 var(--line-2); }
.qr-award-result .ui-facts dd { font-size: var(--fs-14); }
.qr-award-batch-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* =============================================================================
   4. 斷點
   ============================================================================= */
@media (max-width: 1180px) {
  #view-merchants .merchant-layout { grid-template-columns: minmax(0, 1fr) minmax(320px, .9fr); }
  #view-merchants .merchant-filter-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  #view-merchants .merchant-location-row { grid-template-columns: auto minmax(0, 1fr); }
  #view-merchants .merchant-manual-location-form { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  #view-merchants .merchant-view-switch { display: inline-flex; margin-top: var(--sp-4); }
  #view-merchants .merchant-layout { grid-template-columns: minmax(0, 1fr); margin-top: var(--sp-3); }
  #view-merchants .merchant-map-panel { position: static; order: -1; }
  #view-merchants .merchant-map { height: 220px; }
  #view-merchants .merchant-layout.is-map .merchant-map { height: calc(100dvh - 340px); min-height: 360px; }
  #view-merchants .merchant-layout.is-map .merchant-results { display: none; }
}

@media (max-width: 600px) {
  #view-merchants .merchant-filter-form, #view-merchants .merchant-ai-filter-fields, #view-merchants .merchant-manual-location-form { grid-template-columns: minmax(0, 1fr); }
  #view-merchants .merchant-filter-actions > button { flex: 1 1 120px; }
  #view-merchants .merchant-card { flex-wrap: nowrap; }
  #view-merchants .merchant-result-range { text-align: left; }
  /* 分頁：頁數說明在上、上一頁／下一頁各佔一半，不再零散換行 */
  #view-merchants .ui-pagination { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #view-merchants .ui-pagination > span { grid-column: 1 / -1; order: -1; }
  .merchant-detail-title h2 { font-size: var(--fs-20); }

  .qr-scanner-intro > .status { display: none; }
  .qr-type-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .qr-scanner-layout, .qr-stamp-grid, .qr-camera-actions { grid-template-columns: minmax(0, 1fr); }
  .qr-award-scope-options, .qr-award-account-grid, .qr-award-batch-intents, .qr-award-batch-results { grid-template-columns: minmax(0, 1fr); }
  .qr-account-expiry-card .ui-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .qr-result-steps { gap: 6px; }
  .qr-result-steps > li + li::before { width: 14px; }
  .qr-confirm-form > label { max-width: none; }
  .qr-confirm-foot > button { flex: 1 1 100%; }
  .qr-payment-action > button { flex: 1 1 100%; margin-left: 0; }
  /* 手機：掃碼中心是全高的底部抽屜，把手與圓角照舊 */
  #modal:has(.modal-body .qr-scanner), #modal:has(.modal-body .qr-scanner) .modal-card { max-height: calc(100dvh - 10px); }
  #modal:has(.modal-body .qr-scanner) { height: calc(100dvh - 10px); }
}
