/**
 * AI 助手聊天元件樣式
 * 版本：1.0.0
 */

/* ==================== 浮動按鈕 ==================== */
.ai-assistant-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4A6985 0%, #6B8CAE 100%);
    border: none;
    box-shadow: 0 4px 20px rgba(74, 105, 133, 0.4);
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.ai-assistant-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(74, 105, 133, 0.6);
}

.ai-assistant-btn .icon {
    font-size: 28px;
}

/* 未讀訊息徽章 */
.ai-assistant-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #f44336;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* ==================== 聊天視窗 ==================== */
.ai-chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 550px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.ai-chat-window.active {
    display: flex;
}

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

/* ==================== 聊天頭部 ==================== */
.ai-chat-header {
    background: linear-gradient(135deg, #4A6985 0%, #6B8CAE 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-status {
    width: 8px;
    height: 8px;
    background: #4caf50;
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s infinite;
}

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

.ai-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    line-height: 1;
}

.ai-close-btn:hover {
    opacity: 0.8;
}

/* ==================== 訊息區域 ==================== */
.ai-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f5f7fa;
}

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.ai-message {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-message.user {
    flex-direction: row-reverse;
}

.ai-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #4A6985;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.ai-message.user .ai-message-avatar {
    background: #4caf50;
}

.ai-message-content {
    display: flex;
    flex-direction: column;
    max-width: 70%;
}

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

.ai-message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    background: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.ai-message.user .ai-message-bubble {
    background: #4A6985;
    color: white;
}

.ai-message-time {
    font-size: 11px;
    color: #999;
    margin-top: 5px;
    padding: 0 5px;
}

/* ==================== AI 輸入中動畫 ==================== */
.ai-typing-indicator {
    display: none;
    margin-bottom: 15px;
}

.ai-typing-indicator.active {
    display: flex;
    gap: 10px;
}

.ai-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.ai-typing-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.ai-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

/* ==================== 輸入區域 ==================== */
.ai-chat-input-area {
    padding: 15px;
    border-top: 1px solid #e0e0e0;
    background: white;
}

.ai-usage-info {
    font-size: 11px;
    color: #666;
    margin-bottom: 8px;
    text-align: center;
}

.ai-usage-info.warning {
    color: #f44336;
    font-weight: bold;
}

.ai-usage-bar {
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 10px;
}

.ai-usage-fill {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #4A6985);
    transition: width 0.3s ease;
}

.ai-usage-fill.warning {
    background: linear-gradient(90deg, #ff9800, #f44336);
}

.ai-quick-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.ai-quick-btn {
    background: white;
    border: 1px solid #4A6985;
    color: #4A6985;
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-quick-btn:hover {
    background: #4A6985;
    color: white;
    transform: translateY(-1px);
}

.ai-input-wrapper {
    display: flex;
    gap: 10px;
}

.ai-chat-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
    resize: none;
    max-height: 100px;
}

.ai-chat-input:focus {
    border-color: #4A6985;
}

.ai-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #4A6985;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    flex-shrink: 0;
}

.ai-send-btn:hover:not(:disabled) {
    background: #3a5570;
    transform: scale(1.05);
}

.ai-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* ==================== 登入提示 ==================== */
.ai-login-prompt {
    text-align: center;
    padding: 40px 20px;
}

.ai-login-prompt h4 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 18px;
}

.ai-login-prompt p {
    color: #666;
    font-size: 14px;
    margin: 0 0 20px 0;
    line-height: 1.6;
}

.ai-login-btn {
    background: #4A6985;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.ai-login-btn:hover {
    background: #3a5570;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(74, 105, 133, 0.3);
}

/* ==================== 手機版適配 ==================== */
@media (max-width: 768px) {
    .ai-chat-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 120px);
        bottom: 80px;
        right: 20px;
        left: 20px;
    }

    .ai-assistant-btn {
        bottom: 15px;
        right: 15px;
        width: 55px;
        height: 55px;
    }

    .ai-message-content {
        max-width: 80%;
    }

    .ai-quick-actions {
        gap: 6px;
    }

    .ai-quick-btn {
        font-size: 11px;
        padding: 5px 10px;
    }
}

@media (max-width: 480px) {
    .ai-chat-window {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 0;
    }

    .ai-assistant-btn {
        bottom: 10px;
        right: 10px;
    }
}

/* ==================== 首次訪問提示泡泡 ==================== */
.ai-first-visit-tip {
    position: fixed;
    bottom: 95px;
    right: 90px;
    background: white;
    border: 2px solid #4A6985;
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 6px 25px rgba(74, 105, 133, 0.3);
    z-index: 999;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    max-width: 280px;
}

.ai-first-visit-tip.show {
    opacity: 1;
    transform: translateY(0);
}

.ai-tip-close {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    width: 24px;
    height: 24px;
    line-height: 1;
    padding: 0;
}

.ai-tip-close:hover {
    color: #4A6985;
}

.ai-tip-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-tip-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.ai-tip-text {
    flex: 1;
}

.ai-tip-text strong {
    color: #4A6985;
    font-size: 15px;
    display: block;
    margin-bottom: 4px;
}

.ai-tip-text small {
    color: #6B6B6B;
    font-size: 12px;
    line-height: 1.4;
}

/* 指向 AI 按鈕的箭頭 */
.ai-tip-arrow {
    position: absolute;
    bottom: -8px;
    right: 25px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid white;
}

.ai-tip-arrow::before {
    content: '';
    position: absolute;
    bottom: 2px;
    left: -10px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #4A6985;
}

/* 手機版適配 */
@media (max-width: 768px) {
    .ai-first-visit-tip {
        bottom: 80px;
        right: 80px;
        max-width: 240px;
    }

    .ai-tip-text strong {
        font-size: 14px;
    }

    .ai-tip-text small {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .ai-first-visit-tip {
        bottom: 75px;
        right: 75px;
        max-width: calc(100vw - 100px);
    }
}
