/**
 * Стили для универсального CodeEditor компонента
 * Используется в Builder, админке тулов, везде где нужен Python редактор
 * Адаптируется под светлую и темную темы
 */

:root {
    --code-editor-bg: #1a202c;
    --code-editor-toolbar-bg: #2d3748;
    --code-editor-border: #4a5568;
    --code-editor-text: #e2e8f0;
    --code-editor-text-secondary: #cbd5e0;
    --code-editor-hover: #4a5568;
    --code-editor-gutter-bg: #21252b;
    --code-editor-gutter-text: #636d83;
}

[data-theme="light"] {
    --code-editor-bg: #ffffff;
    --code-editor-toolbar-bg: #f7fafc;
    --code-editor-border: #e2e8f0;
    --code-editor-text: #1a202c;
    --code-editor-text-secondary: #4a5568;
    --code-editor-hover: #edf2f7;
    --code-editor-gutter-bg: #f7fafc;
    --code-editor-gutter-text: #a0aec0;
}

.code-editor-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    border: 1px solid var(--code-editor-border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--code-editor-bg);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.code-editor-wrapper.code-editor-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 10000 !important;
    border-radius: 0 !important;
    margin: 0 !important;
}

.code-editor-wrapper.code-editor-fullscreen .code-editor-container {
    height: calc(100vh - 100px) !important;
    max-height: none !important;
    position: relative !important;
    z-index: 10000 !important;
}

.code-editor-wrapper.code-editor-fullscreen .code-editor-toolbar {
    z-index: 10000 !important;
}

/* Модалка переменных настроена ниже */

.code-editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--code-editor-toolbar-bg);
    border-bottom: 1px solid var(--code-editor-border);
    transition: background-color 0.2s ease;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--code-editor-text);
}

.toolbar-label i {
    font-size: 16px;
    color: var(--primary-color, #3b82f6);
}

.toolbar-right {
    display: flex;
    gap: 6px;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--code-editor-text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.toolbar-btn:hover {
    background: var(--code-editor-hover);
    color: var(--code-editor-text);
    transform: translateY(-1px);
}

.toolbar-btn:active {
    transform: translateY(0) scale(0.95);
}

.toolbar-btn i {
    display: inline-block;
    font-family: "tabler-icons" !important;
    font-size: 15px;
    line-height: 1;
    color: inherit;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    speak: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.code-editor-container {
    flex: 1;
    overflow: hidden;
    background: var(--code-editor-bg);
    min-height: 200px;
    position: relative;
}

.code-editor-container .ace_editor {
    width: 100% !important;
    height: 100% !important;
    font-size: 14px;
    line-height: 1.6;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
}

/* Ace Editor темная тема (monokai) */
[data-theme="dark"] .code-editor-container .ace_gutter {
    background: var(--code-editor-gutter-bg) !important;
    border-right: 1px solid var(--code-editor-border);
    color: var(--code-editor-gutter-text) !important;
}

/* Ace Editor светлая тема (github) */
[data-theme="light"] .code-editor-container .ace_gutter {
    background: var(--code-editor-gutter-bg) !important;
    border-right: 1px solid var(--code-editor-border);
    color: var(--code-editor-gutter-text) !important;
}

.code-editor-container .ace_gutter-active-line {
    background-color: rgba(59, 130, 246, 0.15) !important;
}

.code-editor-container .ace_active-line {
    background-color: rgba(59, 130, 246, 0.08) !important;
}

.code-editor-container .ace_selection {
    background-color: rgba(59, 130, 246, 0.25) !important;
}

.code-editor-container .ace_autocomplete {
    background: var(--code-editor-bg) !important;
    border: 1px solid var(--code-editor-border) !important;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    color: var(--code-editor-text) !important;
}

.code-editor-container .ace_autocomplete .ace_marker-layer .ace_active-line {
    background: var(--primary-color, #3b82f6) !important;
}

.code-editor-container .ace_autocomplete .ace_line-hover {
    background: var(--code-editor-hover) !important;
}

.code-editor-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--code-editor-toolbar-bg);
    border-top: 1px solid var(--code-editor-border);
    font-size: 12px;
    color: var(--code-editor-text-secondary);
    transition: background-color 0.2s ease;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-item i {
    font-size: 13px;
}

.status-success {
    color: var(--success-color, #10b981);
}

.status-error {
    color: var(--error-color, #ef4444);
}

.status-warning {
    color: var(--warning-color, #f59e0b);
}

.status-info {
    color: var(--info-color, #3b82f6);
}

.status-validating {
    color: var(--text-secondary, #cbd5e0);
}

/* Модальное окно для переменных */
.code-editor-variables-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 100000 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.code-editor-variables-modal.show {
    opacity: 1;
}

.variables-modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.7) !important;
    z-index: 100000 !important;
}

.variables-modal-content {
    position: relative !important;
    background: var(--code-editor-bg) !important;
    border: 1px solid var(--code-editor-border);
    border-radius: 12px;
    width: 95%;
    max-width: 1200px;
    max-height: 90vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5) !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100001 !important;
}

.variables-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--code-editor-toolbar-bg);
    border-bottom: 1px solid var(--code-editor-border);
}

.variables-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--code-editor-text);
}

.variables-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--code-editor-text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.variables-modal-close i {
    display: inline-block;
    font-family: "tabler-icons" !important;
    font-size: 18px;
    line-height: 1;
    color: inherit;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    speak: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.variables-modal-close:hover {
    background: var(--code-editor-hover);
    color: var(--code-editor-text);
}

.variables-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.vars-section {
    margin-bottom: 24px;
}

.vars-section:last-child {
    margin-bottom: 0;
}

.vars-section h4 {
    margin: 0 0 12px 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--code-editor-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.vars-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.var-item {
    display: grid;
    grid-template-columns: minmax(200px, auto) 1fr auto;
    gap: 12px;
    align-items: start;
    padding: 12px;
    background: var(--code-editor-toolbar-bg);
    border: 1px solid var(--code-editor-border);
    border-radius: 8px;
    transition: all 0.15s ease;
}

.var-item:hover {
    border-color: var(--primary-color, #3b82f6);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

.var-key {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-color, #3b82f6);
    word-break: break-all;
}

.var-value {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 12px;
    color: var(--code-editor-text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
}

.var-copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--code-editor-border);
    border-radius: 6px;
    color: var(--code-editor-text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.var-copy-btn:hover {
    background: var(--primary-color, #3b82f6);
    border-color: var(--primary-color, #3b82f6);
    color: white;
    transform: scale(1.05);
}

.var-copy-btn i {
    font-size: 14px;
}

@media (max-width: 768px) {
    .code-editor-toolbar {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .toolbar-right {
        flex-wrap: wrap;
    }
    
    .code-editor-container {
        min-height: 250px;
    }
}

.code-editor-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--code-editor-text-secondary);
    font-size: 14px;
}

.code-editor-loading i {
    margin-right: 8px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* API Documentation styles */
.api-documentation {
    max-height: 80vh;
    overflow-y: auto;
}

.doc-section {
    margin-bottom: 24px;
}

.doc-section h4 {
    margin: 0 0 12px 0;
    color: var(--code-editor-text-primary);
    font-size: 16px;
    font-weight: 600;
    border-bottom: 1px solid var(--code-editor-border);
    padding-bottom: 4px;
}

.api-item {
    margin-bottom: 16px;
    padding: 12px;
    border: 1px solid var(--code-editor-border);
    border-radius: 6px;
    background: var(--code-editor-bg-secondary);
}

.api-name {
    font-weight: 600;
    color: var(--code-editor-text-primary);
    font-family: 'JetBrains Mono', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    margin-bottom: 4px;
}

.api-signature {
    font-family: 'JetBrains Mono', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace, monospace;
    color: var(--code-editor-accent);
    font-size: 13px;
    margin-bottom: 8px;
    word-break: break-all;
}

.api-description {
    color: var(--code-editor-text-secondary);
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.api-description strong {
    color: var(--code-editor-text-primary);
    font-weight: 600;
}

.api-methods {
    margin-top: 8px;
    padding-left: 16px;
    border-left: 2px solid var(--code-editor-border);
}

.api-method {
    margin-bottom: 8px;
    padding: 6px 0;
}

.method-name {
    font-family: 'JetBrains Mono', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace, monospace;
    font-weight: 500;
    color: var(--code-editor-text-primary);
    margin-right: 8px;
}

.method-signature {
    font-family: 'JetBrains Mono', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace, monospace;
    color: var(--code-editor-accent);
    font-size: 12px;
    margin-right: 8px;
}

.method-description {
    color: var(--code-editor-text-secondary);
    font-size: 13px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin-top: 2px;
}

.method-description strong {
    color: var(--code-editor-text-primary);
    font-weight: 600;
}

