/* ========================================
   CSS 變量定義
   ======================================== */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --background-color: #f8f9fa;
    --card-background: #ffffff;
    --text-color: #2c3e50;
    --light-text: #7f8c8d;
    --border-color: #dee2e6;
    --hover-color: #ecf0f1;
    --shadow-light: rgba(0, 0, 0, 0.05);
    --shadow-medium: rgba(0, 0, 0, 0.1);
    --shadow-dark: rgba(0, 0, 0, 0.15);
    --border-radius: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-width: 280px;
    --header-height: 60px;
    --input-section-height: 120px;
}

/* ========================================
   基礎樣式重置
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    font-size: 14px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
}

/* ========================================
   主應用容器 - 改進的布局
   ======================================== */
.app-container {
    display: flex;
    flex: 1;
    width: 100%;
    min-height: 100vh;
    position: relative;
    overflow: visible;
}

/* ========================================
   側邊欄 - 響應式改進
   ======================================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--card-background);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px var(--shadow-light);
    position: relative;
    z-index: 100;
    transition: var(--transition);
    flex-shrink: 0;
    height: 100vh;
    overflow-y: auto;
    position: sticky;
    top: 0;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    flex-shrink: 0;
}

.sidebar-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.sidebar-header .user-info {
    font-size: 0.85rem;
    opacity: 0.9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.admin-link,
.logout-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: var(--transition);
    white-space: nowrap;
}

.admin-link:hover,
.logout-link:hover {
    background-color: rgba(255, 255, 255, 0.15);
    color: white;
}

/* 新對話按鈕 */
.new-chat-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.new-chat-btn {
    width: 100%;
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.new-chat-btn:hover {
    background-color: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--shadow-medium);
}

/* 對話列表 */
.chat-tabs {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem;
    min-height: 0;
}

.chat-tab {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    user-select: none;
}

.chat-tab:hover {
    background-color: var(--hover-color);
    border-color: var(--border-color);
}

.chat-tab.active {
    background-color: var(--secondary-color);
    color: white;
    box-shadow: 0 2px 8px var(--shadow-medium);
}

.chat-tab-info {
    flex: 1;
    min-width: 0;
}

.chat-tab-name {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-tab-meta {
    font-size: 0.75rem;
    opacity: 0.7;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.chat-tab-actions {
    margin-left: 0.5rem;
    opacity: 0;
    transition: var(--transition);
}

.chat-tab:hover .chat-tab-actions,
.chat-tab.active .chat-tab-actions {
    opacity: 1;
}

.delete-tab-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 3px;
    font-size: 0.8rem;
    transition: var(--transition);
}

.delete-tab-btn:hover {
    background-color: var(--accent-color);
    color: white;
}

/* ========================================
   主內容區域 - 改進的布局
   ======================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* 聊天標題欄 */
.chat-header {
    background: var(--card-background);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px var(--shadow-light);
    flex-shrink: 0;
    min-height: var(--header-height);
    gap: 1rem;
}

.chat-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-options {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.option-group label {
    font-size: 0.85rem;
    color: var(--light-text);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.option-group input[type="checkbox"] {
    cursor: pointer;
}

/* 聊天內容區域 - 改進滾動 */
.chat-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   消息樣式 - 優化顯示
   ======================================== */
.message {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    max-width: 85%;
    animation: fadeInUp 0.3s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

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

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--secondary-color);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--success-color);
    color: white;
}

.message-content {
    background: var(--card-background);
    padding: 1rem 1.25rem;
    border-radius: 16px;
    box-shadow: 0 2px 8px var(--shadow-light);
    border: 1px solid var(--border-color);
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.message.user .message-content {
    background: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
}

.message-text {
    line-height: 1.6;
    font-size: 0.95rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* 用戶消息保持純文本樣式 */
.message.user .message-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.message.user code {
    background: none;
    color: inherit;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
}

/* AI消息格式化 */
.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
    margin: 1rem 0 0.5rem 0;
    color: #2c3e50;
    font-weight: 600;
    line-height: 1.4;
}

.message.assistant h1 {
    font-size: 1.5rem;
    border-bottom: 2px solid #e1e4e8;
    padding-bottom: 0.5rem;
}

.message.assistant h2 {
    font-size: 1.3rem;
    border-bottom: 1px solid #e1e4e8;
    padding-bottom: 0.3rem;
}

.message.assistant h3 {
    font-size: 1.1rem;
}

.message.assistant ul,
.message.assistant ol {
    margin: 0.5rem 0;
    padding-left: 2rem;
}

.message.assistant li {
    margin: 0.3rem 0;
    line-height: 1.6;
}

.message.assistant strong {
    font-weight: 600;
    color: #2c3e50;
}

.message.assistant em {
    font-style: italic;
    color: #495057;
}

/* 行內代碼 */
.message.assistant code:not([class*="language-"]) {
    background: #f3f4f6;
    color: #e83e8c;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

/* 消息元信息 */
.message-meta {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* 消息操作按鈕 */
.message-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    flex-wrap: wrap;
}

.message-action-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--light-text);
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

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

.message.user .message-action-btn {
    border-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.8);
}

.message.user .message-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
    color: white;
}

/* 流式響應動畫 */
.message-content.streaming::after {
    content: '▋';
    animation: blink 1s infinite;
    color: var(--secondary-color);
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* ========================================
   表格樣式 - 響應式優化
   ======================================== */
.table-wrapper {
    overflow-x: auto;
    margin: 1rem 0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #e1e4e8;
    background: white;
    -webkit-overflow-scrolling: touch;
    position: relative;
    max-width: 100%;
}

.markdown-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 100%;
    table-layout: auto;
    background: white;
    font-size: 14px;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.markdown-table thead {
    background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
}

.markdown-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: #2c3e50;
    border: 1px solid #dee2e6;
    background: #f8f9fa;
    white-space: nowrap;
    min-width: 60px;
}

.markdown-table td {
    padding: 10px 16px;
    border: 1px solid #dee2e6;
    color: #495057;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    vertical-align: top;
    white-space: pre-wrap;
}

.markdown-table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

.markdown-table tbody tr:hover {
    background-color: #e3f2fd;
    transition: background-color 0.2s;
}

.markdown-table code {
    background: #f4f4f4;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
    color: #e83e8c;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

/* ========================================
   代碼塊樣式
   ======================================== */
.code-block {
    margin: 1rem 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e1e5e9;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    max-width: 100%;
}

.code-block .code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: #f6f8fa;
    border-bottom: 1px solid #e1e5e9;
    font-size: 12px;
}

.code-block .code-language {
    font-weight: 600;
    color: #586069;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.code-block .code-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.code-block .code-btn {
    padding: 0.375rem 0.75rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #fff;
    color: #656d76;
    border: 1px solid #d0d7de;
}

.code-block .code-btn:hover {
    background: #f3f4f6;
    border-color: #8c959f;
}

.code-block .code-btn.success {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

.code-block .code-content {
    position: relative;
    background: #fff;
    overflow-x: auto;
    max-height: 600px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.code-block pre {
    margin: 0;
    padding: 1rem;
    overflow-x: auto;
    background: transparent;
    white-space: pre;
    word-wrap: normal;
}

.code-block code {
    font-family: inherit;
    background: transparent;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1.6;
    display: block;
    color: #333;
}

/* ========================================
   輸入區域 - 改進的固定定位
   ======================================== */
.chat-input-section {
    background: var(--card-background);
    border-top: 1px solid var(--border-color);
    padding: 1.5rem;
    box-shadow: 0 -2px 10px var(--shadow-light);
    flex-shrink: 0;
    width: 100%;
}

/* 文件上傳區域 */
.file-upload-section {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--background-color);
    border-radius: var(--border-radius);
    border: 2px dashed var(--border-color);
    text-align: center;
    transition: var(--transition);
}

.file-upload-section.dragover {
    border-color: var(--secondary-color);
    background-color: rgba(52, 152, 219, 0.05);
}

.file-upload-btn {
    background: none;
    border: none;
    color: var(--secondary-color);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
}

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

.uploaded-files {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.file-tag {
    background: var(--secondary-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.file-tag .remove-file {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 0.7rem;
    padding: 0;
    line-height: 1;
}

/* 輸入表單 */
.input-form {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.input-group {
    flex: 1;
    position: relative;
}

.message-input {
    width: 100%;
    min-height: 50px;
    max-height: 150px;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    font-size: 0.95rem;
    line-height: 1.4;
    resize: none;
    transition: var(--transition);
    font-family: inherit;
}

.message-input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.send-btn {
    background: var(--secondary-color);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.send-btn:hover {
    background-color: #2980b9;
    transform: scale(1.05);
    box-shadow: 0 4px 12px var(--shadow-medium);
}

.send-btn:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ========================================
   移動設備菜單按鈕
   ======================================== */
.mobile-menu-btn {
    display: none;
    background: var(--secondary-color);
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
    width: 45px;
    height: 45px;
    align-items: center;
    justify-content: center;
}

.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* ========================================
   狀態和提示
   ======================================== */
.loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--light-text);
    padding: 1rem 0;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--light-text);
}

.empty-state h3 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.empty-state p {
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Toast 通知 */
.toast-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--card-background);
    color: var(--text-color);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow-medium);
    z-index: 10000;
    transform: translateX(400px);
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 350px;
}

.toast-notification.show {
    transform: translateX(0);
}

.toast-notification.success {
    background: var(--success-color);
    color: white;
}

.toast-notification.error {
    background: var(--accent-color);
    color: white;
}

.toast-notification.info {
    background: var(--secondary-color);
    color: white;
}

/* 錯誤和成功消息 */
.error-message,
.success-message {
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    margin: 1rem 0;
    font-size: 0.9rem;
    border-left: 4px solid;
}

.error-message {
    background-color: #fdf2f2;
    color: var(--accent-color);
    border-left-color: var(--accent-color);
}

.success-message {
    background-color: #f0f9f0;
    color: var(--success-color);
    border-left-color: var(--success-color);
}

/* ========================================
   登錄頁面
   ======================================== */
body.login-page {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-container {
    background: var(--card-background);
    border-radius: 12px;
    box-shadow: 0 15px 35px var(--shadow-dark);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-header {
    margin-bottom: 2rem;
}

.login-header h1 {
    color: var(--primary-color);
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.login-header p {
    color: #7f8c8d;
    font-size: 0.95rem;
}

.form-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-color);
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.remember-group {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
}

.remember-group input[type="checkbox"] {
    margin-right: 0.5rem;
}

.login-button {
    width: 100%;
    background: linear-gradient(135deg, var(--secondary-color), #2980b9);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.login-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

.login-button:active {
    transform: translateY(0);
}

.footer-info {
    margin-top: 2rem;
    font-size: 0.8rem;
    color: #95a5a6;
}

/* ========================================
   滾動條樣式
   ======================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--light-text);
}

/* ========================================
   平板設備響應式 (768px - 1024px)
   ======================================== */
@media screen and (max-width: 1024px) and (min-width: 769px) {
    .sidebar {
        width: 240px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .chat-header {
        padding: 0.875rem 1rem;
    }
    
    .chat-content {
        padding: 1rem;
    }
}

/* ========================================
   手機設備響應式 (最大768px)
   ======================================== */
@media screen and (max-width: 768px) {
    :root {
        --sidebar-width: 75%;
        --header-height: 50px;
    }
    
    /* 顯示移動菜單按鈕 */
    .mobile-menu-btn {
        display: flex;
    }
    
    /* 側邊欄移動端樣式 */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: var(--sidebar-width);
        max-width: 320px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
    }
    
    .sidebar.mobile-open {
        left: 0;
    }
    
    /* 遮罩層 */
    .mobile-overlay.active {
        display: block;
    }
    
    /* 主內容區調整 */
    .main-content {
        width: 100%;
        margin-left: 0;
    }
    
    .chat-header {
        padding: 0.75rem 1rem;
        padding-left: 60px;
        min-height: var(--header-height);
    }
    
    .chat-title {
        font-size: 1rem;
    }
    
    .chat-options {
        gap: 0.5rem;
    }
    
    .option-group label {
        font-size: 0.8rem;
    }
    
    /* 聊天內容區 */
    .chat-content {
        padding: 1rem 0.75rem;
        gap: 1rem;
    }
    
    /* 消息樣式調整 */
    .message {
        max-width: 92%;
        gap: 0.5rem;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
    
    .message-content {
        padding: 0.75rem 1rem;
        border-radius: 12px;
    }
    
    .message-text {
        font-size: 0.9rem;
    }
    
    /* 表格移動端優化 */
    .table-wrapper {
        margin: 0.75rem -0.75rem;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .markdown-table {
        font-size: 12px;
    }
    
    .markdown-table th,
    .markdown-table td {
        padding: 8px 10px;
        font-size: 12px;
    }
    
    /* 代碼塊移動端 */
    .code-block {
        margin: 0.75rem 0;
        border-radius: 4px;
    }
    
    .code-block .code-header {
        padding: 0.5rem 0.75rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .code-block pre {
        padding: 0.75rem;
        font-size: 12px;
    }
    
    /* 輸入區域移動端 */
    .chat-input-section {
        padding: 1rem 0.75rem;
    }
    
    .file-upload-section {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }
    
    .message-input {
        font-size: 16px; /* 防止iOS縮放 */
        padding: 0.625rem 0.875rem;
        min-height: 45px;
    }
    
    .send-btn {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }
    
    /* 登錄頁面移動端 */
    .login-container {
        padding: 2rem 1.5rem;
        margin: 0 1rem;
    }
    
    .login-header h1 {
        font-size: 1.5rem;
    }
    
    /* Toast 通知移動端 */
    .toast-notification {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
}

/* ========================================
   小屏幕手機優化 (最大480px)
   ======================================== */
@media screen and (max-width: 480px) {
    :root {
        --sidebar-width: 85%;
    }
    
    .chat-header {
        padding: 0.625rem 0.75rem;
        padding-left: 55px;
        gap: 0.5rem;
    }
    
    .chat-options {
        width: 100%;
        justify-content: space-between;
    }
    
    .option-group {
        gap: 0.25rem;
    }
    
    .option-group label {
        font-size: 0.75rem;
    }
    
    .chat-content {
        padding: 0.75rem 0.5rem;
    }
    
    .message {
        max-width: 95%;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }
    
    .message-content {
        padding: 0.625rem 0.875rem;
        font-size: 0.875rem;
    }
    
    .message-text {
        font-size: 0.875rem;
    }
    
    /* 超小屏幕表格 */
    .markdown-table {
        font-size: 11px;
    }
    
    .markdown-table th,
    .markdown-table td {
        padding: 6px 8px;
        font-size: 11px;
    }
    
    /* 輸入區域超小屏幕 */
    .chat-input-section {
        padding: 0.75rem 0.5rem;
    }
    
    .input-form {
        gap: 0.5rem;
    }
    
    .message-input {
        padding: 0.5rem 0.75rem;
        min-height: 40px;
        border-radius: 20px;
    }
    
    .send-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
}

/* ========================================
   橫屏模式優化
   ======================================== */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .chat-header {
        padding: 0.5rem 1rem;
        min-height: 45px;
    }
    
    .chat-content {
        padding: 0.75rem 1rem;
    }
    
    .chat-input-section {
        padding: 0.75rem 1rem;
    }
    
    .message-input {
        min-height: 35px;
        max-height: 80px;
    }
    
    .send-btn {
        width: 40px;
        height: 40px;
    }
}

/* ========================================
   深色模式支持
   ======================================== */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-color: #3498db;
        --secondary-color: #2980b9;
        --background-color: #1a1a1a;
        --card-background: #2c2c2c;
        --text-color: #ffffff;
        --light-text: #bdc3c7;
        --border-color: #404040;
        --hover-color: #3c3c3c;
    }
    
    .table-wrapper {
        background: #2c2c2c;
        border-color: #404040;
    }
    
    .markdown-table {
        background: #2c2c2c;
        color: #e0e0e0;
    }
    
    .markdown-table thead {
        background: linear-gradient(to bottom, #3c3c3c, #2c2c2c);
    }
    
    .markdown-table th {
        color: #ffffff;
        border-color: #404040;
        background: #3c3c3c;
    }
    
    .markdown-table td {
        color: #e0e0e0;
        border-color: #404040;
    }
    
    .markdown-table tbody tr:nth-child(even) {
        background-color: #333333;
    }
    
    .markdown-table tbody tr:hover {
        background-color: #3c3c3c;
    }
    
    .markdown-table code {
        background: #444;
        color: #ff79c6;
    }
    
    .code-block {
        border-color: #30363d;
        background: #0d1117;
    }
    
    .code-block .code-header {
        background: #161b22;
        border-bottom-color: #30363d;
    }
    
    .code-block .code-language {
        color: #8b949e;
    }
    
    .code-block .code-btn {
        background: #21262d;
        border-color: #30363d;
        color: #8b949e;
    }
    
    .code-block .code-btn:hover {
        background: #30363d;
        border-color: #8b949e;
    }
    
    .code-block .code-content {
        background: #0d1117;
    }
    
    .message.assistant code:not([class*="language-"]) {
        background: #444;
        color: #ff79c6;
    }
}

/* ========================================
   輔助功能支持
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --shadow-light: rgba(0, 0, 0, 0.3);
        --shadow-medium: rgba(0, 0, 0, 0.5);
    }
}

/* ========================================
   打印樣式
   ======================================== */
@media print {
    .sidebar,
    .chat-header,
    .chat-input-section,
    .message-actions,
    .code-block .code-actions,
    .mobile-menu-btn,
    .mobile-overlay {
        display: none !important;
    }
    
    .main-content {
        width: 100% !important;
        margin: 0 !important;
    }
    
    .chat-content {
        padding: 0;
        height: auto;
        overflow: visible;
    }
    
    .message {
        break-inside: avoid;
        margin-bottom: 1rem;
        max-width: 100%;
    }
    
    .code-block,
    .table-wrapper {
        break-inside: avoid;
    }
}

/* ========================================
   工具類
   ======================================== */
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 1rem; }

.text-small { font-size: 0.8rem; }
.text-large { font-size: 1.1rem; }
.text-bold { font-weight: 600; }
.text-center { text-align: center; }
.text-muted { color: var(--light-text); }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }

/* 清除浮動 */
.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

/* 隱藏元素但保留給屏幕閱讀器 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 防止文字選擇 */
.no-select {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}