:root {
    --bg-color: #f8f9fa;
    --sidebar-bg: #ffffff;
    --text-color: #212529;
    --accent-color: #007aff;
    --accent-hover: #0056b3;
    --border-color: #e9ecef;
    --danger-color: #ff3b30;
    --editor-bg: #ffffff;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --transition-speed: 0.3s;
    --easing: cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark-mode {
    --bg-color: #121212;
    --sidebar-bg: #1e1e1e;
    --text-color: #e0e0e0;
    --border-color: #333333;
    --editor-bg: #1e1e1e;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

#editor-mount {
    touch-action: auto;
}

#editor-mount ::-webkit-text-selection {
    background: rgba(0, 122, 255, 0.3);
}

#editor-mount {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

[contenteditable]:focus {
    outline: none;
}

#editor-mount {
    pointer-events: auto;
}

#editor-mount {
    -webkit-tap-highlight-color: rgba(0, 122, 255, 0.3);
}

body, html {
    margin: 0;
    padding: 0;
    height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-color);
    background: var(--bg-color);
    overflow: hidden;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

.main-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
    background: var(--bg-color);
}

/* Sidebar Styling */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform var(--transition-speed) var(--easing), background var(--transition-speed);
}

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

.sidebar-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

#file-list {
    list-style: none;
    padding: 0.5rem 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
}

.file-item {
    padding: 0.8rem 1.25rem;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-color);
    opacity: 0.8;
    transition: all 0.2s ease;
    border-radius: 0 20px 20px 0;
    margin-right: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-item:hover {
    background: rgba(0,0,0,0.05);
    opacity: 1;
}

body.dark-mode .file-item:hover {
    background: rgba(255,255,255,0.05);
}

.file-item.active {
    background: rgba(0, 122, 255, 0.1);
    color: var(--accent-color);
    font-weight: 600;
    opacity: 1;
}

.sidebar-footer {
    padding: 1.25rem;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
}

#me-display {
    font-size: 0.8rem;
    color: #868e96;
    margin-bottom: 0.5rem;
}

/* Editor Area */
.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--editor-bg);
    min-width: 0;
}

.editor-header {
    padding: 0.5rem 1.25rem;
    height: 60px;
    display: flex;
    gap: 1rem;
    align-items: center;
    background: var(--editor-bg);
    border-bottom: 1px solid var(--border-color);
}

/* Connection Dot Indicator */
.connection-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ffcc00; /* Yellow for connecting */
    transition: background 0.3s ease, box-shadow 0.3s ease;
    flex-shrink: 0;
}

.connection-status.connected {
    background: #28a745;
    box-shadow: 0 0 8px rgba(40, 167, 69, 0.4);
}

.connection-status.disconnected {
    background: var(--danger-color);
    box-shadow: 0 0 8px rgba(255, 59, 48, 0.4);
}

#current-filename {
    flex: 1;
    border: none;
    font-size: 1.1rem;
    font-weight: 600;
    outline: none;
    background: transparent;
    color: var(--text-color);
}

.save-status {
    font-size: 0.75rem;
    color: #868e96;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.save-status.visible { opacity: 1; }
.save-status.unsaved { color: #ff9500; }
.save-status.saved { color: #28a745; }

/* Header Button Group */
.button-group {
    display: flex;
    align-items: center;
    background: rgba(0,0,0,0.03);
    border-radius: 10px;
    padding: 2px;
}

body.dark-mode .button-group {
    background: rgba(255,255,255,0.05);
}

.btn-action {
    background: transparent;
    border: none;
    color: var(--text-color);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0.7;
}

.btn-action:hover {
    background: rgba(0,0,0,0.05);
    opacity: 1;
}

body.dark-mode .btn-action:hover {
    background: rgba(255,255,255,0.1);
}

.btn-action:disabled {
    opacity: 0.2;
    cursor: not-allowed;
}

.btn-delete:hover {
    color: var(--danger-color);
    background: rgba(255, 59, 48, 0.1);
}

#editor-mount {
    flex: 1;
    width: 100%;
}

#editor-mount.monaco-editor {
    touch-action: manipulation;
}

#editor-mount.monaco-editor ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#editor-mount.monaco-editor::-webkit-scrollbar-track {
    background: transparent;
}

#editor-mount.monaco-editor::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
}

body.dark-mode #editor-mount.monaco-editor::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
}

/* UI Elements */
.btn-icon {
    background: var(--accent-color);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: transform 0.2s ease, background 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    transform: scale(1.1);
    background: var(--accent-hover);
}

.btn-primary {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 0.8rem 2rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-text {
    background: transparent;
    border: none;
    color: var(--accent-color);
    font-size: 0.85rem;
    padding: 0;
    cursor: pointer;
    font-weight: 600;
}

/* Mobile Toggle */
#mobile-menu-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 50%;
    z-index: 1100;
    box-shadow: 0 4px 15px rgba(0, 122, 255, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

#mobile-menu-toggle.hidden {
    transform: scale(0) translateY(20px);
    opacity: 0;
    pointer-events: none;
}

.icon-menu::before { content: '☰'; font-size: 1.5rem; }

/* Modal & Settings */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 5000;
}

.modal.visible { display: flex; }

.modal-content {
    background: var(--sidebar-bg);
    color: var(--text-color);
    padding: 2.5rem;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.settings-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.settings-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.6;
}

.settings-group input[type="text"],
.settings-group select {
    width: 100%;
    padding: 0.8rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
    outline: none;
}

.settings-group input[type="color"] {
    width: 100%;
    height: 40px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    background: transparent;
}

.animate-pop {
    animation: pop 0.4s var(--easing);
}

@keyframes pop {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Remote presence */
.remote-users { display: flex; margin-right: 0.5rem; }
.user-badge {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--editor-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: #fff;
    margin-left: -8px;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease;
}
.user-badge:hover { transform: translateY(-3px); z-index: 10; }

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.2);
    display: none;
    z-index: 900;
}
.sidebar-overlay.visible { display: block; }

/* Responsive adjustments */
@media (max-width: 768px) {
    #mobile-menu-toggle { display: flex; }
    
    .sidebar {
        position: absolute;
        height: 100%;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    }
    
    .editor-header { padding: 0.5rem 1rem; gap: 0.5rem; }
    #current-filename { font-size: 1rem; }
}

/* AI Chat Panel Styling */
.ai-chat-panel {
    position: absolute;
    right: 20px;
    bottom: 20px;
    width: 380px;
    height: 500px;
    max-height: calc(100vh - 100px);
    background: var(--editor-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    z-index: 4000;
    transition: transform 0.3s var(--easing), opacity 0.3s ease;
    overflow: hidden;
}

body.dark-mode .ai-chat-panel {
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.ai-chat-panel.hidden {
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
}

.ai-chat-header {
    padding: 12px 16px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-color);
}

.ai-msg {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.4;
    max-width: 85%;
    word-wrap: break-word;
}

.ai-msg.bot {
    background: var(--editor-bg);
    color: var(--text-color);
    align-self: flex-start;
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.ai-msg.user {
    background: var(--accent-color);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.ai-chat-input-area {
    padding: 12px;
    background: var(--editor-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
}

.ai-chat-input-area textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--bg-color);
    color: var(--text-color);
    outline: none;
}

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