:root {
    --bg-color: #0f111a;
    --text-primary: #e0e6ed;
    --text-secondary: #94a3b8;
    --accent-primary: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.5);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --input-bg: rgba(15, 23, 42, 0.6);
    --user-msg-bg: #2563eb;
    --bot-msg-bg: rgba(51, 65, 85, 0.5);
    --font-main: 'Inter', sans-serif;
    --font-tc: 'Noto Sans TC', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main), var(--font-tc);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Background Effects */
.background-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    animation: float 10s infinite ease-in-out;
}

.orb-1 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.3) 0%, rgba(0, 0, 0, 0) 70%);
    top: -50px;
    left: -50px;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.2) 0%, rgba(0, 0, 0, 0) 70%);
    bottom: -100px;
    right: -100px;
    animation-delay: -5s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(20px, 30px); }
}

/* App Container */
.app-container {
    width: 100%;
    max-width: 1000px;
    height: 100%;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid var(--glass-border);
    border-left: 1px solid var(--glass-border);
    position: relative;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}

@media (min-width: 768px) {
    .app-container {
        height: 95vh;
        max-width: 95%;
        max-height: 95vh;
        border-radius: 20px;
        border: 1px solid var(--glass-border);
    }
}

@media (min-width: 1400px) {
    .app-container {
        max-width: 1400px;
    }
}

/* Header */
.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(15, 23, 42, 0.3);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.new-chat-btn {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #60a5fa;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.new-chat-btn:hover {
    background: rgba(59, 130, 246, 0.3);
    border-color: rgba(59, 130, 246, 0.5);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    color: var(--accent-primary);
    width: 32px;
    height: 32px;
}

.logo-area h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.model-badge {
    font-size: 0.75rem;
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    vertical-align: middle;
    margin-left: 0.25rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ef4444;
    box-shadow: 0 0 5px #ef4444;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.status-indicator.connected .status-dot {
    background-color: #22c55e;
    box-shadow: 0 0 8px #22c55e;
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar { width: 6px; }
.chat-area::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 3px; }

.welcome-message {
    text-align: center;
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    opacity: 0.8;
}

.welcome-message h2 {
    font-size: 1.5rem;
    background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.chip {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.chip:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
    color: var(--text-primary);
}

/* Messages */
.message {
    display: flex;
    gap: 1rem;
    max-width: 85%;
    animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    font-size: 1.2rem;
}

.message.user .avatar { background: linear-gradient(135deg, #6366f1, #a855f7); box-shadow: 0 2px 10px rgba(168, 85, 247, 0.3); }
.message.bot .avatar { background: linear-gradient(135deg, #0ea5e9, #3b82f6); box-shadow: 0 2px 10px rgba(59, 130, 246, 0.3); }

.message-content {
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    font-size: 0.95rem;
    word-break: break-word;
    line-height: 1.6;
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
}

.message.user .message-content { background: var(--user-msg-bg); color: white; border-bottom-right-radius: 2px; }
.message.bot .message-content { background: var(--bot-msg-bg); border: 1px solid var(--glass-border); border-bottom-left-radius: 2px; }

.message-content pre {
    background: #0d1117;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5rem 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

/* Input Area */
.input-area {
    padding: 1.5rem 2rem 2rem 2rem;
    background: linear-gradient(to top, var(--bg-color) 40%, transparent);
    position: relative;
    z-index: 10;
}
.input-glass-container {
    background: var(--input-bg);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column; /* 改為垂直佈局 */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.input-glass-container:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2), 0 10px 30px rgba(0, 0, 0, 0.4);
    background: rgba(15, 23, 42, 0.8);
}

/* 文字輸入區 */
#user-input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    padding: 8px 4px;
    max-height: 200px;
    min-height: 44px;
    outline: none;
    line-height: 1.6;
}
.send-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 10px;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 2px;
}

.send-btn:hover { background: #2563eb; transform: scale(1.05); }

/* 🚀 修改重點：Modal 彈窗優化 */
.modal {
    position: fixed; /* 改為 fixed 確保覆蓋全螢幕 */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #1e293b;
    border: 1px solid var(--glass-border);
    padding: 2rem;
    border-radius: 20px;
    /* 📏 加寬彈窗 */
    width: 90%;
    max-width: 900px; 
    /* 📏 限制高度防止溢出 */
    max-height: 85vh; 
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    position: relative;
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 🤖 模型列表改為 Grid 網格佈局 */
.model-list {
    display: grid;
    /* 在桌面端顯示兩欄，每欄最小 350px */
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
    overflow-y: auto; /* 內容過多時顯示捲軸 */
    padding-right: 10px; /* 給捲軸留點空間 */
    flex: 1; /* 自動撐開佔據空間 */
}

/* 🖱️ 客製化捲軸樣式 */
.model-list::-webkit-scrollbar {
    width: 6px;
}
.model-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.model-option {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 1.2rem;
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    height: 100%; /* 讓 Grid 內的卡片等高 */
}

.model-option:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--accent-primary);
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.model-option.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.2);
}

.model-option strong {
    font-size: 1.1rem;
    color: #60a5fa;
}

.model-option span {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* 📱 手機版適應：改回單欄 */
@media (max-width: 768px) {
    .model-list {
        grid-template-columns: 1fr;
    }
    .modal-content {
        width: 95%;
        padding: 1.5rem;
    }
}

/* 其他小工具 */
.model-select-btn {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #60a5fa;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #1e293b;
    border: 1px solid var(--accent-primary);
    padding: 12px 24px;
    border-radius: 10px;
    z-index: 2000;
    transform: translateY(100px);
    opacity: 0;
    transition: 0.3s;
}


/* 工具列佈局 */
.input-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
/* 附件與一般功能按鈕通用的圓圈樣式 */
.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    border: none;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

/* 檔案上傳專用樣式 */
.file-drop-area {
    position: relative;
}

.file-drop-area.dragover {
    background: rgba(59, 130, 246, 0.2);
    color: var(--accent-primary);
    border-radius: 10px;
}
.file-drop-area svg {
    width: 20px;  /* 從原本可能佔滿 36px 縮小到 20px */
    height: 20px;
    transition: transform 0.2s ease;
}
/* 發送按鈕 */
.send-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 10px;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.send-btn:hover:not(:disabled) {
    background: #2563eb;
    transform: scale(1.05);
}

.send-btn:disabled {
    background: #334155;
    opacity: 0.5;
    cursor: not-allowed;
}

/* 提示文字 */
.disclaimer {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 10px;
    opacity: 0.6;
}

@media (max-width: 768px) {
    .input-area {
        padding: 1rem;
    }
}

.toast.show { transform: translateY(0); opacity: 1; }
