/* ============================================================
   🤖 祥興茶行 AI 導購與隱藏菜單樣式表 (完整版)
   ============================================================ */

/* === Modal Overlay (遮罩) === */
.ai-modal-overlay {
  position: fixed; inset: 0; display: flex; justify-content: center; align-items: flex-end;
  padding: 0 0 40px; background: rgba(0,0,0,0.25);
  backdrop-filter: blur(8px) saturate(140%); -webkit-backdrop-filter: blur(8px) saturate(140%);
  opacity: 0; pointer-events: none; transition: opacity .28s ease; 
  z-index: 9997 !important;
  padding-bottom: env(safe-area-inset-bottom) !important;
}
.ai-modal-overlay.show { opacity: 1; pointer-events: auto; }
/* === 2. 手機版底部間距優化 === */
@media (max-width: 600px) {
  .ai-box {
    /* 確保輸入框不會貼底貼太緊 */
    padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
  }
}
/* === AI Modal Card (主視窗) === */
.ai-box {
  width: 92%; max-width: 450px; max-height: 80vh;
  display: flex; flex-direction: column; padding: 20px 20px 16px; border-radius: 22px;
  background: rgba(255,255,255,0.60);
  backdrop-filter: blur(22px) saturate(180%); -webkit-backdrop-filter: blur(22px) saturate(180%);
  box-shadow: 0 20px 42px rgba(50,70,60,0.22), 0 6px 14px rgba(50,70,60,0.15), inset 0 0 0 1px rgba(255,255,255,0.55);
  border: 1px solid rgba(255,255,255,0.65);
  animation: aiPopIn .36s cubic-bezier(.18,.9,.32,1.2);
  overflow-y: auto !important; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  z-index: 9998 !important;
}
@keyframes aiPopIn {
  0% { transform: translateY(20px) scale(.92); opacity: 0; filter: blur(3px); }
  55% { transform: translateY(-4px) scale(1.02); opacity: 1; filter: blur(0); }
  100% { transform: translateY(0) scale(1); }
}

/* === AI Title === */
.ai-title {
  font-size: 1.2rem; font-weight: 800; color: #2f4b3c; text-align: center; margin-bottom: 15px;
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-shrink: 0;
}

/* === Close Button === */
.ai-close-icon {
  position: absolute; top: 12px; right: 14px; width: 38px; height: 38px;
  display: flex; justify-content: center; align-items: center;
  font-size: 18px; font-weight: 700; color: #3a5c48;
  background: rgba(255,255,255,0.48); border: 1px solid rgba(200,220,210,0.55); border-radius: 50%;
  box-shadow: 0 8px 20px rgba(70,100,80,0.20), inset 0 0 0 1px rgba(255,255,255,0.55);
  backdrop-filter: blur(12px); cursor: pointer; transition: .25s ease;
}
.ai-close-icon:hover { transform: scale(1.08); box-shadow: 0 14px 34px rgba(70,100,80,0.28); }

/* === AI 入口按鈕 === */
.ai-assist-btn {
  width: 100%; padding: 16px 24px; margin-bottom: 22px;
  font-size: 17px; font-weight: 760; color: #2f4b3c; letter-spacing: 0.4px;
  background: rgba(255, 255, 240, 0.55); border: 1px solid rgba(190, 205, 180, 0.60); border-radius: 18px;
  box-shadow: 0 14px 28px rgba(120,150,110,0.20), inset 0 0 0 1px rgba(255,255,255,0.45);
  backdrop-filter: blur(18px); display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all .28s ease; cursor: pointer;
}
.ai-assist-btn:hover {
  background: rgba(255, 255, 250, 0.70); border-color: #bcd8a2; transform: translateY(-3px);
}

/* === Chat Area === */
.ai-chat-area {
  display: flex; flex-direction: column; gap: 14px; margin-top: 14px;
  max-height: 70vh; overflow-y: auto !important; scroll-behavior: smooth;
  padding-right: 4px; touch-action: pan-y; -webkit-overflow-scrolling: touch; flex-grow: 1;
}

/* === Bubbles === */
.ai-bubble {
  max-width: 90%; margin: 10px 0; padding: 16px 18px; border-radius: 18px;
  line-height: 1.65; font-size: 0.95rem; color: #2f4b3c;
  background: rgba(245, 255, 245, 0.55); border: 1px solid rgba(165, 190, 165, 0.50);
  box-shadow: 0 8px 30px rgba(120,150,120,0.20); backdrop-filter: blur(18px);
  animation: aiBubbleFade .25s ease; word-break: break-word;
}
.ai-bubble-ai { align-self: flex-start; border-top-left-radius: 6px; background: rgba(250,255,245,0.60); }
.ai-bubble-user {
  align-self: flex-end; background: linear-gradient(135deg, #9ac89f, #c6d8a4);
  color: #ffffff; border: none; box-shadow: 0 6px 22px rgba(130,160,130,0.28);
}
.ai-bubble-title {
  font-size: 17px; font-weight: 800; margin-bottom: 8px;
  background: linear-gradient(90deg, #688e63, #bacc8b); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
/* 2. 重點文字 (Bold) - 用顯眼的深橘色或茶褐色 */
.ai-bubble strong {
  color: #d35400; 
  font-weight: 700;
  background-color: rgba(255, 243, 224, 0.5); /* 淡淡的底色強調 */
  padding: 0 2px;
  border-radius: 2px;
}

/* 3. 條列式清單 (List) - 縮排與樣式 */
.ai-bubble ul, .ai-bubble ol {
  margin: 8px 0;
  padding-left: 24px; /* 讓圓點縮進去一點 */
}

.ai-bubble li {
  margin-bottom: 4px; /* 列表項目之間留點呼吸空間 */
}

/* 4. 段落 (Paragraph) - 段落間距 */
.ai-bubble p {
  margin-bottom: 10px; 
}
.ai-bubble p:last-child {
  margin-bottom: 0; /* 最後一段不要留白 */
}

/* 5. 標題 (Heading) - 雖然阿興師很少用標題，但預防萬一 */
.ai-bubble h3, .ai-bubble h4 {
  margin: 12px 0 6px 0;
  font-size: 1.1em;
  color: #2c5c45; /* 茶綠色 */
  font-weight: bold;
  border-bottom: 1px dashed #ccc; /* 下底線裝飾 */
  padding-bottom: 4px;
}
@keyframes aiBubbleFade { from { opacity: 0; transform: translateY(6px) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* === Input Area === */
.ai-input-row {
  display: flex;
  align-items: center;
  gap: 10px; /* 拉開間距 */
  margin-top: 16px;
  padding: 12px 16px;
  
  background: #ffffff;
  border: 1px solid rgba(180, 200, 185, 0.3);
  border-radius: 24px; /* 更大的圓角 */
  
  /* 懸浮陰影 */
  box-shadow: 0 4px 20px rgba(0,0,0,0.04);
  backdrop-filter: blur(14px);
  
  /* 固定在底部時的優化 */
  flex-shrink: 0;
}
.ai-text-input {
  flex: 1;
  height: 44px; /* 加高 */
  padding: 0 12px;
  font-size: 16px;
  
  border: none; /* 移除邊框，因為外層已經有框了 */
  background: transparent;
  color: #2f4b3c;
  font-weight: 500;
  
  transition: all .28s ease;
}
.ai-text-input:focus {
  outline: none;
}
.ai-text-input::placeholder {
  color: #aabcb2;
  font-weight: 400;
}

/* === Camera & Send Buttons === */
.ai-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #f0f5f3; /* 淡綠底 */
  color: #5a7b68;
  font-size: 20px;
  display: flex; 
  align-items: center; 
  justify-content: center;
  transition: all 0.2s;
  padding: 0; /* 重置 */
}

.ai-icon-btn:hover {
  background: #e0ebe6;
  color: #2f4b3c;
  transform: scale(1.1);
}

.ai-send-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  padding: 0 !important; /* 強制移除多餘內距 */
  
  background: linear-gradient(135deg, #5a7b68, #7fa38a);
  border: none;
  box-shadow: 0 4px 10px rgba(90, 123, 104, 0.3), inset 0 1px 0 rgba(255,255,255,0.3);
  
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  flex-shrink: 0;
}

.ai-send-btn:hover {
  transform: translateY(-2px) scale(1.05);
  background: linear-gradient(135deg, #668a75, #8fb79c);
  box-shadow: 0 6px 16px rgba(90, 123, 104, 0.4);
}

.ai-send-btn:active {
  transform: scale(0.95);
  box-shadow: 0 2px 6px rgba(90, 123, 104, 0.2);
}

/* 🔥 這裡修正你的 icon 樣式 */
.ai-send-btn i {
  font-size: 20px;
  color: #ffffff !important;
  /* 視需要微調位置，如果覺得歪歪的 */
  margin-left: 2px; 
  margin-top: 1px;
}

/* === Loading Animation === */
.dot-flashing { position: relative; width: 8px; height: 8px; border-radius: 5px; background-color: #999; color: #999; animation: dot-flashing 1s infinite linear alternate; animation-delay: 0.5s; margin: 0 12px; }
.dot-flashing::before, .dot-flashing::after { content: ""; display: inline-block; position: absolute; top: 0; width: 8px; height: 8px; border-radius: 5px; background-color: #999; color: #999; animation: dot-flashing 1s infinite alternate; }
.dot-flashing::before { left: -12px; animation-delay: 0s; }
.dot-flashing::after { left: 12px; animation-delay: 1s; }
@keyframes dot-flashing { 0% { background-color: #999; } 50%, 100% { background-color: #e0e0e0; } }

/* === 🕵️ Secret Card (隱藏版商品) === */
.secret-card {
  background: linear-gradient(135deg, #fff9f0 0%, #fff 100%);
  border: 1px solid #d4af37; box-shadow: 0 0 15px rgba(212, 175, 55, 0.3);
  position: relative; overflow: hidden;
}
.secret-card::before {
  content: ""; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
  background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.8) 50%, rgba(255, 255, 255, 0) 100%);
  transform: rotate(45deg); animation: shine 3s infinite; pointer-events: none;
}
@keyframes shine { 0% { transform: translateX(-150%) rotate(45deg); } 100% { transform: translateX(150%) rotate(45deg); } }
.secret-card .prod-name { color: #b8860b; font-weight: bold; }

/* === AI Options & Products === */
.ai-option-group { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.ai-option-btn {
  padding: 8px 14px; font-size: 14px; border-radius: 12px;
  background: rgba(255,255,245,0.65); border: 1px solid rgba(180,200,170,0.50);
  color: #2f4b3c; box-shadow: 0 5px 14px rgba(130,160,130,0.18); cursor: pointer; transition: .25s ease;
}
.ai-option-btn:hover { background: rgba(255,255,255,0.82); border-color: #bcd99f; transform: translateY(-2px); }

.ai-prod-item {
  margin-top: 12px; padding: 12px 14px; background: rgba(255,255,250,0.65);
  border: 1px solid rgba(170,190,170,0.50); border-radius: 14px; cursor: pointer;
  box-shadow: 0 6px 18px rgba(120,150,110,0.20); transition: all .25s ease;
}
.ai-prod-item:hover { background: rgba(255,255,255,0.85); transform: translateY(-2px); border-color: #9ac89f; }

/* === 📦 Blocks (Brew, Compare, etc.) === */
.brew-item { padding: 10px 12px; background: rgba(255,255,245,0.55); border: 1px solid rgba(185,200,180,0.50); border-radius: 12px; margin-bottom: 10px; }
.brew-tips { margin-top: 10px; padding: 10px 12px; background: rgba(250,255,245,0.65); border: 1px dashed rgba(160,185,160,0.6); border-radius: 12px; font-size: 14px; color: #3c5c46; }

.compare-block { margin-top: 12px; padding: 16px; background: rgba(255,255,245,0.65); border: 1px solid rgba(190,205,180,0.50); border-radius: 16px; display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; }
.compare-summary { margin-top: 12px; padding: 12px 14px; background: rgba(255,255,245,0.75); border-radius: 14px; border: 1px solid rgba(200,210,185,0.50); font-size: 14.5px; line-height: 1.7; color: #304c3a; }

/* 🔥【補全】其他 AI 區塊樣式 */
.pairing-summary { font-size: 14.5px; color: #3c5c46; margin-bottom: 10px; line-height: 1.7; }
.gift-summary { font-size: 15px; color: #35543d; margin-bottom: 10px; line-height: 1.7; }

.masterpick-block {
  padding: 14px 16px; border-radius: 16px; background: rgba(255,255,245,0.55);
  border: 1px solid rgba(180,200,170,0.50); box-shadow: 0 10px 26px rgba(120,150,110,0.15);
  line-height: 1.7; color: #345c45;
}

.person-summary { font-size: 15px; color: #355c45; opacity: .92; line-height: 1.7; margin-bottom: 12px; }

/* 🔥【補全】隱藏版 Modal 專用按鈕 (Gold Theme) */
.secret-qty-btn {
  width: 30px; 
  height: 30px; 
  border: 1px solid #ddd; 
  background: #fff; 
  border-radius: 50%;
  cursor: pointer; 
  font-size: 1.2rem; 
  line-height: 1; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  color: #b8860b;
}
.secret-qty-btn:hover { 
  background: #fffbf0; 
  border-color: #b8860b; 
}

/* 💌 茶籤按鈕 */
.ai-card-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 10px 0;
  background: linear-gradient(135deg, #fffaf0, #fff5e0);
  border: 1px solid #e0d0b0;
  border-radius: 12px;
  color: #b8860b; /* 金色文字 */
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  box-shadow: 0 2px 6px rgba(184, 134, 11, 0.1);
  transition: all 0.3s ease;
}
/* 載入中 */
.loading-state {
  pointer-events: none; /* 禁止連點 */
  opacity: 0.7;
}

/* 準備就緒 */
.ready-state {
  background: linear-gradient(45deg, #2f4b3c, #4a7c64);
  color: #fff !important;
  box-shadow: 0 4px 12px rgba(47, 75, 60, 0.3);
  animation: popIn 0.3s ease-out;
}

@keyframes popIn {
  0% { transform: scale(0.95); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.ai-card-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(184, 134, 11, 0.2);
  background: #fffbf5;
}

.ai-audio-btn {
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(160,180,165,0.5);
  border-radius: 10px;
  font-size: 14px;
  color: #324b3f;
  cursor: pointer;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 12px rgba(90,123,104,0.15);
  transition: 0.25s ease;
}

.ai-audio-btn:hover {
  background: rgba(255,255,255,0.75);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(90,123,104,0.25);
}
/* ============================================================
   📱 手機版優化：轉變為 Bottom Sheet 模式
   (貼在 ai-chat.css 最下方)
   ============================================================ */

@media (max-width: 600px) {
  /* 1. 調整遮罩層：讓內容貼底 */
  .ai-modal-overlay {
    padding-bottom: 0 !important; /* 移除底部留白 */
    align-items: flex-end; /* 確保靠下對齊 */
  }

  /* 2. 主視窗變形：更寬、更高、更靈活 */
  .ai-box {
    width: 100% !important;      /* 寬度佔滿 */
    max-width: 100% !important;  /* 解除最大寬度限制 */
    
    /* 高度控制：關鍵 */
    height: auto !important;      /* 讓高度隨內容自動長高 */
    min-height: 50vh !important;  /* 初始高度至少佔一半螢幕 (看起來才大氣) */
    max-height: 92dvh !important; /* 最高長到螢幕的 92% (預留一點頂部空間) */
    
    /* 造型調整：變成抽屜 */
    border-radius: 28px 28px 0 0 !important; /* 只有上面有圓角 */
    border-bottom: none !important;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.15) !important;
    
    padding: 20px 16px 30px !important; /* 調整內距，底部留多一點給手勢 */
  }

  /* 3. 對話區域：確保能撐開父容器 */
  .ai-chat-area {
    /* 讓它佔據空間，但不要強迫出現捲軸，除非父容器已達 max-height */
    flex: 1; 
    min-height: 0; /* Flexbox 溢出修復 */
    
    /* 修正內距，避免文字貼邊 */
    padding-left: 4px;
    padding-right: 4px;
  }

  /* 4. 輸入框區域：固定在底部 */
  .ai-input-row {
    margin-top: 16px;
    background: #f7f9f8; /* 稍微深一點的底色，區分輸入區 */
  }
  
  /* 5. 修正關閉按鈕位置 */
  .ai-close-icon {
    top: 16px;
    right: 16px;
    background: rgba(240, 240, 240, 0.8); /* 讓它在手機上更明顯 */
  }
}

/* === 📸 修正使用者上傳圖片樣式 === */
.ai-bubble-img {
  display: block;
  max-width: 100%;       /* 確保不超過氣泡範圍 */
  height: auto;          /* 保持比例 */
  max-height: 300px;     /* 限制最大高度，避免洗版 */
  border-radius: 12px;   /* 圖片圓角 */
  margin-top: 4px;
  object-fit: cover;     /* 裁切填滿 */
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* === 🖼 美化茶籤 Modal 的關閉按鈕 === */
#closeTeaCardModal {
  /* 覆蓋原本 ai-send-btn 的圓形設定 */
  width: 100% !important;
  height: auto !important;
  border-radius: 12px !important; /* 改回正常的圓角 */
  padding: 12px 0 !important;     /* 增加上下高度 */
  margin-top: 16px;
  
  /* 按鈕配色 (深綠色系，搭配茶行風格) */
  background: linear-gradient(135deg, #2f4b3c, #1a2e24);
  color: #fff !important;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
  border: none;
  box-shadow: 0 4px 12px rgba(47, 75, 60, 0.3);
  
  /* 移除原本 icon 的偏倚 */
  display: flex;
  align-items: center;
  justify-content: center;
}

#closeTeaCardModal:hover {
  background: linear-gradient(135deg, #3e5c4a, #2a4034);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(47, 75, 60, 0.4);
}

#closeTeaCardModal:active {
  transform: scale(0.98);
}
/* ============================================================
   🏷️ 獨立卡片模式 (Card Mode - 終極防切版)
   請直接覆蓋原本的 Card Mode 區塊
   ============================================================ */

.ai-card-container {
  /* 1. 排版結構：改用 Flex Column，這是解決高度計算錯誤的關鍵 */
  display: flex;
  flex-direction: column;
  
  /* 2. 尺寸設定 */
  width: 100%;
  min-width: 300px; /* 防止在極窄螢幕變形 */
  max-width: 100%;
  height: auto !important; /* 🔥 強制高度隨內容自動長高 */
  
  /* 3. 外觀設定 */
  background: #fff;
  border-radius: 12px;
  /* 陰影稍微加深，增加立體感 */
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  margin: 12px 0;
  border: 1px solid #eee;
  
  /* 4. 關鍵修正：移除 overflow: hidden */
  /* 這樣就算內容超出 1px，也不會被無情切斷，而是會撐開容器 */
  overflow: visible; 
}

/* --- 標題區 --- */
.ai-card-header {
  /* 手動設定圓角 (只圓上面兩個角) */
  border-radius: 12px 12px 0 0;
  
  background: #5c7c5c;
  color: #fff;
  padding: 12px 16px;
  font-weight: bold;
  font-size: 15px;
  letter-spacing: 1px;
  
  /* 防止標題被壓縮 */
  flex-shrink: 0;
}

/* --- 表格區 (Body) --- */
.ai-card-body {
  /* 允許左右滑動，但禁止上下滑動(由父層處理) */
  overflow-x: auto;
  overflow-y: hidden;
  
  /* 讓表格區塊佔據中間剩餘空間 */
  flex: 1 1 auto;
}

.tea-compare-table {
  width: 100%;
  border-collapse: collapse;
  /* 固定表格算法，避免內容把格子撐壞 */
  table-layout: fixed; 
}

.tea-compare-table th {
  background-color: #f8f9fa;
  padding: 12px 8px;
  vertical-align: middle;
  border-bottom: 2px solid #e9ecef;
  text-align: center;
}

/* 表頭大字體 (取代圖片的標題) */
.th-text-large {
  color: #2c3e50;
  font-weight: bold;
  font-size: 14px;
  line-height: 1.4;
  /* 限制最多兩行 */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  height: 40px; /* 固定高度，讓版面整齊 */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 內容格 */
.tea-compare-table td {
  padding: 12px 8px;
  font-size: 13px;
  color: #555;
  text-align: center;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
  word-wrap: break-word;
}

/* 第一欄 (維度名) */
.tea-compare-table td.dim-col {
  font-weight: bold;
  color: #5c7c5c;
  background-color: #fafafa;
  font-size: 12px;
  width: 20%; /* 固定寬度 */
}

/* --- 底部點評 (Footer) --- */
.ai-card-footer {
  /* 手動設定圓角 (只圓下面兩個角) */
  border-radius: 0 0 12px 12px;
  
  background: #fffbf0;
  padding: 16px; /* 增加 padding 讓文字不貼邊 */
  border-top: 1px dashed #e0d0b0;
  
  /* 🔥 救命關鍵：設定為 0 代表「絕對不准壓縮我」 */
  /* 這能保證就算上面表格再長，底部這塊永遠完整顯示 */
  flex-shrink: 0; 
}

.expert-label {
  color: #9c8248;
  font-weight: bold;
  font-size: 13px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.expert-content {
  color: #5d5d5d;
  font-size: 13px;
  line-height: 1.6; /* 行高加大，提升閱讀舒適度 */
  text-align: justify;
}