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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1e1e1e;
    color: #d4d4d4;
    overflow: hidden;
    height: 100vh;
}

/* Main Container */
.js-editor-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Left Panel: Editor (75%) */
.editor-panel {
    flex: 0 0 75%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #3e3e3e;
    background: #1e1e1e;
    overflow: hidden;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #252526;
    border-bottom: 1px solid #3e3e3e;
}

.file-name {
    font-size: 14px;
    font-weight: 500;
    color: #cccccc;
}

.editor-actions {
    display: flex;
    gap: 8px;
}

.btn-action {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #0e639c;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-action:hover {
    background: #1177bb;
}

.btn-action svg {
    flex-shrink: 0;
}

.btn-action:active {
    transform: scale(0.98);
}

/* Editor Wrapper - CodeMirror container */
.editor-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* CodeMirror overrides to match dark theme */
.editor-wrapper .CodeMirror {
    height: 100%;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 22px;
    background: #1e1e1e;
}

.editor-wrapper .CodeMirror-gutters {
    background: #1e1e1e;
    border-right: 1px solid #3e3e3e;
}

.editor-wrapper .CodeMirror-linenumber {
    color: #858585;
}

.editor-wrapper .CodeMirror-activeline-background {
    background: #2a2d2e;
}

.editor-wrapper .CodeMirror-selected {
    background: #264f78 !important;
}

.editor-wrapper .CodeMirror-focused .CodeMirror-selected {
    background: #264f78 !important;
}

.editor-wrapper .CodeMirror-cursor {
    border-left-color: #ffffff;
}

/* Fold gutter */
.editor-wrapper .CodeMirror-foldgutter-open,
.editor-wrapper .CodeMirror-foldgutter-folded {
    color: #858585;
}

.editor-wrapper .CodeMirror-foldgutter-open:hover,
.editor-wrapper .CodeMirror-foldgutter-folded:hover {
    color: #cccccc;
}

/* Error Bar */
.error-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: #5a1d1d;
    border-top: 1px solid #be1100;
    color: #f48771;
    font-size: 13px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    min-height: 30px;
    cursor: pointer;
    user-select: none;
}
.error-bar:hover {
    background: #6a2222;
}
.error-bar.hidden { display: none; }
.error-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: #be1100;
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    flex-shrink: 0;
}

/* Error line highlight in CodeMirror */
.cm-error-line {
    background: rgba(255, 0, 0, 0.15) !important;
    border-left: 3px solid #be1100;
}

/* Right Panel: Functions (25%) */
.functions-panel {
    flex: 0 0 25%;
    min-width: 0;
    width: 25%;
    display: flex;
    flex-direction: column;
    background: #252526;
    overflow: hidden;
}

.functions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #2d2d30;
    border-bottom: 1px solid #3e3e3e;
}

.functions-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: #cccccc;
}

.function-count {
    background: #0e639c;
    color: #fff;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.functions-search {
    padding: 12px 16px;
    border-bottom: 1px solid #3e3e3e;
}

.functions-search input {
    width: 100%;
    padding: 8px 12px;
    background: #3c3c3c;
    border: 1px solid #3e3e3e;
    border-radius: 4px;
    color: #cccccc;
    font-size: 13px;
    outline: none;
}

.functions-search input:focus {
    border-color: #0e639c;
    background: #2d2d30;
}

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

.function-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.2s;
    border-left: 3px solid transparent;
}

.function-item:hover {
    background: #2a2d2e;
    border-left-color: #0e639c;
}

.function-item.active {
    background: #094771;
    border-left-color: #0e639c;
}

.function-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin-top: 2px;
}

.function-icon svg {
    width: 100%;
    height: 100%;
    fill: #dcdcaa;
}

.function-details {
    flex: 1;
    min-width: 0;
}

.function-name {
    font-size: 13px;
    font-weight: 500;
    color: #dcdcaa;
    margin-bottom: 2px;
    word-break: break-word;
}

.function-params {
    font-size: 12px;
    color: #858585;
    font-family: 'Consolas', 'Monaco', monospace;
    word-break: break-word;
}

.function-line {
    font-size: 11px;
    color: #6a6a6a;
    margin-top: 2px;
}

.empty-state {
    padding: 32px 16px;
    text-align: center;
    color: #858585;
    font-size: 13px;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: #1e1e1e;
}

::-webkit-scrollbar-thumb {
    background: #424242;
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background: #4e4e4e;
}

/* Selection */
::selection {
    background: #264f78;
    color: #ffffff;
}

/* AI Button */
.btn-action.btn-ai {
    background: #9a6aff;
}
.btn-action.btn-ai:hover {
    background: #b088ff;
}

/* AI Popup */
#ai-popup-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 3000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    animation: aiFadeIn 150ms ease;
}
#ai-popup-overlay.visible { display: flex; }

@keyframes aiFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes aiSlideUp {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

#ai-popup {
    background: #252526;
    border: 1px solid #3e3e3e;
    border-radius: 8px;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.3);
    animation: aiSlideUp 180ms cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.ai-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #2d2d30;
    border-bottom: 1px solid #3e3e3e;
}
.ai-popup-header h4 {
    font-size: 13px;
    font-weight: 600;
    color: #cccccc;
    margin: 0;
}
.ai-popup-close {
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    color: #858585;
    background: none;
    border: none;
    font-size: 14px;
    transition: background 0.2s;
}
.ai-popup-close:hover { background: #3e3e3e; color: #cccccc; }

.ai-popup-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ai-popup-model-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ai-popup-model-row label {
    font-size: 11px;
    font-weight: 600;
    color: #858585;
    margin: 0;
}
.ai-popup-model-readonly {
    width: 100%;
    background: #2d2d30;
    border: 1px solid #3e3e3e;
    border-radius: 4px;
    color: #ce9178;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 11px;
    padding: 8px 10px;
    outline: none;
}
.ai-popup-model-search {
    width: 100%;
    background: #3c3c3c;
    border: 1px solid #3e3e3e;
    border-radius: 4px;
    color: #cccccc;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 12px;
    padding: 8px 10px;
    outline: none;
    transition: border-color 0.2s;
}
.ai-popup-model-search:focus {
    border-color: #0e639c;
}
.ai-popup-model-select {
    width: 100%;
    max-height: 170px;
    overflow-y: auto;
    background: #3c3c3c;
    border: 1px solid #3e3e3e;
    color: #ce9178;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    border-radius: 4px;
    padding: 2px;
}
.ai-popup-model-select option {
    padding: 5px 8px;
    cursor: pointer;
}
.ai-popup-model-select option:checked {
    background: #0e639c;
    color: #fff;
}
.ai-popup-body textarea {
    width: 100%;
    min-height: 80px;
    max-height: 200px;
    background: #3c3c3c;
    border: 1px solid #3e3e3e;
    border-radius: 4px;
    color: #cccccc;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 12px;
    padding: 10px;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
}
.ai-popup-body textarea:focus {
    border-color: #0e639c;
}
.ai-popup-body textarea::placeholder {
    color: #858585;
}
.ai-popup-status {
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 4px;
    display: none;
}
.ai-popup-status.visible { display: block; }
.ai-popup-status.loading { background: rgba(14,99,156,0.15); color: #4fc1ff; }
.ai-popup-status.success { background: rgba(74,207,138,0.15); color: #4acf8a; }
.ai-popup-status.error { background: rgba(190,17,0,0.15); color: #f48771; }

.ai-popup-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #3e3e3e;
}
.ai-popup-btn {
    padding: 7px 16px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    border: none;
}
.ai-popup-btn-cancel {
    background: #3c3c3c;
    color: #858585;
    border: 1px solid #3e3e3e !important;
}
.ai-popup-btn-cancel:hover { background: #4e4e4e; color: #cccccc; }
.ai-popup-btn-send {
    background: #9a6aff;
    color: #fff;
}
.ai-popup-btn-send:hover:not(:disabled) { background: #b088ff; }
.ai-popup-btn-send:disabled { background: #3a3a3a; color: #666; opacity: 0.6; cursor: not-allowed; }
