/* 響應式規則集中放在此樣式區塊後段 */
#page-loader {
  position: fixed;
  z-index: 3000;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: white;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.6s ease;
}

.loader-content {
  text-align: center;
  animation: fadeInUp 0.6s ease;
}

.loader-content img {
  width: 300px;
  margin-bottom: 1rem;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

body.loaded #page-loader {
  opacity: 0;
  pointer-events: none;
}

#productModal,
#certModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
}

#productModal {
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 9999;
}

#certModal {
  background-color: rgba(255, 253, 253, 0);
  z-index: 10000;
}

/* ===== 認證彈窗自動縮放至視窗大小 ===== */
#certModal .modal-content {
  background: rgba(255, 255, 255, 0);
  padding: 0;
  border-radius: 18px;
  width: auto;
  height: auto;
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
  position: relative;
  display: inline-block;
}

/* ===== 認證彈窗左右導覽箭頭 ===== */
.cert-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(42, 31, 24, 0.42);
  color: #fff;
  font-size: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  z-index: 3;
  touch-action: none;
}

.cert-nav-btn:hover {
  background: rgba(42, 31, 24, 0.62);
}

.cert-nav-btn.left {
  left: 8px;
}

.cert-nav-btn.right {
  right: 8px;
}

/* ===== 商品彈窗基礎 ===== */
#productModal .modal-content {
  position: relative;
}

#productModalCloseBtn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 30;
  padding: 0;
}

#productModalCloseBtn img {
  width: 28px;
  height: 28px;
}

.modal-content {
  background: #ffffff;
  padding: 0.8rem;      /* JS 會覆寫直向 padding，橫向保留這個預設 */
  border-radius: 18px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  color: #1f2933;
  overflow-y: auto;
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
}

.modal-gesture-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  border-radius: 18px;
  background: rgba(20, 20, 20, 0.38);
  backdrop-filter: blur(1px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  color: #fff;
  pointer-events: auto;
  opacity: 0;
  animation: hintFadeIn 0.25s ease forwards;
}

.modal-gesture-overlay .hint-side {
  width: 42%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.modal-gesture-overlay .hint-side i {
  font-size: 1.35rem;
}

.modal-gesture-overlay .hint-side.left i {
  animation: hintArrowLeft 1.2s ease-in-out infinite;
}

.modal-gesture-overlay .hint-side.right i {
  animation: hintArrowRight 1.2s ease-in-out infinite;
}

.modal-gesture-overlay .hint-divider {
  width: 1px;
  height: min(68%, 360px);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.28);
}

@keyframes hintArrowLeft {
  0%, 100% { transform: translateX(0); opacity: 0.65; }
  50% { transform: translateX(-4px); opacity: 1; }
}

@keyframes hintArrowRight {
  0%, 100% { transform: translateX(0); opacity: 0.65; }
  50% { transform: translateX(4px); opacity: 1; }
}

@keyframes hintFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-flex {
  flex: 1 1 auto;
  display: flex;
  gap: 1.5rem;
  min-height: 0;
}

.modal-left {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-radius: calc(18px - 0.8rem);
  touch-action: pan-y;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.modal-right {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
}

/* 主圖樣式 */
.modal-right #modalMainImg {
  width: 100%;
  object-fit: contain;
  border-radius: calc(18px - 0.8rem);
  background: #f8f9fb;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.modal-main-wrap {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.main-img-zone {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 2;
  cursor: pointer;
  background: rgba(0, 0, 0, 0);
}

.main-img-zone-left {
  left: 0;
}

.main-img-zone-right {
  right: 0;
}

/* 縮圖列 */
.modal-right #modalThumbnails {
  display: flex !important;
  gap: 0.5rem;
  flex-wrap: nowrap !important;
  overflow-x: auto !important;
  padding: 0.8rem 0 0.2rem 0;
  scrollbar-width: none;
}

.modal-right #modalThumbnails::-webkit-scrollbar {
  display: none;
}

.modal-right #modalThumbnails img {
  width: 20%;
  min-width: 20%;
  aspect-ratio: 1 / 1;
  height: auto;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.modal-right #modalThumbnails img:hover {
  transform: scale(1.05);
    border-radius: 12px;

}

.modal-right #modalThumbnails img.active-thumb {
  border-color: #004080;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  line-height: 1.6;
  padding-top: 80px; /* 確保內容不被固定導覽列擋住 */
}

body.no-scroll {
  overflow: hidden;
}

main {
  padding: 2rem 0;
  max-width: 1200px;
  margin: 0 auto;
}

/* ===== 高質感四格資訊卡片設計 ===== */
.inventory-card {
  border: none;
  border-radius: 18px;
  height: 100%;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.inventory-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.15);
}

.inventory-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  height: auto;
  object-fit: cover;
  cursor: pointer;
  display: block;
}

.inventory-cover {
  background: #f6f7f9;
}

.inventory-card-body {
  padding: 0.85rem 0.9rem 1rem 0.9rem;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.inventory-brand,
.inventory-subtitle {
  font-size: 0.85rem;
  color: #666;
}

.inventory-brand {
  margin-bottom: 0.2rem;
}

.inventory-subtitle {
  margin-bottom: 0.4rem;
}

.inventory-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.05rem;
  color: #111;
}

.inventory-price {
  font-size: 1.45rem;
  font-weight: 900;
  color: #d62828;
  margin-top: auto;         /* 加這行：自動推到底部 */
  margin-bottom: 0.6rem;
}

/* ===== 卡片列表新佈局樣式 ===== */
.modal-brand-pill {
  display: inline-block;
  margin: 0 auto 0.1rem auto;
  padding: 0.22rem 0.72rem;
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.15;
  border-radius: 999px;
  letter-spacing: 0.06em;
  color: #2f241e;
  border: 1px solid #8b5e3c;
  background: #fff;
}

.empty {
  text-align: center;
  color: #777;
  margin-top: 2rem;
}



.brand-reset-btn {
  border: 1px solid rgba(201, 151, 89, 0.35);
  border-radius: 999px;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 48%),
    linear-gradient(135deg, #fff8ec 0%, #f9dcc0 52%, #f4c89f 100%);
  color: #6f3f1d;
  padding: 0.5rem 1.02rem;
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(151, 96, 43, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease, color 0.18s ease;
}

.brand-reset-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(174, 110, 46, 0.62);
  box-shadow: 0 12px 24px rgba(133, 82, 34, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.56);
  filter: saturate(1.05) brightness(1.02);
  color: #5f2f11;
}

.brand-reset-btn:active {
  transform: translateY(0);
  box-shadow: 0 5px 12px rgba(133, 82, 34, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.brand-reset-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(191, 132, 76, 0.28), 0 8px 18px rgba(151, 96, 43, 0.22);
}

.brand-reset-btn.is-active {
  background:
    radial-gradient(circle at 24% 18%, rgba(255, 255, 255, 0.28) 0%, rgba(255, 255, 255, 0) 45%),
    linear-gradient(135deg, #bb6a2e 0%, #8f4519 100%);
  border-color: #8f4519;
  color: #fff9f0;
  box-shadow: 0 10px 24px rgba(124, 67, 27, 0.35);
}

/* 品牌篩選下拉選單（手機系統風格） */
#brandFilterSelect {
  width: 132px;
  max-width: 132px;
  margin: 0 0 1rem 0.35rem;
  border: none;
  border-bottom: 1px solid #6b7280;
  border-radius: 0;
  padding: 0.15rem 1.2rem 0.15rem 0;
  font-weight: 600;
  color: #6b7280;
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.05rem center;
  background-size: 0.9rem;
  box-shadow: none;
  transition: color 0.2s ease, border-color 0.2s ease;
  cursor: pointer;
  font-size: 0.95rem;
  appearance: none;
  -webkit-appearance: none;
  text-align: left;
  text-align-last: left;
}

#brandFilterSelect:hover,
#brandFilterSelect:focus {
  border-color: #111827;
  color: #111827;
  box-shadow: none;
  background-color: transparent;
  transform: none;
  outline: none;
}

#brandFilterSelect:active {
  transform: none;
}

/* 分頁按鈕 */
/* 風格一：極簡線條 */
.btn-minimal {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  position: relative;
  border: none;
  background: transparent;
  padding: 0.15rem 0;
  color: #6b7280;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.3s ease;
}
.btn-minimal::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 1px;
  background: currentColor;
  transition: width 0.3s ease;
}
.btn-minimal:hover::after {
  width: 100%;
}
.btn-minimal:hover {
  color: #111827;
}
.btn-minimal i {
  transition: transform 0.3s ease;
}
.btn-minimal:hover i {
  transform: translateX(var(--move-dist));
}
.btn-minimal:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(31, 79, 134, 0.16);
  border-radius: 4px;
}
.btn-minimal:disabled {
  color: #c2c8d1;
  cursor: not-allowed;
}
.btn-minimal:disabled::after {
  width: 0;
}

.pagination-minimal {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.05rem;
  margin-top: 1.1rem;
}

.pagination-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #d1d5db;
}

.btn-minimal-prev {
  --move-dist: -5px;
}

.btn-minimal-next {
  --move-dist: 5px;
}


/* 彈窗背景淡入淡出 + 防止橡皮筋捲動 */
#productModal,
#certModal {
  opacity: 0;
  transition: opacity 0.25s ease;
  overscroll-behavior: none; /* 完整阻止捲動連鎖與回彈 */
  backdrop-filter: blur(3px);
}

#productModal {
  touch-action: pan-y; /* 允許彈窗內垂直捲動 */
}

#certModal {
  touch-action: none; /* 認證彈窗維持手勢鎖定 */
}

#productModal.showing,
#certModal.showing {
  opacity: 1;
}

#productModal.closing,
#certModal.closing {
  opacity: 0;
}

/* 彈窗開關平滑動畫 */
#productModal .modal-content,
#certModal .modal-content {
  transform: scale(0.8);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  will-change: transform, opacity;
  backface-visibility: hidden; /* 避免圖形重繪造成細微卡頓 */
  overscroll-behavior: none; /* 在多數瀏覽器阻止回彈 */
  -ms-overflow-style: none; /* 舊版瀏覽器相容設定 */
}

#productModal.showing .modal-content,
#certModal.showing .modal-content {
  transform: scale(1);
  opacity: 1;
}

#productModal.closing .modal-content,
#certModal.closing .modal-content {
  transform: scale(0.8);
  opacity: 0;
}

/* 商品/認證切換淡出動畫 */
#productModal .modal-content.fade-out,
#certModal .modal-content.fade-out {
  opacity: 0;
  transform: scale(0.95);
}

/* 主圖及認證圖交錯淡入淡出動畫 */
#modalMainImg,
#certMainImg {
  transition: opacity 0.25s ease;
}

#modalMainImg {
  position: relative;
  z-index: 1;
}

.fade-img-out {
  opacity: 0;
}

/* 固定資訊圖片（垂直排列） */
.extra-imgs {
  margin-top: 0;
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.extra-imgs img {
  width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: calc(18px - 0.8rem);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* === 車輛詳細資訊彈窗樣式優化 === */
.modal-info-block {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding-top: 0.25rem;
  margin-top: 0.1rem;
  max-height: 100%;
  flex-shrink: 0;
  background: #ffffff;
  border-radius: 12px;
}

/* 防止右側圖片區與資訊區重疊 */
#productModal .modal-right {
  gap: 0.3rem;
}

#productModal .modal-right > div:first-child,
#productModal #modalThumbnails {
  position: relative;
  z-index: 1;
}

.modal-meta-pack {
  padding: 0.7rem 0.8rem;
  border: none;
  border-radius: 12px;
  background: #ffffff;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* 資訊區對齊 */
.modal-info-block .price-specs,
.modal-info-block p {
  text-align: left;
}

/* 商品彈窗主副標題 */
#modalCarName {
  margin: 0 0 0.5rem 0;
  line-height: 1.25;
  text-align: center;
}

#modalCarName .modal-title-main {
  display: block;
  font-size: clamp(1.38rem, 1.1vw + 1rem, 1.85rem);
  font-weight: 900;
  color: #1f1f1f;
  letter-spacing: 0.01em;
  font-family: "Microsoft JhengHei", "PingFang TC", "Heiti TC", "Noto Sans TC", sans-serif;
}

#modalCarName .modal-title-sub {
  display: block;
  margin-top: 0.2rem;
  font-size: clamp(0.9rem, 0.5vw + 0.7rem, 1.05rem);
  font-weight: 700;
  color: #6f7782;
  letter-spacing: 0.03em;
}

#modalCarName .modal-title-sub.is-empty {
  visibility: hidden;
}

.modal-price-line {
  white-space: nowrap;
  font-family: Arial, sans-serif;
  color: #d62828;
}

.modal-price-value {
  font-size: 1.65rem;
  font-weight: 900;
}

.modal-price-note {
  color: #000;
  font-size: 0.8rem;
}

/* 價格與規格區塊 */
.price-specs {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0;
  justify-content: center;
  width: 100%;
}

.price-specs .spec-grid {
  grid-template-columns: repeat(2, minmax(90px, 1fr));
  gap: 0.35rem 0.5rem;
  justify-content: center;
}

.modal-right .price {
  font-size: clamp(2.2rem, 4.8vw + 1rem, 3rem);
  font-weight: 800;
  color: #b33636;
  margin: 0;
  line-height: 1;
  min-width: 6.8rem;
  flex-shrink: 0;
  text-align: left;
}

#showCertBtn {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.42rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #2f6fb4 0%, #1f4f86 100%);
  color: #fff8f2;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 6px 14px rgba(31, 79, 134, 0.3);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

#showCertBtn.is-inactive {
  visibility: hidden;
  pointer-events: none;
}

#showCertBtn i {
  font-size: 0.9rem;
}

#showCertBtn:hover {
  transform: translateY(-1px);
  box-shadow: 0 9px 18px rgba(31, 79, 134, 0.38);
  filter: brightness(1.05);
}

.spec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.75rem 1rem;
}

.spec-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.92rem;
  color: #2f2f2f;
  white-space: nowrap;
}

.spec-copy {
  display: flex;
  flex-direction: column;
}

.spec-value {
  color: #000;
  font-size: 1rem;
}

.spec-label {
  color: #000;
  font-size: 0.75rem;
}

.spec-item i {
  font-size: 1.06rem;
  color: #5f6772;
}

/* ==========================
   響應式媒體查詢
   ========================== */
@media (max-width: 991.98px) {

  .brand-filter-actions {
    width: 100%;
    justify-content: space-between;
  }

  .brand-reset-btn {
    white-space: nowrap;
  }

  #brandFilterSelect {
    width: 132px;
    max-width: 132px;
  }

  #showCertBtn {
    position: static !important;
    margin-top: 0.5rem !important;
    transform: none !important;
  }

  .extra-imgs {
    margin-top: 0.75rem !important;
  }
}

.pagination {
  display: flex;
  justify-content: center;
  margin-top: 2rem;
}

.cert-preview {
  overflow: auto;
  touch-action: none;
}

#certMainImg {
  border-radius: 18px;
  display: block;
  width: auto;
  height: auto;
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  cursor: pointer;
  user-select: none;
}

body.device-mobile #productModal .modal-flex {
  flex-direction: column !important;
  height: auto !important;
}

body.device-mobile #productModal .modal-left {
  display: none !important;
}

body.device-mobile #productModal #modalMainImg {
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 16px;
  background: transparent;
  box-shadow: none;
}

body.device-mobile #modalSpecsDesktop {
  display: none !important;
}

body.device-mobile #modalSpecsMobile {
  display: grid !important;
}

body.device-large #productModal .modal-flex {
  flex-direction: row !important;
}

body.device-large #productModal .modal-left,
body.device-large #productModal .modal-right {
  width: 50% !important;
  max-width: 50% !important;
  order: unset !important;
  margin-top: 0 !important;
}

body.device-large #modalSpecsDesktop {
  display: grid !important;
}

body.device-large #modalSpecsMobile {
  display: none !important;
}


/* ============================================================
   手機版彈窗高度與寬度精準定義
   ============================================================ */
/* 共通設定：手機版時彈窗水平居中 */
body.device-mobile #productModal .modal-content {
  margin: auto;
  flex-direction: column;
}
/* =============================================
   1. 小型設備 (SE 系列): 寬度 < 389px
   ============================================= */
@media screen and (max-width: 389px) {
  /* Safari/Chrome/FB */
  body.device-mobile #productModal .modal-content {
    width: 92vw !important;
    height: 92vh !important; /* SE 高度短，比例要拉高 */
    padding: 1rem;
    padding-bottom: 1rem;
  }
}
/* =============================================
   2. 標準設備 (iPhone 12 ~ 16): 390px - 427px
   ============================================= */
@media screen and (min-width: 390px) and (max-width: 427px) {
  /* Safari/Chrome 正常版 */
  body.device-mobile #productModal .modal-content {
    width: 92vw !important;
    height: auto !important; /* 留出上下呼吸空間 */
    max-height: 88vh;
    padding: 0.8rem;
    padding-bottom: 0.8rem;
  }
}
/* =============================================
   3. 大型設備 (Max / Plus 系列): 428px 以上
   ============================================= */
@media screen and (min-width: 428px) and (max-width: 800px) {
  /* Safari/Chrome 正常版 */
  body.device-mobile #productModal .modal-content {
    width: 92vw !important;
    height: auto !important; /* 大螢幕不需要太長，避免手感太重 */
    max-height: 90vh;
    padding: 0.8rem;
    padding-bottom: 0.8rem;
  }
}
