/* ============================================================================
   Phase 8 + 9 + 10 (2026-05-08) — store enhancements

   Phase 8: 收藏夾頁 /profile/wishlist
   Phase 9: 訂單匯出 CSV button
   Phase 10: PWA 離線 banner
   ============================================================================ */

/* ============================================================================
   BUG #15 fix (Tier 4 audit, 2026-05-08): [hidden] HTML attribute defaults
   to display:none with very low specificity (0,0,0,1). Any class-level
   `display: grid|flex|block` overrides it, breaking JS `el.hidden = true`
   semantics. Affected containers across Phase 2-16:
     .dp-wishlist-empty / .dp-wishlist-login-hint  (display:grid)
     .dp-offline-banner / .dp-recent-browse        (display:flex)
     .dp-resume-cart-banner                         (display:flex, body. selector)
     .dp-orders-empty / .dp-shop-empty              (display:grid, store-phase-2-3.css)
   Symptom verified on /profile/wishlist (not logged in): both #wishlistEmpty
   AND #wishlistLoginHint visible simultaneously.
   Fix: explicit [hidden] override with !important to beat all class chains.
   ============================================================================ */
.dp-wishlist-empty[hidden],
.dp-wishlist-login-hint[hidden],
.dp-offline-banner[hidden],
.dp-recent-browse[hidden],
.dp-resume-cart-banner[hidden],
.dp-orders-empty[hidden],
.dp-shop-empty[hidden] {
  display: none !important;
}

/* ============================================================================
   v45g (2026-05-08): 隱藏 site-audio.js 自動注入的 right-bottom 音樂 FAB
   on 商城頁面 (含 /m/store + /store + /store/*).
   User feedback: 「商城右下角 為什麼會有一個音樂的按鈕?」

   pwa.js (auto-inject 在所有 user page) 會載 /site-audio.js → 後者
   document.body.appendChild 一個 .site-audio-fab (position:fixed bottom-right
   48×48 button). 商城頁面 topbar 本來就有音樂 toggle (.dp-top-icon--music
   on /m/store 或 .site-music-toggle on /store), 多一個 bottom-right FAB
   是冗餘 + 擋到 cart FAB / 結帳 button.

   策略: CSS-only hide via :has() detection of store-specific markers.
   不能單純用 body.galaxy.marine 因為 /index.html homepage 也是該 class
   (homepage 仍要保留 FAB 一致行為).

   涵蓋:
     - /m/store, /m/store/* (mobile)        → body.dp-body--store
     - /store (desktop hero)                 → body:has(.store-page)
     - /store/cart                           → body:has(.store-cart-page)
     - /store/checkout / /store/payment / /store/confirm
       (uses dp-checkout-page / dp-confirm-page)
     - /store/orders                         → body:has(.store-orders-shell)
     - /store/orders/:id (SSR)               → body:has(.store-order-detail-page)
     - /store/item/:id (SSR)                 → body:has(.store-detail-page)
     - /store/order-success                  → body:has(.store-order-success)
   ============================================================================ */
body.dp-body--store .site-audio-fab,
body.dp-body--store .site-audio-panel,
body:has(.store-page) .site-audio-fab,
body:has(.store-page) .site-audio-panel,
body:has(.store-cart-page) .site-audio-fab,
body:has(.store-cart-page) .site-audio-panel,
body:has(.dp-checkout-page) .site-audio-fab,
body:has(.dp-checkout-page) .site-audio-panel,
/* R206 hardcore-gould (2026-05-10): payment 頁面 main class is dp-payment-page,
   原 selector 漏了, FAB 在付款選擇頁仍會出現蓋住 sticky bar — 補加. */
body:has(.dp-payment-page) .site-audio-fab,
body:has(.dp-payment-page) .site-audio-panel,
body:has(.dp-confirm-page) .site-audio-fab,
body:has(.dp-confirm-page) .site-audio-panel,
body:has(.store-detail-page) .site-audio-fab,
body:has(.store-detail-page) .site-audio-panel,
body:has(.store-order-detail-page) .site-audio-fab,
body:has(.store-order-detail-page) .site-audio-panel,
body:has(.store-orders-shell) .site-audio-fab,
body:has(.store-orders-shell) .site-audio-panel,
/* R206 hardcore-gould (2026-05-10): order-success 頁面 main class 實際是
   store-success-page (不是 store-order-success), 原 selector 永遠 match 不到
   → FAB 在訂單完成頁仍會出現. 改名對齊實際 markup. 保留原 store-order-success
   selector 也 OK 但不影響. */
body:has(.store-success-page) .site-audio-fab,
body:has(.store-success-page) .site-audio-panel,
body:has(.store-order-success) .site-audio-fab,
body:has(.store-order-success) .site-audio-panel,
body:has(.dp-wishlist-page) .site-audio-fab,
body:has(.dp-wishlist-page) .site-audio-panel {
  display: none !important;
}

/* ============================================================================
   Phase 8 — 收藏夾頁
   ============================================================================ */

.dp-wishlist-page {
  padding: 96px 16px 96px;
  max-width: 1200px;
  margin: 0 auto;
}

.dp-wishlist-head-actions {
  display: flex;
  gap: 8px;
}

.dp-wishlist-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0 12px;
  padding: 0 4px;
}

.dp-wishlist-tab {
  appearance: none;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.18);
  color: rgba(203, 213, 225, 0.85);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.dp-wishlist-tab:hover {
  background: rgba(34, 211, 238, 0.08);
  border-color: rgba(34, 211, 238, 0.4);
  color: #22d3ee;
}

.dp-wishlist-tab.is-active {
  background: linear-gradient(135deg, #22d3ee 0%, #0ea5e9 100%);
  border-color: rgba(34, 211, 238, 0.65);
  color: #0a1a3e;
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.35);
}

.dp-wishlist-tab__count {
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dp-wishlist-tab.is-active .dp-wishlist-tab__count {
  background: rgba(10, 26, 62, 0.32);
}

.dp-wishlist-shell {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.7) 0%, rgba(7, 16, 38, 0.84) 100%);
  border: 1px solid rgba(34, 211, 238, 0.16);
  border-radius: 16px;
  padding: 16px;
  min-height: 280px;
}

.dp-wishlist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.dp-wishlist-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.dp-wishlist-card:hover {
  border-color: rgba(34, 211, 238, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px -8px rgba(34, 211, 238, 0.25);
}

.dp-wishlist-card__media {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  background: rgba(8, 14, 27, 0.6);
}

.dp-wishlist-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.dp-wishlist-card__img--placeholder {
  object-fit: contain;
  opacity: 0.7;
  padding: 24px;
}

.dp-wishlist-card__badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: rgba(15, 23, 42, 0.86);
  color: #f1f5f9;
}

.dp-wishlist-card__badge--soldout {
  background: rgba(239, 68, 68, 0.92);
  color: #ffffff;
}

.dp-wishlist-card__body {
  padding: 12px;
  display: grid;
  gap: 6px;
  flex: 1;
}

.dp-wishlist-card__head {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dp-wishlist-card__type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: rgba(148, 163, 184, 0.15);
  color: rgba(148, 163, 184, 0.85);
}

.dp-wishlist-card__type--store {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.16) 0%, rgba(234, 157, 34, 0.08) 100%);
  color: #facc15;
  border: 1px solid rgba(250, 204, 21, 0.32);
}

.dp-wishlist-card__type--pool {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.16) 0%, rgba(14, 165, 233, 0.08) 100%);
  color: #22d3ee;
  border: 1px solid rgba(34, 211, 238, 0.32);
}

.dp-wishlist-card__title {
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 700;
  color: #f1f5f9;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dp-wishlist-card__title a {
  color: inherit;
  text-decoration: none;
}

.dp-wishlist-card__title a:hover {
  color: #22d3ee;
}

.dp-wishlist-card__meta {
  font-size: 12px;
  color: rgba(148, 163, 184, 0.85);
  font-variant-numeric: tabular-nums;
}

.dp-wishlist-card__date {
  font-size: 11px;
  color: rgba(148, 163, 184, 0.6);
  font-variant-numeric: tabular-nums;
}

.dp-wishlist-card__actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
}

.dp-wishlist-card__remove {
  margin-left: auto;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dp-wishlist-card__remove:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.4);
}

.btn-compact.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

/* Empty state */
.dp-wishlist-empty {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 48px 20px;
  gap: 14px;
}

.dp-wishlist-empty__icon {
  width: 220px;
  height: 220px;
  object-fit: contain;
  opacity: 0.92;
  filter: drop-shadow(0 8px 28px rgba(34, 211, 238, 0.22));
}

.dp-wishlist-empty h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #f1f5f9;
}

.dp-wishlist-empty p {
  margin: 0;
  max-width: 360px;
  font-size: 14px;
  line-height: 1.6;
  color: rgba(203, 213, 225, 0.85);
}

.dp-wishlist-empty__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.dp-wishlist-login-hint {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 64px 20px;
  gap: 12px;
}

.dp-wishlist-login-hint h3 {
  margin: 0;
  font-size: 18px;
  color: #f1f5f9;
  font-weight: 700;
}

.dp-wishlist-login-hint p {
  margin: 0;
  font-size: 14px;
  color: rgba(203, 213, 225, 0.85);
}

.dp-wishlist-login-hint__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 6px;
}

@media (max-width: 640px) {
  .dp-wishlist-page {
    padding: 80px 12px 80px;
  }
  .dp-wishlist-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
  }
  .dp-wishlist-card__title {
    font-size: 13px;
  }
  .dp-wishlist-empty__icon {
    width: 160px;
    height: 160px;
  }
}

/* ============================================================================
   Phase 9 — 訂單匯出 head actions row
   ============================================================================ */

.dp-orders-head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#storeOrdersExport:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 560px) {
  .dp-orders-head-actions {
    width: 100%;
    justify-content: stretch;
  }
  .dp-orders-head-actions .btn {
    flex: 1 1 0;
  }
}

/* ============================================================================
   Phase 10 — PWA 離線 banner
   ============================================================================ */

.dp-offline-banner {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  z-index: 1980;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #ea9d22 0%, #f97316 100%);
  color: #0a1a3e;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.32);
  animation: dpOfflineBannerIn 0.3s ease-out;
}

@keyframes dpOfflineBannerIn {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.dp-offline-banner__icon {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(10, 26, 62, 0.18);
}

.dp-offline-banner__body {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.dp-offline-banner__title {
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: 14px;
}

.dp-offline-banner__desc {
  font-size: 12px;
  opacity: 0.86;
}

/* When offline, push topbar down to make room for banner */
body.dp-offline-mode .topbar {
  margin-top: 56px;
  transition: margin-top 0.2s ease;
}

@media (max-width: 640px) {
  .dp-offline-banner {
    padding: 8px 12px;
    gap: 8px;
  }
  .dp-offline-banner__icon {
    width: 28px;
    height: 28px;
  }
  .dp-offline-banner__title {
    font-size: 13px;
  }
  .dp-offline-banner__desc {
    font-size: 11px;
  }
  body.dp-offline-mode .topbar {
    margin-top: 64px;
  }
}

/* ============================================================================
   Phase 14 (2026-05-08) — 商品分享 button
   Co-located here (instead of new file) since it's a small addition.
   ============================================================================ */

.dp-share-btn {
  display: inline-flex;
  align-items: center;
  gap: 0;
  font-weight: 600;
  border-color: rgba(34, 211, 238, 0.32);
  background: rgba(34, 211, 238, 0.06);
  color: #22d3ee;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.dp-share-btn:hover,
.dp-share-btn:focus-visible {
  background: rgba(34, 211, 238, 0.16);
  border-color: rgba(34, 211, 238, 0.65);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -4px rgba(34, 211, 238, 0.4);
  outline: none;
}

.dp-share-btn:active {
  transform: translateY(0);
}

.dp-share-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* Add error variant for shared toast */
.dp-store-toast.dp-store-toast--error {
  border-color: rgba(239, 68, 68, 0.55);
  color: #fef2f2;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.92) 0%, rgba(185, 28, 28, 0.92) 100%);
}

@media (max-width: 640px) {
  .dp-share-btn {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================================================
   Phase 15 (2026-05-08) — wishlist 排序 + 即時價格/庫存 enrichment
   ============================================================================ */

.dp-wishlist-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 16px 0 12px;
  padding: 0 4px;
}

.dp-wishlist-toolbar .dp-wishlist-tabs {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}

.dp-wishlist-sort {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.dp-wishlist-sort__label {
  font-size: 12px;
  font-weight: 600;
  color: rgba(148, 163, 184, 0.85);
  letter-spacing: 0.04em;
}

.dp-wishlist-sort select {
  font-size: 13px;
  padding: 6px 28px 6px 10px;
  border-radius: 8px;
  background-color: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.18);
  color: #f1f5f9;
}

.dp-wishlist-sort select:hover,
.dp-wishlist-sort select:focus-visible {
  border-color: rgba(34, 211, 238, 0.55);
  outline: none;
}

/* Low-stock badge (Phase 15) */
.dp-wishlist-card__badge--low {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.92) 0%, rgba(234, 157, 34, 0.92) 100%);
  color: #0a1a3e;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Price meta (Phase 15) */
.dp-wishlist-card__price {
  color: #facc15;
  font-weight: 700;
  font-size: 13px;
}

@media (max-width: 560px) {
  .dp-wishlist-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .dp-wishlist-sort {
    justify-content: space-between;
    padding: 4px 2px;
  }
  .dp-wishlist-sort select {
    flex: 1 1 auto;
    max-width: 200px;
  }
}

/* ============================================================================
   Phase 16 (2026-05-08) — 最近瀏覽 carousel
   Cross-platform: works on desktop /store + mobile /m/store
   ============================================================================ */

.dp-recent-browse {
  margin: 24px auto 16px;
  padding: 16px;
  max-width: 1200px;
  width: 100%;
  border: 1px solid rgba(34, 211, 238, 0.18);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.62) 0%, rgba(7, 16, 38, 0.78) 100%);
  box-shadow: 0 6px 24px -8px rgba(34, 211, 238, 0.16);
}

.dp-recent-browse__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 0 4px;
}

.dp-recent-browse__title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: #f1f5f9;
  letter-spacing: 0.02em;
}

.dp-recent-browse__title::before {
  content: "🕒 ";
  margin-right: 4px;
}

.dp-recent-browse__clear {
  appearance: none;
  background: transparent;
  border: 0;
  font-size: 12px;
  color: rgba(148, 163, 184, 0.7);
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.dp-recent-browse__clear:hover,
.dp-recent-browse__clear:focus-visible {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
  outline: none;
}

.dp-recent-browse__scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scroll-behavior: smooth;
  padding: 4px 4px 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(34, 211, 238, 0.4) transparent;
}

.dp-recent-browse__scroll::-webkit-scrollbar {
  height: 6px;
}

.dp-recent-browse__scroll::-webkit-scrollbar-thumb {
  background: rgba(34, 211, 238, 0.32);
  border-radius: 3px;
}

.dp-recent-browse__scroll::-webkit-scrollbar-track {
  background: transparent;
}

/* BUG #12 fix: <article> wrapper instead of nested <button> in <a> */
.dp-recent-browse__card {
  flex-shrink: 0;
  width: 132px;
  scroll-snap-align: start;
  display: block;
  position: relative;
  background: rgba(15, 23, 42, 0.62);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

/* The clickable link inside the article — fills card */
.dp-recent-browse__link {
  display: block;
  text-decoration: none;
  color: inherit;
  outline: none;
}

.dp-recent-browse__card:hover,
.dp-recent-browse__card:focus-within {
  border-color: rgba(34, 211, 238, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px -8px rgba(34, 211, 238, 0.32);
}

.dp-recent-browse__card.is-disabled {
  opacity: 0.6;
}

.dp-recent-browse__media {
  position: relative;
  aspect-ratio: 1 / 1;
  background: rgba(8, 14, 27, 0.6);
  overflow: hidden;
}

.dp-recent-browse__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.dp-recent-browse__img--placeholder {
  object-fit: contain;
  padding: 16px;
  opacity: 0.7;
}

.dp-recent-browse__badge {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: rgba(15, 23, 42, 0.86);
  color: #f1f5f9;
}

.dp-recent-browse__badge--soldout {
  background: rgba(239, 68, 68, 0.92);
  color: #ffffff;
}

.dp-recent-browse__badge--inactive {
  background: rgba(148, 163, 184, 0.92);
  color: #0a1a3e;
}

.dp-recent-browse__body {
  padding: 8px 10px 10px;
  display: grid;
  gap: 4px;
  min-height: 56px;
}

.dp-recent-browse__name {
  font-size: 12px;
  line-height: 1.35;
  color: #f1f5f9;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dp-recent-browse__price {
  font-size: 12px;
  font-weight: 700;
  color: #facc15;
  font-variant-numeric: tabular-nums;
}

.dp-recent-browse__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.62);
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, color 0.15s ease;
  opacity: 0;
}

.dp-recent-browse__card:hover .dp-recent-browse__remove,
.dp-recent-browse__card:focus-within .dp-recent-browse__remove,
.dp-recent-browse__remove:focus-visible {
  opacity: 1;
}

.dp-recent-browse__remove:hover {
  background: rgba(239, 68, 68, 0.92);
  color: #ffffff;
}

@media (max-width: 640px) {
  .dp-recent-browse {
    padding: 12px;
    margin: 16px auto 12px;
    border-radius: 14px;
  }
  .dp-recent-browse__title {
    font-size: 15px;
  }
  .dp-recent-browse__card {
    width: 116px;
  }
  .dp-recent-browse__remove {
    opacity: 1; /* always visible on mobile (no hover) */
  }
}
