/**
 * @name: chat.css
 * @description: 前台線上對話浮動元件樣式
 * @version: 1.0.0
 */

/* ================================
   浮動按鈕 (FAB)
   ================================ */
.chat-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: var(--text-inverse);
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 1040;
    transition: transform var(--transition-speed), box-shadow var(--transition-speed), opacity var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.chat-fab:active {
    transform: scale(0.95);
}

.chat-fab.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
}

/* 未讀 badge */
.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #dc3545;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
}

/* ================================
   對話視窗 (小視窗模式)
   ================================ */
.chat-window {
    position: fixed;
    bottom: 96px;
    right: 28px;
    width: 380px;
    height: 520px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    z-index: 1041;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
}

/* 進場動畫 */
.chat-window.chat-entering {
    animation: chatSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.chat-window.chat-leaving {
    animation: chatSlideOut 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes chatSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes chatSlideOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
}

/* 放大模式 */
.chat-window.chat-expanded {
    bottom: 50%;
    right: 50%;
    transform: translate(50%, 50%);
    width: 850px;
    height: 700px;
    border-radius: 12px;
    transform-origin: center center;
}

/* 遮罩 */
.chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1040;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
}

/* ================================
   頂部工具列
   ================================ */
.chat-window-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--primary-color);
    color: var(--text-inverse);
    flex-shrink: 0;
}

.chat-window-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.95rem;
}

.chat-window-actions {
    display: flex;
    gap: 4px;
}

.chat-header-btn {
    background: transparent;
    border: none;
    color: var(--text-inverse);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: background var(--transition-speed);
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ================================
   訊息區域
   ================================ */
.chat-window-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-secondary);
}

[data-theme="dark"] .chat-window-body {
    background: var(--bg-tertiary);
}

/* 歡迎訊息 */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-tertiary);
    text-align: center;
    gap: 12px;
}

.chat-welcome i {
    font-size: 2.5rem;
    opacity: 0.5;
}

.chat-welcome p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* 訊息氣泡包裝 */
.chat-bubble-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.chat-bubble-wrapper.sent {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-bubble-wrapper.received {
    align-self: flex-start;
    align-items: flex-start;
}

/* 訊息氣泡 */
.chat-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    position: relative;
    font-size: 0.88rem;
    line-height: 1.5;
}

.chat-bubble-wrapper.sent .chat-bubble {
    background: var(--primary-color);
    color: var(--text-inverse);
    border-bottom-right-radius: 4px;
}

.chat-bubble-wrapper.received .chat-bubble {
    background: #fffde7;
    color: #212121;
    border: 1px solid #f9e79f;
    border-bottom-left-radius: 4px;
}

[data-theme="dark"] .chat-bubble-wrapper.received .chat-bubble {
    background: #f9e79f;
    color: #212121;
}

.chat-bubble-sender {
    font-size: 0.72rem;
    font-weight: 600;
    margin-bottom: 3px;
    opacity: 0.75;
}

.chat-bubble-content {
    white-space: pre-wrap;
    word-break: break-word;
}

/* 時間顯示在泡泡外側右下方 */
.chat-bubble-time {
    font-size: 0.66rem;
    color: var(--text-tertiary);
    margin-top: 3px;
    padding: 0 4px;
}

/* 附件顯示 */
.chat-bubble-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.chat-bubble-attachment {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.15);
    text-decoration: none;
    color: inherit;
    transition: background var(--transition-speed);
}

.chat-bubble-wrapper.received .chat-bubble-attachment {
    background: rgba(0, 0, 0, 0.07);
    color: #212121;
}

.chat-bubble-attachment:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-bubble-wrapper.received .chat-bubble-attachment:hover {
    background: rgba(0, 0, 0, 0.12);
}

/* 圖片附件在泡泡內預覽 */
.chat-bubble-img-link {
    display: inline-block;
    border-radius: 8px;
    overflow: hidden;
    line-height: 0;
    transition: opacity var(--transition-speed);
}

.chat-bubble-img-link:hover {
    opacity: 0.85;
}

.chat-bubble-img {
    width: 160px;
    height: 160px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
}

/* 貼上預覽（輸入區域上方） */
.chat-paste-preview {
    position: relative;
    display: inline-block;
}

.chat-paste-preview img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid var(--border-color);
}

.chat-paste-preview .chat-attachment-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #dc3545;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    cursor: pointer;
    border: none;
    padding: 0;
}

/* ================================
   附件預覽列
   ================================ */
.chat-attachments-preview {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.chat-attachment-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    max-width: 150px;
}

.chat-attachment-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-attachment-remove {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0;
    font-size: 0.8rem;
    line-height: 1;
    flex-shrink: 0;
}

.chat-attachment-remove:hover {
    color: #dc3545;
}

/* ================================
   輸入區域
   ================================ */
.chat-window-footer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px 4px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

[data-theme="dark"] .chat-window-footer {
    background: var(--bg-secondary);
}

.chat-attach-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: color var(--transition-speed), background var(--transition-speed);
    flex-shrink: 0;
}

.chat-attach-btn:hover {
    color: var(--primary-color);
    background: var(--bg-tertiary);
}

.chat-input {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 0.88rem;
    resize: none;
    max-height: calc(1.4em * 3 + 18px);  /* 小型模式最多 3 行 */
    line-height: 1.4;
    background: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed), max-height var(--transition-speed);
    overflow-y: auto;
}

/* 大型模式輸入框最多 6 行 */
.chat-expanded .chat-input {
    max-height: calc(1.4em * 6 + 18px);
}

.chat-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(195, 13, 35, 0.15);
}

[data-theme="dark"] .chat-input:focus {
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.15);
}

.chat-send-btn {
    background: var(--primary-color);
    border: none;
    color: var(--text-inverse);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: transform var(--transition-speed), background var(--transition-speed);
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.08);
}

.chat-send-btn:active {
    transform: scale(0.92);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-footer-hint {
    text-align: center;
    padding: 0 12px 8px;
    background: var(--bg-primary);
    flex-shrink: 0;
}

[data-theme="dark"] .chat-footer-hint {
    background: var(--bg-secondary);
}

.chat-footer-hint small {
    color: var(--text-tertiary);
    font-size: 0.7rem;
}

/* ================================
   載入狀態
   ================================ */
.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--text-tertiary);
}

.chat-loading-dots {
    display: inline-flex;
    gap: 4px;
}

.chat-loading-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: chatDotPulse 1.2s infinite;
}

.chat-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatDotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* ================================
   日期分隔線
   ================================ */
.chat-date-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
    color: var(--text-tertiary);
    font-size: 0.72rem;
}

.chat-date-divider::before,
.chat-date-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

/* ================================
   響應式
   ================================ */
@media (max-width: 480px) {
    .chat-window {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    .chat-window.chat-expanded {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        transform: none;
        border-radius: 0;
    }

    .chat-fab {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
}

/* ================================================================
   超級 AI 助理模式
   ================================================================ */

/* FAB 按鈕 - AI 漸層 */
.chat-fab-ai {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.chat-fab-ai:hover {
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

/* Header - AI 漸層 */
.chat-header-ai {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

/* AI 視窗稍微寬一點 */
.chat-window-ai {
    width: 420px;
    height: 560px;
}

/* ================================================================
   主動提醒：泡泡 icon 拉伸→變形為搖晃驚嘆號 + 提示氣泡（停留約 50 秒後觸發）
   由 chat.js 對 #chatToggleBtn 加上 .chat-attention 觸發
   ================================================================ */

/* --- 雙 glyph 疊放容器：泡泡與驚嘆號佔同一格，視覺上是「同一顆 icon」 --- */
.chat-fab-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1em;
    height: 1em;
    line-height: 1;
}

.chat-fab-icon .chat-fab-bubble,
.chat-fab-icon .chat-fab-bang {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    /* 由底部變形，squash 時像被壓在地上的果凍 */
    transform-origin: 50% 100%;
    will-change: transform, opacity;
    backface-visibility: hidden;
    /* 白晝模式：紅底配品牌金色 icon 最醒目（紅＋金為 TECPEL 品牌配色），覆蓋繼承色 */
    color: #d4af37;
}

.chat-fab-icon .chat-fab-bang {
    opacity: 0;            /* 平常隱藏，只有變身時出現 */
    font-size: 1.15em;     /* 驚嘆號視覺較瘦，放大補回份量感 */
}

/* 夜間模式按鈕底色本身已是金 (#d4af37)，icon 改回深色才看得清 */
[data-theme="dark"] .chat-fab-icon .chat-fab-bubble,
[data-theme="dark"] .chat-fab-icon .chat-fab-bang {
    color: var(--text-inverse);
}

/* --- 觸發：泡泡壓扁→在最低點交接→驚嘆號彈起變身→搖晃→復原，整段循環 --- */
.chat-fab.chat-attention .chat-fab-bubble {
    animation: chatBubbleMorph 2.6s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
}

.chat-fab.chat-attention .chat-fab-bang {
    animation: chatBangMorph 2.6s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
}

/* hover 立即停止（chat.js 也會移除 class，此為雙保險） */
.chat-fab.chat-attention:hover .chat-fab-bubble,
.chat-fab.chat-attention:hover .chat-fab-bang {
    animation: none;
}

/* 泡泡：預拉伸(anticipation)→急壓扁→最低點淡出交接→末段反向接回並 overshoot 復原 */
@keyframes chatBubbleMorph {
    0%   { transform: scaleX(1) scaleY(1) translateY(0); opacity: 1; }
    8%   { transform: scaleX(0.94) scaleY(1.12) translateY(0); opacity: 1; }     /* 預拉伸蓄力 */
    16%  { transform: scaleX(1.28) scaleY(0.12) translateY(18%); opacity: 1; }   /* 壓扁到地 */
    17%  { transform: scaleX(1.28) scaleY(0.12) translateY(18%); opacity: 0; }   /* 最低點淡出，硬切換身 */
    84%  { transform: scaleX(1.28) scaleY(0.12) translateY(18%); opacity: 0; }   /* 驚嘆號演出期間維持隱藏 */
    85%  { transform: scaleX(1.28) scaleY(0.12) translateY(18%); opacity: 1; }   /* 末段淡回，接手復原 */
    92%  { transform: scaleX(0.92) scaleY(1.16) translateY(-6%); opacity: 1; }   /* 彈起 overshoot */
    100% { transform: scaleX(1) scaleY(1) translateY(0); opacity: 1; }
}

/* 驚嘆號：以壓扁狀態接手→彈起 stretch overshoot→wiggle 搖晃→反向壓扁交回泡泡 */
@keyframes chatBangMorph {
    0%, 16% { transform: scaleX(1.28) scaleY(0.12) translateY(18%) rotate(0deg); opacity: 0; }
    17% { transform: scaleX(1.28) scaleY(0.12) translateY(18%) rotate(0deg); opacity: 1; }  /* 換身瞬間接手 */
    27% { transform: scaleX(0.86) scaleY(1.18) translateY(-8%) rotate(0deg); opacity: 1; }  /* 彈起 stretch overshoot */
    33% { transform: scaleX(1.04) scaleY(0.96) translateY(0) rotate(0deg); opacity: 1; }    /* 回彈 settle */
    37% { transform: scaleX(1) scaleY(1) translateY(0) rotate(0deg); opacity: 1; }          /* 站定＝變身完成 */
    44% { transform: translateY(-10%) rotate(13deg); opacity: 1; }                          /* wiggle 搖晃（幅度遞減） */
    52% { transform: translateY(0) rotate(-11deg); opacity: 1; }
    60% { transform: translateY(-7%) rotate(8deg); opacity: 1; }
    68% { transform: translateY(0) rotate(-5deg); opacity: 1; }
    74% { transform: translateY(-3%) rotate(3deg); opacity: 1; }
    78% { transform: scaleX(1) scaleY(1) translateY(0) rotate(0deg); opacity: 1; }          /* 搖完歸正 */
    83% { transform: scaleX(0.96) scaleY(1.1) translateY(0) rotate(0deg); opacity: 1; }     /* 蓄力 */
    84% { transform: scaleX(1.28) scaleY(0.12) translateY(18%) rotate(0deg); opacity: 1; }  /* 壓扁 */
    85%, 100% { transform: scaleX(1.28) scaleY(0.12) translateY(18%) rotate(0deg); opacity: 0; } /* 淡出交回泡泡 */
}

/* --- 提示氣泡 --- */
.chat-teaser {
    position: fixed;
    bottom: 36px;
    right: 96px;
    max-width: 240px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 12px 34px 12px 16px;
    font-size: 0.9rem;
    line-height: 1.45;
    z-index: 1040;
    transform-origin: bottom right;
}

.chat-teaser.chat-teaser-in {
    animation: chatTeaserIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.chat-teaser.chat-teaser-out {
    animation: chatTeaserOut 0.25s ease forwards;
}

/* 氣泡尾巴指向按鈕 */
.chat-teaser::after {
    content: '';
    position: absolute;
    right: -8px;
    bottom: 16px;
    width: 16px;
    height: 16px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    transform: rotate(-45deg);
}

.chat-teaser-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    line-height: 1;
}

.chat-teaser-close:hover {
    background: var(--bg-secondary, rgba(0, 0, 0, 0.06));
    color: var(--text-primary);
}

@keyframes chatTeaserIn {
    from { opacity: 0; transform: translateX(12px) scale(0.9); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes chatTeaserOut {
    from { opacity: 1; transform: translateX(0) scale(1); }
    to   { opacity: 0; transform: translateX(12px) scale(0.9); }
}

@media (max-width: 480px) {
    .chat-teaser {
        right: 76px;
        bottom: 22px;
        max-width: 190px;
        font-size: 0.82rem;
    }
}

/* 尊重使用者「減少動態」偏好：不壓扁、不搖晃，
   但仍直接把泡泡淡出、靜態驚嘆號淡入，使用者依然能注意到提醒 */
@media (prefers-reduced-motion: reduce) {
    .chat-fab.chat-attention .chat-fab-bubble,
    .chat-fab.chat-attention .chat-fab-bang {
        animation: none;
        transition: opacity 0.3s ease;
    }
    .chat-fab.chat-attention .chat-fab-bubble {
        opacity: 0;
    }
    .chat-fab.chat-attention .chat-fab-bang {
        opacity: 1;
        transform: none;
    }
    .chat-teaser.chat-teaser-in,
    .chat-teaser.chat-teaser-out {
        animation: none;
    }
}

.chat-window-ai.chat-expanded {
    width: 900px;
    height: 720px;
}

/* 發送按鈕 AI 漸層 */
.chat-send-btn-ai {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

/* 歡迎畫面 - AI 快捷按鈕 */
.chat-ai-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
    padding: 0 12px;
}

.chat-ai-quick-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all var(--transition-speed);
    white-space: nowrap;
}

.chat-ai-quick-btn:hover {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    border-color: transparent;
    transform: translateY(-1px);
    box-shadow: 0 3px 12px rgba(99, 102, 241, 0.3);
}

.chat-ai-quick-btn i {
    font-size: 0.85rem;
}

/* AI 回覆泡泡 - Markdown 內容 */
.chat-bubble-ai {
    max-width: 100%;
}

.chat-ai-content {
    white-space: normal;
    word-break: break-word;
    line-height: 1.6;
}

.chat-ai-content p {
    margin: 0 0 8px;
}

.chat-ai-content p:last-child {
    margin-bottom: 0;
}

.chat-ai-content ul,
.chat-ai-content ol {
    margin: 4px 0 8px;
    padding-left: 20px;
}

.chat-ai-content li {
    margin-bottom: 2px;
}

.chat-ai-content code {
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.82em;
    background: var(--bg-tertiary);
    color: #e83e8c;
    font-family: 'Consolas', 'Monaco', monospace;
}

[data-theme="dark"] .chat-ai-content code {
    color: #f0abfc;
}

.chat-ai-content pre {
    margin: 8px 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    overflow-x: auto;
    font-size: 0.82em;
    line-height: 1.5;
}

[data-theme="dark"] .chat-ai-content pre {
    background: #1e1e2e;
}

.chat-ai-content pre code {
    padding: 0;
    background: transparent;
    color: inherit;
}

.chat-ai-content h1, .chat-ai-content h2, .chat-ai-content h3,
.chat-ai-content h4, .chat-ai-content h5, .chat-ai-content h6 {
    margin: 12px 0 6px;
    font-weight: 600;
    line-height: 1.3;
}

.chat-ai-content h1 { font-size: 1.1em; }
.chat-ai-content h2 { font-size: 1.05em; }
.chat-ai-content h3 { font-size: 1em; }

.chat-ai-content blockquote {
    margin: 8px 0;
    padding: 6px 12px;
    border-left: 3px solid #6366f1;
    background: var(--bg-tertiary);
    border-radius: 0 6px 6px 0;
    color: var(--text-secondary);
    font-size: 0.9em;
}

.chat-ai-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.85em;
}

.chat-ai-content th,
.chat-ai-content td {
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.chat-ai-content th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.chat-ai-content a {
    color: #6366f1;
    text-decoration: none;
}

.chat-ai-content a:hover {
    text-decoration: underline;
}

/* 錯誤泡泡 */
.chat-bubble-error {
    background: #fef2f2 !important;
    border: 1px solid #fecaca !important;
    color: #dc2626 !important;
}

[data-theme="dark"] .chat-bubble-error {
    background: #451a1a !important;
    border-color: #7f1d1d !important;
    color: #fca5a5 !important;
}

/* AI 思考中指示器 */
.chat-ai-thinking-indicator {
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ================================
   工具呼叫結果區塊
   ================================ */
.chat-ai-tool-block {
    margin: 6px 12px;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    font-size: 0.82rem;
    max-width: 85%;
}

[data-theme="dark"] .chat-ai-tool-block {
    background: var(--bg-secondary);
}

.chat-ai-tool-label {
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
}

.chat-ai-tool-meta {
    color: var(--text-tertiary);
    font-size: 0.78rem;
    line-height: 1.4;
    margin-top: 4px;
}

/* 圖片工具結果 */
.chat-ai-tool-image {
    border-color: #c4b5fd;
}

.chat-ai-generated-image {
    max-width: 100%;
    max-height: 240px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity var(--transition-speed);
    display: block;
    margin-top: 4px;
}

.chat-ai-generated-image:hover {
    opacity: 0.85;
}

/* 搜尋工具結果 */
.chat-ai-tool-search {
    border-color: #93c5fd;
}

.chat-ai-search-results {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-ai-search-item {
    padding: 4px 0;
    border-bottom: 1px solid var(--border-color);
}

.chat-ai-search-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.chat-ai-search-title {
    color: #6366f1;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.8rem;
}

.chat-ai-search-title:hover {
    text-decoration: underline;
}

.chat-ai-search-snippet {
    color: var(--text-tertiary);
    font-size: 0.75rem;
    line-height: 1.4;
    margin-top: 2px;
}

/* 資料庫工具結果 */
.chat-ai-tool-db {
    border-color: #86efac;
}

/* 網頁擷取結果 */
.chat-ai-tool-fetch {
    border-color: #fcd34d;
}

/* 工具錯誤 */
.chat-ai-tool-error {
    border-color: #fca5a5;
    background: #fef2f2;
}

[data-theme="dark"] .chat-ai-tool-error {
    background: #451a1a;
    border-color: #7f1d1d;
}

/* ================================
   AI 模式響應式
   ================================ */
@media (max-width: 480px) {
    .chat-window-ai {
        width: 100%;
        height: 100%;
    }

    .chat-window-ai.chat-expanded {
        width: 100%;
        height: 100%;
    }

    .chat-ai-quick-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-ai-quick-btn {
        justify-content: center;
    }
}

/* ================================
 * 代理黏著欄 & 對話列表
 * ================================ */

.chat-agent-bar {
    background: var(--bs-primary-bg-subtle, #e0e7ff);
    color: var(--bs-primary-text-emphasis, #3730a3);
    padding: 4px 12px;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--bs-border-color-translucent, #dee2e6);
}

[data-theme="dark"] .chat-agent-bar {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
}

.chat-agent-bar button {
    color: inherit;
    font-size: 0.85rem;
}

/* 對話列表面板 */
.chat-topic-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    background: var(--bs-body-bg, #fff);
    display: flex;
    flex-direction: column;
}

.chat-topic-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    font-size: 0.9rem;
    font-weight: 600;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.chat-topic-panel-header button {
    color: var(--bs-body-color, #333);
    text-decoration: none;
}

.chat-topic-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.chat-topic-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--bs-border-color-translucent, #f0f0f0);
    transition: background 0.15s;
}

.chat-topic-item:hover {
    background: var(--bs-tertiary-bg, #f8f9fa);
}

[data-theme="dark"] .chat-topic-item:hover {
    background: rgba(255,255,255,0.05);
}

.chat-topic-item.active {
    background: var(--bs-primary-bg-subtle, #e0e7ff);
}

[data-theme="dark"] .chat-topic-item.active {
    background: rgba(99, 102, 241, 0.15);
}

.chat-topic-title {
    font-size: 0.85rem;
    display: inline;
    word-break: break-word;
}

.chat-topic-delete {
    opacity: 0;
    transition: opacity 0.15s;
}

.chat-topic-item:hover .chat-topic-delete {
    opacity: 1;
}

/* 代理欄工具執行動畫 */
.agent-bar-tools {
    font-size: 0.75rem;
}

.agent-tool-active {
    color: var(--bs-warning-text-emphasis, #cc9a06);
}

.spin-animation {
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.tool-name-pulse {
    animation: toolPulse 1.5s ease-in-out infinite;
}

@keyframes toolPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-pulse {
    animation: toolPulse 2s ease-in-out infinite;
    color: var(--bs-info-text-emphasis, #087990);
}

.agent-bar-status {
    font-size: 0.72rem;
    opacity: 0.85;
}