﻿/* ===== 聊天面板樣式 ===== */

.chat-panel-container {
    position: relative;
    z-index: 1000;
}

.chat-toggle-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #007bff;
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(0,123,255,0.4);
    z-index: 1001;
    transition: all 0.3s ease;
}

    .chat-toggle-btn:hover {
        background: #0056b3;
        transform: scale(1.1);
    }

    .chat-toggle-btn.active {
        background: #28a745;
    }

.chat-notification {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background: #dc3545;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-panel {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 400px;
    height: 600px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
}

    .chat-panel.show {
        display: flex;
        animation: slideUp 0.3s ease-out;
    }

    .chat-panel.minimized {
        height: 70px;
    }

        .chat-panel.minimized .chat-content {
            display: none;
        }

    /* 拖曳相關樣式 */
    .chat-panel.dragging {
        transform: scale(1.02);
        box-shadow: 0 20px 40px rgba(0,0,0,0.3);
        transition: transform 0.1s ease;
    }

        .chat-panel.dragging .chat-header {
            background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
            cursor: grabbing !important;
        }

/* 聊天標題欄樣式增強 */
.chat-header {
    padding: 15px 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-bottom: 1px solid #dee2e6;
    border-radius: 12px 12px 0 0;
    position: relative;
    cursor: grab;
    user-select: none;
}

    .chat-header:hover {
        background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
    }

    .chat-header:active {
        cursor: grabbing;
    }

    .chat-header::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 8px;
        transform: translateY(-50%);
        width: 4px;
        height: 20px;
        background: repeating-linear-gradient( to bottom, #6c757d 0px, #6c757d 2px, transparent 2px, transparent 4px );
        opacity: 0.5;
        transition: opacity 0.2s ease;
    }

    .chat-header:hover::before {
        opacity: 0.8;
    }

    /* 拖曳提示圖示 */
    .chat-header .drag-hint {
        position: absolute;
        left: 20px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 14px;
        color: #6c757d;
        opacity: 0;
        transition: opacity 0.2s ease;
        pointer-events: none;
    }

    .chat-header:hover .drag-hint {
        opacity: 0.6;
    }

    /* 調整標題內容的左邊距，避免與拖曳圖示重疊 */
    .chat-header > div {
        margin-left: 15px;
    }

/* 最小化狀態下不允許拖曳 */
.chat-panel.minimized .chat-header {
    cursor: default;
}

    .chat-panel.minimized .chat-header::before {
        display: none;
    }

/* 防止在拖曳時選中文字 */
.chat-panel.dragging,
.chat-panel.dragging * {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.context-info {
    padding: 12px 15px;
    background: #e3f2fd;
    border-bottom: 1px solid #bbdefb;
    max-height: 150px;
    overflow-y: auto;
    transition: max-height 0.3s ease;
    /* 已移除背景資訊區域，保留樣式以防需要 */
    display: none;
}

    .context-info.collapsed {
        max-height: 40px;
        overflow: hidden;
    }

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #fafafa;
}

/* 記憶提醒樣式 */
.memory-reminder {
    padding: 8px 15px;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    border-bottom: 1px solid #dee2e6;
}

.memory-info {
    font-size: 0.8rem;
}

.memory-indicator .progress {
    border-radius: 2px;
    background-color: #e9ecef;
}

.memory-reminder.warning .memory-text {
    color: #856404 !important;
}

.memory-reminder.warning .progress-bar {
    background-color: #ffc107 !important;
}

.chat-input {
    padding: 15px;
    background: white;
    border-top: 1px solid #dee2e6;
    border-radius: 0 0 12px 12px;
}

.message-bubble {
    margin-bottom: 15px;
    max-width: 85%;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-bubble.user {
    margin-left: auto;
    background: #007bff;
    color: white;
    padding: 12px 16px;
    border-radius: 20px 20px 6px 20px;
    box-shadow: 0 2px 8px rgba(0,123,255,0.3);
}

.message-bubble.ai {
    background: white;
    color: #333;
    padding: 12px 16px;
    border-radius: 20px 20px 20px 6px;
    border: 1px solid #e9ecef;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.message-timestamp {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.8);
    margin-top: 5px;
}

.message-bubble.ai .message-timestamp {
    color: #6c757d;
}

.typing-indicator {
    display: flex;
    align-items: center;
    color: #6c757d;
    font-style: italic;
    margin-bottom: 15px;
}

/* 思考中泡泡樣式 */
.typing-indicator-bubble .typing-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.typing-indicator-bubble .typing-text {
    color: #495057;
    font-weight: 500;
}

.typing-dots {
    display: inline-flex;
    margin-left: 10px;
}

    .typing-dots span {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: #6c757d;
        margin: 0 2px;
        animation: typing 1.4s infinite ease-in-out;
    }

        .typing-dots span:nth-child(1) {
            animation-delay: -0.32s;
        }

        .typing-dots span:nth-child(2) {
            animation-delay: -0.16s;
        }

        .typing-dots span:nth-child(3) {
            animation-delay: 0s;
        }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.suggested-questions .btn {
    font-size: 0.8rem;
    border-radius: 15px;
}

/* 聊天面板控制按鈕 */
.chat-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-minimize-btn,
.chat-close-btn {
    background: none;
    border: none;
    color: #6c757d;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

    .chat-minimize-btn:hover,
    .chat-close-btn:hover {
        background: rgba(108, 117, 125, 0.1);
        color: #495057;
    }

/* 聊天輸入區增強 */
.chat-input-group {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input-field {
    flex: 1;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 10px 15px;
    resize: none;
    outline: none;
    font-family: inherit;
    max-height: 100px;
    min-height: 40px;
}

    .chat-input-field:focus {
        border-color: #007bff;
        box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    }

.chat-send-btn {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

    .chat-send-btn:hover {
        background: #0056b3;
        transform: scale(1.05);
    }

    .chat-send-btn:disabled {
        background: #6c757d;
        cursor: not-allowed;
        transform: none;
    }

/* 聊天訊息特殊類型 */
.message-bubble.system {
    background: #f8f9fa;
    color: #6c757d;
    border: 1px solid #dee2e6;
    margin: 10px auto;
    text-align: center;
    font-style: italic;
    max-width: 70%;
}

.message-bubble.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.message-bubble.warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

/* 聊天訊息動作按鈕 */
.message-actions {
    display: flex;
    gap: 5px;
    margin-top: 5px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message-bubble:hover .message-actions {
    opacity: 1;
}

.message-action-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.message-bubble.ai .message-action-btn {
    color: #6c757d;
}

.message-action-btn:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

.message-bubble.ai .message-action-btn:hover {
    background: rgba(108, 117, 125, 0.1);
    color: #495057;
}

/* 聊天面板載入狀態 */
.chat-panel.loading {
    pointer-events: none;
}

    .chat-panel.loading::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(255, 255, 255, 0.8);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1;
    }

/* 聊天歷史滾動指示 */
.chat-messages::before {
    content: '';
    position: sticky;
    top: 0;
    display: block;
    height: 1px;
    background: linear-gradient(to right, transparent, #dee2e6, transparent);
    margin-bottom: 10px;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

    .chat-messages::-webkit-scrollbar-thumb:hover {
        background: rgba(0, 0, 0, 0.3);
    }

/* 聊天面板在不同位置的自適應樣式 */
.chat-panel.edge-left {
    border-radius: 0 12px 12px 0;
}

.chat-panel.edge-right {
    border-radius: 12px 0 0 12px;
}

.chat-panel.edge-top {
    border-radius: 0 0 12px 12px;
}

.chat-panel.edge-bottom {
    border-radius: 12px 12px 0 0;
}

/* 提供視覺反饋的拖曳邊界 */
.chat-panel-drag-boundary {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    border: 2px dashed transparent;
    transition: border-color 0.2s ease;
    z-index: 999;
}

.chat-panel.dragging ~ .chat-panel-drag-boundary {
    border-color: rgba(0, 123, 255, 0.3);
}

/* 觸控設備的拖曳樣式 */
@media (hover: none) and (pointer: coarse) {
    .chat-header {
        padding: 18px 20px; /* 在觸控設備上增加點擊區域 */
    }

        .chat-header::before {
            width: 6px;
            height: 24px;
        }
}

/* 響應式設計 */
@media (max-width: 768px) {
    .chat-panel {
        width: calc(100vw - 20px);
        height: 70vh;
        bottom: 10px;
        right: 10px;
        left: 10px;
    }

    .chat-toggle-btn {
        bottom: 20px;
        right: 20px;
    }

    .chat-panel.dragging {
        transform: scale(1.01); /* 較小的縮放效果 */
    }
}

@media (max-width: 480px) {
    .chat-panel {
        height: 80vh;
    }

    .chat-header {
        padding: 10px 15px;
    }

    .chat-messages {
        padding: 10px;
    }

    .chat-input {
        padding: 10px;
    }

    .message-bubble {
        max-width: 90%;
    }

    /* 在很小的螢幕上簡化拖曳提示 */
    .chat-header::before {
        display: none;
    }
}
