/* ====== CORE STYLES ====== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #21162e;
    --bg-tertiary: #231a2c;
    --border-color: #362d4c;
    --text-primary: #e2e8f0;
    --text-secondary: #a0aec0;
    --success-color: #752cc3;
    --error-color: #ff6b6b;
    --output-bg: #110a15;
    --output-header: #752cc3;
    --output-text: #c6c0e0;
    --output-border: #752cc3;
    --warning-bg-start: #FFA500;
    --warning-bg-end: #FF8C00;
    --warning-border: #FF4500;
    --warning-text: #241e1e;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-primary);
    color: #fff;
    overflow-x: hidden;
    padding-bottom: 40px;
    padding-top: 60px;
}

/* ====== TOP BAR ====== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--output-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
}

.status-indicator {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.status-ready { background: #4a5568; color: white; }
.status-loading { background: #5a6c7d; color: white; }
.status-error { background: #6b7280; color: white; }

/* ====== MAIN LAYOUT ====== */
.main-container {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 40px;
    display: flex;
    flex-direction: column;
}

/* Editor Section */
.editor-section {
    flex: 0 0 60%;
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.editor-header {
    height: 40px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.editor-container {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

.line-numbers {
    width: 40px;
    background: var(--bg-tertiary);
    color: #718096;
    padding: 12px 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    line-height: 1.6;
    text-align: right;
    user-select: none;
    white-space: pre;
    overflow: hidden;
    border-right: 1px solid var(--border-color);
}

.editor-wrapper {
    flex: 1;
    position: relative;
    background: var(--bg-secondary);
}

.code-editor {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    line-height: 1.6;
    background: transparent;
    color: transparent;
    caret-color: var(--text-primary);
    padding: 12px;
    border: none;
    resize: none;
    outline: none;
    overflow: auto;
    white-space: pre;
    word-wrap: normal;
    z-index: 2;
}

.syntax-highlight {
    position: absolute;
    inset: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    line-height: 1.6;
    background: var(--bg-secondary);
    padding: 12px;
    overflow: auto;
    pointer-events: none;
    white-space: pre;
    word-wrap: normal;
    z-index: 1;
    color: #d4d4d4;
}

/* Output Section */
.output-section {
    flex: 0 0 40%;
    background: var(--output-bg);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.output-header {
    height: 40px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--output-text);
}

.output-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.args-btn {
    background: rgba(74, 143, 74, 0.3);
    border: 1px solid var(--output-border);
    color: var(--output-text);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.args-btn:hover {
    background: rgba(91, 74, 143, 0.5);
}

.output-area {
    flex: 1;
    padding: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    line-height: 1.6;
    color: var(--output-text);
    overflow-y: auto;
    overflow-x: hidden;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 0;
}

.output-area img {
    max-width: 100%;
    height: auto;
    max-height: 400px;
    border: 2px solid var(--output-border);
    border-radius: 8px;
    margin: 8px 0;
    display: block;
}

/* Compatibility Warning Styles */
.compatibility-warning {
    background: linear-gradient(135deg, var(--warning-bg-start), var(--warning-bg-end));
    color: var(--warning-text);
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 8px;
    border-left: 4px solid var(--warning-border);
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.4;
}

.compatibility-warning-title {
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 14px;
}

.compatibility-warning-item {
    margin-bottom: 6px;
    padding-left: 16px;
}

.compatibility-warning-item strong {
    font-weight: 600;
}

.compatibility-warning-suggestion {
    margin-top: 8px;
    font-style: italic;
}

/* Input Field for input() function */
.input-container {
    display: inline-flex;
    gap: 8px;
    margin: 0 5px;
    align-items: center;
    vertical-align: middle;
}

.input-container.inline {
    display: inline-flex;
    margin-left: 5px;
}

.input-prompt {
    color: #a0aec0;
    font-size: 14px;
}

.input-field {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--output-border);
    color: var(--output-text);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    outline: none;
    min-width: 200px;
}

.input-field:focus {
    border-color: var(--success-color);
    background: rgba(255, 255, 255, 0.15);
}

.input-submit {
    background: var(--success-color);
    border: none;
    color: white;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

.input-submit:hover {
    background: #45a049;
}

/* ====== BOTTOM CONTROLS ====== */
.bottom-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: var(--bg-secondary);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid #333;
    display: flex;
    justify-content: center;
    padding: 6px 16px;
    gap: 12px;
    z-index: 1000;
}

.control-btn {
    flex: 1;
    height: 32px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-run {
    background: linear-gradient(135deg, #33881e, #345e36);
    color: white;
}

.btn-run:hover:not(:disabled) {
    background: linear-gradient(135deg, #63bc4b, #378c26);
    transform: translateY(-1px);
}

.btn-clear {
    background: linear-gradient(135deg, #5a6c7d, #485a6b);
    color: white;
}

.btn-clear:hover:not(:disabled) {
    background: linear-gradient(135deg, #485a6b, #3e4c59);
    transform: translateY(-1px);
}

.btn-copy {
    background: linear-gradient(135deg, #4a5568, #2d3748);
    color: white;
}

.btn-copy:hover:not(:disabled) {
    background: linear-gradient(135deg, #2d3748, #1a202c);
    transform: translateY(-1px);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-running {
    background: linear-gradient(45deg, #2c3e50, #34495e);
    background-size: 400% 400%;
    animation: gradientShift 2s ease infinite;
}

.btn-success {
    background: var(--success-color) !important;
}

.btn-error {
    background: var(--error-color) !important;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* ====== SYNTAX HIGHLIGHTING ====== */
.syntax-highlight .token.comment { color: #6a9955; }
.syntax-highlight .token.keyword { color: #569cd6; }
.syntax-highlight .token.string { color: #ce9178; }
.syntax-highlight .token.number { color: #b5cea8; }
.syntax-highlight .token.function { color: #dcdcaa; }
.syntax-highlight .token.operator { color: #d4d4d4; }
.syntax-highlight .token.punctuation { color: #d4d4d4; }
.syntax-highlight .token.class-name { color: #4ec9b0; }
.syntax-highlight .token.boolean { color: #569cd6; }
.syntax-highlight .token.builtin { color: #569cd6; }

/* ====== MODALS ====== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10001;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    animation: fadeIn 0.2s ease;
}

.modal.show {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    max-width: 95vw;
    max-height: 95vh;
    position: relative;
    overflow: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: var(--border-color);
    border: none;
    color: var(--text-primary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.modal-close:hover {
    background: #5a6c7d;
}

/* Arguments Modal */
.args-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.args-input {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    outline: none;
    min-height: 80px;
    resize: vertical;
}

.args-input:focus {
    border-color: var(--success-color);
}

.args-help {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

.args-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 16px;
}

.args-save, .args-cancel {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.args-save {
    background: var(--success-color);
    color: white;
}

.args-save:hover {
    background: #45a049;
}

.args-cancel {
    background: var(--border-color);
    color: white;
}

.args-cancel:hover {
    background: #5a6c7d;
}

/* Chart Modal */
.chart-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
    margin: 0 auto;
}

.chart-actions {
    margin-top: 16px;
    display: flex;
    gap: 12px;
    justify-content: center;
}

.chart-btn {
    background: var(--border-color);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s ease;
}

.chart-btn:hover {
    background: #5a6c7d;
}

/* ====== LOADING OVERLAY ====== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    transition: opacity 0.3s ease;
}

.loading-overlay.hiding {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    background: var(--bg-secondary);
    padding: 32px;
    border-radius: 16px;
    text-align: center;
    max-width: 320px;
    width: 90%;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #333;
    border-top: 4px solid var(--success-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
}

.loading-details {
    color: var(--text-secondary);
    font-size: 14px;
}

.loading-msg {
    color: var(--text-secondary);
    animation: pulse 1.5s ease infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ====== TERMINAL STYLING ====== */
.terminal-output {
    color: var(--output-text);
    white-space: pre-wrap;
    word-break: break-word;
}

.terminal-error {
    color: var(--error-color);
    font-weight: 600;
}

.terminal-success {
    color: var(--success-color);
}

.terminal-loading {
    color: var(--text-secondary);
}

/* ====== RESPONSIVE ====== */
@media (min-width: 768px) {
    .main-container {
        flex-direction: row;
    }

    .editor-section {
        flex: 0 0 55%;
        border-right: 2px solid var(--border-color);
        border-bottom: none;
    }

    .output-section {
        flex: 0 0 45%;
    }

    .control-btn {
        flex: 0 0 140px;
        max-width: 140px;
    }
}

@media (min-width: 1024px) {
    body {
        padding-top: 70px;
        padding-bottom: 50px;
    }

    .top-bar {
        height: 60px;
        padding: 0 24px;
    }

    .bottom-controls {
        height: 50px;
        padding: 8px 24px;
        justify-content: center;
    }

    .control-btn {
        flex: 0 0 120px;
        height: 36px;
        font-size: 14px;
    }

    .code-editor,
    .syntax-highlight,
    .output-area {
        font-size: 14px;
        line-height: 1.5;
    }

    .line-numbers {
        font-size: 14px;
        line-height: 1.5;
    }
}

/* ====== ACCESSIBILITY ====== */
.control-btn:focus-visible {
    outline: none;
}

.code-editor:focus {
    outline: none;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #5a6c7d;
}

.output-area::-webkit-scrollbar-track {
    background: var(--output-header);
}

.output-area::-webkit-scrollbar-thumb {
    background: var(--output-border);
}

/* Performance optimizations */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

.text-center {
    text-align: center!important;
}

/* INFO MODAL*/
.custom-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    color: #1a1a1a;
}
.custom-modal.show {
    display: flex;
}
.custom-modal-content {
    background: #fff;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.custom-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
}
.custom-modal-header h5 {
    margin: 0;
}
.custom-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}
.custom-modal-body {
    padding: 20px;
}
.custom-modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    text-align: right;
}
.custom-modal-btn {
    padding: 8px 16px;
    background: #6c757d;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
.custom-modal-btn:hover {
    background: #5a6268;
}