:root {
    --sidebar-bg: #0f0f1a;
    --sidebar-hover: #1a1a2e;
    --sidebar-active: #252540;
    --sidebar-text: #a0a0b8;
    --sidebar-width: 280px;
    --main-bg: #f7f7f8;
    --chat-bg: #ffffff;
    --user-msg-bg: #f0f0f5;
    --ai-msg-bg: #ffffff;
    --border-color: #e5e5ea;
    --text-primary: #1a1a2e;
    --text-secondary: #6b6b80;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --danger: #ef4444;
    --code-bg: #1e1e2e;
    --input-bg: #ffffff;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

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

body.ai-studio-page {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    height: 100vh;
    overflow: hidden;
    background: var(--main-bg);
    color: var(--text-primary);
}

/* ===== LAYOUT ===== */
.ai-studio {
    display: flex;
    height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    text-decoration: none;
}

.sidebar-brand i { color: var(--accent); font-size: 22px; }
.sidebar-brand span { color: var(--accent); }

.new-chat-btn {
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}
.new-chat-btn:hover { background: var(--sidebar-hover); }
.new-chat-btn i { font-size: 13px; }

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

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.chat-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 2px;
    transition: background 0.2s;
    position: relative;
}
.chat-item:hover { background: var(--sidebar-hover); }
.chat-item.active { background: var(--sidebar-active); }

.chat-item-icon { color: var(--sidebar-text); font-size: 14px; flex-shrink: 0; }

.chat-item-title {
    flex: 1;
    font-size: 13px;
    color: var(--sidebar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-item.active .chat-item-title { color: #fff; }

.chat-item-delete {
    display: none;
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 4px;
    font-size: 12px;
    border-radius: 4px;
    flex-shrink: 0;
}
.chat-item:hover .chat-item-delete { display: block; }
.chat-item-delete:hover { color: var(--danger); background: rgba(239,68,68,0.15); }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-footer-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    transition: background 0.2s;
}
.sidebar-footer-link:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-footer-link i { width: 18px; text-align: center; }

/* ===== MAIN CHAT AREA ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.chat-topbar {
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--chat-bg);
    flex-shrink: 0;
}

.chat-topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 6px;
}
.sidebar-toggle:hover { background: var(--user-msg-bg); }

.model-badge {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--user-msg-bg);
    padding: 4px 10px;
    border-radius: 20px;
}

/* ===== WELCOME SCREEN ===== */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.welcome-icon {
    width: 72px;
    height: 72px;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: #fff;
    margin-bottom: 24px;
    box-shadow: 0 8px 32px rgba(99,102,241,0.3);
}

.welcome-title {
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 40px;
    max-width: 500px;
}

.capability-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 640px;
    width: 100%;
    margin-bottom: 36px;
}

.capability-card {
    padding: 20px 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--chat-bg);
    text-align: center;
    transition: border-color 0.2s, transform 0.2s;
}
.capability-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.capability-card i {
    font-size: 24px;
    color: var(--accent);
    margin-bottom: 10px;
    display: block;
}

.capability-card h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.capability-card p {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.prompt-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 640px;
}

.prompt-chip {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--chat-bg);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}
.prompt-chip:hover { border-color: var(--accent); color: var(--accent); background: rgba(99,102,241,0.05); }

/* ===== MESSAGES ===== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    display: none;
}

.messages-container.active { display: block; }

.messages-container::-webkit-scrollbar { width: 6px; }
.messages-container::-webkit-scrollbar-thumb { background: #d1d1d6; border-radius: 6px; }

.message {
    padding: 24px 0;
    border-bottom: 1px solid var(--border-color);
}

.message:last-child { border-bottom: none; }

.message-inner {
    max-width: 780px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 16px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .message-avatar { background: var(--accent); color: #fff; }
.message.assistant .message-avatar { background: linear-gradient(135deg, #10b981, #059669); color: #fff; }

.message-content {
    flex: 1;
    min-width: 0;
    line-height: 1.7;
    font-size: 15px;
}

.message-role {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.message.user { background: var(--user-msg-bg); }
.message.assistant { background: var(--ai-msg-bg); }

/* File attachment indicator */
.file-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    background: rgba(99,102,241,0.1);
    color: var(--accent);
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 8px;
}
.file-badge i { font-size: 11px; }

/* ===== MARKDOWN CONTENT ===== */
.message-content p { margin-bottom: 12px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 12px 0; padding-left: 24px; }
.message-content li { margin-bottom: 6px; }
.message-content h1, .message-content h2, .message-content h3 { margin: 20px 0 10px; }
.message-content h1 { font-size: 22px; }
.message-content h2 { font-size: 18px; }
.message-content h3 { font-size: 16px; }
.message-content blockquote { border-left: 3px solid var(--accent); padding-left: 16px; margin: 12px 0; color: var(--text-secondary); }
.message-content table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.message-content th, .message-content td { padding: 8px 12px; border: 1px solid var(--border-color); text-align: left; }
.message-content th { background: var(--user-msg-bg); font-weight: 600; }
.message-content a { color: var(--accent); }
.message-content img { max-width: 100%; border-radius: 8px; }

.message-content code:not(pre code) {
    background: rgba(99,102,241,0.1);
    color: #d63384;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Fira Code', 'Cascadia Code', monospace;
}

/* ===== CODE BLOCKS ===== */
.code-wrapper {
    margin: 16px 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #2d2d3f;
    background: var(--code-bg);
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: #16161e;
    border-bottom: 1px solid #2d2d3f;
}

.code-lang {
    font-size: 12px;
    color: #a0a0b8;
    font-weight: 500;
    text-transform: lowercase;
}

.code-actions { display: flex; gap: 4px; }

.code-action-btn {
    background: none;
    border: none;
    color: #a0a0b8;
    font-size: 12px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
}
.code-action-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.code-action-btn.copied { color: #10b981; }

.code-wrapper pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.6;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

.code-wrapper pre code {
    background: none !important;
    padding: 0 !important;
    color: #e2e8f0;
    font-size: 13px;
}

/* Preview iframe */
.code-preview {
    border-top: 1px solid #2d2d3f;
    background: #fff;
}
.code-preview iframe {
    width: 100%;
    height: 300px;
    border: none;
}

/* ===== THINKING INDICATOR ===== */
.thinking {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 0;
}
.thinking span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: bounce 1.4s infinite ease-in-out;
}
.thinking span:nth-child(1) { animation-delay: 0s; }
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }
.thinking .thinking-text {
    width: auto;
    height: auto;
    border-radius: 0;
    background: none;
    animation: none;
    margin-left: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
}

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


/* ===== INPUT AREA ===== */
.input-area {
    padding: 16px 24px 20px;
    background: var(--main-bg);
    flex-shrink: 0;
}

.input-wrapper {
    max-width: 780px;
    margin: 0 auto;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 8px 12px;
    box-shadow: var(--shadow);
    transition: border-color 0.2s;
}
.input-container:focus-within { border-color: var(--accent); }

.file-upload-btn, .send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: all 0.2s;
}

.file-upload-btn {
    background: transparent;
    color: var(--text-secondary);
}
.file-upload-btn:hover { background: var(--user-msg-bg); color: var(--accent); }

.send-btn {
    background: var(--accent);
    color: #fff;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn.stop-btn { background: var(--danger); }
.send-btn.stop-btn:hover { background: #dc2626; }

#chat-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 15px;
    font-family: inherit;
    line-height: 1.5;
    max-height: 200px;
    min-height: 24px;
    padding: 6px 4px;
    background: transparent;
    color: var(--text-primary);
}
#chat-input::placeholder { color: #b0b0c0; }

.file-preview {
    max-width: 780px;
    margin: 0 auto 8px;
    display: none;
}
.file-preview.active { display: block; }

.file-preview-inner {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(99,102,241,0.08);
    border: 1px solid rgba(99,102,241,0.2);
    border-radius: 8px;
    font-size: 13px;
    color: var(--accent);
}
.file-preview-inner i { font-size: 14px; }

.file-remove-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 2px;
    border-radius: 4px;
}
.file-remove-btn:hover { color: var(--danger); }

.input-disclaimer {
    text-align: center;
    font-size: 11px;
    color: #b0b0c0;
    margin-top: 8px;
}

/* ===== PREVIEW PANEL (right side) ===== */
.preview-panel {
    width: 0;
    overflow: hidden;
    background: #fff;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    flex-shrink: 0;
}

.preview-panel.open {
    width: 45%;
    min-width: 380px;
}

.chat-main.preview-open {
    flex: 1;
    min-width: 0;
}

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

.preview-header-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-header-title::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
}

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

.preview-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.preview-action-btn:hover {
    background: var(--user-msg-bg);
    color: var(--accent);
    border-color: var(--accent);
}

.preview-frame {
    flex: 1;
    width: 100%;
    border: none;
    background: #fff;
}

/* ===== SIDEBAR OVERLAY (mobile) ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

/* ===== RESPONSIVE ===== */

/* Make welcome screen scrollable on all sizes */
.welcome-screen {
    overflow-y: auto;
    min-height: 0;
}

/* Laptops & smaller (under 1400px): collapse sidebar to hamburger */
@media (max-width: 1400px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .sidebar-toggle { display: block; }
}

/* Medium screens */
@media (max-width: 1024px) {
    .capability-grid { grid-template-columns: repeat(2, 1fr); max-width: 440px; }
    .welcome-title { font-size: 28px; }
    .welcome-subtitle { font-size: 14px; margin-bottom: 28px; }
    .preview-panel.open { width: 50%; min-width: 340px; }
}

/* Small screens / tablets */
@media (max-width: 768px) {
    .welcome-icon { width: 56px; height: 56px; font-size: 24px; margin-bottom: 16px; border-radius: 14px; }
    .capability-card { padding: 14px 12px; }
    .capability-card i { font-size: 20px; margin-bottom: 6px; }
    .capability-card h4 { font-size: 12px; }
    .capability-card p { font-size: 10px; }
    .prompt-suggestions { max-width: 420px; }
    .prompt-chip { font-size: 12px; padding: 6px 12px; }
    .message-inner { padding: 0 16px; }
    .input-area { padding: 12px 16px 16px; }
    .preview-panel.open { position: fixed; right: 0; top: 0; bottom: 0; width: 100%; min-width: 0; z-index: 200; }
}

/* Short viewports (laptop screens are often 768px-900px tall) */
@media (max-height: 800px) {
    .welcome-screen { padding: 20px 16px; justify-content: flex-start; }
    .welcome-icon { width: 48px; height: 48px; font-size: 20px; margin-bottom: 10px; border-radius: 12px; }
    .welcome-title { font-size: 24px; margin-bottom: 4px; }
    .welcome-subtitle { font-size: 13px; margin-bottom: 16px; }
    .capability-grid { margin-bottom: 16px; gap: 8px; }
    .capability-card { padding: 10px 8px; }
    .capability-card i { font-size: 18px; margin-bottom: 4px; }
    .capability-card h4 { font-size: 11px; }
    .capability-card p { font-size: 10px; }
    .prompt-chip { font-size: 12px; padding: 6px 12px; }
    .input-area { padding: 10px 16px 12px; }
}

/* Very short viewports */
@media (max-height: 650px) {
    .welcome-screen { padding: 12px; }
    .welcome-icon { width: 40px; height: 40px; font-size: 18px; margin-bottom: 8px; }
    .welcome-title { font-size: 20px; }
    .welcome-subtitle { margin-bottom: 12px; }
    .capability-grid { margin-bottom: 12px; }
    .capability-card { padding: 8px 6px; }
    .capability-card i { font-size: 16px; margin-bottom: 2px; }
}

/* Phones */
@media (max-width: 480px) {
    .capability-grid { grid-template-columns: 1fr 1fr; max-width: 320px; }
    .prompt-suggestions { flex-direction: column; align-items: center; }
    .welcome-screen { padding: 16px 12px; }
}
