/* ═══════════════════════════════════════════════════════
   Back to Top 浮動按鈕（跟 chat FAB 錯開；位置在 chat FAB 上方）
   ═══════════════════════════════════════════════════════ */
#gd-back-to-top {
    position: fixed;
    right: 24px;
    bottom: 96px;                    /* chat FAB bottom:24 + 60px + 12 gap */
    z-index: 1079;                   /* 比 chat 少 1 */
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(30, 40, 50, .82);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(0,0,0,.22);
    cursor: pointer;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity .22s ease, transform .22s ease, background .15s;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
#gd-back-to-top.is-visible {
    opacity: 1;
    transform: translateY(0);
}
#gd-back-to-top:hover {
    background: var(--gd-primary, #70B020);
}
#gd-back-to-top i { font-size: 24px; line-height: 1; }

@media (max-width: 480px) {
    #gd-back-to-top { right: 12px; bottom: 78px; width: 40px; height: 40px; }
    #gd-back-to-top i { font-size: 22px; }
}

/* ═══════════════════════════════════════════════════════
   GD Floating Chat Widget
   MVP：純 FAQ 卡片式，不打 LLM
   品牌色：#70B020 (var(--gd-primary))
   ═══════════════════════════════════════════════════════ */

#gd-chat { position: fixed; right: 24px; bottom: 24px; z-index: 1080; font-family: inherit; }

/* ── FAB 泡泡 ────────────────────────────────────────── */
.gd-chat-fab {
    display: flex; align-items: center; justify-content: center;
    width: 60px; height: 60px; border-radius: 50%;
    background: var(--gd-primary, #70B020);
    color: #fff; border: none;
    box-shadow: 0 6px 18px rgba(0,0,0,.22), 0 2px 6px rgba(0,0,0,.12);
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease;
    position: relative;
}
.gd-chat-fab:hover { transform: scale(1.08); box-shadow: 0 8px 22px rgba(0,0,0,.28); }
.gd-chat-fab i { font-size: 28px; line-height: 1; }
.gd-chat-fab-dot {
    position: absolute; top: 10px; right: 10px;
    width: 10px; height: 10px; border-radius: 50%;
    background: #ff4757; border: 2px solid #fff;
    animation: gdChatPulse 2.5s ease-out infinite;
}
@keyframes gdChatPulse {
    0%   { box-shadow: 0 0 0 0 rgba(255,71,87,.6); }
    70%  { box-shadow: 0 0 0 10px rgba(255,71,87,0); }
    100% { box-shadow: 0 0 0 0 rgba(255,71,87,0); }
}

/* ── 面板 ────────────────────────────────────────────── */
.gd-chat-panel {
    position: absolute; right: 0; bottom: 72px;
    width: 380px; max-width: calc(100vw - 32px);
    height: 560px; max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 36px rgba(0,0,0,.20), 0 4px 12px rgba(0,0,0,.08);
    display: flex; flex-direction: column;
    overflow: hidden;
    animation: gdChatSlideUp .28s cubic-bezier(.2,.9,.3,1);
}
@keyframes gdChatSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Header ─────────────────────────────────────────── */
.gd-chat-header {
    background: linear-gradient(135deg, var(--gd-primary, #70B020) 0%, #5a9a1a 100%);
    color: #fff;
    padding: 16px;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.gd-chat-header-title { display: flex; align-items: center; gap: 12px; }
.gd-chat-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,.25);
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
}
.gd-chat-close {
    background: transparent; border: none; color: #fff;
    width: 32px; height: 32px; border-radius: 50%;
    cursor: pointer; opacity: .8;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    transition: background .15s;
}
.gd-chat-close:hover { background: rgba(255,255,255,.15); opacity: 1; }

/* ── Body ─────────────────────────────────────────────── */
.gd-chat-body {
    flex: 1; overflow-y: auto;
    padding: 16px;
    background: #fafafa;
}
.gd-chat-loading { color: #999; text-align: center; padding: 40px 0; }
.gd-chat-loading i { font-size: 24px; margin-right: 8px; }

/* 歡迎訊息 */
.gd-chat-welcome {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    color: #333;
    font-size: 14px;
    line-height: 1.55;
}

/* FAQ 卡片列表（首屏 6 顆 featured）*/
.gd-chat-cards { display: grid; gap: 8px; }
.gd-chat-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    display: flex; align-items: center; gap: 10px;
    transition: border-color .15s, transform .1s, box-shadow .15s;
    text-align: left;
    color: #333;
    font-size: 14px;
}
.gd-chat-card:hover {
    border-color: var(--gd-primary, #70B020);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(112,176,32,.10);
}
.gd-chat-card i { color: var(--gd-primary, #70B020); font-size: 20px; flex-shrink: 0; }
.gd-chat-card-title { flex: 1; }

/* 對話氣泡 */
.gd-chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    margin-bottom: 8px;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.gd-chat-bubble.user {
    background: var(--gd-primary, #70B020);
    color: #fff;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}
.gd-chat-bubble.bot {
    background: #fff;
    color: #333;
    border: 1px solid #eee;
    border-bottom-left-radius: 4px;
}
.gd-chat-bubble-time { font-size: 11px; color: #999; margin: 2px 6px 8px; }
.gd-chat-bubble-time.user { text-align: right; }

/* 「更多問題」區塊 */
.gd-chat-more { margin-top: 12px; padding-top: 12px; border-top: 1px dashed #ddd; }
.gd-chat-more-title { font-size: 12px; color: #999; margin-bottom: 6px; padding: 0 4px; }

/* 底部「回到問題列表」按鈕 */
.gd-chat-back {
    display: block; width: 100%;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--gd-primary, #70B020);
    color: var(--gd-primary, #70B020);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    margin-top: 8px;
    transition: background .15s;
}
.gd-chat-back:hover { background: rgba(112,176,32,.08); }

/* ── 輸入區（Phase 3）─────────────────────────────────── */
.gd-chat-input {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}
.gd-chat-input textarea {
    flex: 1;
    resize: none;
    max-height: 120px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 18px;
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    background: #f5f5f5;
    color: #333;
    transition: border-color .15s, background .15s;
}
.gd-chat-input textarea:focus {
    border-color: var(--gd-primary, #70B020);
    background: #fff;
}
.gd-chat-input textarea:disabled {
    opacity: .5; cursor: not-allowed;
}
.gd-chat-send {
    flex-shrink: 0;
    width: 40px; height: 40px;
    background: var(--gd-primary, #70B020);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    transition: background .15s, transform .1s;
}
.gd-chat-send:hover:not(:disabled) { background: #5a9a1a; transform: scale(1.05); }
.gd-chat-send:disabled { opacity: .5; cursor: not-allowed; }

/* Loading 動畫（AI 回覆中）*/
.gd-chat-thinking {
    display: inline-flex; gap: 3px; padding: 8px 14px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 14px;
    margin-bottom: 8px;
}
.gd-chat-thinking span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--gd-primary, #70B020);
    animation: gdChatDot 1.4s infinite ease-in-out both;
}
.gd-chat-thinking span:nth-child(1) { animation-delay: -0.32s; }
.gd-chat-thinking span:nth-child(2) { animation-delay: -0.16s; }
@keyframes gdChatDot {
    0%, 80%, 100% { transform: scale(0); }
    40%           { transform: scale(1); }
}

/* Source badge（faq / ai / block）*/
.gd-chat-source {
    display: inline-block;
    font-size: 10.5px;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 4px;
    color: #fff;
    vertical-align: middle;
}
.gd-chat-source.faq { background: #5a9a1a; }
.gd-chat-source.ai  { background: #6c5ce7; }
.gd-chat-source.block,
.gd-chat-source.refuse,
.gd-chat-source.quota,
.gd-chat-source.budget,
.gd-chat-source.error { background: #b0b0b0; }

[data-bs-theme="dark"] .gd-chat-input { background: #2b2c40; border-top-color: #3a3b52; }
[data-bs-theme="dark"] .gd-chat-input textarea { background: #232434; color: #e5e5e5; border-color: #3a3b52; }
[data-bs-theme="dark"] .gd-chat-input textarea:focus { background: #2b2c40; }
[data-bs-theme="dark"] .gd-chat-thinking { background: #2b2c40; border-color: #3a3b52; }

/* ── Footer ──────────────────────────────────────────── */
.gd-chat-footer {
    padding: 10px 16px;
    background: #f5f5f5;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}
.gd-chat-footer .small { font-size: 11.5px; }

/* ── Dark mode 相容 ──────────────────────────────────── */
[data-bs-theme="dark"] .gd-chat-panel { background: #2b2c40; }
[data-bs-theme="dark"] .gd-chat-body { background: #232434; }
[data-bs-theme="dark"] .gd-chat-welcome,
[data-bs-theme="dark"] .gd-chat-card,
[data-bs-theme="dark"] .gd-chat-bubble.bot { background: #2b2c40; color: #e5e5e5; border-color: #3a3b52; }
[data-bs-theme="dark"] .gd-chat-footer { background: #1e1f2e; border-top-color: #3a3b52; }

/* ── RWD ─────────────────────────────────────────────── */
@media (max-width: 480px) {
    #gd-chat { right: 12px; bottom: 12px; }
    .gd-chat-panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 96px);
        max-height: 640px;
        right: 0; bottom: 72px;
    }
    .gd-chat-fab { width: 54px; height: 54px; }
    .gd-chat-fab i { font-size: 26px; }
}
