/* docs/style.css */

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

:root {
    --bg-primary:    #1E1E2E;
    --bg-secondary:  #181825;
    --bg-header:     #11111B;
    --bg-editor:     #1A1A2A;
    --bg-terminal:   #141420;
    --bg-input:      #1E1E2E;
    --text-primary:  #CDD6F4;
    --text-secondary:#A6ADC8;
    --text-dim:      #6C7086;
    --accent:        #89B4FA;
    --green:         #A6E3A1;
    --red:           #F38BA8;
    --yellow:        #F9E2AF;
    --border:        #313244;
    --scrollbar-thumb:   #45475A;
    --scrollbar-thumb-hover: #6C7086;
    --line-number:   #45475A;
    --font-mono:     'Source Code Pro', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    --font-sans:     'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ═══ Header ═══════════════════════════════════════════════════════════════ */

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

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--accent);
}

.logo span {
    color: var(--text-dim);
    font-weight: 400;
    font-size: 12px;
    margin-left: 8px;
}

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

/* ═══ Buttons ══════════════════════════════════════════════════════════════ */

.btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.btn-run {
    background: #2D6B3F;
    color: var(--green);
}

.btn-run:hover:not(:disabled) {
    background: #357A48;
}

.btn-stop {
    background: #6B2D3F;
    color: var(--red);
}

.btn-stop:hover:not(:disabled) {
    background: #7A3548;
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
    color: var(--text-primary);
}

/* ═══ Main Layout ══════════════════════════════════════════════════════════ */

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

/* ═══ Sidebar (File Tree) ══════════════════════════════════════════════════ */

#sidebar {
    width: 220px;
    min-width: 150px;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    position: relative;
    flex-shrink: 0;
}

#sidebar.collapsed {
    width: 0 !important;
    min-width: 0;
    overflow: hidden;
    border-right: none;
}

#sidebar.collapsed .file-tree,
#sidebar.collapsed .sidebar-collapse-btn {
    display: none;
}

.sidebar-collapse-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.15s;
    z-index: 10;
}

.sidebar-collapse-btn:hover {
    background: var(--border);
    color: var(--text-primary);
}

#btn-expand-sidebar {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 60px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 4px 4px 0;
    color: var(--text-dim);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    z-index: 100;
}

#btn-expand-sidebar:hover {
    background: var(--border);
    color: var(--text-primary);
}

#btn-expand-sidebar.visible {
    display: flex;
}

#file-tree {
    flex: 1;
    overflow: auto;
}

.file-tree {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    user-select: none;
}

.file-tree-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.file-tree-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    letter-spacing: 1px;
}

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

.file-tree-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}

.file-tree-btn:hover {
    background: var(--border);
    color: var(--text-primary);
}

.file-tree-content {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.file-tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    cursor: pointer;
    transition: background 0.1s;
    font-size: 13px;
    color: var(--text-secondary);
}

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

.file-tree-item.selected {
    background: rgba(137, 180, 250, 0.15);
    color: var(--text-primary);
}

.file-tree-item.dragging {
    opacity: 0.5;
}

.file-tree-item.drag-over {
    background: rgba(137, 180, 250, 0.25);
}

.file-tree-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.file-tree-item-spacer {
    flex: 1;
}

.file-tree-item-menu {
    opacity: 0;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: opacity 0.15s, background 0.15s;
    flex-shrink: 0;
}

.file-tree-item:hover .file-tree-item-menu,
.file-tree-item.selected .file-tree-item-menu {
    opacity: 1;
}

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

/* ═══ Context Menu ═════════════════════════════════════════════════════════ */

.file-tree-context-menu {
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 0;
    min-width: 160px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.file-tree-context-item {
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.1s;
}

.file-tree-context-item:hover {
    background: rgba(137, 180, 250, 0.15);
    color: var(--text-primary);
}

.file-tree-context-separator {
    height: 1px;
    background: var(--border);
    margin: 4px 8px;
}

/* ═══ Tabs ═════════════════════════════════════════════════════════════════ */

.tabs-container {
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    height: 36px;
    flex-shrink: 0;
    overflow: hidden;
}

.tabs-wrapper {
    display: flex;
    align-items: center;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

.tabs-wrapper::-webkit-scrollbar {
    height: 3px;
}

.tabs-wrapper::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.tabs-empty {
    padding: 0 16px;
    color: var(--text-dim);
    font-size: 12px;
    font-style: italic;
}

.tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    height: 100%;
    border-right: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: background 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
}

.tab:hover {
    background: rgba(255, 255, 255, 0.05);
}

.tab.active {
    background: var(--bg-editor);
    color: var(--text-primary);
    border-bottom: 2px solid var(--accent);
    margin-bottom: -1px;
}

.tab.modified .tab-name {
    font-style: italic;
}

.tab-icon {
    font-size: 14px;
}

.tab-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-modified-dot {
    color: var(--accent);
    font-size: 10px;
    margin-left: -2px;
}

.tab-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    border-radius: 4px;
    transition: all 0.1s;
    margin-left: 4px;
}

.tab-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.tab.modified .tab-close {
    color: var(--accent);
}

/* ═══ Editor Panel ═════════════════════════════════════════════════════════ */

#editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 300px;
    overflow: hidden;
}

#tabs-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    height: 36px;
    flex-shrink: 0;
    overflow: hidden;
}

.tabs-wrapper {
    display: flex;
    align-items: center;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    flex: 1;
}

.tabs-wrapper::-webkit-scrollbar {
    height: 3px;
}

.tabs-empty {
    padding: 0 16px;
    color: var(--text-dim);
    font-size: 12px;
    font-style: italic;
}

.format-btn {
    background: transparent;
    border: none;
    border-left: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    padding: 0 16px;
    height: 100%;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.format-btn:hover {
    background: rgba(137, 180, 250, 0.15);
    color: var(--accent);
}

.format-btn:active {
    transform: scale(0.95);
}

#editor-container {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.editor-container {
    display: flex;
    height: 100%;
    background: var(--bg-editor);
    position: relative;
}

.editor-line-numbers {
    width: 50px;
    padding: 12px 8px;
    background: var(--bg-secondary);
    text-align: right;
    color: var(--line-number);
    user-select: none;
    overflow: hidden;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
}

.editor-line-numbers .line-number {
    height: 1.6em;
}

.editor-line-numbers .line-error {
    background: rgba(243, 139, 168, 0.2);
    color: var(--red);
    font-weight: 600;
}

.editor-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.editor-textarea,
.editor-highlight {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 12px;
    margin: 0;
    border: none;
    outline: none;
    resize: none;
    overflow: auto;
    white-space: pre;
    word-wrap: normal;
}

.editor-textarea {
    background: transparent;
    color: transparent;
    caret-color: var(--text-primary);
    z-index: 2;
}

.editor-highlight {
    background: var(--bg-editor);
    color: var(--text-primary);
    z-index: 1;
    pointer-events: none;
}

.editor-highlight code {
    display: block;
}

/* ═══ Syntax Highlighting ══════════════════════════════════════════════════ */

.hl-keyword    { color: #c586b1; }
.hl-typeName   { color: #4a9ad6; }
.hl-className  { color: #4ec9a2; }
.hl-function   { color: #dcd98f; }
.hl-object     { color: #9fe4ff; }
.hl-string     { color: #ce8453; }
.hl-number     { color: #b5cb8e; }
.hl-comment    { color: #6a994e; font-style: italic; }
.hl-brackets   { color: #ced4d4; }

/* ═══ Output Panel ═════════════════════════════════════════════════════════ */

#output-panel {
    width: 350px;
    min-width: 200px;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    background: var(--bg-terminal);
    border-left: 1px solid var(--border);
    flex-shrink: 0;
}

#output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.output-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.output-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
}

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

/* ═══ GUI Panel ════════════════════════════════════════════════════════════ */

#gui-panel {
    flex-direction: column;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 100px;
    max-height: 80%;
    height: 250px;
    overflow: hidden;
}

#gui-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.gui-title {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-dim);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.gui-close-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    border-radius: 4px;
    transition: all 0.15s;
}

.gui-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--red);
}

#gui-output {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 16px;
    overflow: auto;
    background: #181825;
}

#gui-output:empty {
    display: none !important;
}

/* ═══ Terminal ═════════════════════════════════════════════════════════════ */

#terminal-body {
    flex: 1;
}

.terminal-container {
    height: 100%;
    overflow-y: auto;
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
}

.terminal-output {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.terminal-system {
    display: inline;
    white-space: pre-wrap;
}

.terminal-info    { color: var(--text-dim); }
.terminal-error   { color: var(--red); }
.terminal-success { color: var(--green); }

.terminal-input-container {
    display: flex;
    align-items: center;
    margin-top: 4px;
}

.terminal-input-label {
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 14px;
}

.terminal-input-field {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
}

.terminal-input-field:focus {
    border-color: var(--accent);
}

/* ═══ Resizers ═════════════════════════════════════════════════════════════ */

.resizer {
    background: var(--border);
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.resizer:hover {
    background: var(--accent);
}

.resizer-horizontal {
    width: 4px;
    cursor: col-resize;
}

.resizer-vertical {
    height: 4px;
    cursor: row-resize;
}

#resizer-gui-terminal {
    height: 4px;
    background: var(--border);
    cursor: row-resize;
    flex-shrink: 0;
    transition: background 0.15s;
}

#resizer-gui-terminal:hover {
    background: var(--accent);
}

/* ═══ Autocomplete ═════════════════════════════════════════════════════════ */

.autocomplete-container {
    position: absolute;
    z-index: 10000;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    max-height: 220px;
    overflow: hidden;
    min-width: 220px;
    max-width: 350px;
}

.autocomplete-list {
    overflow-y: auto;
    max-height: 220px;
}

.autocomplete-list::-webkit-scrollbar {
    width: 8px;
}

.autocomplete-list::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.autocomplete-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.autocomplete-list::-webkit-scrollbar-thumb:hover {
    background: #585B70;
}

.autocomplete-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: rgba(137, 180, 250, 0.2);
    color: var(--text-primary);
}

.autocomplete-icon {
    font-size: 13px;
    flex-shrink: 0;
    width: 18px;
    text-align: center;
}

.autocomplete-label {
    font-family: var(--font-mono);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.autocomplete-detail {
    color: var(--text-dim);
    font-size: 11px;
    flex-shrink: 0;
    margin-left: 8px;
}

.autocomplete-more {
    padding: 4px 10px;
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

/* ═══ Modal ════════════════════════════════════════════════════════════════ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(2px);
}

.modal {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    min-width: 320px;
    max-width: 450px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.modal-message {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-input-wrapper {
    position: relative;
    margin-bottom: 20px;
}

.modal-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color 0.15s;
}

.modal-input:focus {
    border-color: var(--accent);
}

.modal-input::placeholder {
    color: var(--text-dim);
}

.modal-extension-hint {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    font-size: 14px;
    font-family: var(--font-mono);
    pointer-events: none;
    transition: opacity 0.15s;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.modal-btn-cancel {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.modal-btn-cancel:hover {
    background: var(--border);
    color: var(--text-primary);
}

.modal-btn-confirm {
    background: var(--accent);
    color: #1e1e2e;
}

.modal-btn-confirm:hover {
    background: #9fc5ff;
}

.modal-btn-danger {
    background: var(--red);
    color: #1e1e2e;
}

.modal-btn-danger:hover {
    background: #ff8fa3;
}

/* ═══ Scrollbar (global) ═══════════════════════════════════════════════════ */

.terminal-container::-webkit-scrollbar,
.editor-textarea::-webkit-scrollbar,
.editor-highlight::-webkit-scrollbar,
#gui-output::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.terminal-container::-webkit-scrollbar-track,
.editor-textarea::-webkit-scrollbar-track,
.editor-highlight::-webkit-scrollbar-track,
#gui-output::-webkit-scrollbar-track {
    background: transparent;
}

.terminal-container::-webkit-scrollbar-thumb,
.editor-textarea::-webkit-scrollbar-thumb,
.editor-highlight::-webkit-scrollbar-thumb,
#gui-output::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

.terminal-container::-webkit-scrollbar-thumb:hover,
.editor-textarea::-webkit-scrollbar-thumb:hover,
.editor-highlight::-webkit-scrollbar-thumb:hover,
#gui-output::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}



/* ═══ Responsive ═══════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
    #sidebar {
        width: 180px;
    }
    
    #output-panel {
        width: 280px;
    }
}

@media (max-width: 768px) {
    #main {
        flex-direction: column;
    }
    
    #sidebar {
        width: 100% !important;
        max-width: none;
        height: 150px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    #output-panel {
        width: 100% !important;
        max-width: none;
        height: 200px;
        border-left: none;
        border-top: 1px solid var(--border);
    }
    
    .resizer-horizontal {
        display: none;
    }
    
    #editor-panel {
        flex: 1;
    }
}