:root {
    --bg-color: #1e1e24;
    --panel-bg: #2b2b36;
    --text-color: #f1f1f1;
    --primary-color: #5c6bc0;
    --primary-hover: #3f51b5;
    --border-color: #444;
    --chat-user-bg: #4a5c9a;
    --chat-ai-bg: #353545;
    --font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: 60px;
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 10;
}

.logo {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.header-actions button {
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.header-actions button:hover {
    background-color: var(--border-color);
}

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: var(--panel-bg);
    padding: 25px;
    border-radius: 8px;
    width: 400px;
    max-width: 90%;
    position: relative;
    border: 1px solid var(--border-color);
}

.modal-large {
    width: 80%;
    max-width: 1000px;
}

.two-column-form {
    display: flex;
    gap: 30px;
    margin-bottom: 20px;
}
.form-col {
    flex: 1;
    background: rgba(0,0,0,0.2);
    padding: 15px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.form-col h3 {
    margin-bottom: 10px;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    cursor: pointer;
    font-size: 1.5rem;
    transition: 0.3s;
}

.close-btn:hover { color: red; }

.form-group {
    margin: 15px 0;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
    color: #ccc;
}

.form-group input {
    width: 100%;
    padding: 10px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 4px;
}

.primary-btn {
    background-color: var(--primary-color);
    color: #fff;
    border: none;
    padding: 10px 15px;
    width: 100%;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s;
}

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

textarea#source-code {
    width: 100%;
    height: 400px;
    background: var(--bg-color);
    color: #0f0;
    font-family: 'Courier New', Courier, monospace;
    padding: 15px;
    border: 1px solid var(--border-color);
    margin: 15px 0;
    resize: vertical;
}

/* Layout */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left: Chat */
.chat-section {
    width: 35%;
    min-width: 300px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background-color: var(--panel-bg);
}

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

.status-indicator {
    font-size: 0.8rem;
    padding: 3px 8px;
    border-radius: 10px;
}

.status-indicator.disconnected { background: #555; color: #fff; }
.status-indicator.ready { background: #4caf50; color: #fff; }

.chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    padding: 10px 15px;
    border-radius: 8px;
    max-width: 90%;
    line-height: 1.4;
    word-break: break-word;
}

.message.system {
    background-color: #2e2e38;
    color: #bbb;
    align-self: center;
    text-align: center;
    font-size: 0.9rem;
    border: 1px dashed var(--border-color);
}

.message.user {
    background-color: var(--chat-user-bg);
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}
.message.ai {
background-color: var(--chat-ai-bg);
align-self: flex-start;
border-bottom-left-radius: 2px;
border: 1px solid #444;
}

.msg-actions {
    margin-top: 8px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    font-size: 0.8rem;
    opacity: 0.7;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 5px;
}

.msg-actions span {
    cursor: pointer;
    transition: 0.2s;
}

.msg-actions span:hover {
    opacity: 1;
    color: #4bd8c8;
    text-decoration: underline;
}

/* 底部功能栏 */
.chat-input-area {
    padding: 15px;
    background-color: var(--bg-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input-area textarea {
    flex: 1;
    background: var(--panel-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 10px;
    resize: none;
    height: 60px;
    font-family: inherit;
    outline: none;
}

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

.chat-input-area button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.3s;
}

.chat-input-area button:hover {
    background-color: var(--primary-hover);
}

.chat-input-area button:disabled {
    background-color: #555;
    cursor: not-allowed;
}

/* 魔法渲染聊天窗全屏覆盖 */
.chat-section.fullscreen-chat {
    width: 100%;
    min-width: 100%;
    border-right: none;
    background: transparent; /* 为了能够让AI输出动态背景穿透 */
    display: flex;
    flex-direction: column;
    z-index: 1; /* 内容始终要在最前层 */
}

/* UI气泡的底层隔离 */
.chat-header, .chat-input-area {
    background-color: var(--panel-bg);
    z-index: 10;
}

.chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    position: relative;
    /* 让对话区域有一层很淡的黑色罩着避免字体看不清 */
    background: rgba(30, 30, 36, 0.4); 
}

/* 强行使所有用户气泡与AI内容组件拥有高渲染权重 */
.message {
    z-index: 5;
    position: relative;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.ai-code-render-box {
    margin-top: 10px;
    width: 100%;
    min-height: 50px;
    padding: 10px;
    border: 1px dashed var(--primary-color);
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.05); /* 让AI插入的原生HTML保持隔离又可以交互 */
    overflow: hidden;
    position: relative;
    z-index: 2; /* 确保在这个页面内的控件不遮挡对话框自己 */
}

/* Loading Overlay 在对话流中的小气泡样式 */
.loading-bubble {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--chat-ai-bg);
    padding: 10px 15px;
    border-radius: 8px;
    color: #fff;
    margin-top: 5px;
}
.loading-bubble.hidden {
    display: none !important;
}

.spinner-small {
    border: 2px solid rgba(255,255,255,0.2);
    width: 20px; height: 20px;
    border-radius: 50%;
    border-left-color: var(--primary-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@media (max-width: 800px) {
    .app-header {
        flex-direction: column;
        height: auto;
        padding: 10px;
        gap: 10px;
    }
    .header-actions {
        justify-content: center;
    }
    .header-actions button {
        flex: 1;
        min-width: 30%;
    }
    .chat-header h3 { font-size: 1rem; }
    .chat-input-area { padding: 10px; }
}
