:root {
    /* Apple-style 亮色系配色與現代設計代幣 */
    --app-bg: #f2f2f7; /* iOS system background */
    --surface-bg: #ffffff;
    --text-primary: #000000;
    --text-secondary: #8e8e93;
    --primary-color: #007aff; /* iOS blue */
    --primary-color-hover: #0056b3;
    --chat-bubble-received: #e5e5ea;
    --chat-text-received: #000000;
    --chat-bubble-sent: #007aff;
    --chat-text-sent: #ffffff;
    --border-color: rgba(60, 60, 67, 0.1);
    
    /* 玻璃擬態與陰影 */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-blur: blur(10px);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);

    /* 字體 */
    --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-stack);
    background-color: var(--app-bg);
    color: var(--text-primary);
    line-height: 1.5;
    /* 防止在手機上滑動過度 */
    overflow: hidden; 
    height: 100vh;
    display: flex;
    justify-content: center;
}

/* 主容器 - 模擬手機畫面 */
.app-container {
    width: 100%;
    max-width: 480px; /* 大多數手機橫向範圍內 */
    height: 100vh;
    background-color: var(--app-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: var(--shadow-md);
}

/* 頂部導覽列 */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    height: 60px;
    background-color: var(--glass-bg);
    backdrop-filter: var(--glass-blur); /* 毛玻璃特效 */
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-color);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 10;
}

.chat-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chat-title h2 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.4px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    background-color: #34c759; /* iOS green */
    border-radius: 50%;
    margin-top: 2px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

/* 右側控制區與結束對話按鈕 */
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-btn {
    background-color: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    padding: 6px 12px;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background-color: var(--primary-color);
    color: white;
}

/* Modal 彈窗樣式 */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--surface-bg);
    width: 90%;
    max-width: 320px;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    padding: 20px;
    transform: translateY(0) scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-overlay.hidden .modal-content {
    transform: translateY(20px) scale(0.95);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.setting-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.model-select-full {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    background-color: #f2f2f7;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
    cursor: pointer;
    background-image: url('data:image/svg+xml;utf8,<svg fill="%238e8e93" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.setting-hint {
    font-size: 12px;
    color: var(--text-secondary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.primary-btn:hover {
    background-color: var(--primary-color-hover);
}

/* 聊天內容區域 */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 80px 16px 20px 16px; /* 為標題列與底部預留空間 */
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

/* 隱藏卷軸但保留滾動功能 (針對美觀) */
.chat-area::-webkit-scrollbar {
    width: 0;
    background: transparent;
}

.time-stamp {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    margin: 8px 0;
    font-weight: 500;
}

.message {
    display: flex;
    max-width: 85%;
    align-items: flex-end;
    gap: 8px;
    animation: fadeIn 0.3s ease forwards;
}

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

.message.received {
    align-self: flex-start;
}

.message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--surface-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.avatar .material-symbols-rounded {
    font-size: 18px;
}

.bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
}

/* 收到的訊息：灰色氣泡 */
.message.received .bubble {
    background-color: var(--chat-bubble-received);
    color: var(--chat-text-received);
    border-bottom-left-radius: 4px;
}

/* 傳出的訊息：藍色氣泡 */
.message.sent .bubble {
    background-color: var(--chat-bubble-sent);
    color: var(--chat-text-sent);
    border-bottom-right-radius: 4px;
}

/* 底部邊界與主容器 */
.footer-container {
    background-color: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-top: 1px solid var(--border-color);
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

/* 附件預覽區 */
.attachment-preview {
    padding: 12px 16px 0 16px;
    display: flex;
    transition: all 0.3s ease;
}

.attachment-preview.hidden {
    display: none;
}

.preview-content {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--surface-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px;
    box-shadow: var(--shadow-sm);
    min-width: 60px;
    min-height: 60px;
    max-width: 120px;
}

.preview-content img {
    max-width: 100%;
    max-height: 80px;
    border-radius: 8px;
    object-fit: cover;
}

#previewDoc {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--primary-color);
    gap: 4px;
}

.doc-name {
    font-size: 11px;
    color: var(--text-secondary);
    max-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background-color: var(--text-secondary);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.remove-btn .material-symbols-rounded {
    font-size: 14px;
}

/* 聊天氣泡內的圖片或文件 */
.bubble-attachment {
    max-width: 100%;
    border-radius: 12px;
    margin-bottom: 6px;
    display: block;
}

.bubble-doc {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: rgba(255, 255, 255, 0.2);
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 13px;
}

/* 底部輸入區域 */
.input-area {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
}

.attachment-btn {
    color: var(--text-secondary);
}

.input-wrapper {
    flex: 1;
    display: flex;
    background-color: var(--surface-bg);
    border-radius: 20px;
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
}

#messageInput {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 15px;
    font-family: var(--font-stack);
    padding: 4px 0;
}

.send-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s, opacity 0.2s;
}

.send-btn .material-symbols-rounded {
    font-size: 20px;
}

.send-btn:active {
    transform: scale(0.9);
}

.send-btn:disabled {
    background-color: var(--chat-bubble-received);
    color: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.7;
}

.hidden {
    display: none !important;
}
