/* Interactive Python Code Blocks - VS Code Style */

.interactive-python-block {
    margin: 1.5em 0;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    background: #ffffff;
}

/* Editor header with run button */
.python-editor-header {
    background: #f6f8fa;
    border-bottom: 1px solid #e1e4e8;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.run-python-btn {
    background: #0969da;
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.run-python-btn:hover:not(:disabled) {
    background: #0860ca;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(9, 105, 218, 0.3);
}

.run-python-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
    opacity: 0.6;
}

.run-python-btn:active:not(:disabled) {
    background: #0757ba;
    transform: translateY(0);
}

/* Dark theme header - removed prefers-color-scheme, only use data-bs-theme */

[data-bs-theme="dark"] .interactive-python-block {
    background: #0d1117;
    border-color: #30363d;
}

[data-bs-theme="dark"] .python-editor-header {
    background: #161b22;
    border-bottom-color: #30363d;
}

.python-output {
    margin-top: 8px;
    padding: 16px;
    background: #f8f9fa;
    border: 1px solid #e1e4e8;
    border-left: 3px solid #0066cc;
    border-radius: 6px;
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: #24292e;
}

.python-output:empty {
    display: none !important;
}

.python-output-error {
    background: #fff5f5;
    border-left-color: #dc3545;
    color: #c00;
}

/* Notification */
.pyodide-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease-out;
    max-width: 400px;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.pyodide-notification.fade-out {
    animation: fadeOut 0.5s ease-out;
    opacity: 0;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

.pyodide-notification-info {
    background: #e3f2fd;
    color: #1976d2;
    border: 1px solid #90caf9;
}

.pyodide-notification-success {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #81c784;
}

.pyodide-notification-warning {
    background: #fff3e0;
    color: #e65100;
    border: 1px solid #ffb74d;
}

.pyodide-notification-error {
    background: #ffebee;
    color: #c62828;
    border: 1px solid #e57373;
}

/* Dark mode support - removed prefers-color-scheme */

/* Support both dark mode methods */
[data-bs-theme="dark"] .python-output {
    background: #2d2d2d !important;
    border: 1px solid #404040 !important;
    border-left: 3px solid #4a9eff !important;
    color: #e4e4e4 !important;
}

[data-bs-theme="dark"] .python-output-error {
    background: #3a2020 !important;
    border: 1px solid #5a3030 !important;
    border-left-color: #ff6b6b !important;
    color: #ffb3b3 !important;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .pyodide-notification {
        right: 10px;
        left: 10px;
        max-width: none;
    }

    .run-python-btn {
        font-size: 13px;
        padding: 5px 12px;
    }
}

/* Print styles - hide interactive elements */
@media print {
    .python-run-container,
    .python-output,
    .pyodide-notification {
        display: none !important;
    }

    .interactive-python-block {
        border: none;
        box-shadow: none;
    }
}

/* Monaco Editor container */
.python-code-editor {
    width: 100%;
    height: 300px;
    min-height: 150px;
    border: 1px solid #e1e4e8;
    border-radius: 4px;
    overflow: hidden;
}

[data-bs-theme="dark"] .python-code-editor {
    border-color: #30363d;
}

/* CodeMirror 5 styling */
.python-code-editor .CodeMirror {
    height: auto;
    min-height: 120px;
    max-height: 600px;
    font-family: 'Fira Code', 'SF Mono', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.6;
    border: none;
    background: #faf4ed;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

.python-code-editor .CodeMirror-scroll {
    min-height: 120px;
    max-height: 600px;
    padding: 8px 0;
}

/* Line numbers styling - Monokai Pro Light */
.python-code-editor .CodeMirror-gutters {
    background-color: #f0ebe0;
    border-right: none;
    padding-right: 4px;
}

.python-code-editor .CodeMirror-linenumber {
    color: #9893a5;  /* Monokai Pro Light muted purple-gray */
    padding: 0 12px 0 8px;
    text-align: right;
    font-size: 13px;
    font-weight: 400;
}

/* Fold gutter */
.python-code-editor .CodeMirror-foldgutter {
    width: 16px;
}

.python-code-editor .CodeMirror-foldmarker {
    color: #237893;
    cursor: pointer;
    font-family: monospace;
}

/* Cursor visibility */
.python-code-editor .CodeMirror-cursor {
    border-left: 2px solid #0969da;
    border-right: none;
    width: 0;
}

.python-code-editor .CodeMirror-focused .CodeMirror-cursor {
    border-left-color: #0969da;
}

/* Selected text - VS Code style with high specificity to override theme */
.python-code-editor .cm-s-monokai-pro-light .CodeMirror-selected,
.python-code-editor .CodeMirror.cm-s-monokai-pro-light .CodeMirror-selected,
.python-code-editor .CodeMirror-selected {
    background: #cce7ff !important;
}

.python-code-editor .cm-s-monokai-pro-light .CodeMirror-focused .CodeMirror-selected,
.python-code-editor .CodeMirror.cm-s-monokai-pro-light.CodeMirror-focused .CodeMirror-selected,
.python-code-editor .CodeMirror-focused .CodeMirror-selected {
    background: #add6ff !important;
}

/* Selection styling for pre tags (for line wrapping) */
.python-code-editor .cm-s-monokai-pro-light .CodeMirror-line > span::selection,
.python-code-editor .CodeMirror-line > span::selection,
.python-code-editor .cm-s-monokai-pro-light .CodeMirror-line > span > span::selection,
.python-code-editor .CodeMirror-line > span > span::selection {
    background: #add6ff;
}

.python-code-editor .cm-s-monokai-pro-light .CodeMirror-line > span::-moz-selection,
.python-code-editor .CodeMirror-line > span::-moz-selection,
.python-code-editor .cm-s-monokai-pro-light .CodeMirror-line > span > span::-moz-selection,
.python-code-editor .CodeMirror-line > span > span::-moz-selection {
    background: #add6ff;
}

/* Current line highlight */
.python-code-editor .CodeMirror-activeline-background {
    background: rgba(175, 184, 193, 0.08);
}

/* Code padding */
.python-code-editor .CodeMirror-lines {
    padding: 8px 0;
}

.python-code-editor .CodeMirror-line {
    padding: 0 8px;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

.python-code-editor .CodeMirror-lines {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

/* Dark theme support - removed prefers-color-scheme */

[data-bs-theme="dark"] .python-code-editor {
    background: #0d1117;
}

[data-bs-theme="dark"] .python-code-editor .CodeMirror {
    background: #0d1117;
}

[data-bs-theme="dark"] .python-code-editor .CodeMirror-gutters {
    background-color: #161b22;
    border-right-color: #30363d;
}

[data-bs-theme="dark"] .python-code-editor .CodeMirror-linenumber {
    color: #8b949e;
}

[data-bs-theme="dark"] .python-code-editor .CodeMirror-cursor {
    border-left-color: #58a6ff;
}

[data-bs-theme="dark"] .python-code-editor .cm-s-monokai .CodeMirror-selected,
[data-bs-theme="dark"] .python-code-editor .CodeMirror.cm-s-monokai .CodeMirror-selected,
[data-bs-theme="dark"] .python-code-editor .CodeMirror-selected {
    background: #264f78 !important;
}

[data-bs-theme="dark"] .python-code-editor .cm-s-monokai .CodeMirror-focused .CodeMirror-selected,
[data-bs-theme="dark"] .python-code-editor .CodeMirror.cm-s-monokai.CodeMirror-focused .CodeMirror-selected,
[data-bs-theme="dark"] .python-code-editor .CodeMirror-focused .CodeMirror-selected {
    background: #3a5a7e !important;
}

/* Dark theme selection for native text selection */
[data-bs-theme="dark"] .python-code-editor .cm-s-monokai .CodeMirror-line > span::selection,
[data-bs-theme="dark"] .python-code-editor .CodeMirror-line > span::selection,
[data-bs-theme="dark"] .python-code-editor .cm-s-monokai .CodeMirror-line > span > span::selection,
[data-bs-theme="dark"] .python-code-editor .CodeMirror-line > span > span::selection {
    background: #3a5a7e;
}

[data-bs-theme="dark"] .python-code-editor .cm-s-monokai .CodeMirror-line > span::-moz-selection,
[data-bs-theme="dark"] .python-code-editor .CodeMirror-line > span::-moz-selection,
[data-bs-theme="dark"] .python-code-editor .cm-s-monokai .CodeMirror-line > span > span::-moz-selection,
[data-bs-theme="dark"] .python-code-editor .CodeMirror-line > span > span::-moz-selection {
    background: #3a5a7e;
}

[data-bs-theme="dark"] .python-code-editor .CodeMirror-activeline-background {
    background: rgba(110, 118, 129, 0.1);
}

/* Code-fold compatibility - adjust button position */
div.sourceCode.cell-code .python-run-container {
    right: 48px !important;
}

/* Loading skeleton for better UX */
.pyodide-loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    height: 20px;
    border-radius: 4px;
    margin: 4px 0;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
