/* ===== 基础样式 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f9f9f9;
    --bg-sidebar: #f5f5f5;
    --text-primary: #111111;
    --text-secondary: #6b7280;
    --border-color: #e5e5e5;
    --accent-color: #d97757;
    --accent-hover: #c46a4a;
    --user-bg: #f0f0f0;
    --assistant-bg: #ffffff;
    --error-color: #ef4444;
    --success-color: #22c55e;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

/* ===== 登录页面 ===== */
.login-page {
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-box {
    background: white;
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
}

.logo h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.input-group {
    display: flex;
    gap: 8px;
}

.input-group input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus {
    border-color: var(--accent-color);
}

.btn-primary {
    padding: 12px 24px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.error-message {
    color: var(--error-color);
    font-size: 13px;
    margin-top: 12px;
    min-height: 20px;
}

/* ===== 主应用布局 ===== */
.app-container {
    display: flex;
    height: 100vh;
}

/* ===== 侧边栏 ===== */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 16px;
}

.sidebar-header {
    margin-bottom: 12px;
}

.sidebar-header .logo {
    justify-content: flex-start;
    margin-bottom: 0;
}

.sidebar-header .logo span {
    font-size: 18px;
    font-weight: 600;
}

/* 项目信息 */
.project-info {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.current-project {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.project-type {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.project-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 操作按钮 */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.btn-new-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-new-chat:hover {
    background: var(--bg-secondary);
    border-color: var(--text-secondary);
}

.btn-new-chat.temp {
    background: #fef3e2;
    border-color: #f59e0b;
    color: #92400e;
}

.btn-new-chat.temp:hover {
    background: #fde68a;
}

/* 项目列表 */
.projects-section {
    flex: 1;
    overflow-y: auto;
}

.projects-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding: 0 8px;
}

.projects-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.project-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.project-item:hover {
    background: var(--bg-secondary);
}

.project-item.active {
    background: white;
    border: 1px solid var(--accent-color);
}

.project-item-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.project-item-icon.temp {
    color: #f59e0b;
}

.project-item-info {
    flex: 1;
    min-width: 0;
}

.project-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-item-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

.project-item-delete {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.2s;
}

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

.project-item-delete:hover {
    background: var(--error-color);
    color: white;
}

/* 项目横幅 */
.project-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #fef3e2;
    border-bottom: 1px solid #f59e0b;
    font-size: 13px;
}

.project-banner.project {
    background: #e0f2fe;
    border-bottom-color: #0ea5e9;
}

.badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    background: #f59e0b;
    color: white;
}

.project-banner.project .badge {
    background: #0ea5e9;
}

.expiry-hint {
    color: var(--text-secondary);
    font-size: 11px;
    margin-left: auto;
}

.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
}

.status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 0 8px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success-color);
}

.status-dot.connecting {
    background: #f59e0b;
    animation: pulse 1.5s infinite;
}

.status-dot.error {
    background: var(--error-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.btn-logout {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: var(--error-color);
    color: white;
    border-color: var(--error-color);
}

/* ===== 聊天区域 ===== */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

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

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

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

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.assistant-avatar {
    background: transparent;
}

.message-content {
    background: var(--user-bg);
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

.user-message .message-content {
    background: var(--accent-color);
    color: white;
    border-radius: 16px 16px 4px 16px;
}

.assistant-message .message-content {
    background: var(--assistant-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px 16px 16px 4px;
}

.message-content p {
    margin-bottom: 8px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content pre {
    background: #f4f4f4;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-content code {
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

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

/* 打字动画 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator 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);
    padding: 16px 20px;
    background: var(--bg-primary);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px 12px;
}

.input-wrapper:focus-within {
    border-color: var(--accent-color);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 14px;
    line-height: 1.5;
    max-height: 150px;
    min-height: 24px;
    outline: none;
    font-family: inherit;
}

.btn-send {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: var(--accent-hover);
}

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

.input-hint {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* ===== 弹窗样式 ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-content h3 {
    margin-bottom: 16px;
    font-size: 18px;
}

.modal-content input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.modal-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-secondary {
    padding: 10px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--bg-secondary);
}

/* ===== 响应式设计 ===== */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .message {
        max-width: 90%;
    }
}

/* ===== Markdown 样式 ===== */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    margin: 16px 0 8px;
    font-weight: 600;
}

.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

.message-content blockquote {
    border-left: 3px solid var(--accent-color);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
}

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

.message-content th,
.message-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.message-content th {
    background: var(--bg-secondary);
    font-weight: 600;
}
