/* AI 编程助手 - 样式表 */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-input: #0f1629;
    --accent: #e94560;
    --accent-hover: #c23152;
    --text-primary: #e0e0e0;
    --text-secondary: #999;
    --border: #0f3460;
    --success: #2ecc71;
    --warning: #f39c12;
    --radius: 10px;
    --sidebar-width: 260px;
    --header-height: 48px;
    --timeline-width: 200px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

/* ========== 左侧项目列表 ========== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header .logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

.project-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.project-item {
    padding: 12px;
    margin: 2px 0;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.project-item:hover {
    background: rgba(233, 69, 96, 0.1);
}

.project-item.active {
    background: rgba(233, 69, 96, 0.2);
    border: 1px solid var(--accent);
}

.project-item .proj-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.project-item .proj-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

/* ========== 主内容区 ========== */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* 顶部栏 */
.topbar {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    flex-shrink: 0;
}

.topbar .current-project {
    font-size: 14px;
    font-weight: 600;
    margin-left: 4px;
    color: var(--text-primary);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar .spacer {
    flex: 1;
}

.topbar .topbar-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.2s;
    margin-left: 8px;
}

.topbar .topbar-btn:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
}

.topbar .topbar-btn.new-project {
    margin-right: 16px;
}

/* 聊天区 */
.chat-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    scroll-behavior: smooth;
}

.message {
    margin-bottom: 24px;
    display: flex;
    gap: 12px;
    max-width: 900px;
    width: 100%;
}

.message.user {
    flex-direction: row-reverse;
    margin-left: auto;
}

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

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

.ai .avatar {
    background: var(--border);
}

.msg-content {
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.7;
    word-break: break-word;
    flex: 1;
    min-width: 0;
}

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

.msg-content p {
    margin: 4px 0;
}

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

/* 代码块 */
.code-block-wrapper {
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #0d1117;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #161b22;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
}

.code-block-header .lang-tag {
    font-weight: 600;
    color: var(--accent);
}

.code-block-header .code-actions {
    display: flex;
    gap: 8px;
}

.code-block-header button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.code-block-header button:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
}

.code-block-body {
    padding: 12px 16px;
    overflow-x: auto;
    max-height: 300px;
    transition: max-height 0.3s;
}

.code-block-body.expanded {
    max-height: none;
}

.code-block-body pre {
    margin: 0;
    font-family: "Consolas", "Monaco", "Courier New", monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre;
}

code {
    font-family: "Consolas", "Monaco", "Courier New", monospace;
    font-size: 13px;
    background: rgba(255,255,255,0.06);
    padding: 2px 6px;
    border-radius: 4px;
}

pre code {
    background: none;
    padding: 0;
}

/* 输入区 */
.input-area {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

.input-area textarea {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 8px;
    resize: none;
    height: 44px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

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

.input-area .action-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.input-area .action-btn:hover {
    background: rgba(233, 69, 96, 0.1);
    color: var(--accent);
    border-color: var(--accent);
}

.input-area .send-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0 20px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.input-area .send-btn:hover {
    background: var(--accent-hover);
}

.input-area .send-btn:disabled {
    background: #555;
    cursor: not-allowed;
}

/* 右侧时间轴 */
.timeline {
    width: var(--timeline-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    padding: 12px 8px;
    overflow-y: auto;
    flex-shrink: 0;
}

.timeline h4 {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding: 0 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.timeline-item {
    padding: 8px 10px;
    margin: 2px 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-left: 2px solid transparent;
}

.timeline-item:hover {
    background: rgba(255,255,255,0.04);
    color: var(--text-primary);
}

.timeline-item.active {
    background: rgba(233, 69, 96, 0.1);
    border-left-color: var(--accent);
    color: var(--accent);
}

.timeline-item .tl-role {
    font-weight: 600;
    margin-right: 4px;
}

/* 弹窗/设置面板 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h3 {
    margin-bottom: 16px;
    color: var(--accent);
}

.modal label {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--text-secondary);
}

.modal input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 14px;
    outline: none;
}

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

.modal .modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.modal button {
    padding: 8px 20px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.modal .btn-save {
    background: var(--accent);
    color: white;
}

.modal .btn-cancel {
    background: #333;
    color: var(--text-primary);
}

/* 图片预览 */
.img-preview {
    max-width: 200px;
    max-height: 40px;
    border-radius: 4px;
    vertical-align: middle;
}

/* 流式光标 */
.cursor-blink {
    display: inline-block;
    width: 2px;
    height: 16px;
    background: var(--accent);
    animation: blink 0.8s infinite;
    vertical-align: text-bottom;
    margin-left: 2px;
}

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

/* 加载动画 */
.loading-dots {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: bounce 1.4s infinite both;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 100;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .timeline {
        display: none;
    }
    
    .chat-messages {
        padding: 12px;
    }
    
    .msg-content {
        max-width: 100%;
    }
    
    .topbar .current-project {
        max-width: 150px;
    }
    
    .modal {
        width: 95%;
        padding: 16px;
    }
}

@media (max-width: 1024px) {
    .timeline {
        width: 160px;
    }
}

/* 滚动条 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

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

/* 复制成功提示 */
.copy-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: white;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 2000;
    animation: fadeInOut 2s ease;
}

@keyframes fadeInOut {
    0% { opacity: 0; top: 10px; }
    15% { opacity: 1; top: 20px; }
    85% { opacity: 1; top: 20px; }
    100% { opacity: 0; top: 10px; }
}

/* 工具栏 */
.toolbar {
    padding: 4px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 6px;
    align-items: center;
}

.toolbar-btn {
    background: var(--border);
    border: none;
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

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