/**
 * 聊天小工具 CSS
 * Line 風格的聊天介面
 */

/* 全局盒模型設定 */
.chat-widget-container *,
.chat-widget-container *::before,
.chat-widget-container *::after {
    box-sizing: border-box;
}

/* 浮動按鈕容器 */
.chat-float-container {
    position: fixed;
    bottom: 230px;
    right: 30px;
    z-index: 9998;
    display: flex;
    align-items: center;
    gap: 15px;
}

/* 醒目文字提示框 */
.chat-message-box {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    max-width: 200px;
    position: relative;
    animation: slideIn 1s ease-out;
}

.chat-message-box:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.6);
}

.chat-message-text {
    margin-right: 20px;
}

.chat-message-close {
    position: absolute;
    top: 4px;
    right: 8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chat-message-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 滑入動畫 */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 浮動聊天按鈕 */
.chat-float-button {
    position: relative;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #06c755 0%, #05b248 100%);
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(6, 199, 85, 0.4);
    cursor: pointer;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    animation: pulse 2s infinite;
}

.chat-float-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(6, 199, 85, 0.6);
}

.chat-float-button i {
    color: white;
    font-size: 24px;
}

/* 聊天按鈕提示文字框 */
.chat-float-button-tooltip {
    position: absolute;
    right: 70px;
    bottom: 50%;
    transform: translateY(50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    pointer-events: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

.chat-float-button-tooltip::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 100%;
    margin-top: -5px;
    border: 5px solid transparent;
    border-left-color: rgba(0, 0, 0, 0.8);
}

.chat-float-button:hover .chat-float-button-tooltip {
    opacity: 1;
    visibility: visible;
    right: 75px;
}

/* 脈動動畫 */
@keyframes pulse {
    0% {
        box-shadow: 0 4px 20px rgba(6, 199, 85, 0.4);
    }
    50% {
        box-shadow: 0 4px 20px rgba(6, 199, 85, 0.8);
    }
    100% {
        box-shadow: 0 4px 20px rgba(6, 199, 85, 0.4);
    }
}

/* 聊天視窗容器 */
.chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    height: 640px; /* 增加高度為貓咪圖片留空間 */
    border-radius: 16px;
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: visible; /* 允許貓咪圖片顯示在外面 */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

/* 聊天內容區域 */
.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 16px;
    overflow: hidden;
    margin-top: 40px; /* 為貓咪圖片留出空間 */
}

/* 貓咪裝飾圖片容器 */
.chat-cat-decoration {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    pointer-events: none;
}

/* 貓咪GIF圖片 */
.chat-cat-gif {
    display: block;
    width: 100px;
    height: auto;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.15));
}

.chat-widget-container.active {
    display: flex;
}

/* 聊天標題列 */
.chat-header {
    background: linear-gradient(135deg, #06c755 0%, #05b248 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: between;
}

.chat-header-info {
    flex: 1;
}

.chat-header-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.chat-header-subtitle {
    font-size: 12px;
    opacity: 0.8;
    margin: 2px 0 0 0;
}

.chat-header-actions {
    display: flex;
    gap: 10px;
}

.chat-close-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 暱稱輸入區域 */
.chat-nickname-screen {
    padding: 30px 20px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.chat-nickname-screen h3 {
    color: #333;
    margin-bottom: 10px;
    font-size: 18px;
}

.chat-nickname-screen p {
    color: #666;
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.5;
}

.nickname-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e5e5e5;
    border-radius: 25px;
    font-size: 14px;
    margin-bottom: 20px;
    outline: none;
    transition: border-color 0.3s;
    box-sizing: border-box;
}

.nickname-input:focus {
    border-color: #06c755;
}

.start-chat-btn {
    background: #06c755;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.start-chat-btn:hover {
    background: #05b248;
}

.start-chat-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 聊天區域 */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
}

/* 訊息列表 */
.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    max-height: 400px;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 2px;
}

/* 訊息氣泡 */
.message {
    margin-bottom: 12px;
    display: flex;
    align-items: flex-end;
}

.message.user {
    justify-content: flex-end;
}

.message.admin {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    white-space: normal;
    word-wrap: break-word;
}

/* 訊息中的連結樣式 */
.message-bubble a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}

.message.admin .message-bubble a {
    color: #0066cc !important;
}

.message.user .message-bubble a {
    color: #ffffff !important;
    text-decoration: underline;
}

.message.user .message-bubble {
    background: #06c755;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.admin .message-bubble {
    background: white;
    color: #333;
    border: 1px solid #e5e5e5;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #999;
    margin: 0 8px;
    align-self: flex-end;
}

.message-image {
    max-width: 200px;
    border-radius: 8px;
    cursor: pointer;
}

/* 系統訊息 */
.message.system .message-bubble {
    background: #f0f0f0;
    color: #666;
    text-align: center;
    font-size: 12px;
    border-radius: 12px;
    margin: 0 auto;
}

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

.chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f8f9fa;
    border: 1px solid #e5e5e5;
    border-radius: 20px;
    padding: 8px 12px;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    resize: none;
    font-size: 14px;
    line-height: 1.4;
    max-height: 80px;
    min-height: 20px;
    font-family: inherit;
}

.chat-input::placeholder {
    color: #999;
}

.chat-input-actions {
    display: flex;
    gap: 5px;
}

.chat-action-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #666;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-action-btn:hover {
    background: #e5e5e5;
    color: #333;
}

.chat-send-btn {
    background: #06c755;
    color: white;
}

.chat-send-btn:hover {
    background: #05b248;
}

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

/* Email 收集視窗 */
.email-collection-screen {
    padding: 30px 20px;
    text-align: center;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    position: absolute;
    top:40px;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    justify-content: center;
    border-radius: 16px; /* 添加圓角 */
}

.email-collection-screen.active {
    display: flex;
}

.email-collection-screen h3 {
    color: #333;
    margin-bottom: 10px;
    font-size: 18px;
}

.email-collection-screen h3::before {
    content: "📧";
    font-size: 24px;
    display: block;
    margin-bottom: 10px;
}

.email-collection-screen p {
    color: #666;
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.5;
}

.email-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e5e5e5;
    border-radius: 25px;
    font-size: 14px;
    margin-bottom: 20px;
    outline: none;
    transition: border-color 0.3s;
    box-sizing: border-box;
}

.email-input:focus {
    border-color: #06c755;
}

.email-submit-btn, .email-skip-btn {
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin: 5px;
}

.email-submit-btn {
    background: #06c755;
    color: white;
    border: none;
}

.email-submit-btn:hover {
    background: #05b248;
}

.email-skip-btn {
    background: transparent;
    color: #666;
    border: 1px solid #e5e5e5;
}

.email-skip-btn:hover {
    background: #f8f9fa;
}

/* 載入動畫 */
.chat-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: #06c755;
    border-radius: 50%;
    animation: loadingPulse 1.5s infinite ease-in-out;
}

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

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

@keyframes loadingPulse {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 響應式設計 */
@media (max-width: 480px) {
    .chat-widget-container {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: calc(100vh - 60px); /* 保留頂部空間，避免佔滿整個螢幕 */
        max-height: 600px; /* 限制最大高度 */
        border-radius: 16px 16px 0 0; /* 只有頂部圓角 */
    }
    
    .chat-float-container {
        bottom: 165px;
        right: 20px;
        gap: 10px;
    }
    
    .chat-message-box {
        max-width: 150px;
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .chat-message-text {
        margin-right: 16px;
    }
    
    .chat-message-close {
        width: 18px;
        height: 18px;
        font-size: 12px;
        top: 2px;
        right: 6px;
    }
    
    .chat-float-button {
        width: 45px;
        height: 45px;
    }
    
    .chat-float-button i {
        font-size: 18px;
    }
    
    /* 手機版本的提示文字框 */
    .chat-float-button-tooltip {
        right: 55px;
        bottom: 0;
        transform: translateY(0);
        font-size: 12px;
        padding: 6px 10px;
    }
    
    .chat-float-button:hover .chat-float-button-tooltip {
        right: 60px;
    }
    
    /* 手機版本的貓咪圖片調整 */
    .chat-cat-decoration {
        top: -15px; /* 稍微往上偏移，但不會被裁切 */
        left: 50%;
        transform: translateX(-50%);
    }
    
    .chat-cat-gif {
        width: 80px; /* 手機版稍微小一點 */
    }
    
    /* 手機版本的聊天內容區域調整 */
    .chat-content {
        margin-top: 25px; /* 手機版減少頂部空間 */
        height: calc(100% - 25px); /* 確保內容區域高度正確 */
    }
    
    /* 手機版Email收集畫面優化 */
    .email-collection-screen {
        background: linear-gradient(135deg, #06c755 0%, #05b248 20%, #f8f9fa 20%, #e9ecef 100%);
        border-radius: 16px 16px 0 0; /* 手機版只有頂部圓角 */
        padding: 25px 20px 20px 20px; /* 調整間距避免超出 */
        top: 25px; /* 配合chat-content的margin-top */
        bottom: auto; /* 取消固定底部 */
        height: calc(100% - 25px); /* 明確設定高度 */
        max-height: calc(100vh - 120px); /* 確保不超出螢幕 */
        overflow-y: auto; /* 內容過多時可滾動 */
        justify-content: flex-start; /* 從頂部開始排列 */
    }
    
    .email-collection-screen h3 {
        color: #333;
        font-size: 18px; /* 稍微縮小標題 */
        margin-bottom: 12px;
    }
    
    .email-collection-screen h3::before {
        font-size: 28px; /* 稍微縮小emoji */
        margin-bottom: 12px;
    }
    
    .email-collection-screen p {
        font-size: 14px;
        color: #555;
        margin-bottom: 20px;
        line-height: 1.5;
    }
    
    /* 手機版Discord邀請區域調整 */
    .email-collection-screen .discord-invitation {
        margin: 15px 0 !important;
        padding: 15px !important;
    }
    
    .email-collection-screen .discord-invitation h4 {
        font-size: 16px !important;
        margin-bottom: 10px !important;
    }
    
    .email-collection-screen .discord-invitation p {
        font-size: 13px !important;
        margin-bottom: 15px !important;
    }
    
    .email-collection-screen .discord-invitation a {
        padding: 10px 20px !important;
        font-size: 14px !important;
    }
    
    /* 手機版Email輸入和按鈕調整 */
    .email-collection-screen .email-input {
        margin-bottom: 15px;
        font-size: 16px; /* 避免iOS自動縮放 */
    }
    
    .email-collection-screen .email-submit-btn,
    .email-collection-screen .email-skip-btn {
        padding: 12px 20px;
        font-size: 15px;
        margin: 5px;
        min-height: 44px; /* 確保點擊區域足夠大 */
    }
}

/* 隱藏預設檔案輸入 */
.hidden-file-input {
    display: none;
}