/* 展開報告內容按鈕 */
.show-context-btn {
	position: absolute;
	right: 16px;
	top: 8px;
	background: #10b981;
	color: #fff;
	border: none;
	padding: 6px 10px;
	border-radius: 8px;
	font-size: 12px;
	cursor: pointer;
}

.show-context-btn:hover {
	filter: brightness(0.95);
}
/* Theme Variables */
:root {
    /* Light Blue Theme (Default) */
    --bg-primary: #f0f9ff;
    --bg-secondary: #e0f2fe;
    --bg-tertiary: #b3e5fc;
    --border-primary: #0288d1;
    --border-secondary: rgba(2, 136, 209, 0.3);
    --accent-primary: #0288d1;
    --accent-primary-rgb: 2, 136, 209;
    --accent-secondary: #0277bd;
    --text-primary: #1a202c;
    --text-secondary: #2d3748;
    --text-muted: #718096;
    --text-contrast: #ffffff;
}

/* Black Gold Theme */
[data-theme="black-gold"] {
    --bg-primary: #000000;
    --bg-secondary: #1f2937;
    --bg-tertiary: #374151;
    --border-primary: #c8a27a;
    --border-secondary: rgba(200, 162, 122, 0.5);
    --accent-primary: #D9B790;
    --accent-primary-rgb: 217, 183, 144;
    --accent-secondary: #c8a27a;
    --text-primary: #ffffff;
    --text-secondary: #f9fafb;
    --text-muted: #9ca3af;
    --text-contrast: #000000;
}

/* Dark Purple Theme */
[data-theme="dark-purple"] {
    --bg-primary: #1a0b2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --border-primary: #9c27b0;
    --border-secondary: rgba(156, 39, 176, 0.5);
    --accent-primary: #ba68c8;
    --accent-primary-rgb: 186, 104, 200;
    --accent-secondary: #9c27b0;
    --text-primary: #ffffff;
    --text-secondary: #f3e5f5;
    --text-muted: #b39ddb;
    --text-contrast: #ffffff;
}

/* Forest Green Theme */
[data-theme="forest-green"] {
    --bg-primary: #0d1b2a;
    --bg-secondary: #1b263b;
    --bg-tertiary: #415a77;
    --border-primary: #4caf50;
    --border-secondary: rgba(76, 175, 80, 0.5);
    --accent-primary: #66bb6a;
    --accent-primary-rgb: 102, 187, 106;
    --accent-secondary: #4caf50;
    --text-primary: #ffffff;
    --text-secondary: #e8f5e8;
    --text-muted: #a5d6a7;
    --text-contrast: #ffffff;
}

/* Sunset Orange Theme */
[data-theme="sunset-orange"] {
    --bg-primary: #3e2723;
    --bg-secondary: #5d4037;
    --bg-tertiary: #8d6e63;
    --border-primary: #ff9800;
    --border-secondary: rgba(255, 152, 0, 0.5);
    --accent-primary: #ffb74d;
    --accent-primary-rgb: 255, 183, 77;
    --accent-secondary: #ff9800;
    --text-primary: #ffffff;
    --text-secondary: #fff3e0;
    --text-muted: #ffcc02;
    --text-contrast: #3e2723;
}

/* Taiwan Red Theme - 台灣道教紅色主題 */
[data-theme="taiwan-red"] {
    --bg-primary: #1a0d0d;
    --bg-secondary: #2d1414;
    --bg-tertiary: #4a1e1e;
    --border-primary: #dc2626;
    --border-secondary: rgba(220, 38, 38, 0.5);
    --accent-primary: #ef4444;
    --accent-primary-rgb: 239, 68, 68;
    --accent-secondary: #dc2626;
    --text-primary: #fef2f2;
    --text-secondary: #fed7d7;
    --text-muted: #fca5a5;
    --text-contrast: #ffffff;
    
    /* 特殊的金色裝飾元素 */
    --gold-accent: #fbbf24;
    --gold-accent-rgb: 251, 191, 36;
}

/* General Styling */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease;
}

/* Taiwan Red Theme Special Effects */
[data-theme="taiwan-red"] body {
    background: linear-gradient(135deg, var(--bg-primary) 0%, #220f0f 50%, var(--bg-primary) 100%);
}

[data-theme="taiwan-red"] .message.assistant-message .message-content {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border: 1px solid var(--border-primary);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.2);
}

[data-theme="taiwan-red"] .speech-button {
    background: linear-gradient(45deg, var(--accent-primary), var(--gold-accent));
    border-color: var(--gold-accent);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3), 0 0 20px rgba(251, 191, 36, 0.2);
}

[data-theme="taiwan-red"] .speech-button:hover:not(:disabled) {
    box-shadow: 0 6px 25px rgba(239, 68, 68, 0.4), 0 0 30px rgba(251, 191, 36, 0.3);
    animation: taiwan-glow 2s infinite;
}

@keyframes taiwan-glow {
    0%, 100% {
        box-shadow: 0 6px 25px rgba(239, 68, 68, 0.4), 0 0 30px rgba(251, 191, 36, 0.3);
    }
    50% {
        box-shadow: 0 6px 30px rgba(239, 68, 68, 0.5), 0 0 35px rgba(251, 191, 36, 0.4);
    }
}

[data-theme="taiwan-red"] .menu-toggle-btn {
    background: linear-gradient(45deg, var(--accent-primary), var(--gold-accent));
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

[data-theme="taiwan-red"] .menu-toggle-btn:hover {
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4), 0 0 15px rgba(251, 191, 36, 0.3);
}

/* Taiwan Red Theme Enhanced Selectors */
[data-theme="taiwan-red"] #theme-selector,
[data-theme="taiwan-red"] #language {
    border-color: var(--border-primary);
    box-shadow: 0 0 8px rgba(220, 38, 38, 0.2);
    font-weight: 600;
}

[data-theme="taiwan-red"] #theme-selector:focus,
[data-theme="taiwan-red"] #language:focus {
    border-color: var(--gold-accent);
    box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.3), 0 0 12px rgba(220, 38, 38, 0.3);
}

[data-theme="taiwan-red"] #theme-selector option,
[data-theme="taiwan-red"] #language option {
    font-weight: 600;
}

/* 極強優先級 - 覆蓋所有可能的樣式 */
html body #theme-selector,
html body #language {
    color: var(--text-primary) !important;
    font-weight: 600 !important;
}

html body select#theme-selector.tertiary-bg,
html body select#language.tertiary-bg {
    color: var(--text-primary) !important;
    font-weight: 600 !important;
}

/* 針對每個主題的極強選擇器 */
html body[data-theme="black-gold"] #theme-selector,
html body[data-theme="black-gold"] #language {
    color: #ffffff !important;
}

html body[data-theme="dark-purple"] #theme-selector,
html body[data-theme="dark-purple"] #language {
    color: #ffffff !important;
}

html body[data-theme="forest-green"] #theme-selector,
html body[data-theme="forest-green"] #language {
    color: #ffffff !important;
}

html body[data-theme="sunset-orange"] #theme-selector,
html body[data-theme="sunset-orange"] #language {
    color: #ffffff !important;
}

html body[data-theme="taiwan-red"] #theme-selector,
html body[data-theme="taiwan-red"] #language {
    color: #fef2f2 !important;
}

/* 預設主題(清新藍色) */
html body:not([data-theme]) #theme-selector,
html body:not([data-theme]) #language,
html body[data-theme="light-blue"] #theme-selector,
html body[data-theme="light-blue"] #language {
    color: #1a202c !important;
}

/* 手機版彈窗按鈕文字顏色 */
.modal-overlay button {
    color: var(--text-primary) !important;
    font-weight: 500 !important;
}

.modal-overlay .primary-text {
    color: var(--text-primary) !important;
    font-weight: 600 !important;
}

.modal-overlay h3.primary-text {
    color: var(--text-primary) !important;
    font-weight: 700 !important;
}

/* 針對各主題的手機版彈窗按鈕 */
[data-theme="black-gold"] .modal-overlay button,
[data-theme="dark-purple"] .modal-overlay button,
[data-theme="forest-green"] .modal-overlay button,
[data-theme="sunset-orange"] .modal-overlay button {
    color: #ffffff !important;
}

[data-theme="taiwan-red"] .modal-overlay button {
    color: #fef2f2 !important;
}

:not([data-theme]) .modal-overlay button,
[data-theme="light-blue"] .modal-overlay button {
    color: #1a202c !important;
}

/* 手機版彈窗hover效果 */
.modal-overlay button:hover {
    background-color: rgba(var(--accent-primary-rgb), 0.2) !important;
}

/* 手機版彈窗選中狀態 */
.modal-overlay button.bg-accent {
    background-color: rgba(var(--accent-primary-rgb), 0.3) !important;
    color: var(--text-contrast) !important;
    font-weight: 600 !important;
}

/* Loading Screen Styling */
#loading-screen {
    transition: opacity 0.5s ease-out;
    background-color: var(--bg-primary);
    z-index: 9999; /* Ensure it's on top of all other elements */
}

#loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--bg-tertiary);
    border-top: 4px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Custom scrollbar for webkit browsers */
#chat-messages {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: var(--accent-secondary);
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* Base message styling */
.message {
    display: flex;
    align-items: flex-start;
    margin-bottom: 1rem; /* 16px */
    max-width: 90%;
}

/* 長輩機優化 - 小螢幕裝置垂直堆疊佈局 */
@media (max-width: 480px) {
    /* AI助理訊息垂直堆疊佈局 */
    .assistant-message {
        flex-direction: column;
        max-width: 100% !important;
        margin-right: 0 !important;
        margin-bottom: 1.5rem;
    }
    
    .assistant-message .avatar {
        margin-right: 0 !important;
        margin-bottom: 8px;
        align-self: flex-start;
        width: 32px;
        height: 32px;
    }
    
    .assistant-message .content-wrapper {
        width: 100%;
        max-width: 100%;
    }
    
    .assistant-message .text-content {
        max-width: 100% !important;
        width: 100%;
        border-radius: 12px !important;
        font-size: 17px !important;
        line-height: 1.7 !important;
        padding: 18px 16px !important;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* 長輩機文字優化 */
    .assistant-message .text-content h1,
    .assistant-message .text-content h2,
    .assistant-message .text-content h3 {
        font-size: 18px !important;
        margin: 16px 0 12px 0 !important;
        font-weight: bold;
    }
    
    .assistant-message .text-content p {
        margin: 12px 0 !important;
        font-size: 17px !important;
        line-height: 1.7 !important;
    }
    
    .assistant-message .text-content ul,
    .assistant-message .text-content ol {
        margin: 12px 0 !important;
        padding-left: 20px !important;
    }
    
    .assistant-message .text-content li {
        margin: 8px 0 !important;
        font-size: 17px !important;
        line-height: 1.6 !important;
    }
    
    /* 用戶訊息也稍作調整 */
    .user-message {
        max-width: 85% !important;
    }
    
    .user-message .text-content {
        font-size: 16px !important;
        line-height: 1.5 !important;
        padding: 12px 16px !important;
    }
    
    /* 聊天輸入區域優化 */
    #prompt-input-container {
        padding: 12px !important;
    }
    
    #promptInput {
        font-size: 16px !important;
        min-height: 44px !important;
        padding: 12px 16px !important;
    }
    
    /* 按鈕和互動元素優化 */
    .quick-reply-buttons button,
    .suggestion-button {
        font-size: 15px !important;
        padding: 12px 16px !important;
        min-height: 44px !important;
        margin: 6px 4px !important;
    }
    
    /* 聊天容器整體調整 */
    #chat-messages {
        padding: 12px 8px !important;
    }
    
    /* 確保所有連結在長輩機上容易點擊 */
    .text-content a {
        padding: 4px 8px !important;
        font-size: 16px !important;
        min-height: 32px !important;
        display: inline-block;
    }
}

/* 為帶有快速回覆按鈕的訊息增加額外的底部間距 */
.message.has-quick-replies {
    margin-bottom: 1.75rem; /* 28px */
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}
          
.text-content {
    padding: 0.75rem 1rem; /* 12px 16px */
    border-radius: 1.25rem; /* 20px */
    line-height: 1.5;
    max-width: fit-content;
}

/* 連結高亮顯示 */
.text-content a {
    color: var(--accent-primary);
    text-decoration: underline;
    font-weight: 600;
    background: rgba(var(--accent-primary-rgb), 0.12);
    padding: 1px 6px;
    border-radius: 6px;
    word-break: break-all;
}

.text-content a:hover {
    background: rgba(var(--accent-primary-rgb), 0.2);
}

.text-content a[target="_blank"]::after {
    content: '↗';
    margin-left: 4px;
    font-size: 0.8em;
    opacity: 0.8;
}

/* 移除桌面式 code block 樣式，簡化為行內程式碼外觀，提升行動端閱讀性 */
.text-content pre { background: transparent; color: inherit; padding: 0; border-radius: 0; overflow: visible; max-width: 100%; }
.text-content pre code { background: rgba(0,0,0,0.06); color: inherit; padding: 0.2rem 0.35rem; border-radius: 6px; display: inline-block; white-space: pre-wrap; word-break: break-word; }
.text-content code:not(pre code) { background: rgba(0,0,0,0.06); color: inherit; padding: 0.1rem 0.3rem; border-radius: 6px; }
.code-block, .copy-btn, .lang-badge { display: none !important; }

/* 打字指示器（三個跳動小圓點） */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 1.25rem;
}
.typing-indicator span {
    width: 6px;
    height: 6px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    display: inline-block;
    animation: typing-bounce 1.2s infinite ease-in-out;
}
.user-message .typing-indicator span {
    background-color: var(--text-contrast);
}
.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.text-content p {
    margin: 0;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Markdown heading styles within messages */
.text-content h1,
.text-content h2,
.text-content h3,
.text-content h4,
.text-content h5,
.text-content h6 {
    margin: 12px 0 8px 0;
    font-weight: bold;
    color: var(--accent-primary);
}

.text-content h1 { font-size: 1.5em; }
.text-content h2 { font-size: 1.3em; }
.text-content h3 { font-size: 1.1em; }
.text-content h4 { font-size: 1em; }
.text-content h5 { font-size: 0.9em; }
.text-content h6 { font-size: 0.8em; }

/* List styles within messages */
.text-content ul,
.text-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.text-content li {
    margin: 4px 0;
}

/* Horizontal rule styles */
.text-content hr {
    border: none;
    border-top: 1px solid var(--border-secondary);
    margin: 16px 0;
}

/* Assistant (left-aligned) message */
.assistant-message {
    justify-content: flex-start;
    margin-right: auto;
}
          
.assistant-message .avatar {
    margin-right: 0.75rem; /* 12px */
}

.assistant-message .text-content {
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    border-bottom-left-radius: 0.375rem; /* 6px */
}

/* User (right-aligned) message */
.user-message {
    flex-direction: row-reverse;
    justify-content: flex-start;
    margin-left: auto;
}

.user-message .avatar {
    margin-left: 0.75rem; /* 12px */
}

.user-message .text-content {
    background-color: var(--accent-primary);
    color: var(--text-contrast);
    border-bottom-right-radius: 0.375rem; /* 6px */
}

/* Wrapper for text content and subsequent elements like buttons */
.content-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

.assistant-message .content-wrapper {
    align-items: flex-start;
}

.user-message .content-wrapper {
    align-items: flex-end;
}

/* Quick Replies Container */
.quick-replies-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
    margin-top: 12px; /* Increased for more space from the message bubble */
}

.quick-reply-button {
    padding: 8px 16px;
    border: 1px solid var(--border-primary);
    border-radius: 9999px;
    background-color: transparent;
    color: var(--accent-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.quick-reply-button:hover {
    background-color: var(--accent-primary);
    color: var(--text-contrast);
    transform: translateY(-1px);
}

/* 延伸追問（AI 生成）樣式，沿用 quick-replies 外觀但更緊湊 */
.followups-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.followup-chip {
    padding: 6px 12px;
    border: 1px solid var(--border-primary);
    border-radius: 9999px;
    color: var(--accent-primary);
    background: rgba(var(--accent-primary-rgb), 0.08);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all .2s ease;
}

.followup-chip:hover {
    background: var(--accent-primary);
    color: var(--text-contrast);
    transform: translateY(-1px);
}

/* 延伸追問載入中樣式 */
.followup-chip.loading {
    background: var(--bg-tertiary);
    border-color: var(--border-secondary);
    color: var(--text-muted);
    pointer-events: none;
    animation: subtle-pulse 1.2s ease-in-out infinite;
}

@keyframes subtle-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Link buttons can have a slightly different style */
.quick-reply-button[data-type="web_url"] {
    background-color: rgba(252, 211, 77, 0.1); /* yellow-300 with alpha */
}

.quick-reply-button[data-type="web_url"]:hover {
    background-color: #fcd34d; /* yellow-300 */
    color: #111827; /* gray-900 */
}

/* Voice input recording indicator */
.is-recording {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* Speech Button Styling - Enhanced for Visibility */
.speech-button-container {
    padding-top: 12px;
    text-align: left;
    margin-bottom: 16px;
}

/* Speech Button Below Message - New positioning */
.speech-button-below-message {
	position: static;
	/* top: 100%; */
	/* left: 60px;  對齊頭像右側 */
	/* right: 20px; */
	padding-top: 8px;
	padding-bottom: 0;
	margin-top: 8px;
	margin-bottom: 8px;
	text-align: left;
	/* z-index: 1; */
}

/* 為有語音按鈕的訊息添加額外的底部間距 */
.message.has-speech-button {
    margin-bottom: 60px; /* 為語音按鈕留出空間 */
}

/* 訊息內的音頻播放器容器 */
.message-audio-container {
    display: block;
    width: 100%;
    max-width: 400px;
    margin: 12px 0;
    padding: 8px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    border: 1px solid var(--border-primary);
}

/* 訊息內的音頻播放器樣式 */
.message-audio-container audio {
    display: block;
    width: 100%;
    height: 40px;
    margin-bottom: 8px;
    border-radius: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-primary);
    outline: none;
}

/* 音頻下載連結樣式 */
.audio-download-link {
    display: inline-block;
    padding: 4px 12px;
    color: var(--accent-primary);
    font-size: 14px;
    text-decoration: none;
    border-radius: 12px;
    background: var(--bg-secondary);
    transition: all 0.2s ease;
}

.audio-download-link:hover {
    background: var(--accent-primary);
    color: var(--text-contrast);
    transform: translateY(-1px);
}

/* 有音頻播放器的訊息需要更多底部空間 */
.message:has(.message-audio-container) {
    margin-bottom: 80px;
}

/* 兼容性：如果瀏覽器不支持:has()選擇器 */
.message.has-audio-player {
    margin-bottom: 80px;
}

.speech-button {
    padding: 10px 20px;
    border: 2px solid var(--accent-primary);
    border-radius: 25px;
    background: linear-gradient(45deg, var(--accent-primary), rgba(var(--accent-primary-rgb, 217, 183, 144), 0.8));
    color: var(--text-contrast);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
}

.speech-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
}

.speech-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    border-color: var(--accent-primary);
    animation: pulse-glow 2s infinite;
}

.speech-button:hover:not(:disabled)::before {
    left: 100%;
}

.speech-button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.speech-button:disabled {
    cursor: not-allowed;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border-color: var(--bg-tertiary);
    box-shadow: none;
    transform: none;
}

/* 轉真人客服按鈕 - LINE 綠色樣式 */
.speech-button.human-transfer-button {
    background: linear-gradient(135deg, #00C851 0%, #00A043 100%);
    border-color: #00C851;
    color: white;
    box-shadow: 0 4px 15px rgba(0, 200, 81, 0.3);
}

.speech-button.human-transfer-button::before {
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
}

.speech-button.human-transfer-button:hover:not(:disabled) {
    background: linear-gradient(135deg, #00A043 0%, #007E33 100%);
    border-color: #00A043;
    box-shadow: 0 6px 20px rgba(0, 200, 81, 0.4);
    animation: line-green-glow 2s infinite;
}

.speech-button.human-transfer-button:active:not(:disabled) {
    background: linear-gradient(135deg, #007E33 0%, #006629 100%);
    box-shadow: 0 3px 8px rgba(0, 200, 81, 0.3);
}

@keyframes line-green-glow {
    0%, 100% {
        box-shadow: 0 6px 20px rgba(0, 200, 81, 0.4);
    }
    50% {
        box-shadow: 0 6px 25px rgba(0, 200, 81, 0.5);
    }
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    }
    50% {
        box-shadow: 0 6px 25px rgba(217, 183, 144, 0.4), 0 0 15px rgba(217, 183, 144, 0.3);
    }
}

/* Message Timestamp Styling */
.message-timestamp {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
    opacity: 0.7;
}

/* Hide legacy elements if they exist */
#audioBtn, #audioHint, .chat-bubble, .message-container {
    display: none;
  }

/* Utility Classes for Theme Variables */
.main-bg { background-color: var(--bg-primary); }
.secondary-bg { background-color: var(--bg-secondary); }
.tertiary-bg { background-color: var(--bg-tertiary); }
.primary-bg { background-color: var(--bg-primary); }

.border-primary { border-color: var(--border-primary); }
.border-secondary { border-color: var(--border-secondary); }

.accent-bg { background-color: var(--accent-primary); }
.accent-text { color: var(--accent-primary); }

.primary-text { color: var(--text-primary); }
.secondary-text { color: var(--text-secondary); }
.muted-text { color: var(--text-muted); }
.contrast-text { color: var(--text-contrast); }

.placeholder-muted::placeholder { color: var(--text-muted); }

.focus\:ring-accent:focus { --tw-ring-color: var(--accent-primary); }

/* Fix mobile external browser input bar visibility */
footer {
  position: sticky;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 20;
  padding-bottom: max(env(safe-area-inset-bottom), 12px);
}

#chat-messages { padding-bottom: 88px; }

@supports (-webkit-touch-callout: none) {
  #chat-messages { padding-bottom: 96px; }
}

/* Theme Selector & Language Dropdowns */
#theme-selector, #language {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 2rem; /* space for arrow */
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    border: 1px solid var(--border-secondary);
    color: var(--text-primary) !important; /* 確保文字顏色顯眼 */
    font-weight: 600 !important; /* 增加字重並強制應用 */
}

/* 額外增強選擇器的優先級 */
select#theme-selector, select#language {
    color: var(--text-primary) !important;
    font-weight: 600 !important;
}

/* 針對所有主題強制設定文字顏色 */
:root select#theme-selector, 
:root select#language {
    color: var(--text-primary) !important;
}

[data-theme] select#theme-selector,
[data-theme] select#language {
    color: var(--text-primary) !important;
}

/* Light Blue Theme Arrow */
:root #theme-selector, 
:root #language {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%230288d1' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    color: #1a202c !important; /* 深色文字 */
}

/* Black Gold Theme Arrow */
[data-theme="black-gold"] #theme-selector,
[data-theme="black-gold"] #language {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23D9B790' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    color: #ffffff !important; /* 白色文字 */
}

/* Dark Purple Theme Arrow */
[data-theme="dark-purple"] #theme-selector,
[data-theme="dark-purple"] #language {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23ba68c8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    color: #ffffff !important; /* 白色文字 */
}

/* Forest Green Theme Arrow */
[data-theme="forest-green"] #theme-selector,
[data-theme="forest-green"] #language {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2366bb6a' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    color: #ffffff !important; /* 白色文字 */
}

/* Sunset Orange Theme Arrow */
[data-theme="sunset-orange"] #theme-selector,
[data-theme="sunset-orange"] #language {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23ffb74d' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    color: #ffffff !important; /* 白色文字 */
}

/* Taiwan Red Theme Arrow */
[data-theme="taiwan-red"] #theme-selector,
[data-theme="taiwan-red"] #language {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23fbbf24' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    color: #fef2f2 !important; /* 淺紅色文字 */
}

#theme-selector:focus, #language:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--border-secondary);
    color: var(--text-primary) !important;
}

/* 強化各主題的focus狀態文字顏色 */
:root #theme-selector:focus, 
:root #language:focus {
    color: #1a202c !important;
}

[data-theme="black-gold"] #theme-selector:focus,
[data-theme="black-gold"] #language:focus {
    color: #ffffff !important;
}

[data-theme="dark-purple"] #theme-selector:focus,
[data-theme="dark-purple"] #language:focus {
    color: #ffffff !important;
}

[data-theme="forest-green"] #theme-selector:focus,
[data-theme="forest-green"] #language:focus {
    color: #ffffff !important;
}

[data-theme="sunset-orange"] #theme-selector:focus,
[data-theme="sunset-orange"] #language:focus {
    color: #ffffff !important;
}

[data-theme="taiwan-red"] #theme-selector:focus,
[data-theme="taiwan-red"] #language:focus {
    color: #fef2f2 !important;
}

#theme-selector option, #language option {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 500;
}

/* AI Disclaimer Modal */
.ai-disclaimer-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.ai-disclaimer-modal.show {
    opacity: 1;
    visibility: visible;
}

.ai-disclaimer-content {
    background: var(--bg-primary);
    border: 2px solid var(--border-primary);
    border-radius: 16px;
    max-width: 90vw;
    max-height: 90vh;
    width: 600px;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    transform: scale(0.9) translateY(20px);
    transition: all 0.3s ease;
}

.ai-disclaimer-modal.show .ai-disclaimer-content {
    transform: scale(1) translateY(0);
}

.ai-disclaimer-header {
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border-secondary);
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-disclaimer-icon {
    font-size: 32px;
    color: var(--accent-primary);
}

.ai-disclaimer-title {
    font-size: 20px;
    font-weight: bold;
    color: var(--text-primary);
}

.ai-disclaimer-body {
    padding: 20px 24px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.ai-disclaimer-summary {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 16px;
    text-align: center;
    line-height: 1.6;
}

.ai-disclaimer-details {
    margin-top: 16px;
    border-top: 1px solid var(--border-secondary);
    padding-top: 16px;
}

.ai-disclaimer-toggle {
    display: flex;
    justify-content: center;
    margin-top: 16px;
}

.ai-disclaimer-toggle-btn {
    background: none;
    border: 1px solid var(--border-primary);
    color: var(--accent-primary);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    transition: all 0.3s ease;
}

.ai-disclaimer-toggle-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

.toggle-arrow {
    font-size: 12px;
    transition: transform 0.3s ease;
}

/* 轉真人服務按鈕 */
.human-transfer-btn {
    position: absolute;
    bottom: -35px;
    right: 10px;
    background: linear-gradient(135deg, #00C851 0%, #00A043 100%);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(0, 200, 81, 0.3);
    transition: all 0.3s ease;
    white-space: nowrap;
    z-index: 10;
}

.human-transfer-btn:hover {
    background: linear-gradient(135deg, #00A043 0%, #007E33 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 200, 81, 0.4);
}

.human-transfer-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 200, 81, 0.3);
}

.human-transfer-btn svg {
    flex-shrink: 0;
}

/* 確保助理訊息有足夠的底部間距給轉真人按鈕 */
.message.assistant-message {
    margin-bottom: 45px;
}

.ai-disclaimer-section {
    margin-bottom: 12px;
}

.ai-disclaimer-section-title {
    font-weight: bold;
    color: var(--accent-primary);
    margin-bottom: 4px;
    font-size: 15px;
}

.ai-disclaimer-section-content {
    margin-bottom: 6px;
    padding-left: 8px;
    font-size: 14px;
    line-height: 1.4;
}

.ai-disclaimer-footer {
    padding: 16px 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    border-top: 1px solid var(--border-secondary);
}

.ai-disclaimer-button {
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    min-width: 100px;
    text-align: center;
}

.ai-disclaimer-button.secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-color: var(--border-secondary);
}

.ai-disclaimer-button.secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--border-primary);
}

.ai-disclaimer-button.primary {
    background: var(--accent-primary);
    color: var(--text-contrast);
    border-color: var(--accent-primary);
}

.ai-disclaimer-button.primary:hover {
    background: var(--accent-secondary);
    border-color: var(--accent-secondary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Mobile optimizations for disclaimer modal */
@media (max-width: 768px) {
    .ai-disclaimer-content {
        max-width: 95vw;
        max-height: 95vh;
        margin: 10px;
    }
    
    .ai-disclaimer-header {
        padding: 16px 20px 10px;
    }
    
    .ai-disclaimer-body {
        padding: 16px 20px;
        font-size: 13px;
        line-height: 1.4;
    }
    
    .ai-disclaimer-summary {
        font-size: 15px;
        margin-bottom: 14px;
    }
    
    .ai-disclaimer-toggle-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .ai-disclaimer-section {
        margin-bottom: 10px;
    }
    
    .ai-disclaimer-section-title {
        font-size: 14px;
        margin-bottom: 3px;
    }
    
    .ai-disclaimer-section-content {
        font-size: 13px;
        line-height: 1.3;
        margin-bottom: 4px;
    }
    
    .ai-disclaimer-footer {
        padding: 12px 20px 16px;
        flex-direction: column;
    }
    
    /* 轉真人按鈕移動端優化 */
    .human-transfer-btn {
        bottom: -30px;
        right: 5px;
        padding: 6px 12px;
        font-size: 12px;
        border-radius: 15px;
    }
    
    .human-transfer-btn svg {
        width: 14px;
        height: 14px;
    }
    
    .ai-disclaimer-button {
        width: 100%;
    }
}

/* Menu Content */
.menu-content {
    position: absolute;
    bottom: 70px; /* Position above the toggle button */
    right: 0;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    width: 300px; /* Fixed width */
    
    /* Start hidden */
    display: none;
    opacity: 0;
    transform: translateY(15px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.menu-content.show {
    display: flex; /* Use flexbox */
    flex-direction: column; /* Stack items vertically */
    gap: 8px; /* Space between buttons */
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Custom Scrollbar for Menu */
.menu-content::-webkit-scrollbar {
    width: 5px;
}

/* Adjust persistent menu buttons for floating layout */
.menu-content .persistent-menu-btn {
    /* Base styles */
    border: 1px solid var(--border-primary);
    border-radius: 9999px;
    background-color: transparent;
    color: var(--accent-primary);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    align-items: center;
    justify-content: center;

    /* Layout styles */
    display: inline-flex;
    width: auto;
    margin-bottom: 6px;
    text-align: center;
    white-space: normal;
    word-wrap: break-word;
    line-height: 1.3;
    min-height: 32px;
    padding: 8px 16px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.menu-content .persistent-menu-btn:hover {
    background-color: var(--accent-primary);
    color: var(--text-contrast);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.menu-content .persistent-menu-btn[data-type="web_url"] {
    border-color: var(--accent-primary);
}

.menu-content .persistent-menu-btn:last-child {
    margin-bottom: 0;
}

/* Reset Position Button */
.reset-position-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: none; /* 直接隱藏按鈕 */
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.reset-position-btn:hover {
    background-color: var(--accent-primary);
    color: var(--text-contrast);
    opacity: 1;
    transform: scale(1.1);
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .floating-menu-container {
        right: 1rem; /* 16px */
        bottom: 7rem; /* 112px */
    }
    
    .menu-toggle-btn {
        width: 48px;
        height: 48px;
    }
    
    .menu-content {
        min-width: 200px;
        max-width: calc(100vw - 3rem);
        max-height: 50vh;
        padding: 2.5rem 0.75rem 0.75rem 0.75rem;
        bottom: 60px;
    }
}

/* Floating Menu Container */
.floating-menu-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    z-index: 1000;
    cursor: grab;
    user-select: none;
    /* Smooth transition for boundary checks, but not for dragging */
    transition: top 0.2s, left 0.2s;
}

/* Menu Toggle Button */
.menu-toggle-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--accent-primary);
    color: var(--text-contrast);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease-in-out;
    position: relative;
    z-index: 1001;
}

.menu-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.menu-toggle-btn:active {
    transform: scale(0.95);
}

.floating-menu-container.dragging {
    transition: none; /* Disable transition during drag for immediate feedback */
    cursor: grabbing;
}

.floating-menu-container.dragging .menu-toggle-btn {
    cursor: grabbing;
}

/* 錄音狀態樣式 */
.recording-active {
    animation: pulse-recording 2s infinite;
    border: 2px solid #ef4444;
}

@keyframes pulse-recording {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }
}

/* AI 正在思考動畫 */
.thinking-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    animation: thinking-pulse 2s ease-in-out infinite;
}

.thinking-text {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.thinking-dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

.thinking-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color, #3b82f6);
    animation: thinking-dot-bounce 1.4s infinite ease-in-out;
}

.thinking-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.thinking-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes thinking-dot-bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

@keyframes thinking-pulse {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    50% {
        box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
    }
}

/* 不同主題的思考動畫顏色 */
[data-theme="black-gold"] .thinking-dot {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

[data-theme="dark-purple"] .thinking-dot {
    background: linear-gradient(135deg, #a855f7 0%, #9333ea 100%);
}

[data-theme="forest-green"] .thinking-dot {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

[data-theme="sunset-orange"] .thinking-dot {
    background: linear-gradient(135deg, #fb923c 0%, #f97316 100%);
}

[data-theme="taiwan-red"] .thinking-dot {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
}

/* 長輩機優化 - 放大思考指示器 */
@media (max-width: 480px) {
    .thinking-indicator {
        padding: 14px 18px;
    }
    
    .thinking-text {
        font-size: 16px;
    }
    
    .thinking-dot {
        width: 10px;
        height: 10px;
    }
}