* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #334155;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: 280px;
    background: var(--surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.sidebar-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.btn-new-chat {
    padding: 8px 12px;
    font-size: 13px;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* 对话列表 */
.conversations-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.conversation-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: left;
    width: 100%;
    position: relative;
    group: conversation-item;
}

.conversation-item:hover {
    background: var(--surface-light);
}

.conversation-item.active {
    background: var(--primary-color);
    color: white;
}

.conversation-item-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.conversation-item-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 12px;
    opacity: 0.7;
}

.conversation-item-model {
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    font-size: 11px;
}

.conversation-item.active .conversation-item-model {
    background: rgba(255, 255, 255, 0.2);
}

.conversation-item-time {
    font-size: 12px;
}

.empty-conversations {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

.conversation-item-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.conversation-item:hover .conversation-item-actions {
    opacity: 1;
}

.conversation-item.active .conversation-item-actions {
    opacity: 1;
}

.conversation-delete-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    transition: all 0.2s;
}

.conversation-delete-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.conversation-delete-btn svg {
    width: 14px;
    height: 14px;
}

.model-selector {
    margin-bottom: 8px;
}

.model-selector label {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.select-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.select-input:hover {
    border-color: var(--primary-color);
}

.select-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    border-color: var(--primary-color);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 主内容区 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.welcome-message h2 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.message {
    display: flex;
    gap: 12px;
    padding: 16px;
    border-radius: 12px;
    max-width: 85%;
    animation: fadeIn 0.3s ease-in;
    word-wrap: break-word;
    overflow-wrap: break-word;
}


@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-user {
    align-self: flex-end;
    background: var(--primary-color);
    color: white;
    margin-left: auto;
}

.message-assistant {
    align-self: flex-start;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.message-user .message-avatar {
    background: rgba(255, 255, 255, 0.2);
}

.message-assistant .message-avatar {
    background: var(--primary-color);
    color: white;
}

.message-content {
    flex: 1;
    line-height: 1.6;
    word-wrap: break-word;
}

.message-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-text code.inline-code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-user .message-text code.inline-code {
    background: rgba(255, 255, 255, 0.2);
}

/* 代码块样式 */
.code-block-wrapper {
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
}

.message-user .code-block-wrapper {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.code-block-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.message-user .code-block-header {
    background: rgba(255, 255, 255, 0.05);
}

.code-language {
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 11px;
}

.code-copy-btn,
.code-toggle-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    transition: all 0.2s;
    white-space: nowrap;
}

.code-copy-btn:hover,
.code-toggle-btn:hover {
    background: var(--surface-light);
    color: var(--text-primary);
}

.code-copy-btn.copied {
    color: var(--success);
}

.code-copy-btn.copied .code-copy-text::after {
    content: '✓';
    margin-left: 2px;
}

.code-toggle-icon {
    transition: transform 0.2s;
    width: 14px;
    height: 14px;
}

.code-block-content {
    overflow-x: auto;
    background: #0d1117;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.code-block-content pre {
    margin: 0;
    padding: 16px;
    background: transparent;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    word-wrap: normal;
    word-break: normal;
}

.code-block-content code {
    font-family: 'Fira Code', 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    color: #c9d1d9;
    display: block;
    white-space: pre;
    word-wrap: normal;
    word-break: normal;
    overflow-wrap: normal;
    max-width: 100%;
}

.code-block-content.hljs {
    background: #0d1117;
}

/* 确保代码高亮样式正确 */
.code-block-content .hljs {
    background: #0d1117 !important;
    padding: 16px;
}

.message-meta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    opacity: 0.8;
    font-family: 'Courier New', monospace;
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
}

.message-user .message-meta {
    text-align: right;
}

.message-loading {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.message-loading span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: bounce 1.4s infinite ease-in-out;
}

.message-loading span:nth-child(1) {
    animation-delay: -0.32s;
}

.message-loading span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* 输入区 */
.input-container {
    border-top: 1px solid var(--border-color);
    background: var(--surface);
    padding: 16px 24px;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    resize: none;
    max-height: 200px;
    overflow-y: auto;
    font-family: inherit;
    line-height: 1.5;
}

.message-input:focus {
    outline: none;
}

.message-input::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-footer {
    margin-top: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-text {
    font-size: 12px;
    color: var(--text-secondary);
}

/* 文件上传和预览 */
.file-preview-container {
    padding: 12px 24px 0;
    border-bottom: 1px solid var(--border-color);
}

.file-preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.file-preview-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
}

.file-preview-item img,
.file-preview-item video {
    display: block;
    max-width: 120px;
    max-height: 120px;
    width: auto;
    height: auto;
    object-fit: cover;
}

.file-preview-item .file-info {
    padding: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-preview-item .file-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
}

.file-preview-item .file-remove:hover {
    background: rgba(220, 38, 38, 0.8);
    transform: scale(1.1);
}

.attach-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.attach-btn:hover {
    background: var(--surface-light);
    color: var(--primary-color);
}

.attach-btn:active {
    transform: scale(0.95);
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px var(--shadow);
    border: 1px solid var(--border-color);
}

.modal-small {
    max-width: 400px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--surface-light);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.model-list {
    margin-bottom: 24px;
}

.model-item {
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.model-item-info h3 {
    font-size: 16px;
    margin-bottom: 4px;
}

.model-item-info p {
    font-size: 12px;
    color: var(--text-secondary);
}

.model-item-actions {
    display: flex;
    gap: 8px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* 响应式设计 */
@media (max-width: 768px) {
    body {
        height: 100vh;
        height: 100dvh; /* 支持动态视口高度 */
    }
    
    .container {
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
    }
    
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 200px;
        min-height: 200px;
        overflow-y: auto;
        padding: 12px;
        flex-shrink: 0;
    }
    
    .sidebar-header {
        flex-wrap: wrap;
        margin-bottom: 12px;
    }
    
    .sidebar-header h1 {
        font-size: 20px;
    }
    
    .btn-new-chat {
        width: 100%;
        margin-top: 8px;
        padding: 10px 12px;
        font-size: 14px;
    }
    
    .conversation-item {
        padding: 10px;
    }
    
    .conversation-item-title {
        font-size: 14px;
    }
    
    .conversation-item-meta {
        font-size: 11px;
    }
    
    .main-content {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }
    
    .messages-container {
        flex: 1;
        padding: 16px 12px;
        gap: 12px;
        min-height: 0;
    }
    
    .message {
        max-width: 90%;
        padding: 12px 14px;
        gap: 8px;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .message-content {
        font-size: 15px;
        line-height: 1.5;
    }
    
    .message-text {
        font-size: 15px;
    }
    
    .message-meta {
        font-size: 10px;
        margin-bottom: 6px;
        padding-bottom: 6px;
        word-break: break-all;
        line-height: 1.3;
    }
    
    .input-container {
        padding: 12px;
        flex-shrink: 0;
    }
    
    .input-wrapper {
        padding: 10px;
        gap: 8px;
    }
    
    .message-input {
        font-size: 16px; /* 防止iOS自动缩放 */
        line-height: 1.4;
    }
    
    .attach-btn {
        width: 36px;
        height: 36px;
    }
    
    .send-btn {
        width: 36px;
        height: 36px;
    }
    
    .input-footer {
        margin-top: 6px;
    }
    
    .status-text {
        font-size: 11px;
    }
    
    .file-preview-container {
        padding: 8px 12px 0;
    }
    
    .file-preview-item {
        max-width: 100px;
        max-height: 100px;
    }
    
    .file-preview-item img,
    .file-preview-item video {
        max-width: 100px;
        max-height: 100px;
    }
    
    .code-block-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 10px;
    }
    
    .code-block-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .code-block-content {
        font-size: 12px;
    }
    
    .code-block-content pre {
        padding: 10px;
    }
    
    .code-block-content code {
        font-size: 12px;
    }
    
    .welcome-message {
        padding: 20px;
    }
    
    .welcome-icon {
        font-size: 48px;
    }
    
    .welcome-message h2 {
        font-size: 20px;
    }
    
    .welcome-message p {
        font-size: 14px;
    }
}

/* 小屏幕手机优化 */
@media (max-width: 480px) {
    .sidebar {
        max-height: 180px;
        min-height: 180px;
        padding: 10px;
    }
    
    .sidebar-header h1 {
        font-size: 18px;
    }
    
    .messages-container {
        padding: 12px 10px;
        gap: 10px;
    }
    
    .message {
        max-width: 92%;
        padding: 10px 12px;
    }
    
    .message-avatar {
        width: 24px;
        height: 24px;
        font-size: 11px;
    }
    
    .message-content {
        font-size: 14px;
    }
    
    .message-text {
        font-size: 14px;
    }
    
    .input-container {
        padding: 10px;
    }
    
    .input-wrapper {
        padding: 8px;
    }
    
    .message-input {
        font-size: 16px;
    }
}

