/* ===== 全局变量 ===== */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --bg: #f8fafc;
    --bg-white: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
}

/* ===== 重置 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ===== 布局 ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

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

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.site-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.site-selector select {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg-white);
    min-width: 200px;
    cursor: pointer;
}

.main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===== 对话面板 ===== */
.chat-panel {
    width: 420px;
    min-width: 360px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-white);
}

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

/* 欢迎界面 */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 20px;
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.welcome-screen h2 {
    font-size: 22px;
    margin-bottom: 8px;
    color: var(--text);
}

.welcome-screen p {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 360px;
}

.quick-btn {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    transition: all .2s;
    color: var(--text);
}

.quick-btn:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

/* 消息气泡 */
.message {
    margin-bottom: 16px;
    animation: fadeIn .3s ease;
}

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

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

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

.message.user .message-avatar {
    background: #dbeafe;
}

.message.assistant .message-avatar {
    background: var(--primary-light);
}

.message-role {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

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

.message.user .message-body {
    background: var(--primary);
    color: white;
    margin-left: 36px;
}

.message.assistant .message-body {
    background: var(--bg);
    border: 1px solid var(--border-light);
    margin-left: 36px;
}

/* 操作标签 */
.action-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    margin-left: 36px;
}

.action-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.action-tag.create { background: #dcfce7; color: #166534; }
.action-tag.modify { background: #dbeafe; color: #1e40af; }
.action-tag.delete { background: #fee2e2; color: #991b1b; }

/* ===== 输入区 ===== */
.chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-white);
}

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

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

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    font-family: inherit;
    color: var(--text);
}

.chat-input::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all .2s;
}

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

.send-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
}

/* ===== 预览面板 ===== */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-white);
    min-width: 0;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    height: 44px;
    flex-shrink: 0;
}

.preview-tabs {
    display: flex;
    gap: 4px;
}

.tab {
    padding: 8px 14px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all .2s;
}

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

.tab.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}

.preview-actions {
    display: flex;
    gap: 8px;
}

.preview-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.tab-content {
    display: none;
    height: 100%;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* 预览框架 */
.preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 14px;
    gap: 8px;
}

/* 文件列表 */
.file-list {
    padding: 16px;
    overflow-y: auto;
    height: 100%;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all .2s;
}

.file-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.file-item-name {
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-item-size {
    font-size: 12px;
    color: var(--text-secondary);
}

/* 代码查看器 */
.code-viewer {
    height: 100%;
    overflow: auto;
    padding: 0;
}

.code-viewer pre {
    margin: 0;
    padding: 16px;
    font-size: 13px;
    line-height: 1.6;
    font-family: "SF Mono", "Fira Code", Consolas, monospace;
    white-space: pre-wrap;
    word-break: break-all;
    background: #1e293b;
    color: #e2e8f0;
    min-height: 100%;
}

.code-file-header {
    padding: 10px 16px;
    background: #0f172a;
    color: #94a3b8;
    font-size: 12px;
    font-family: monospace;
    border-bottom: 1px solid #334155;
    position: sticky;
    top: 0;
    z-index: 1;
}

/* ===== 按钮 ===== */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all .2s;
    text-decoration: none;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

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

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

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

.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
}

/* ===== 弹窗 ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.4);
}

.modal-content {
    position: relative;
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 24px;
    width: 420px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
}

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

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .2s;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--primary);
}

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

/* ===== Loading ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-spinner {
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin: 0 auto 12px;
}

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

.loading-spinner p {
    font-size: 14px;
    color: var(--text-secondary);
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .main {
        flex-direction: column;
    }

    .chat-panel {
        width: 100%;
        min-width: unset;
        height: 50%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .preview-panel {
        height: 50%;
    }

    .quick-actions {
        grid-template-columns: 1fr;
    }
}
