/* 🤖 小魔 AI 聊天助手樣式 v4 - 多模態版本 */

:root {
    --chatbot-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --chatbot-bg: rgba(20, 20, 30, 0.98);
    --chatbot-panel-bg: rgba(30, 30, 45, 0.95);
    --chatbot-border: rgba(255, 255, 255, 0.1);
    --chatbot-text: #ffffff;
    --chatbot-text-secondary: rgba(255, 255, 255, 0.7);
    --chatbot-user-msg: linear-gradient(135deg, #5c8cff 0%, #4776e6 100%);
    --chatbot-bot-msg: rgba(255, 255, 255, 0.08);
    --chatbot-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* 觸發按鈕 */
.chatbot-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    background: var(--chatbot-primary);
    color: white;
    border: none;
    border-radius: 50px;
    box-shadow: var(--chatbot-shadow);
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.chatbot-trigger:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(102, 126, 234, 0.5);
}

.trigger-icon {
    font-size: 20px;
}

.chatbot-badge {
    display: none !important;
    visibility: hidden !important;
}

/* 背景遮罩 */
.chatbot-overlay {
    background: transparent;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    pointer-events: none;
}

.chatbot-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* 聊天面板 */
.chatbot-panel {
    background: var(--chatbot-bg);
    box-shadow: var(--chatbot-shadow);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.chatbot-panel.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* 調整大小時的性能優化 */
.chatbot-panel.resizing {
    will-change: width, height;
    transition: none !important;
    pointer-events: auto;
}

.chatbot-panel.resizing * {
    pointer-events: none;
    user-select: none;
}

/* 拖放上傳高亮效果 */
.chatbot-panel.drag-over {
    background: linear-gradient(135deg, rgba(92, 140, 255, 0.15) 0%, rgba(102, 126, 234, 0.15) 100%);
    border: 3px dashed rgba(92, 140, 255, 0.8) !important;
    box-shadow: 0 0 0 4px rgba(92, 140, 255, 0.2), 0 8px 32px rgba(0, 0, 0, 0.4);
}

.chatbot-panel.drag-over::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(92, 140, 255, 0.05);
    z-index: 999;
    pointer-events: none;
    border-radius: inherit;
}

.chatbot-panel.drag-over::after {
    content: '📷 放開以上傳圖片';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 24px 48px;
    border-radius: 20px;
    font-size: 20px;
    font-weight: 700;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 12px 40px rgba(102, 126, 234, 0.5);
    animation: dropHintPulse 1s ease-in-out infinite;
}

@keyframes dropHintPulse {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.05);
    }
}

/* 頭部 */
.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--chatbot-panel-bg);
    border-bottom: 1px solid var(--chatbot-border);
}

.chatbot-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-title svg {
    color: #5c8cff;
}

.chatbot-title-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chatbot-name {
    font-weight: 600;
    font-size: 16px;
    color: var(--chatbot-text);
}

.chatbot-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--chatbot-text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.chatbot-status.offline .status-dot {
    background: #ef4444;
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-actions {
    display: flex;
    gap: 8px;
}

.chatbot-action-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--chatbot-text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.chatbot-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--chatbot-text);
}

/* 訊息區域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 12px 8px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 用戶訊息 */
.user-message {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.user-message .message-bubble {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-width: 75%;
}

.user-message .message-content {
    background: var(--chatbot-user-msg);
    color: white;
    padding: 12px 16px;
    border-radius: 18px 18px 4px 18px;
    max-width: 400px;
    word-wrap: break-word;
    word-break: break-word;
    width: auto;
}

.user-message .message-time {
    text-align: right;
    margin-top: 4px;
    font-size: 11px;
    color: var(--chatbot-text-secondary);
}

/* 機器人訊息 */
.bot-message {
    flex-direction: row;
}

.message-avatar {
    width: 36px;
    height: 36px;
    background: var(--chatbot-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.message-bubble {
    max-width: 75%;
}

.bot-message .message-content {
    background: var(--chatbot-bot-msg);
    color: var(--chatbot-text);
    padding: 12px 16px;
    border-radius: 18px 18px 18px 4px;
    line-height: 1.6;
}

.bot-message .message-time {
    margin-top: 4px;
    font-size: 11px;
    color: var(--chatbot-text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-badge {
    background: rgba(92, 140, 255, 0.2);
    color: #5c8cff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 500;
}

/* 訊息中的圖片 */
.message-images {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.user-message .message-images {
    justify-content: flex-end;
}

.message-image {
    max-width: 150px;
    max-height: 150px;
    border-radius: 12px;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.05);
}

/* 系統訊息 */
.system-message {
    justify-content: center;
}

.system-message .message-content {
    background: rgba(255, 255, 255, 0.05);
    color: var(--chatbot-text-secondary);
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 13px;
    text-align: center;
}

/* Loading 動畫 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--chatbot-text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* 快速建議 */
.quick-suggestions {
    padding: 16px 20px;
    background: var(--chatbot-panel-bg);
    border-top: 1px solid var(--chatbot-border);
}

.quick-suggestions[style*="display: none"] {
    display: none !important;
    padding: 0 !important;
    margin: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
}

.suggestion-title {
    font-size: 13px;
    color: var(--chatbot-text-secondary);
    margin-bottom: 12px;
}

.suggestion-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.suggestion-chip {
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--chatbot-border);
    border-radius: 12px;
    color: var(--chatbot-text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.suggestion-chip:hover {
    background: rgba(92, 140, 255, 0.2);
    border-color: rgba(92, 140, 255, 0.4);
    transform: translateY(-2px);
}

/* 輸入區域 */
.chat-input-container {
    background: var(--chatbot-panel-bg);
    border-top: 1px solid var(--chatbot-border);
    position: relative;
}

/* 可拖動的調整大小分隔線 */
.input-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 6px;
    cursor: ns-resize;
    background: transparent;
    z-index: 10;
    transform: translateY(-3px);
}

.input-resize-handle:hover {
    background: rgba(92, 140, 255, 0.3);
}

.input-resize-handle:active {
    background: rgba(92, 140, 255, 0.5);
}

.chat-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
}

.chat-input {
    flex: 1 1 auto;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--chatbot-border);
    border-radius: 12px;
    padding: 8px 12px;
    color: var(--chatbot-text);
    font-size: 14px;
    font-family: inherit;
    resize: vertical !important;
    max-height: 300px !important;
    min-height: 36px !important;
    height: auto !important;
    transition: none !important;
    overflow: auto !important;
    display: block !important;
}

.chat-input::-webkit-resizer {
    display: block !important;
    width: 16px !important;
    height: 16px !important;
    background: rgba(92, 140, 255, 0.5) !important;
    border-radius: 0 0 12px 0 !important;
    cursor: nwse-resize !important;
}

.chat-input::-webkit-scrollbar {
    width: 4px;
}

.chat-input::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.chat-input::-webkit-scrollbar-track {
    background: transparent;
}

.chat-input:focus {
    outline: none;
    border-color: rgba(92, 140, 255, 0.5);
    background: rgba(255, 255, 255, 0.08);
}

.chat-input::placeholder {
    color: var(--chatbot-text-secondary);
}

.chat-send-btn,
.chat-upload-btn,
.chat-voice-btn {
    width: 36px;
    height: 36px;
    background: var(--chatbot-primary);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(92, 140, 255, 0.4);
}

.chat-upload-btn {
    background: rgba(92, 140, 255, 0.15);
    color: #5c8cff;
    border: 1px solid rgba(92, 140, 255, 0.3);
}

.chat-upload-btn:hover {
    background: rgba(92, 140, 255, 0.25);
    border-color: rgba(92, 140, 255, 0.5);
    transform: scale(1.05);
}

/* 垂直按鈕組 */
.chat-buttons-vertical {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.chat-upload-btn.has-images {
    background: var(--chatbot-primary);
    color: white;
    border-color: transparent;
}

.chat-voice-btn {
    background: rgba(92, 140, 255, 0.15);
    color: #5c8cff;
    border: 1px solid rgba(92, 140, 255, 0.3);
}

.chat-voice-btn:hover {
    background: rgba(92, 140, 255, 0.25);
    border-color: rgba(92, 140, 255, 0.5);
    transform: scale(1.05);
}

.chat-voice-btn.recording {
    background: #ff4757;
    color: white;
    border-color: #ff4757;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(255, 71, 87, 0);
    }
}

.chat-send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(92, 140, 255, 0.4);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-input-hint {
    display: flex;
    justify-content: space-between;
    padding: 0 12px 2px 12px;
    font-size: 11px;
    color: var(--chatbot-text-secondary);
}

/* 響應式設計 */
@media (max-width: 640px) {
    .chatbot-trigger {
        padding: 12px;
        border-radius: 16px;
    }

    .chatbot-label {
        display: none;
    }

    .chatbot-panel {
        border-radius: 20px 20px 0 0 !important;
    }

    .message-content,
    .message-bubble {
        max-width: 85%;
    }

    .suggestion-grid {
        grid-template-columns: 1fr;
    }
}

/* LLM 模型選擇面板 */
.model-selector-panel {
    position: absolute;
    top: 60px;
    right: 20px;
    width: 300px;
    background: var(--chatbot-panel-bg);
    border: 1px solid var(--chatbot-border);
    border-radius: 16px;
    box-shadow: var(--chatbot-shadow);
    z-index: 10;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.model-selector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--chatbot-border);
}

.model-selector-header h3 {
    font-size: 16px;
    color: var(--chatbot-text);
    margin: 0;
}

.model-selector-close {
    background: transparent;
    border: none;
    color: var(--chatbot-text-secondary);
    font-size: 24px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.model-selector-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--chatbot-text);
}

.model-selector-content {
    padding: 16px;
    max-height: 300px;
    overflow-y: auto;
}

.model-selector-hint {
    color: var(--chatbot-text-secondary);
    font-size: 13px;
    text-align: center;
}

.model-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.model-item {
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--chatbot-border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.model-item:hover {
    background: rgba(92, 140, 255, 0.1);
    border-color: rgba(92, 140, 255, 0.4);
    transform: translateX(4px);
}

.model-item.active {
    background: var(--chatbot-primary);
    border-color: transparent;
}

.model-name {
    font-weight: 600;
    color: var(--chatbot-text);
    font-size: 14px;
}

.model-desc {
    font-size: 12px;
    color: var(--chatbot-text-secondary);
    line-height: 1.4;
}

.model-item-name {
    font-weight: 600;
    color: var(--chatbot-text);
    margin-bottom: 4px;
}

.model-item-info {
    font-size: 12px;
    color: var(--chatbot-text-secondary);
}

/* 日間模式樣式 */
[data-theme="light"] .chatbot-panel {
    background: #ffffff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .chatbot-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

[data-theme="light"] .chat-messages {
    background: #f8fafc;
}

[data-theme="light"] .chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

[data-theme="light"] .user-message .message-text,
[data-theme="light"] .user-message .message-content {
    background: linear-gradient(135deg, #5c8cff 0%, #4776e6 100%);
    color: white;
}

[data-theme="light"] .bot-message .message-text,
[data-theme="light"] .bot-message .message-content {
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.08);
    color: #1a202c;
}

[data-theme="light"] .bot-message .message-text code {
    background: #f1f5f9;
    color: #1a202c;
}

[data-theme="light"] .bot-message .message-text pre {
    background: #f1f5f9;
    border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .quick-suggestions,
[data-theme="light"] .chat-input-container {
    background: #ffffff;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .suggestion-chip {
    background: #f1f5f9;
    color: #475569;
    border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .suggestion-chip:hover {
    background: #e2e8f0;
    border-color: rgba(92, 140, 255, 0.4);
}

[data-theme="light"] .chat-input-wrapper {
    background: #f8fafc;
    border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .chat-input {
    color: #1a202c;
}

[data-theme="light"] .chat-input::placeholder {
    color: #94a3b8;
}

[data-theme="light"] .chatbot-overlay {
    background: rgba(0, 0, 0, 0.4);
}

[data-theme="light"] .chatbot-trigger {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.98) 0%, rgba(139, 92, 246, 0.95) 50%, rgba(168, 85, 247, 0.98) 100%);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.35), 0 8px 32px rgba(139, 92, 246, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

[data-theme="light"] .chatbot-trigger:hover {
    box-shadow: 0 8px 32px rgba(99, 102, 241, 0.45), 0 12px 44px rgba(139, 92, 246, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

[data-theme="light"] .message-actions button {
    color: #64748b;
}

[data-theme="light"] .message-actions button:hover {
    color: #334155;
    background: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .typing-indicator span {
    background: #94a3b8;
}

[data-theme="light"] .model-selector {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .model-dropdown {
    background: white;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .model-item {
    border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .model-item:hover {
    background: rgba(92, 140, 255, 0.08);
    border-color: rgba(92, 140, 255, 0.3);
}

[data-theme="light"] .model-name,
[data-theme="light"] .model-item-name {
    color: #1a202c;
}

[data-theme="light"] .model-desc,
[data-theme="light"] .model-item-info {
    color: #64748b;
}

[data-theme="light"] .chat-image-preview {
    background: rgba(0, 0, 0, 0.03);
}
