﻿/* 官網 AI 智能購車助理。所有選擇器以 .ai-chat- 為前綴，不污染全域樣式。
   座標與 z-index 依規格 §7：避開既有 .btn-gotop（bottom:150px / 120px，z-index 1）。
   main.css 全檔最大 z-index 為 14，故用 20 / 21。斷點 820px 對齊 main.css 既有 media query。 */

.ai-chat-fab {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 20;
    width: 64px;
    height: 64px;
    padding: 0;
    border: 3px solid #eb0a1e;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
    overflow: hidden;
}

.ai-chat-fab:hover { border-color: #c00819; }

.ai-chat-fab-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-chat-panel {
    position: fixed;
    right: 20px;
    bottom: 94px;
    z-index: 21;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, .25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-chat-panel[hidden] { display: none; }

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #eb0a1e;
    color: #fff;
    flex: 0 0 auto;
}

.ai-chat-title { font-size: 16px; font-weight: 700; }

.ai-chat-close {
    border: 0;
    background: none;
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.ai-chat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    background: #f5f5f5;
}

.ai-chat-msg { margin-bottom: 14px; max-width: 88%; }
.ai-chat-msg--bot { margin-right: auto; }
.ai-chat-msg--user { margin-left: auto; }

.ai-chat-text {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    background: #fff;
    color: #333;
    margin-bottom: 6px;
}

.ai-chat-msg--user .ai-chat-text { background: #eb0a1e; color: #fff; }

.ai-chat-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.ai-chat-tag {
    border: 1px solid #eb0a1e;
    background: #fff;
    color: #eb0a1e;
    border-radius: 16px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
}

.ai-chat-tag:hover { background: #eb0a1e; color: #fff; }
.ai-chat-tag[disabled] { opacity: .5; cursor: default; }
.ai-chat-tag[disabled]:hover { background: #fff; color: #eb0a1e; }

/* 引導問答 */
.ai-chat-guide-meta { margin-top: 4px; font-size: 12px; color: #888; }
.ai-chat-tags--grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ai-chat-tag.is-selected,
.ai-chat-tag--primary { background: #eb0a1e; color: #fff; }
.ai-chat-tag--primary[disabled]:hover { background: #eb0a1e; color: #fff; }
.ai-chat-tag--ghost { border-style: dashed; border-color: #aaa; color: #666; }
.ai-chat-tag--ghost:hover { background: #f2f2f2; color: #333; }

.ai-chat-cards { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.ai-chat-card {
    display: flex;
    gap: 10px;
    background: #fff;
    border-radius: 10px;
    padding: 10px;
    text-decoration: none;
    color: #333;
}

.ai-chat-card:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }
.ai-chat-card-img { width: 96px; height: 72px; object-fit: cover; border-radius: 6px; flex: 0 0 auto; background: #eee; }
.ai-chat-card-info { flex: 1 1 auto; min-width: 0; font-size: 13px; }
.ai-chat-card-name { font-weight: 700; margin-bottom: 4px; word-break: break-word; }
.ai-chat-card-price { color: #eb0a1e; font-weight: 700; }
.ai-chat-card-meta { color: #777; font-size: 12px; margin-top: 2px; }

.ai-chat-input {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e0e0e0;
    background: #fff;
    flex: 0 0 auto;
}

.ai-chat-field {
    flex: 1 1 auto;
    min-width: 0;
    height: 40px;
    padding: 0 12px;
    border: 1px solid #ccc;
    border-radius: 20px;
    font-size: 14px;
}

.ai-chat-send {
    flex: 0 0 auto;
    height: 40px;
    padding: 0 18px;
    border: 0;
    border-radius: 20px;
    background: #eb0a1e;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

.ai-chat-field[disabled], .ai-chat-send[disabled] { opacity: .5; }

.ai-chat-typing { font-size: 13px; color: #888; padding: 4px 2px; }

@media only screen and (max-width: 820px) {
    .ai-chat-fab { right: 15px; bottom: 20px; }

    .ai-chat-panel {
        right: 0;
        bottom: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }
}

/* Agent 回覆的 Markdown 渲染結果（marked + DOMPurify）。
   main.css 有全域 reset（ol,ul{list-style:none}），清單樣式必須重新宣告。 */
.ai-chat-text--md { white-space: normal; }
.ai-chat-text--md > *:first-child { margin-top: 0; }
.ai-chat-text--md > *:last-child { margin-bottom: 0; }
.ai-chat-text--md p { margin: 0 0 8px; }
.ai-chat-text--md h1,
.ai-chat-text--md h2,
.ai-chat-text--md h3,
.ai-chat-text--md h4,
.ai-chat-text--md h5,
.ai-chat-text--md h6 { font-size: 15px; font-weight: 700; line-height: 1.4; margin: 12px 0 6px; }
.ai-chat-text--md strong { font-weight: 700; }
.ai-chat-text--md em { font-style: italic; }
.ai-chat-text--md del { text-decoration: line-through; }
.ai-chat-text--md ul,
.ai-chat-text--md ol { margin: 0 0 8px; padding-left: 20px; }
.ai-chat-text--md ul { list-style: disc; }
.ai-chat-text--md ol { list-style: decimal; }
.ai-chat-text--md li { margin-bottom: 4px; }
.ai-chat-text--md hr { border: 0; border-top: 1px solid #e0e0e0; margin: 10px 0; }
.ai-chat-text--md a { color: #eb0a1e; text-decoration: underline; }
.ai-chat-text--md code { background: #f0f0f0; border-radius: 3px; padding: 1px 4px; font-size: 12px; }
.ai-chat-text--md pre { background: #f0f0f0; border-radius: 6px; padding: 8px; margin: 0 0 8px; overflow-x: auto; }
.ai-chat-text--md pre code { background: none; padding: 0; }
.ai-chat-text--md blockquote { border-left: 3px solid #e0e0e0; padding-left: 10px; color: #666; margin: 0 0 8px; }
.ai-chat-text--md table { border-collapse: collapse; width: 100%; margin: 0 0 8px; font-size: 12px; }
.ai-chat-text--md th,
.ai-chat-text--md td { border: 1px solid #e0e0e0; padding: 4px 6px; text-align: left; }
