
/* --- THEME VARIABLES --- */
:root {
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.4);
    --secondary: #8b5cf6;
    --bg-body: #f8fafc;
    --bg-sidebar: rgba(255, 255, 255, 0.85);
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-input: rgba(255, 255, 255, 0.5);
    --border: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --glass-blur: blur(12px);
    
    /* Editor Specific */
    --editor-bg: #0d1117; 
    --editor-gutter: #161b22;
    --editor-border: #30363d;
    --console-bg: #0d1117;
    --console-text: #3fb950;
    --accent-glow: 0 0 20px rgba(59, 130, 246, 0.15);
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-glow: rgba(129, 140, 248, 0.3);
    --secondary: #c084fc;
    --bg-body: linear-gradient(135deg, #020617 0%, #0f172a 50%, #172554 100%);
    --bg-sidebar: rgba(15, 23, 42, 0.6);
    --bg-card: rgba(30, 41, 59, 0.6);
    --bg-hover: rgba(51, 65, 85, 0.5);
    --bg-input: rgba(15, 23, 42, 0.6);
    --border: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --glass-blur: blur(20px); 
}

/* --- RESET & BASE --- */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; transition: background 0.4s ease, color 0.2s ease, border-color 0.3s ease; }
body { height: 100vh; display: flex; background: var(--bg-body); background-size: 200% 200%; color: var(--text-main); overflow: hidden; }

/* --- SIDEBAR --- */
.sidebar { width: 270px; background: var(--bg-sidebar); backdrop-filter: var(--glass-blur); border-right: 1px solid var(--border); padding: 24px 16px; display: flex; flex-direction: column; z-index: 20; flex-shrink: 0; overflow-y: auto; }
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.logo-container { display: flex; align-items: center; gap: 12px; padding: 0 12px 20px; }
.logo-icon { width: 34px; height: 34px; background: linear-gradient(135deg, var(--primary), #4f46e5); border-radius: 8px; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 15px var(--primary-glow); color: white; font-size: 1.2rem; }
.logo-text { font-size: 1.3rem; font-weight: 700; color: var(--text-main); }
.sidebar-divider { height: 1px; background: var(--border); margin: 8px 8px 20px; }
.section-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.05em; margin: 20px 12px 10px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 12px; color: var(--text-muted); text-decoration: none; font-size: 0.95rem; font-weight: 500; margin-bottom: 4px; cursor: pointer; position: relative; overflow: hidden; z-index: 1; }
.nav-item::before { content: ''; position: absolute; top: 0; left: 0; bottom: 0; right: 0; background: var(--bg-hover); z-index: -1; border-radius: 12px; transform: scaleX(0); transform-origin: left; transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); }
.nav-item.active { color: var(--primary); font-weight: 600; }
.nav-item.active::before { transform: scaleX(1); background: var(--bg-hover); opacity: 0.5; }
.nav-item:hover { color: var(--text-main); transform: translateX(6px); }
.nav-item:hover::before { transform: scaleX(1); }
.nav-item i { width: 24px; text-align: center; transition: transform 0.3s; }
.nav-item:hover i { transform: scale(1.15) rotate(5deg); color: var(--primary); }

/* --- MAIN LAYOUT --- */
.main-layout { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.top-bar { height: 72px; padding: 0 32px; display: flex; align-items: center; justify-content: space-between; background: var(--bg-sidebar); backdrop-filter: var(--glass-blur); border-bottom: 1px solid var(--border); z-index: 10; }
.search-wrapper { position: relative; width: 400px; }
.search-input { width: 100%; padding: 11px 16px 11px 44px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text-main); font-size: 0.9rem; }
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); background: var(--bg-card); }
.search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.header-actions { display: flex; align-items: center; gap: 16px; }
.action-btn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-muted); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s; }
.action-btn:hover { background: var(--bg-hover); color: var(--text-main); border-color: var(--primary); transform: translateY(-2px); }
.profile-avatar { width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, #6366f1, #d946ef); display: flex; align-items: center; justify-content: center; color: white; font-weight: 700; cursor: pointer; }

/* --- EDITOR WORKSPACE --- */
.editor-container { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 20px; gap: 16px; background: radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.03) 0%, transparent 40%); }
.editor-toolbar { display: flex; justify-content: space-between; align-items: center; background: var(--bg-card); padding: 8px 12px; border-radius: 16px; border: 1px solid var(--border); box-shadow: var(--shadow); flex-shrink: 0; backdrop-filter: blur(10px); }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; }

.lang-select-wrapper { position: relative; }
.lang-select { padding: 8px 36px 8px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text-main); font-weight: 600; cursor: pointer; outline: none; appearance: none; font-size: 0.9rem; transition: all 0.3s; }
.lang-select:hover, .lang-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.lang-select-icon { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; font-size: 0.8rem; }

.toolbar-btn { padding: 8px 12px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text-muted); font-weight: 500; font-size: 0.9rem; cursor: pointer; display: flex; align-items: center; gap: 8px; transition: all 0.2s; }
.toolbar-btn:hover { background: var(--bg-hover); color: var(--text-main); }
.toolbar-btn.primary { background: var(--bg-hover); color: var(--primary); border-color: var(--border); }
.toolbar-btn.primary:hover { border-color: var(--primary); transform: translateY(-1px); }

.run-btn { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; border: none; padding: 8px 24px; border-radius: 10px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 8px; transition: all 0.3s; box-shadow: 0 4px 15px var(--primary-glow); }
.run-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--primary-glow); filter: brightness(1.1); }
.run-btn:active { transform: translateY(0); }

.editor-main-area { flex: 1; display: flex; gap: 16px; overflow: hidden; position: relative; }
.editor-left-pane { flex: 1; display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* Code Editor */
.code-wrapper { flex: 1; display: flex; flex-direction: column; background: var(--editor-bg); border-radius: 16px; overflow: hidden; border: 1px solid var(--editor-border); box-shadow: var(--accent-glow); position: relative; }
.code-glow-line { position: absolute; top: 0; left: 0; width: 100%; height: 2px; background: linear-gradient(90deg, var(--primary), var(--secondary), var(--primary)); background-size: 200% 100%; animation: shimmer 3s infinite linear; opacity: 0; transition: opacity 0.3s; z-index: 10; }
.code-wrapper.running .code-glow-line { opacity: 1; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

.editor-inner { display: flex; flex: 1; overflow: hidden; position: relative; }
.editor-viewport { flex: 1; position: relative; overflow: auto; }
#code-editor { min-height: 100%; font-family: 'Fira Code', monospace; font-size: 14px; line-height: 1.6; color: #c9d1d9; padding: 20px; tab-size: 4; outline: none; caret-color: var(--primary); }

/* Syntax Highlighting overrides */
code[class*="language-"], pre[class*="language-"] { text-shadow: none !important; font-family: 'Fira Code', monospace !important; }
.token.operator { background: none !important; }

.editor-status-bar { height: 30px; background: var(--editor-gutter); border-top: 1px solid var(--editor-border); display: flex; align-items: center; justify-content: flex-end; padding: 0 16px; font-family: 'Fira Code', monospace; font-size: 11px; color: #8b949e; gap: 16px; user-select: none; }
.status-item { display: flex; align-items: center; gap: 6px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: #3fb950; }

/* Console */
.console-panel { height: 180px; background: var(--console-bg); border-radius: 16px; border: 1px solid var(--editor-border); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 10px 30px -10px rgba(0,0,0,0.3); flex-shrink: 0; }
.console-header { background: rgba(255,255,255,0.03); padding: 10px 20px; font-size: 0.75rem; font-weight: 700; color: #8b949e; text-transform: uppercase; letter-spacing: 0.1em; border-bottom: 1px solid var(--editor-border); display: flex; justify-content: space-between; align-items: center; }
.console-body { flex: 1; padding: 15px 20px; font-family: 'Fira Code', monospace; font-size: 13px; color: var(--console-text); overflow-y: auto; scrollbar-color: #30363d transparent; }
.console-body::-webkit-scrollbar { width: 8px; }
.console-body::-webkit-scrollbar-thumb { background: #30363d; border-radius: 4px; }
.log-error { color: #f85149; }
.log-warn { color: #d29922; }
.log-info { color: #58a6ff; }
.log-sys { color: #8b949e; font-style: italic; }
.console-clear { cursor: pointer; color: #8b949e; transition: color 0.2s; font-size: 0.9em; }
.console-clear:hover { color: #f85149; }

/* Right Pane: Team Chat */
.team-chat-panel {
    width: 320px; background: var(--bg-card); border-radius: 16px; border: 1px solid var(--border);
    display: flex; flex-direction: column; overflow: hidden;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, margin 0.3s;
    backdrop-filter: blur(20px);
    flex-shrink: 0;
}
.team-chat-panel.collapsed { width: 0; opacity: 0; border: none; margin-left: 0; }
.tc-header { padding: 16px; border-bottom: 1px solid var(--border); font-weight: 600; color: var(--text-main); display: flex; justify-content: space-between; align-items: center; }
.tc-status { width: 8px; height: 8px; background: #10b981; border-radius: 50%; box-shadow: 0 0 8px rgba(16, 185, 129, 0.6); animation: pulse 2s infinite; }
@keyframes pulse { 0% { opacity: 0.5; transform: scale(0.9); } 50% { opacity: 1; transform: scale(1.1); } 100% { opacity: 0.5; transform: scale(0.9); } }
.tc-body { flex: 1; padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; background: rgba(0,0,0,0.02); }
.tc-msg { font-size: 0.85rem; padding: 10px 14px; border-radius: 14px; max-width: 85%; line-height: 1.4; position: relative; }
.tc-msg-remote { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border); color: var(--text-main); border-bottom-left-radius: 2px; }
.tc-msg-local { align-self: flex-end; background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; border-bottom-right-radius: 2px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
.tc-footer { padding: 12px; border-top: 1px solid var(--border); background: var(--bg-card); }
.tc-input-wrapper { display: flex; gap: 8px; background: var(--bg-input); border: 1px solid var(--border); padding: 4px 4px 4px 12px; border-radius: 24px; }
.tc-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text-main); font-size: 0.9rem; padding: 8px 0; }
.tc-send-btn { width: 36px; height: 36px; background: var(--primary); border-radius: 50%; border: none; color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform 0.2s; }
.tc-send-btn:hover { transform: scale(1.05); }

/* AI Widget */
.ai-widget { position: absolute; bottom: 30px; right: 30px; z-index: 999; }
.ai-minimized { background: var(--bg-card); backdrop-filter: blur(16px); border: 1px solid var(--border); border-radius: 50px; padding: 12px 24px; box-shadow: var(--shadow); color: var(--text-main); font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 10px; transition: transform 0.3s; }
.ai-minimized:hover { transform: translateY(-3px) scale(1.02); }
.widget-status { width: 8px; height: 8px; background: #10b981; border-radius: 50%; box-shadow: 0 0 10px #10b981; }
.chat-interface { position: absolute; bottom: 0; right: 0; width: 380px; height: 550px; background: var(--bg-card); backdrop-filter: blur(20px); border: 1px solid var(--border); border-radius: 24px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); display: flex; flex-direction: column; overflow: hidden; opacity: 0; pointer-events: none; transform: translateY(20px) scale(0.95); transition: all 0.4s; }
.ai-widget.expanded .chat-interface { opacity: 1; pointer-events: auto; transform: translateY(0) scale(1); }
.ai-widget.expanded .ai-minimized { opacity: 0; pointer-events: none; display: none; }
.chat-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; background: rgba(255, 255, 255, 0.05); }
.ai-profile { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.ai-avatar-small { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, #10b981, #059669); display: flex; align-items: center; justify-content: center; color: white; }
.close-chat { background: none; border: none; color: var(--text-muted); cursor: pointer; }
.chat-body { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.msg { padding: 12px 16px; font-size: 0.9rem; line-height: 1.5; max-width: 85%; border-radius: 12px; }
.msg-user { align-self: flex-end; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: white; border-radius: 18px 18px 0 18px; }
.msg-ai { align-self: flex-start; background: var(--bg-hover); border: 1px solid var(--border); color: var(--text-main); border-radius: 18px 18px 18px 0; }
.msg-code-block { background: rgba(0,0,0,0.1); padding: 8px; border-radius: 6px; font-family: 'Fira Code', monospace; font-size: 0.8em; margin-top: 5px; white-space: pre-wrap; }
.chat-footer { padding: 16px; }
.chat-input-container { background: var(--bg-card); border: 1px solid var(--border); border-radius: 50px; padding: 6px 6px 6px 16px; display: flex; align-items: center; }
.chat-input { flex: 1; border: none; background: transparent; outline: none; color: var(--text-main); }
.send-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: white; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* Typing Indicator */
.typing-indicator { display: flex; gap: 4px; padding: 12px 16px; align-self: flex-start; background: var(--bg-hover); border-radius: 18px; border: 1px solid var(--border); width: fit-content; }
.dot { width: 6px; height: 6px; background: var(--text-muted); border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; }
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* Toast */
#toast-container { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { background: rgba(15, 23, 42, 0.9); color: white; padding: 12px 24px; border-radius: 12px; display: flex; align-items: center; gap: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.1); backdrop-filter: blur(10px); opacity: 0; transform: translateY(20px); transition: all 0.3s; }
.toast.show { opacity: 1; transform: translateY(0); }

/* Mobile */
.mobile-menu-btn { display: none; margin-right: 15px; background: transparent; border: none; font-size: 1.4rem; color: var(--text-muted); cursor: pointer; }
@media (max-width: 1024px) {
    .sidebar { position: fixed; transform: translateX(-100%); transition: transform 0.3s; z-index: 30; height: 100%; box-shadow: 2px 0 10px rgba(0,0,0,0.1); }
    .sidebar.open { transform: translateX(0); }
    .mobile-menu-btn { display: block; }
    .editor-container { padding: 10px; }
    .ai-widget { bottom: 80px; right: 20px; }
    .chat-interface { width: 300px; height: 450px; bottom: 0; right: -20px; }
    
    .team-chat-panel { position: absolute; right: 0; top: 72px; bottom: 0; z-index: 25; width: 85%; max-width: 320px; box-shadow: -5px 0 15px rgba(0,0,0,0.1); }
    .team-chat-panel.collapsed { transform: translateX(100%); width: 85%; opacity: 1; }
}

/* --- Responsive fixes (small screens) --- */
@media (max-width: 600px) {
    .editor-toolbar { flex-wrap: wrap; gap: 8px; }
    .toolbar-left, .toolbar-right { flex-wrap: wrap; gap: 8px; }
    .toolbar-btn { white-space: nowrap; }
}

@media (max-width: 600px) {
    .top-bar { padding: 0 16px; gap: 10px; }
    .search-wrapper { width: auto; flex: 1; min-width: 0; }
    .header-actions { gap: 8px; flex-shrink: 0; }
    .action-btn { width: 38px; height: 38px; }
    .mobile-menu-btn { margin-right: 4px; }
}
