/* ============================================================
   QSEC 宏禦全球 — QSEC AI Security Advisor 對話視窗樣式
   （沿用元件架構模式，色彩改用 QSEC 深色情資主控台配色）
   輸入框下方常駐 LINE 導流膠囊按鈕（.ai-chat-line-pin），
   確保訪客隨時可一鍵切換至 LINE 聯絡業務顧問。
   ============================================================ */

/* ---------- 浮動開啟按鈕 ---------- */
.ai-chat-launcher{
  position:fixed; right:20px; bottom:20px; z-index:91;
  width:56px; height:56px; border-radius:50%;
  background:var(--brand-grad);
  display:flex; align-items:center; justify-content:center;
  box-shadow:0 10px 26px -6px rgba(34,211,238,0.5);
  border:none; cursor:pointer; padding:0;
  transition:transform .15s ease;
}
.ai-chat-launcher:hover{transform:scale(1.08);}
.ai-chat-launcher svg{width:26px; height:26px; color:#04101F;}
.ai-chat-launcher .ai-chat-dot{
  position:absolute; top:2px; right:2px; width:12px; height:12px; border-radius:50%;
  background:#22C55E; border:2px solid #fff;
}
.ai-chat-launcher.is-hidden{display:none;}

/* ---------- 對話視窗容器 ---------- */
.ai-chat-window{
  position:fixed; right:20px; bottom:20px; z-index:120;
  width:min(380px, calc(100vw - 32px));
  height:min(560px, calc(100vh - 52px));
  background:var(--card); border-radius:var(--radius-lg);
  box-shadow:var(--shadow-lg), 0 0 0 1px var(--line);
  display:none; flex-direction:column; overflow:hidden;
}
.ai-chat-window.is-open{display:flex;}

@media (prefers-reduced-motion: no-preference){
  .ai-chat-window.is-open{animation:aiChatFadeIn .18s ease both;}
}
@keyframes aiChatFadeIn{
  from{opacity:0; transform:translateY(10px) scale(0.98);}
  to{opacity:1; transform:translateY(0) scale(1);}
}

/* ---------- 標題列 ---------- */
.ai-chat-header{
  background:var(--brand-grad); color:#04101F;
  padding:14px 16px; display:flex; align-items:center; gap:10px; flex-shrink:0;
}
.ai-chat-header .ai-chat-avatar{
  width:36px; height:36px; border-radius:50%; background:rgba(4,16,31,0.14);
  display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.ai-chat-header .ai-chat-avatar svg{width:20px; height:20px; color:#04101F;}
.ai-chat-header-text{flex:1; min-width:0;}
.ai-chat-header-text .ai-chat-title{font-weight:700; font-size:0.95rem; line-height:1.3;}
.ai-chat-header-text .ai-chat-subtitle{font-size:0.75rem; opacity:0.75; line-height:1.3;}
.ai-chat-close{
  background:none; border:none; cursor:pointer; color:#04101F; opacity:0.7;
  width:28px; height:28px; display:flex; align-items:center; justify-content:center; flex-shrink:0;
  border-radius:8px; transition:background .15s ease;
}
.ai-chat-close:hover{background:rgba(4,16,31,0.12); opacity:1;}
.ai-chat-close svg{width:18px; height:18px;}

/* ---------- 訊息區 ---------- */
.ai-chat-body{
  flex:1; overflow-y:auto; padding:16px; display:flex; flex-direction:column; gap:12px;
  background:var(--bg);
}
.ai-chat-msg{
  max-width:82%; padding:10px 14px; border-radius:16px; font-size:0.88rem; line-height:1.6;
  white-space:pre-wrap; word-break:break-word;
}
.ai-chat-msg.from-ai{
  align-self:flex-start; background:var(--card); color:var(--ink);
  border:1px solid var(--line); border-bottom-left-radius:4px;
}
.ai-chat-msg.from-user{
  align-self:flex-end; background:var(--brand-grad); color:#04101F;
  border-bottom-right-radius:4px;
}
.ai-chat-msg.is-error{
  align-self:flex-start; background:rgba(239,68,68,0.12); color:#FCA5A5; border:1px solid rgba(239,68,68,0.3);
}
[data-theme="light"] .ai-chat-msg.is-error{
  background:#FEF2F2; color:#B91C1C; border-color:#FECACA;
}

/* 打字中動畫 */
.ai-chat-typing{
  align-self:flex-start; display:flex; gap:4px; padding:12px 14px;
  background:var(--card); border:1px solid var(--line); border-radius:16px; border-bottom-left-radius:4px;
}
.ai-chat-typing span{
  width:6px; height:6px; border-radius:50%; background:var(--ink-faint);
  animation:aiChatTypingBounce 1.2s infinite ease-in-out;
}
.ai-chat-typing span:nth-child(2){animation-delay:0.15s;}
.ai-chat-typing span:nth-child(3){animation-delay:0.3s;}
@keyframes aiChatTypingBounce{
  0%,60%,100%{transform:translateY(0); opacity:0.5;}
  30%{transform:translateY(-4px); opacity:1;}
}
@media (prefers-reduced-motion: reduce){
  .ai-chat-typing span{animation:none; opacity:0.8;}
}

/* 導流 LINE 快捷按鈕（AI 判斷有成交意願時出現） */
.ai-chat-cta{
  align-self:flex-start; display:flex; flex-direction:column; gap:8px;
  background:rgba(34,197,94,0.1); border:1px solid rgba(34,197,94,0.3); border-radius:14px; padding:12px 14px;
  max-width:88%;
}
.ai-chat-cta p{font-size:0.82rem; color:#86EFAC; line-height:1.5;}
[data-theme="light"] .ai-chat-cta{background:#ECFDF3; border-color:#BBF7D0;}
[data-theme="light"] .ai-chat-cta p{color:#166534;}
.ai-chat-cta a{
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  background:#06C755; color:#fff; font-size:0.85rem; font-weight:700;
  padding:9px 14px; border-radius:999px; transition:opacity .15s ease;
}
.ai-chat-cta a:hover{opacity:0.9;}
.ai-chat-cta svg{width:16px; height:16px;}

/* ---------- 初次開啟提示語（快捷提問） ---------- */
.ai-chat-suggestions{
  display:flex; flex-wrap:wrap; gap:6px; padding:0 16px 12px; flex-shrink:0;
}
.ai-chat-suggestions button{
  background:var(--card); border:1px solid var(--line); border-radius:999px;
  padding:6px 12px; font-size:0.78rem; color:var(--ink-soft); cursor:pointer;
  transition:border-color .15s ease, color .15s ease;
}
.ai-chat-suggestions button:hover{border-color:var(--cyan); color:var(--cyan);}

/* ---------- 輸入區 ---------- */
.ai-chat-inputbar{
  display:flex; align-items:flex-end; gap:8px; padding:12px 14px;
  border-top:1px solid var(--line); background:var(--card); flex-shrink:0;
}
.ai-chat-inputbar textarea{
  flex:1; resize:none; border:1px solid var(--line); border-radius:14px;
  padding:10px 12px; font-family:inherit; font-size:0.88rem; line-height:1.5;
  max-height:96px; color:var(--ink); background:var(--bg);
}
.ai-chat-inputbar textarea:focus{outline:none; border-color:var(--cyan);}
.ai-chat-send{
  width:38px; height:38px; border-radius:50%; border:none; cursor:pointer;
  background:var(--brand-grad); display:flex; align-items:center; justify-content:center;
  flex-shrink:0; transition:opacity .15s ease;
}
.ai-chat-send:disabled{opacity:0.45; cursor:not-allowed;}
.ai-chat-send svg{width:17px; height:17px; color:#04101F;}

/* ---------- 常駐 LINE 導流膠囊（V7.0 新增，輸入框下方永遠顯示） ----------
   與對話內偶爾出現的 .ai-chat-cta（AI 判斷有成交意願時才顯示）不同，
   這是不論對話進度如何都固定顯示在輸入框正下方的常駐入口，
   確保訪客隨時能一鍵改用 LINE，不必等 AI 主動導流。 */
.ai-chat-line-pin{
  flex-shrink:0; padding:0 14px 10px;
}
.ai-chat-line-pin a{
  display:flex; align-items:center; justify-content:center; gap:7px;
  width:100%; background:#06C755; color:#fff; font-size:0.85rem; font-weight:700;
  padding:10px 14px; border-radius:999px; transition:opacity .15s ease, transform .15s ease;
}
.ai-chat-line-pin a:hover{opacity:0.92; transform:translateY(-1px);}
.ai-chat-line-pin svg{width:17px; height:17px; flex-shrink:0;}

.ai-chat-disclaimer{
  font-size:0.68rem; color:var(--ink-faint); text-align:center; padding:0 14px 10px; flex-shrink:0;
}

/* ---------- 手機版微調 ---------- */
@media (max-width:480px){
  .ai-chat-window{
    right:12px; left:12px; bottom:16px; width:auto;
    height:min(70vh, calc(100vh - 42px));
  }
  .ai-chat-launcher{right:16px; bottom:16px;}
}
