/* 全域樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #cbd5e1;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-primary);
}

/* 頁面切換 */
.page {
    display: none;
}

.page.active {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

/* ===== 登入頁面 ===== */
.login-container {
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 48px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.login-header h1 {
    font-size: 24px;
    color: var(--primary);
    margin-bottom: 8px;
}

.login-header h2 {
    font-size: 18px;
    color: var(--text-secondary);
    font-weight: normal;
    margin-bottom: 32px;
}

.login-form input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 16px;
    transition: border-color 0.3s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary);
}

.login-form button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.login-form button:hover {
    background: var(--primary-dark);
}

.error-message {
    color: var(--danger);
    font-size: 14px;
    margin-top: 12px;
    min-height: 20px;
}

.login-footer {
    margin-top: 32px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== 聊天介面 ===== */
.chat-container {
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    max-width: 1200px;
    width: 95%;
    height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 頂部導航 */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 2px solid var(--bg-tertiary);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.header-left h1 {
    font-size: 16px;
    margin-bottom: 2px;
}

.status {
    font-size: 11px;
    opacity: 0.9;
}

.header-right {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.3s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 對話區域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-secondary);
}

.message {
    margin-bottom: 20px;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-content {
    max-width: 80%;
    padding: 16px 20px;
    border-radius: 12px;
    line-height: 1.6;
}

.message.user .message-content {
    background: var(--primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: white;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-content p {
    margin-bottom: 12px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul,
.message-content ol {
    margin-left: 20px;
    margin-bottom: 12px;
}

.message-content li {
    margin-bottom: 6px;
}

.message-content code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
    font-size: 14px;
}

.message-content pre {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 12px;
}

.source-reference {
    margin-top: 12px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-left: 3px solid var(--primary);
    border-radius: 4px;
    font-size: 14px;
}

.source-reference strong {
    color: var(--primary);
}

/* 快速問題 */
.quick-questions {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    background: white;
}

.quick-questions button {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    color: var(--text-primary);
}

.quick-questions button:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* 輸入區域 */
.chat-input {
    display: flex;
    gap: 12px;
    padding: 20px 24px;
    border-top: 2px solid var(--bg-tertiary);
    background: white;
}

.chat-input textarea {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    transition: border-color 0.3s;
}

.chat-input textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.chat-input button {
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 20px;
    transition: background 0.3s;
    min-width: 60px;
}

.chat-input button:hover:not(:disabled) {
    background: var(--primary-dark);
}

.chat-input button:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
}

/* 響應式設計 */
@media (max-width: 768px) {
    .chat-container {
        width: 100%;
        height: 100vh;
        border-radius: 0;
    }

    .message-content {
        max-width: 90%;
    }

    .quick-questions {
        flex-direction: column;
    }

    .quick-questions button {
        width: 100%;
    }
}

/* 滾動條樣式 */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}