/* 商品頁「問 AI 導購」小卡＋對話區。
   顏色、圓角、陰影全部吃 neon_theme.css 的全站變數（翡翠綠 × 暖象牙白），不另外寫死色碼。
   未發問前是一張小卡；第一次發問後 .is-open 讓對話區平滑展開。手機 390px 不溢位、輸入框 16px 防 iOS 放大。 */

.aig [hidden] { display: none !important; }

.aig-card {
  position: relative;
  background: linear-gradient(180deg, var(--accent-soft) 0, var(--surface) 96px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 14px;
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

/* ── 標題列 ── */
.aig-head { display: flex; align-items: flex-start; gap: 12px; }
.aig-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--accent-border);
  color: var(--accent);
}
.aig-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.aig-head-text { flex: 1 1 auto; min-width: 0; }
.aig .aig-title {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.35;
  color: var(--ink);
}
.aig-title:focus { outline: none; }
.aig-title:focus-visible { outline: 2px solid var(--accent-border); outline-offset: 3px; border-radius: 6px; }
.aig-sub { margin: 3px 0 0; font-size: 13.5px; line-height: 1.6; color: var(--ink-2); }

.aig-clear {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  animation: aig-fade .28s ease both;
  transition: color .15s ease, border-color .15s ease, background .15s ease, transform .12s ease;
}
/* 視覺小巧、點擊熱區撐到 40px 以上 */
.aig-clear::after { content: ""; position: absolute; inset: -6px -4px; }
.aig-clear svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.aig-clear:hover { color: var(--accent); border-color: var(--accent-border); background: var(--accent-soft); }
.aig-clear:active { transform: scale(.95); }

/* ── 對話區：0fr → 1fr 平滑展開 ── */
.aig-log-wrap {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows .38s cubic-bezier(.2, .7, .2, 1), opacity .28s ease, margin-top .38s ease;
}
.aig.is-open .aig-log-wrap { grid-template-rows: 1fr; opacity: 1; margin-top: 14px; }
.aig-log { min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 12px; }
/* 左右各留 3px，鍵盤焦點框不會被裁掉 */
.aig.is-open .aig-log { margin: 0 -3px; padding: 14px 3px 3px; border-top: 1px solid var(--line); }

.aig-msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  animation: aig-in .34s cubic-bezier(.2, .7, .2, 1) both;
  scroll-margin-top: 140px;
  scroll-margin-bottom: calc(84px + env(safe-area-inset-bottom));
}
.aig-msg.is-user { align-items: flex-end; }
.aig-msg.is-ai { align-items: flex-start; }

.aig-bubble {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.75;
  overflow-wrap: anywhere;
}
.aig-msg.is-user .aig-bubble {
  max-width: 86%;
  background: var(--accent);
  color: var(--accent-ink);
  border-bottom-right-radius: 6px;
  white-space: pre-line;
}
.aig-msg.is-ai .aig-bubble {
  background: var(--field);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}
.aig-bubble p { margin: 0; }
.aig-bubble p + p, .aig-bubble p + ul, .aig-bubble p + ol, .aig-bubble ul + p, .aig-bubble ol + p, .aig-bubble ul + ol, .aig-bubble ol + ul { margin-top: 8px; }
.aig-bubble ul, .aig-bubble ol { margin: 0; padding-left: 1.35em; }
.aig-bubble li + li { margin-top: 3px; }
.aig-bubble li::marker { color: var(--accent); }
.aig-bubble strong { font-weight: 700; color: var(--ink); }

/* 思考中：溫柔三點跳動 */
.aig-msg.is-thinking .aig-bubble { display: inline-flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 14px; }
.aig-dots { display: inline-flex; gap: 4px; }
.aig-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .35; animation: aig-dot 1.2s ease-in-out infinite; }
.aig-dots i:nth-child(2) { animation-delay: .16s; }
.aig-dots i:nth-child(3) { animation-delay: .32s; }

/* 已即時查詢最新行情 */
.aig-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
}
.aig-tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* 參考來源 */
.aig-sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 100%; margin: 0; padding: 0; list-style: none; }
.aig-sources-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.aig-source {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  max-width: 100%;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.aig-source span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aig-source:hover { color: var(--accent); border-color: var(--accent-border); background: var(--accent-soft); text-decoration: none; }

/* 站內同類可比較 */
.aig-alts { width: 100%; }
.aig-alts-title { margin: 2px 0 6px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.aig-alts-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.aig-alt {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.aig-alt:hover { border-color: var(--accent-border); box-shadow: var(--shadow); transform: translateY(-1px); text-decoration: none; }
.aig-alt:active { transform: scale(.98); }
.aig-alt-title { font-size: 14px; font-weight: 600; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.aig-alt-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.aig-alt-cond { padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; font-weight: 600; white-space: nowrap; }
.aig-alt-price { margin-left: auto; color: var(--price); font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── 快問／追問氣泡 ── */
.aig-quick, .aig-follow { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.aig-quick { margin-top: 14px; }
.aig-follow { margin-top: 2px; max-width: 100%; }
.aig-quick li, .aig-follow li { min-width: 0; max-width: 100%; }
.aig-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 40px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent-border);
  background: var(--surface);
  color: var(--accent);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .14s cubic-bezier(.3, 1.6, .5, 1);
}
.aig-chip:hover { background: var(--accent-soft); border-color: var(--accent); }
.aig-chip:active { transform: scale(.95); }
.aig-chip:disabled { opacity: .5; cursor: default; transform: none; }
.aig-follow .aig-chip { background: var(--gold-soft); border-color: var(--gold-border); color: var(--ink); font-weight: 500; }
.aig-follow .aig-chip:hover { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }

/* ── 暖色輕提醒條 ── */
.aig-alert {
  margin: 12px 0 0;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  border: 1px solid var(--gold-border);
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.6;
  animation: aig-fade .25s ease both;
}

/* ── 輸入列 ── */
.aig-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 12px;
  scroll-margin-bottom: calc(84px + env(safe-area-inset-bottom));
}
.aig .aig-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  max-height: 140px;
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px; /* 至少 16px：iOS Safari 點輸入框不會自動放大畫面 */
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
  field-sizing: content;
  box-shadow: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.aig .aig-input::placeholder { color: var(--muted); }
.aig .aig-input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }

.aig-send {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease, transform .14s cubic-bezier(.3, 1.6, .5, 1);
}
.aig-send svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.aig-send:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.aig-send:active:not(:disabled) { transform: scale(.94); }
.aig-send:disabled { opacity: .55; cursor: default; }
.aig-chip:focus-visible, .aig-send:focus-visible, .aig-clear:focus-visible, .aig-source:focus-visible, .aig-alt:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 419px) {
  .aig-card { padding: 14px 14px 12px; }
  .aig-send { padding: 0 13px; }
  .aig-msg.is-user .aig-bubble { max-width: 92%; }
}

@keyframes aig-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes aig-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes aig-dot { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-4px); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .aig-log-wrap, .aig-chip, .aig-send, .aig-clear, .aig-alt, .aig-source { transition: none; }
  .aig-msg, .aig-alert, .aig-clear { animation: none; }
  .aig-dots i { animation: none; opacity: .7; }
  .aig-chip:active, .aig-send:active:not(:disabled), .aig-alt:hover, .aig-alt:active, .aig-clear:active { transform: none; }
}
