/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #0f0f0f;
    color: #e0e0e0;
    overflow: hidden;
}

.page {
    width: 100%;
    height: 100vh;
}

/* 登录页面 */
#loginPage {
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.login-container {
    background: #1e1e1e;
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    width: 90%;
    max-width: 360px;
}

.login-container h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #4a9eff;
    font-size: 1.8rem;
}

.login-container input {
    width: 100%;
    padding: 0.875rem;
    margin-bottom: 1rem;
    border: 2px solid #333;
    border-radius: 8px;
    background: #2a2a2a;
    color: #e0e0e0;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.login-container input:focus {
    outline: none;
    border-color: #4a9eff;
}

.login-container button {
    width: 100%;
    padding: 0.875rem;
    background: #4a9eff;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.login-container button:hover {
    background: #357abd;
}

.error-message {
    color: #ff6b6b;
    text-align: center;
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* 聊天页面布局 */
#chatPage {
    display: grid;
    grid-template-rows: auto 1fr;
    grid-template-columns: auto 1fr;
    height: 100vh;
    height: 100dvh; /* 适配移动端动态高度 */
}

/* 顶部栏 */
.header {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: #1e1e1e;
    border-bottom: 1px solid #333;
    height: 56px;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header h1 {
    font-size: 1.2rem;
    color: #4a9eff;
}

.icon-btn {
    background: #2a2a2a;
    border: none;
    padding: 0.5rem 0.875rem;
    border-radius: 6px;
    color: #e0e0e0;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background 0.3s;
}

.icon-btn:hover {
    background: #3a3a3a;
}

.model-select {
    padding: 0.5rem 0.75rem;
    background: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    max-width: 200px;
}

/* 侧边栏 */
.sidebar {
    grid-row: 2;
    grid-column: 1;
    width: 280px;
    background: #1a1a1a;
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar.hidden {
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid #333;
}

.sidebar-header h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: #b0b0b0;
}

.new-chat-btn {
    width: 100%;
    padding: 0.625rem;
    background: #4a9eff;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.new-chat-btn:hover {
    background: #357abd;
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.session-item {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: #252525;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s;
    position: relative;
}

.session-item:hover {
    background: #2e2e2e;
}

.session-item.active {
    background: #4a9eff;
    color: white;
}

.session-item-title {
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-item-meta {
    font-size: 0.75rem;
    color: #888;
    display: flex;
    justify-content: space-between;
}

.session-item.active .session-item-meta {
    color: rgba(255, 255, 255, 0.7);
}

.session-delete {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: #ff4444;
    border: none;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.3s;
}

.session-item:hover .session-delete {
    opacity: 1;
}

/* 聊天区域 */
.chat-container {
    grid-row: 2;
    grid-column: 2;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    scroll-behavior: smooth;
    min-height: 0;
}

.welcome-message {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.welcome-message h2 {
    margin-bottom: 0.5rem;
    color: #888;
}

.message {
    margin-bottom: 1.5rem;
    display: flex;
    gap: 0.75rem;
    animation: fadeIn 0.3s ease;
}

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

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

.message.user .message-avatar {
    background: #4a9eff;
}

.message.assistant .message-avatar {
    background: #2ecc71;
}

.message-content {
    flex: 1;
    background: #252525;
    padding: 0.875rem 1rem;
    border-radius: 12px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user .message-content {
    background: #4a9eff;
    color: white;
}

/* Markdown 样式 */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.message-content h1 { font-size: 1.5rem; }
.message-content h2 { font-size: 1.3rem; }
.message-content h3 { font-size: 1.1rem; }

.message-content p {
    margin-bottom: 0.75rem;
}

.message-content code {
    background: #1a1a1a;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message.user .message-content code {
    background: rgba(0, 0, 0, 0.2);
}

.message-content pre {
    background: #1a1a1a;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.75rem 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content ul,
.message-content ol {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.message-content blockquote {
    border-left: 3px solid #4a9eff;
    padding-left: 1rem;
    margin: 0.75rem 0;
    color: #aaa;
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75rem 0;
}

.message-content th,
.message-content td {
    border: 1px solid #444;
    padding: 0.5rem;
    text-align: left;
}

.message-content th {
    background: #2a2a2a;
}

/* LaTeX 样式 */
.katex {
    font-size: 1.1em;
}

.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
}

/* 输入区域 */
.input-container {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    background: #1e1e1e;
    border-top: 1px solid #333;
}

#messageInput {
    flex: 1;
    padding: 0.875rem;
    background: #2a2a2a;
    border: 2px solid #444;
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.4;
}

#messageInput:focus {
    outline: none;
    border-color: #4a9eff;
}

.send-btn {
    padding: 0.875rem 1.5rem;
    background: #4a9eff;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
    white-space: nowrap;
}

.send-btn:hover:not(:disabled) {
    background: #357abd;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.loading-indicator {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #2a2a2a;
    padding: 0.75rem 1.5rem;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #666;
    border-top-color: #4a9eff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 响应式设计 - 小屏幕适配 (Apple Watch, 手机等) */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        z-index: 100;
        height: calc(100vh - 56px);
        transform: translateX(-100%);
    }
    
    .sidebar.visible {
        transform: translateX(0);
    }
    
    .chat-container {
        grid-column: 1 / -1;
    }
    
    .header h1 {
        font-size: 1rem;
    }
    
    .model-select {
        font-size: 0.8rem;
        max-width: 120px;
    }
}

@media (max-width: 320px) {
    /* Apple Watch 和极小屏幕优化 */
    .header {
        padding: 0.5rem;
        height: 48px;
    }
    
    .header h1 {
        font-size: 0.9rem;
    }
    
    .icon-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.9rem;
    }
    
    .model-select {
        font-size: 0.75rem;
        padding: 0.4rem;
        max-width: 100px;
    }
    
    .messages {
        padding: 0.75rem;
    }
    
    .message {
        gap: 0.5rem;
        margin-bottom: 1rem;
    }
    
    .message-avatar {
        width: 24px;
        height: 24px;
        font-size: 0.9rem;
    }
    
    .message-content {
        padding: 0.625rem;
        font-size: 0.875rem;
    }
    
    .input-container {
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    #messageInput {
        padding: 0.625rem;
        font-size: 0.875rem;
    }
    
    .send-btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
    }
    
    .sidebar {
        width: 100%;
    }
    
    .login-container {
        padding: 1.5rem;
    }
    
    .login-container h1 {
        font-size: 1.5rem;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #1a1a1a;
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}
