:root {
    --primary-color: #4a6fa5;
    --secondary-color: #6b8cae;
    --accent-color: #ff7e5f;
    --light-bg: #f8f9fa;
    --dark-text: #333;
    --light-text: #f8f9fa;
    --user-message-bg: #e3f2fd;
    --bot-message-bg: #f5f5f5;
    --error-color: #e74c3c;
    --warning-color: #f39c12;
    --message-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    --input-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Microsoft JhengHei', sans-serif;
    background-color: var(--light-bg);
    color: var(--dark-text);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 0;
}

.container {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    background-color: white;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    background-color: var(--primary-color);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.header h1 {
    font-size: 1.2rem;
    font-weight: 600;
    text-align: center;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background-color: #f5f7fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    margin-bottom: 2px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
    animation: fadeIn 0.3s ease;
    box-shadow: var(--message-shadow);
}

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

.user-message {
    align-self: flex-end;
    background-color: var(--user-message-bg);
    color: var(--dark-text);
    border-bottom-right-radius: 5px;
}

.bot-message {
    align-self: flex-start;
    background-color: white;
    color: var(--dark-text);
    border-bottom-left-radius: 5px;
    border: 1px solid #eaeaea;
}

.error-message {
    align-self: flex-start;
    background-color: #fde8e8;
    color: var(--error-color);
    border-bottom-left-radius: 5px;
}

.image-message {
    max-width: calc(100% - 20px);
    max-height: 50vh;
    border-radius: 12px;
    margin-top: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    object-fit: contain;
}

.input-area {
    padding: 12px 15px;
    background-color: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 8px;
    align-items: center;
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.03);
}

.input-container {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
}

#message-input {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #e0e0e0;
    border-radius: 25px;
    font-size: 1rem;
    resize: none;
    max-height: 120px;
    min-height: 50px;
    outline: none;
    transition: all 0.3s;
    background-color: #f8f9fa;
    box-shadow: var(--input-shadow);
}

#message-input:focus {
    border-color: var(--primary-color);
    background-color: white;
}

.image-preview-container {
    position: relative;
    margin-bottom: 8px;
    align-self: flex-start;
}

.image-preview {
    max-width: 80px;
    max-height: 80px;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
}

.remove-image-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    background-color: var(--error-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.action-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 0.95rem;
    min-width: 44px;
    min-height: 44px;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 2px 5px rgba(74, 111, 165, 0.3);
}

.btn-primary:hover {
    background-color: var(--secondary-color);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #f0f0f0;
    color: var(--dark-text);
}

.btn-secondary:hover {
    background-color: #e0e0e0;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.typing-indicator {
    display: inline-block;
    padding: 10px 16px;
    background-color: white;
    border-radius: 18px;
    align-self: flex-start;
    color: #777;
    font-style: italic;
    border: 1px solid #eaeaea;
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    height: 17px;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    margin: 0 2px;
    background-color: #999;
    border-radius: 50%;
    display: inline-block;
    animation: typingAnimation 1.4s infinite ease-in-out;
}

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

.file-input {
    display: none;
}

.file-upload-label {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border-radius: 50%;
    transition: all 0.2s;
    min-width: 44px;
    min-height: 44px;
}

.file-upload-label:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.message-time {
    display: block;
    font-size: 0.7rem;
    color: #888;
    margin-top: 4px;
    text-align: right;
}

/* 手機專用優化 */
@media (max-width: 768px) {
    .container {
        height: 100vh;
        border-radius: 0;
    }
    
    .header {
        padding: 12px 15px;
    }
    
    .chat-container {
        padding: 12px;
        gap: 10px;
    }
    
    .message {
        max-width: 90%;
        padding: 10px 14px;
    }
    
    .input-area {
        padding: 10px 12px;
    }
    
    #message-input {
        padding: 10px 14px;
        min-height: 44px;
        font-size: 0.95rem;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    .image-message {
        max-height: 45vh;
    }
    
    /* 改善觸控目標大小 */
    .btn, .file-upload-label {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* 優化輸入框在iOS上的表現 */
    input, textarea {
        -webkit-appearance: none;
        border-radius: 25px;
    }
    
    /* 防止手機上文字縮放 */
    body {
        -webkit-text-size-adjust: 100%;
    }
}

/* 針對小於400px的超小屏幕 */
@media (max-width: 400px) {
    .header h1 {
        font-size: 1.1rem;
    }
    
    .message {
        max-width: 95%;
    }
    
    .action-buttons {
        gap: 5px;
    }
    
    .btn {
        padding: 8px;
    }
    
    .image-message {
        max-height: 40vh;
    }
}