/* Main container and layout */
.ex-code-container {
    display: flex;
    height: 100%;
    background-color: var(--bg-light);
    color: var(--purple-dark);
    min-width: 1200px;
}

/* Sidebar styles */
.ex-code-sidebar {
    width: 250px;
    background-color: var(--bg-mid);
    border-right: 2px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-tabs {
    display: flex;
    background-color: var(--purple-light);
    border-bottom: 2px solid var(--border-dark);
}

.tab {
    padding: 8px 16px;
    cursor: pointer;
    color: var(--purple-darker);
    font-size: 12px;
    border-right: 1px solid var(--border-dark);
    user-select: none;
}

.tab:hover {
    background-color: var(--border-light);
}

.tab.active {
    background-color: var(--bg-mid);
    color: var(--purple-darker);
    border-bottom: 2px solid var(--purple-dark);
    font-weight: bold;
    margin-bottom: -2px;
}

/* Main editor area */
.ex-code-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Editor wrapper and content */
.editor-wrapper {
    display: flex;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-lightest);
    position: relative;
}

.editor-content {
    flex: 1;
    position: relative;
    overflow: hidden;
    height: 100%;
}

/* Line numbers */
.line-numbers {
    padding: 10px 8px 8px 0; /* Match editor top padding */
    text-align: right;
    background-color: #1a1a1a;
    color: #808080;
    user-select: none;
    border-right: 2px solid #333333;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
    min-width: 40px;
    opacity: 0.6;
    white-space: pre;
    overflow-y: hidden;
    box-sizing: border-box;
}

.line-number {
    color: #808080;
    height: 1.5em;
    padding-right: 8px;
    line-height: 1.5;
}

/* Main editor textarea */
.ex-code-editor {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 8px 8px 8px; /* Increased top padding for text alignment */
    margin: 0;
    border: none;
    background-color: transparent;
    caret-color: #ffffff;
    color: transparent;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    white-space: pre;
    overflow-y: auto;
    overflow-x: hidden; /* Hide horizontal scrollbar by default */
    tab-size: 4;
    z-index: 2;
    width: 100%;
    height: 100%;
    box-sizing: border-box; /* Ensure padding is included in width calculation */
}

/* Add hover/focus state for horizontal scroll */
.ex-code-editor:hover,
.ex-code-editor:focus {
    overflow-x: auto; /* Show horizontal scrollbar only when needed */
}

/* Syntax highlighting overlay */
.syntax-highlighter {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 8px 8px 8px; /* Match editor padding */
    margin: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre;
    overflow: auto;
    pointer-events: none;
    tab-size: 4;
    z-index: 1;
    background-color: #000000;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    color: #abb2bf; /* Light gray for default text color */
}

/* Syntax highlighting colors */
.cat-keyword { color: #c678dd !important; }
.cat-string { color: #98c379 !important; }
.cat-number { color: #e5c07b !important; }
.cat-operator { color: #56b6c2 !important; }
.cat-comment { color: #7f848e !important; }
.cat-function { color: #61afef !important; }
.cat-constant { color: #af79f6 !important; }

.current-line {
    background-color: rgba(255, 255, 255, 0.1);
    display: inline-block;
    width: calc(100% + 16px); /* Account for padding */
    margin-left: -8px;
    padding-left: 8px;
    margin-right: -8px;
    padding-right: 8px;
}

/* Menu bar styles */
.ex-code-menubar {
    display: flex;
    background-color: var(--purple-light);
    border-bottom: 2px solid var(--border-dark);
    padding: 2px;
}

.ex-code-menu-item {
    padding: 4px 12px;
    cursor: pointer;
    color: var(--purple-darker);
    user-select: none;
}

.ex-code-menu-item:hover {
    background-color: var(--border-light);
}

/* Dropdown menu */
.ex-code-dropdown-menu {
    position: fixed;
    background-color: var(--bg-lightest);
    border: 1px solid var(--border-dark);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    z-index: 1000;
}

.menu-item {
    padding: 6px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.menu-item:hover {
    background-color: var(--border-light);
}

.menu-separator {
    height: 1px;
    background-color: var(--border-dark);
    margin: 4px 0;
}

.shortcut {
    color: var(--purple-light);
    font-size: 0.9em;
    margin-left: 20px;
}

/* Console styles */
.ex-code-console {
    height: 150px;
    background-color: #000000;
    border-top: 2px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 100px;
    resize: vertical;
    overflow: hidden;
}

.console-header {
    padding: 4px 8px;
    background-color: var(--purple-light);
    border-bottom: 1px solid var(--border-dark);
    font-size: 12px;
    font-weight: bold;
    color: var(--purple-darker);
    cursor: ns-resize;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.console-output {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.4;
    background-color: #000000;
    color: #ffffff;
    height: 0; /* Force scrolling to work in flex container */
}

.console-line {
    padding: 2px 0;
    white-space: pre-wrap;
    word-break: break-all;
    color: #ffffff;
}

/* Context help popup */
.context-help {
    position: absolute;
    right: 20px;
    top: 20px;
    background-color: var(--bg-mid);
    border: 2px solid var(--border-dark);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    max-width: 300px;
    z-index: 1000;
    display: none;
}

.context-help-content {
    padding: 12px;
}

.context-help-content h4 {
    margin: 0 0 8px 0;
    color: var(--purple-darker);
    font-weight: bold;
}

.context-help-content code {
    display: block;
    background-color: var(--bg-lightest);
    padding: 8px;
    margin: 8px 0;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--purple-dark);
}

/* Scrollbar styles */
.ex-code-editor::-webkit-scrollbar,
.syntax-highlighter::-webkit-scrollbar,
.console-output::-webkit-scrollbar {
    width: 12px;
    height: 0; /* Hide horizontal scrollbar */
    background: transparent;
}

.ex-code-editor::-webkit-scrollbar-track,
.syntax-highlighter::-webkit-scrollbar-track,
.console-output::-webkit-scrollbar-track {
    background: transparent;
}

.ex-code-editor::-webkit-scrollbar-thumb,
.syntax-highlighter::-webkit-scrollbar-thumb,
.console-output::-webkit-scrollbar-thumb {
    background: #404040;
    border: 3px solid #1a1a1a;
    border-radius: 6px;
    min-height: 40px;
}

/* Ensure horizontal scrolling still works */
.ex-code-editor,
.syntax-highlighter,
.console-output {
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

/* Remove all horizontal scrollbars */
.ex-code-editor::-webkit-scrollbar-horizontal,
.syntax-highlighter::-webkit-scrollbar-horizontal,
.console-output::-webkit-scrollbar-horizontal {
    display: none;
}

/* Selection styles */
.ex-code-editor::selection {
    background: rgba(100, 100, 255, 0.3);
    color: transparent;
}

/* File tree styles */
.file-tree {
    padding: 8px;
    font-size: 12px;
}

/* Tab content */
.tab-content {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
}

/* Ensure proper stacking of editor elements */
.ex-code-editor-container {
    position: relative;
    flex: 1;
    overflow: hidden;
}

/* Focus styles */
.ex-code-editor:focus {
    outline: none;
}

/* Responsive design adjustments */
@media (max-width: 1200px) {
    .ex-code-sidebar {
        width: 200px;
    }
}

@media (max-width: 800px) {
    .ex-code-sidebar {
        display: none;
    }
}