/* 全局样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #667eea;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-color: #f093fb;
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --background-primary: #f7fafc;
    --background-secondary: #edf2f7;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
}

/* 主容器 */
.chat-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    position: relative;
}

/* 应用整体布局与侧边栏 */
.app-shell {
    display: flex;
    height: 100vh;
    width: 100%;
}

.sidebar {
    width: 280px;
    background: white;
    border-right: 1px solid var(--border-color);
    padding: 0;
    box-shadow: var(--shadow-sm);
    transition: width 0.2s ease, transform 0.2s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100vh; /* 确保全屏高度 */
}

.sidebar.hidden {
    display: none;
}

.sidebar.collapsed {
    width: 56px;
}

.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .conversations-list {
    display: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--background-primary);
}

.sidebar-btn {
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.sidebar-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.sidebar .sidebar-title {
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    text-align: center;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* 顶部导航栏 */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.top-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-toggle {
    display: none; /* 默认隐藏，在移动端显示 */
}

.title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.title i {
    color: var(--primary-color);
    animation: heartbeat 2s ease-in-out infinite;
}

.controls,
.top-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    border-radius: var(--radius-lg);
    background: var(--background-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
}

.control-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
}

/* 设置面板 */
.settings-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.settings-panel.active {
    display: flex;
}

.settings-content {
    background: white;
    border-radius: var(--radius-xl);
    padding: 1rem;
    max-width: 28rem;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease-out;
    /* 自定义滚动条样式 */
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--background-secondary);
}

/* 为设置面板定制更美观的滚动条 */
.settings-content::-webkit-scrollbar {
    width: 8px;
}

.settings-content::-webkit-scrollbar-track {
    background: var(--background-secondary);
    border-radius: 4px;
    margin: 4px 0;
}

.settings-content::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--primary-color), #5a67d8);
    border-radius: 4px;
    transition: background 0.3s ease;
}

.settings-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #5a67d8, var(--primary-color));
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.settings-header h2 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 600;
}

.close-settings {
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: var(--radius-md);
    background: var(--background-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 1.25rem; /* 增加字体大小确保居中 */
    line-height: 1; /* 确保垂直居中 */
}

.close-settings:hover {
    background: #ef4444;
    color: white;
}

.settings-section {
    margin-bottom: 0.5rem;
}

.settings-section h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
    font-size: 1.125rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

/* 流式传输开关 */
.streaming-setting {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
    background: var(--background-primary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.switch {
    position: relative;
    width: 3rem;
    height: 1.5rem;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 1.5rem;
}

.slider:before {
    position: absolute;
    content: "";
    height: 1.125rem;
    width: 1.125rem;
    left: 0.1875rem;
    bottom: 0.1875rem;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(1.5rem);
}

.setting-label {
    font-weight: 500;
    color: var(--text-primary);
}

.setting-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* 角色和模型选择 */
.role-selection,
.model-selection {
    display: grid;
    gap: 0.75rem;
}

.role-option,
.model-option {
    display: block;
    cursor: pointer;
}

.role-option input,
.model-option input {
    display: none;
}

.role-label,
.model-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: white;
    transition: all 0.2s ease;
    color: var(--text-primary);
    font-weight: 500;
}

.role-option input:checked + .role-label,
.model-option input:checked + .model-label {
    border-color: var(--primary-color);
    background: rgba(102, 126, 234, 0.1);
    color: var(--primary-color);
    transform: translateY(-1px);
}

.role-label i {
    font-size: 1.25rem;
    color: var(--primary-color);
}

/* 模型参数设置样式 */
.parameter-setting {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--background-primary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.parameter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.parameter-value {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.875rem;
    background: white;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    min-width: 3rem;
    text-align: center;
}

.parameter-slider {
    width: 100%;
    height: 6px;
    background: var(--background-secondary);
    border-radius: 3px;
    outline: none;
    margin-bottom: 0.5rem;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.parameter-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.parameter-slider::-webkit-slider-thumb:hover {
    background: #5a67d8;
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.parameter-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.parameter-slider::-moz-range-thumb:hover {
    background: #5a67d8;
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.parameter-slider::-moz-range-track {
    height: 6px;
    background: var(--background-secondary);
    border-radius: 3px;
    border: none;
}

.parameter-actions {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.btn-secondary {
    background: var(--background-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.875rem;
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

/* 对话列表样式更新 */
.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    background: white;
}

.conversation-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    position: relative;
}

.conversation-item:hover {
    background: var(--background-primary);
    border-color: var(--border-color);
}

.conversation-item.active {
    background: rgba(102, 126, 234, 0.1);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.conversation-title {
    font-weight: 500;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 0.5rem;
}

.conversation-delete {
    width: 1.5rem;
    height: 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0;
    flex-shrink: 0;
}

.conversation-item:hover .conversation-delete {
    opacity: 1;
}

.conversation-delete:hover {
    background: #ef4444;
    color: white;
    transform: scale(1.1);
}

/* 聊天消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--background-primary);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.welcome-content i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
    animation: pulse 2s infinite;
}

.welcome-content p {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
}

/* 消息样式 */
.message {
    display: flex;
    gap: 0.75rem;
    max-width: 100%;
    animation: messageSlide 0.3s ease-out;
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    flex-shrink: 0;
    font-weight: 500;
}

.message.user .message-avatar {
    background: var(--primary-gradient);
    color: white;
}

.message.ai .message-avatar {
    background: var(--secondary-gradient);
    color: white;
}

.message-content {
    flex: 1;
    max-width: calc(100% - 3.25rem);
    padding: 0.875rem 1.125rem;
    border-radius: var(--radius-lg);
    position: relative;
    word-wrap: break-word;
    line-height: 1.6;
}

.message.user .message-content {
    background: var(--primary-gradient);
    color: white;
    border-bottom-right-radius: var(--radius-sm);
}

.message.ai .message-content {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-bottom-left-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.5rem;
}

.message.user .message-time {
    text-align: right;
}

/* 流式输出指示器 */
.streaming-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
    color: var(--primary-color);
    margin-top: 0.5rem;
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
}

.typing-dots span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--primary-color);
    animation: typingDots 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

/* 思考状态指示器 */
.thinking-indicator .message-content {
    background: linear-gradient(135deg, #f8f9ff 0%, #f0f4ff 100%);
    border: 2px solid var(--primary-color);
    position: relative;
}

.thinking-text {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    font-size: 0.9rem;
    color: var(--primary-color);
    font-weight: 500;
}

.thinking-icon {
    font-size: 1.2rem;
    animation: thinkingPulse 2s infinite ease-in-out;
}

.thinking-label {
    flex: 1;
    font-weight: 600;
}

.thinking-timer {
    font-size: 0.8rem;
    background: var(--primary-color);
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 1rem;
    font-weight: 600;
    min-width: 2rem;
    text-align: center;
}

.typing-cursor {
    display: inline-block;
    width: 2px;
    background-color: var(--primary-color);
    animation: cursorBlink 1s infinite;
    margin-left: 2px;
}

/* 输入区域 */
.input-area {
    padding: 1rem 1.5rem 1.5rem;
    background: white;
    border-top: 1px solid var(--border-color);
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--background-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-xl);
    transition: border-color 0.2s ease;
}

.input-container:focus-within {
    border-color: var(--primary-color);
}

#messageInput {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 1rem;
    line-height: 1.5;
    max-height: 8rem;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

.send-btn,
.stop-btn {
    width: 1.5rem;
    height: 1.5rem;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
    flex-shrink: 0;
}

.send-btn {
    background: var(--primary-gradient);
    color: white;
}

.send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.stop-btn {
    background: #ef4444;
    color: white;
    display: none;
}

.stop-btn:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 100%;
    animation: slideIn 0.3s ease-out;
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem;
    background: #fef2f2;
    color: #dc2626;
    border-bottom: 1px solid var(--border-color);
}

.modal-header i {
    font-size: 1.25rem;
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
}

.modal-body {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-primary);
    line-height: 1.6;
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    padding: 1.5rem;
    background: var(--background-primary);
}

.btn {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-cancel {
    background: white;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-cancel:hover {
    background: var(--background-secondary);
}

.btn-confirm {
    background: #ef4444;
    color: white;
}

.btn-confirm:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

/* 代码块样式 */
.message pre {
    background: var(--background-secondary);
    padding: 1rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 0.5rem 0;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
}

.message code {
    background: var(--background-secondary);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
}

.message pre code {
    background: transparent;
    padding: 0;
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar,
.conversations-list::-webkit-scrollbar,
.settings-content::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.conversations-list::-webkit-scrollbar-track,
.settings-content::-webkit-scrollbar-track {
    background: var(--background-secondary);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb,
.conversations-list::-webkit-scrollbar-thumb,
.settings-content::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.conversations-list::-webkit-scrollbar-thumb:hover,
.settings-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Toast 通知 */
.toast {
    position: fixed;
    top: 5rem;
    right: 1rem;
    background: white;
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    z-index: 3000;
    animation: toastSlide 0.3s ease-out;
}

/* 新的选择区域样式 */
.selection-area {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: white;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.selection-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.selection-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
}

.selection-dropdown {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: white;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.selection-dropdown:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.selection-dropdown:hover {
    border-color: var(--primary-color);
}

/* 动画效果 */
@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

@keyframes slideIn {
    from { transform: translateY(-1rem) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes messageSlide {
    from { transform: translateY(0.5rem); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes typingDots {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

@keyframes cursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@keyframes toastSlide {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes thinkingPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .chat-container {
        height: 100vh;
    }

    /* 为移动端优化整体布局 */
    body {
        padding: 0;
        margin: 0;
        overflow: hidden;
    }

    .app-shell {
        height: 100vh;
        /* 使用 100dvh 确保在移动端正确计算可视区域高度 */
        height: 100dvh;
        /* 移除之前的底部padding，让输入框直接贴底 */
    }

    .input-area {
        /* 移除底部padding/margin，让输入框紧贴屏幕底部 */
        padding: 0.75rem 1rem;
        margin: 0;
        /* 确保在最底层 */
        position: relative;
        z-index: 100;
        /* 添加顶部边框增加视觉分离 */
        border-top: 2px solid var(--border-color);
        /* 移动端输入框高度自适应 */
        min-height: auto;
    }

    .input-container {
        /* 优化输入框容器的padding */
        padding: 0.5rem 0.75rem;
        /* 减少边框宽度避免占用太多空间 */
        border: 1px solid var(--border-color);
        /* 确保圆角一致 */
        border-radius: var(--radius-lg);
    }

    #messageInput {
        /* 移动端输入框字体大小，防止iOS自动缩放 */
        font-size: 16px !important;
        /* 减少行高节省空间 */
        line-height: 1.4;
        /* 调整最大高度 */
        max-height: 100px;
        /* 移除默认的外边距 */
        margin: 0;
        padding: 0;
    }

    .top-bar {
        padding: 0.75rem 1rem;
        /* 减少顶部栏的高度占用 */
        min-height: auto;
    }

    .title {
        font-size: 1.125rem;
    }

    .controls,
    .top-actions {
        gap: 0.25rem;
    }

    .control-btn {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 0.875rem;
    }

    /* 在移动端显示侧边栏切换按钮 */
    .sidebar-toggle {
        display: flex !important;
    }

    .chat-messages {
        padding: 0.75rem;
        gap: 0.75rem;
        /* 优化聊天消息区域的底部空间，为输入框留出位置 */
        padding-bottom: 1rem;
        /* 确保消息区域不会与输入框重叠 */
        margin-bottom: 0;
        /* 使用flex-grow确保充分利用空间 */
        flex: 1;
        /* 确保可以正确滚动 */
        overflow-y: auto;
        /* 平滑滚动 */
        scroll-behavior: smooth;
    }

    /* 优化消息样式 */
    .message-content {
        max-width: calc(100% - 2.75rem);
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .message-avatar {
        width: 2rem;
        height: 2rem;
        font-size: 1rem;
    }

    .send-btn,
    .stop-btn {
        width: 1.5rem;
        height: 1.5rem;
        font-size: 0.875rem;
    }

    .settings-content {
        padding: 1.5rem;
        margin: 0.5rem;
        /* 确保设置面板在移动端也不会被键盘遮挡 */
        max-height: calc(100vh - 2rem);
        max-height: calc(100dvh - 2rem);
    }

    .welcome-content {
        padding: 2rem 1rem;
    }

    .welcome-content i {
        font-size: 2.5rem;
    }

    .welcome-content p {
        font-size: 1rem;
    }

    /* 移动端侧边栏 - 修复z-index和定位 */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        z-index: 1300; /* 提高z-index确保在最上层 */
        height: 100vh;
        height: 100dvh;
        width: 280px;
        max-width: 85vw; /* 确保不超过屏幕宽度的85% */
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.active {
        left: 0;
    }

    /* 移动端不使用collapsed状态，直接隐藏 */
    .sidebar.collapsed {
        left: -100%;
    }

    .main-area {
        margin-left: 0;
        width: 100%;
        /* 确保主区域使用全部可用高度 */
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
    }

    .selection-area {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem 1rem;
    }

    .selection-group {
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
    }

    .selection-label {
        font-size: 0.8125rem;
    }

    .selection-dropdown {
        font-size: 0.8125rem;
    }

    /* 遮罩层样式 */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1250; /* 在侧边栏下方但在主内容上方 */
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    /* 修复虚拟键盘弹出时的布局问题 */
    .app-shell {
        /* 当虚拟键盘弹出时，浏览器会调整视口，我们确保布局能够适应 */
        position: relative;
    }

    /* 输入获得焦点时的优化 */
    #messageInput:focus {
        /* 防止iOS Safari在输入时页面跳动 */
        transform: translateZ(0);
    }
}

@media (max-width: 480px) {
    .message-content {
        max-width: calc(100% - 2.5rem);
        padding: 0.625rem 0.875rem;
        font-size: 0.875rem;
    }

    .message-avatar {
        width: 1.75rem;
        height: 1.75rem;
        font-size: 0.875rem;
    }

    .settings-content {
        padding: 1rem;
        margin: 0.25rem;
    }

    .modal-content {
        margin: 1rem;
    }

    .chat-messages {
        padding: 0.5rem;
    }

    .selection-area {
        padding: 0.5rem;
    }

    .input-container {
        padding: 0.4rem 0.6rem;
    }

    .input-area {
        padding: 0.5rem 0.75rem;
    }
}
