/* V38：防止手機點擊輸入框時自動縮放（iOS Safari 規範：字體需至少 16px） */
@media screen and (max-width: 768px) {
  input, select, textarea, .input, .v37-auth-input, .mr-form-input, .mr-form-select {
    font-size: 16px !important;
  }
}

/* Restyle existing modal without changing original IDs */
#cardModal.modal:not(.hidden){
  display:flex !important;
  align-items:center;
  justify-content:center;
}

#cardModal{
  backdrop-filter:blur(8px);
}

#cardModal .modal-panel{
  width:min(460px,94vw) !important;
  max-height:92vh;
  display: flex !important;
  flex-direction: column !important;
  overflow:visible;           /* 保持 visible 讓關閉鈕在外面 */
  border-radius:30px !important;
  background:rgba(255,255,250,.96) !important;
  box-shadow:0 30px 90px rgba(0,0,0,.22) !important;
  animation:v28ModalPop .22s cubic-bezier(.2,.8,.2,1);
}

@keyframes v28ModalPop{
  from{opacity:0;transform:translateY(12px) scale(.97)}
  to{opacity:1;transform:translateY(0) scale(1)}
}

#cardModal .modal-close{
  position: fixed !important;
  top: 16px !important;
  right: 16px !important;
  border-radius:50% !important;
  background:rgba(255,255,255,0.28) !important;
  backdrop-filter:blur(6px);
  box-shadow: 0 2px 8px rgba(0,0,0,.10);
  color: rgba(60,60,60,0.45);
  opacity: 0.55;
  transition: opacity 0.2s ease, background 0.2s ease, color 0.2s ease;
}

#cardModal .modal-close:hover {
  background:rgba(255,255,255,0.82) !important;
  color: rgba(40,40,40,0.9);
  opacity: 1;
}

#modalCardImage{
  width:100%;
  height:100%;
  max-height:58vh;
  object-fit:contain;
  background:#eceee5;
  display: block;
  /* 避免載入前變形 */
  aspect-ratio: 1/1; 
}

#cardModal .modal-content{
  padding:18px !important;
  margin-top: -56px !important; /* Moved up another 3px (total -56px) */
  position: relative;
  z-index: 5;
  background: linear-gradient(to top, rgba(255,255,250,1) 85%, rgba(255,255,250,0)); 
  border-radius: 0 0 30px 30px; /* Fix square bottom corners */
}

#modalCardTitle{
  font-size:18px;
  font-weight:820;
}

#modalCardLocation{
  color:var(--v28-muted);
  font-size:14px;
  line-height:1.65;
  margin: 2px 0 6px 0 !important; /* Minimize space */
}

/* 點擊複製座標樣式 */
.copyable-coords {
  cursor: pointer;
  background: transparent;
  color: #4a6a43;
  padding: 0;
  transition: all 0.2s ease;
  display: inline-block;
  font-family: monospace;
  font-weight: 600;
  border: none;
}

.copyable-coords:hover {
  background: transparent;
  text-decoration: underline;
}

.copyable-coords:active {
  transform: translateY(0) scale(0.96);
}

.copyable-coords.copied-feedback {
  background: #10b981 !important;
  color: white !important;
  border-color: #10b981 !important;
}

.copyable-coords.copied-feedback::after {
  content: " 已複製!";
  font-size: 11px;
  margin-left: 4px;
}

#modalMapLink{
  display:flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  width:72% !important; /* Further shrink from 82% */
  margin: 12px auto 0 !important;
  border:0 !important;
  border-radius:999px !important;
  padding:2px 16px !important;
  font-size: 13px !important; 
  font-weight: 600 !important;
  cursor:pointer;
  text-align:center !important;
  justify-content:center !important;
  align-items:center !important;
  text-decoration:none;
  background: #9ecb74 !important; /* 柔和粉綠色 */
  color: #ffffff !important;      /* 白色文字 */
  box-shadow: none !important;
  transition: transform 0.2s ease, filter 0.2s ease !important;
}

#modalMapLink:hover {
  transform: translateY(-2px) !important;
  filter: brightness(1.05) !important;
  color: #ffffff !important;
}

#modalMapLink .map-link-text {
  flex: 1;
  text-align: center;
  letter-spacing: 0.02em;
}

#modalMapLink .map-link-icon {
  width: 38px !important; /* Force larger size */
  height: 38px !important;
  border-radius: 50%;
  background: #ffffff; /* 白色圓圈 */
  display: flex;
  align-items: center;
  justify-content: center;
  color: #222222; /* 黑色箭頭 */
  flex-shrink: 0;
}

#modalMapLink .map-link-icon svg {
  width: 16px; /* Slightly smaller arrow relative to circle */
  height: 16px;
}

/* ── 圖片包裹層：負責圖片上方圓角裁切 ── */
.modal-image-wrap {
  position: relative;
  display: block;
  line-height: 0;
  overflow: hidden;            /* 裁切圖片超出的部分 */
  border-radius: 30px 30px 0 0; /* 上方兩角和 panel 圓角一致 */
  aspect-ratio: 1/1;          /* 預留 1:1 的空間避免跳動 */
  background: #eceee5;
}

/* ── 分享 icon 按鈕：透明底，灰綠圖示 (強制生效) ── */
#modalShareCardBtn.modal-share-icon {
  position: static !important;
  width: 40px !important;
  height: 40px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border: none !important;
  background: transparent !important;
  border-radius: 50% !important;
  cursor: pointer !important;
  color: #a2d37c !important;
  opacity: 1.0 !important;
  box-shadow: none !important;
  transition: all 0.24s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
  z-index: 5 !important;
}

#modalShareCardBtn.modal-share-icon svg {
  width: 22px !important;
  height: 22px !important;
  fill: #a2d37c !important; /* 切換為亮綠色 */
  stroke: none !important;
}

#modalShareCardBtn.modal-share-icon:hover {
  background: rgba(107, 138, 117, 0.1) !important;
  color: #4a6352 !important;
  transform: scale(1.18) !important;
}

#modalShareCardBtn.modal-share-icon:hover svg {
  fill: #86b366 !important;
  stroke: none !important;
}

.modal-share-icon:active {
  transform: scale(0.95);
}

/* ── 圖片切換淡入淡出 ── */
#modalCardImage {
  transition: opacity 0.18s ease;
}
#modalCardImage.img-fade {
  opacity: 0;
}

/* ── 明信片切換箭頭（卡片內左右兩側）── */
.modal-nav-btn {
  position: absolute;
  top: calc(50% - 80px);
  transform: translateY(-50%);
  width: 142px;
  height: 294px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0 !important;
  background: transparent !important;
  cursor: pointer;
  color: rgba(60,60,60,0.35) !important;
  z-index: 4;
  opacity: 0.5;
  box-shadow: none !important;
  filter: none !important;
}

.modal-nav-btn svg {
  width: 22px;
  height: 22px;
}

.modal-prev-btn { left: 3px; justify-content: flex-start !important; padding-left: 7px; }
.modal-next-btn { right: 3px; justify-content: flex-end !important; padding-right: 7px; }

.modal-nav-btn:hover {
  opacity: 1 !important;
  background: transparent !important;
  color: rgba(40,40,40,0.85) !important;
  transform: translateY(-50%) !important;
  box-shadow: none !important;
  filter: none !important;
}

.modal-nav-btn:active {
  opacity: 0.6 !important;
  transform: translateY(-50%) !important;
}

/* 只剩一張時隱藏 */
.modal-nav-btn[data-hidden="true"] {
  opacity: 0;
  pointer-events: none;
}

/* 觸控設備：略微可見 */
@media (hover: none) {
  .modal-nav-btn { opacity: 0.4; }
}

/* ── 新增欄位樣式 ── */
.modal-info-list {
  position: relative;
  margin-top: 4px; /* Reduced from 8px to move it up */
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid rgba(0,0,0,0.05);
  padding: 12px 0 4px 0;
}

.info-item {
  display: flex;
  align-items: flex-start;
  font-size: 14px;
  line-height: 1.5;
}

.info-label {
  color: var(--v28-muted);
  font-weight: 600;
  white-space: nowrap;
  min-width: 75px;
  margin-right: 4px;
}

.info-value {
  color: #444;
  word-break: break-all;
  overflow-wrap: anywhere;
  flex: 1;
}

.visit-website-link {
  display: inline-block;
  color: #78c96b;
  text-decoration: none;
  font-weight: 700;
  border-bottom: none;
  transition: all 0.2s ease;
  padding: 2px 0;
}

.visit-website-link:hover {
  color: #2f7438;
  border-bottom-color: #2f7438;
  transform: translateY(-1px);
}

.description-text {
  background: rgba(0,0,0,0.02);
  padding: 10px 14px;
  border-radius: 12px;
  margin-top: 6px;
  width: 100%;
  font-style: normal;
  color: #555;
  border: 1px solid rgba(0,0,0,0.03);
  line-height: 1.6;
}

/* 確保 modal-panel 的內容如果太長可以滾動，但維持關閉鈕位置 */
#cardModal .modal-panel {
  display: flex !important;
  flex-direction: column !important;
  overflow: visible !important; 
  max-height: 90vh !important;
}

.modal-image-wrap {
  flex-shrink: 0;
}

#cardModal .modal-content {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 12px !important; /* Reduced from 24px */
  min-height: 0; /* 關鍵：允許 flex 子元素縮小並滾動 */
  
  /* 隱藏滑桿 (Scrollbar) 但保持滾動功能 */
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;    /* Firefox */
}

#cardModal .modal-content::-webkit-scrollbar {
  display: none; /* Chrome, Safari and Opera */
}

/* 側邊欄也隱藏滑桿 */
.sidebar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar {
  display: none;
}

/* ── V33 Universal Upload Modal Styles ── */

/* 基礎樣式：電腦與手機通用 */
#uploadModal.modal:not(.hidden) {
  display: flex !important;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  align-items: center;
  justify-content: center;
  z-index: 300000 !important; /* 高於一切，包含工具列 */
  backdrop-filter: blur(12px);
  background: rgba(0, 0, 0, 0.3);
  animation: v28FadeIn 0.3s ease;
}

.upload-modal-panel {
  width: min(600px, 94vw) !important;
  max-height: 88vh;
  background: rgba(255, 255, 252, 0.98) !important;
  border-radius: 40px !important;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.3) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden; /* 防止內容溢出圓角 */
  animation: v28ModalPop 0.4s cubic-bezier(0.2, 0.8, 0.2, 1.1);
  position: relative;
}

/* Modal 標題 */
.upload-modal-panel .modal-header {
  padding: 30px 25px 0;
  text-align: center;
}

/* 關閉按鈕 */
.upload-modal-panel .modal-close {
  position: absolute;
  top: 25px;
  right: 25px;
  width: 38px;
  height: 38px;
  background: #eee;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.2s;
}

.upload-modal-panel .modal-close:hover {
  background: #e2e2e2;
  transform: rotate(90deg);
}

.upload-modal-panel .modal-content {
  padding: 30px 40px 50px !important;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.1) transparent;
  margin-bottom: 25px;
}

.upload-modal-panel .modal-content::-webkit-scrollbar {
  width: 6px;
}
.upload-modal-panel .modal-content::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 3px;
}

/* 上傳區域優化 */
.upload-drop {
  min-height: 100px !important;
  border: none !important;
  background: transparent !important;
  border-radius: 20px !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 10px !important;
  transition: all 0.3s ease;
  margin-bottom: 15px !important;
}

.upload-drop:hover {
  background: rgba(120, 201, 107, 0.05) !important;
}

.upload-svg-icon {
  width: 64px !important;
  height: 64px !important;
  opacity: 0.5;
  color: var(--green);
}

.upload-main-text {
  font-size: 18px !important;
  font-weight: 600;
  color: var(--ink);
}

/* 表單區塊優化 */
.sidebar-form-grid {
  margin-top: 5px !important;
  gap: 0px 12px !important;
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0;
  margin-bottom: 10px !important;
}

/* 確保上傳按鈕也維持間距 (補償位移，讓它不移動) */
#addCardBtn {
  width: 100% !important;
  height: 50px !important;
  border-radius: 15px !important;
  margin-top: 120px !important; /* 暴力位移測試：直接拉開 120px */
  font-size: 16px;
  font-weight: 700;
}

/* 📱 手機版微調 */
@media (max-width: 768px) {
  .upload-modal-panel {
    width: 96vw !important;
    max-height: 82vh !important; /* 再進一步縮短整體高度 */
    border-radius: 24px !important;
  }
  .upload-modal-panel .modal-header {
    padding: 15px 15px 0 !important;
  }
  .upload-modal-panel .modal-close {
    top: 15px !important;
    right: 15px !important;
  }
  .upload-modal-panel .modal-content {
    padding: 10px 15px 20px !important;
  }
  .upload-drop {
    min-height: 70px !important; /* 縮短圖片上傳區 */
    margin-bottom: 10px !important;
  }
  .upload-svg-icon {
    width: 40px !important;
    height: 40px !important;
  }
  .upload-main-text {
    font-size: 14px !important;
  }
  .upload-modal-panel .sidebar-form-grid {
    padding: 10px !important;
    gap: 6px 0 !important;
  }
  .upload-modal-panel .sidebar-label {
    font-size: 13px !important;
  }
  #addCardBtn {
    margin-top: 15px !important;
    height: 44px !important;
  }
}

/* 側邊欄觸發按鈕樣式 */
#openUploadBtn {
  width: 100%;
  height: 58px;
  border-radius: 29px;
  background: var(--green) !important;
  color: white !important;
  font-size: 17px;
  font-weight: 700;
  display: flex !important;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: none;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(120, 201, 107, 0.3);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  margin-top: 10px;
}

#openUploadBtn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 15px 35px rgba(120, 201, 107, 0.4);
}

#openUploadBtn:active {
  transform: scale(0.98);
}

#openUploadBtn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 28px rgba(120, 201, 107, 0.45);
  background: #6ab55e !important;
}

#openUploadBtn:active {
  transform: translateY(0) scale(0.98);
}

#openUploadBtn .plus-icon {
  font-size: 22px;
  line-height: 1;
}

/* 讓 Modal 內的表單格子更好看 */
.upload-modal-panel .sidebar-form-grid {
  background: rgba(0, 0, 0, 0.03);
  padding: 20px;
  border-radius: 20px;
  margin-top: 15px;
}

.upload-modal-panel .sidebar-label {
  color: #666;
  font-weight: 600;
}

.upload-modal-panel .input {
  background: white;
  border: 1px solid #eee;
  border-radius: 12px;
}

/* 阻止彈出視窗開啟時背景網頁滾動 (涵蓋所有種類的彈窗) */
body.modal-open,
body.v37-modal-open,
body:has(.modal:not(.hidden)),
body:has(.edit-modal:not(.hidden)),
body:has(.mr-modal-backdrop.show),
body:has(#v37AuthPanelBackdrop.show) {
  overflow: hidden !important;
  overscroll-behavior: none !important; /* 阻止 iOS 橡皮筋回彈效果帶動背景 */
}

/* 針對行動裝置的額外保險：如果是在彈窗開啟狀態，鎖定 html 層級 */
html:has(body.modal-open), 
html:has(body.v37-modal-open) {
  overflow: hidden !important;
}

/* 阻止在各類彈出視窗底層背景滑動 (針對行動裝置強化) */
.modal-backdrop, 
.mr-modal-backdrop, 
#v37AuthPanelBackdrop {
  touch-action: none; /* 防止透過背景層滑動到底下的網頁 */
}

/* 阻止在各類彈出視窗內滑動到底部時觸發背景網頁的滑動 (Scroll Chaining) */
.modal, .modal-panel, .modal-content,
.mr-modal-panel, .mr-modal-content,
.v37-auth-panel, .edit-modal-panel {
  overscroll-behavior: contain !important;
  touch-action: auto !important; /* 確保彈窗內部的滑動仍然正常 */
}

/* 在彈出視窗開啟時隱藏所有右下角的懸浮按鈕 (+) 與 (^) */
body.modal-open .mobile-upload-fab,
body.modal-open .mobile-scroll-top-fab,
body.modal-open .v28-create-fab,
body.v37-modal-open .mobile-upload-fab,
body.v37-modal-open .mobile-scroll-top-fab,
body.v37-modal-open .v28-create-fab,
body:has(.mr-modal-backdrop.show) .mobile-upload-fab,
body:has(.mr-modal-backdrop.show) .mobile-scroll-top-fab,
body:has(.mr-modal-backdrop.show) .v28-create-fab {
  display: none !important;
}/* 瀏覽模式下隱藏懸浮按鈕 */
body.is-browse-mode .mobile-upload-fab,
body.is-browse-mode .mobile-scroll-top-fab,
body.is-browse-mode .v28-create-fab {
  display: none !important;
}

/* 明信片內頁編輯按鈕 */
.modal-edit-btn {
  position: absolute;
  top: 60px;
  right: 20px;
  background: var(--green);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(120, 201, 107, 0.3);
  transition: all 0.2s ease;
}

.modal-edit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(120, 201, 107, 0.4);
}

@media screen and (max-width: 768px) {
  .modal-edit-btn {
    position: static !important; /* 切換為靜態佈局 */
    padding: 4px 10px;
    font-size: 12px;
    height: 28px;
    display: flex;
    align-items: center;
  }
}
/* V38: Modal 內的愛心與去過按鈕樣式 */
.modal-heart-btn {
  background: transparent !important;
  border: none !important;
  border-radius: 999px !important;
  padding: 8px 14px !important;
  font-size: 15px !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  color: #555 !important;
}

.modal-heart-btn:hover {
  background: rgba(0,0,0,0.1) !important;
  transform: translateY(-1px);
}

.modal-heart-btn.active {
  background: #fff0f0 !important;
  border-color: #ffcccc !important;
}

.modal-share-icon {
  /* margin-left: auto; */
}
