/* Online compiler / editor (ACE) — dev theme overrides */

/* Toolbar buttons */
.dev-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--dev-border);
    border-radius: var(--dev-radius-sm);
    background: #fff;
    color: var(--dev-text);
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.dev-btn:hover {
    border-color: var(--dev-border-strong);
    background: #f8fafc;
}

.dev-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.dev-btn--primary {
    border-color: var(--dev-accent);
    background: var(--dev-accent);
    color: #fff;
}

.dev-btn--primary:hover {
    border-color: var(--dev-accent-hover);
    background: var(--dev-accent-hover);
    color: #fff;
}

.dev-btn--danger {
    border-color: #fecaca;
    background: #fef2f2;
    color: #dc2626;
}

.dev-btn--danger:hover {
    border-color: #fca5a5;
    background: #fee2e2;
}

.dev-toolbar__group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.dev-toolbar__label {
    font-size: 12px;
    color: var(--dev-text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.dev-toolbar #select2-version {
    display: inline-block;
    vertical-align: middle;
}

/* ACE host */
.dev-ace-host {
    position: relative;
    flex: 1;
    min-height: 0;
}

.dev-ace-host > #content {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    float: none !important;
}

/* Run pages: split = 100vh − header − workspace pad − tabs − title − ad(122) — same as homepage */
body.dev-run-page {
    --dev-ad-slot-h: 122px;
    --dev-run-split-h: calc(
        100vh
        - var(--dev-header-h, 50px)
        - var(--dev-workspace-pad-top, 8px)
        - var(--dev-tabs-block-h, 44px)
        - var(--dev-page-title-h, 0px)
        - var(--dev-ad-slot-h, 122px)
    );
}

body.dev-run-page:not(:has(.dev-ad-slot > *)) {
    --dev-ad-slot-h: 0px;
}

body.dev-run-page .dev-editor-split {
    margin-bottom: 0;
    align-items: stretch;
    height: var(--dev-run-split-h);
    min-height: 320px;
}

body.dev-run-page .dev-ad-slot:has(> *) {
    height: var(--dev-ad-slot-h, 122px) !important;
    min-height: var(--dev-ad-slot-h, 122px) !important;
    max-height: var(--dev-ad-slot-h, 122px) !important;
}

.dev-run-page .dev-panel,
.dev-run-page .dev-run-compiler__right {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

/* Run pages: 5:5 default split (homepage JSON uses 42:58 in dev-theme.css) */
.dev-run-editor.dev-editor-split,
.dev-run-compiler.dev-editor-split {
    grid-template-columns: minmax(240px, 50fr) minmax(280px, 50fr);
}

.dev-run-editor.dev-split-4-6,
.dev-run-compiler.dev-split-4-6 {
    grid-template-columns: minmax(220px, 40fr) minmax(280px, 60fr);
}

.dev-run-editor.dev-split-6-4,
.dev-run-compiler.dev-split-6-4 {
    grid-template-columns: minmax(280px, 60fr) minmax(220px, 40fr);
}

.dev-run-editor.dev-split-3-7,
.dev-run-compiler.dev-split-3-7 {
    grid-template-columns: minmax(200px, 30fr) minmax(280px, 70fr);
}

.dev-run-editor.dev-split-7-3,
.dev-run-compiler.dev-split-7-3 {
    grid-template-columns: minmax(280px, 70fr) minmax(200px, 30fr);
}

.dev-run-editor .dev-split-ratio,
.dev-run-compiler .dev-split-ratio {
    width: 72px;
    min-width: 72px;
    padding: 0 6px;
}

/* Bottom ad slot — hard lock 122px on run pages */
body.dev-page.dev-run-page .dev-ad-slot:has(> *) {
    display: block !important;
    height: 122px !important;
    min-height: 122px !important;
    max-height: 122px !important;
    margin: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

.dev-page.dev-run-page .dev-ad-slot:not(:has(*)) {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    border: 0 !important;
    margin: 0 !important;
}

.dev-run-page:not(:has(.dev-ad-slot > *)) {
    --dev-ad-slot-h: 0px;
}

/* ACE / preview fill panel — height driven by grid row */
.dev-run-editor .dev-ace-host,
.dev-run-compiler .dev-ace-host,
.dev-run-editor .dev-run-preview,
.dev-run-output-panel {
    flex: 1 1 auto;
    min-height: 0;
    height: auto !important;
}

/* Compiler right column — tabbed stdin / result */
.dev-run-compiler__right {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.dev-run-output-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: auto !important;
}

/* HTML editor preview */
.dev-run-preview {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    background: #fff;
}

.dev-run-preview > #iframeResult,
.dev-run-result__body > #iframeResult {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

.dev-run-panel-tabs {
    justify-content: space-between;
    gap: 10px;
}

.dev-panel-tabs__nav {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.dev-panel-tabs__item {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: var(--dev-radius-sm);
    background: transparent;
    color: var(--dev-text-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.dev-panel-tabs__item:hover {
    color: var(--dev-text);
    background: #fff;
    border-color: var(--dev-border);
}

.dev-panel-tabs__item.is-active {
    color: var(--dev-accent);
    background: #fff;
    border-color: var(--dev-border);
    box-shadow: inset 0 -2px 0 var(--dev-accent);
}

.dev-panel-tabs__actions {
    margin-left: auto;
}

.dev-panel-tabs__action-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dev-panel-tabs__action-group[hidden] {
    display: none !important;
}

.dev-panel-tabs__body {
    flex: 1;
    min-height: 0;
    padding: 0;
    position: relative;
}

.dev-panel-tabs__pane {
    display: none;
    height: 100%;
    min-height: 0;
}

.dev-panel-tabs__pane.is-active {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.dev-panel-tabs__pane > #stdin {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 100%;
    padding: 10px 12px;
    border: 0;
    resize: none;
    outline: none;
    background: #fafbfc;
    color: var(--dev-text);
    font-family: var(--dev-mono);
    font-size: 13px;
    line-height: 1.45;
    box-sizing: border-box;
}

.dev-run-result__body,
#iframewrapper {
    flex: 1;
    min-height: 0;
    position: relative;
    background: #fff;
    width: 100%;
    height: 100%;
}

.dev-run-compiler #iframewrapper > #iframeResult {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.dev-run-editor.is-full-right.dev-editor-split,
.dev-run-compiler.is-full-right.dev-editor-split {
    grid-template-columns: 1fr !important;
}

.dev-run-editor.is-full-right #editorL {
    display: none;
}

/* HTML editor — preview / console tabs */
.dev-run-console {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #0b1220;
    overflow: hidden;
}

.dev-run-console__log {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 10px 12px;
    font-family: var(--dev-mono);
    font-size: 12px;
    line-height: 1.55;
}

.dev-run-console__empty {
    padding: 12px;
    color: #94a3b8;
    font-style: italic;
    font-size: 12px;
    line-height: 1.5;
}

.dev-run-console__empty.is-hidden {
    display: none;
}

.dev-run-console__line {
    margin: 0 0 6px;
    white-space: pre-wrap;
    word-break: break-word;
}

.dev-run-console__line--log {
    color: #e2e8f0;
}

.dev-run-console__line--info {
    color: #7dd3fc;
}

.dev-run-console__line--warn {
    color: #fcd34d;
}

.dev-run-console__line--error {
    color: #f87171;
}

.dev-run-console__line--debug {
    color: #94a3b8;
}

.dev-console-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    margin-left: 6px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    vertical-align: middle;
}

.dev-console-badge.is-zero {
    display: none;
}

.dev-panel-tabs__item .dev-console-badge {
    pointer-events: none;
}

/* Modal */
.dev-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.dev-modal.is-open {
    display: flex;
}

.dev-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.dev-modal__dialog {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: var(--dev-radius);
    box-shadow: 0 20px 48px rgba(15, 23, 42, 0.18);
    overflow: hidden;
}

.dev-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--dev-border);
}

.dev-modal__title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--dev-text);
}

.dev-modal__close {
    border: 0;
    background: transparent;
    color: var(--dev-text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.dev-modal__body {
    padding: 16px;
}

.dev-modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--dev-border);
}

.dev-form-group {
    margin-bottom: 14px;
}

.dev-form-group:last-child {
    margin-bottom: 0;
}

.dev-form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--dev-text-muted);
}

.dev-input {
    width: 100%;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--dev-border);
    border-radius: var(--dev-radius-sm);
    font-size: 13px;
    color: var(--dev-text);
    background: #fff;
    box-sizing: border-box;
}

.dev-input:focus {
    outline: none;
    border-color: var(--dev-accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

@media screen and (max-width: 1440px) {
    .dev-run-editor .dev-toolbar,
    .dev-run-compiler .dev-panel--input .dev-toolbar {
        flex-wrap: wrap;
        align-content: flex-start;
        overflow: hidden;
        height: auto;
        min-height: var(--dev-panel-header-h);
        row-gap: 6px;
        padding: 6px 10px;
    }

    .dev-run-editor .dev-toolbar__group,
    .dev-run-compiler .dev-panel--input .dev-toolbar__group {
        flex-wrap: wrap;
    }

    .dev-run-panel-tabs {
        flex-wrap: wrap;
        height: auto;
        min-height: var(--dev-panel-header-h);
        row-gap: 6px;
        padding: 6px 10px;
    }

    .dev-run-panel-tabs .dev-panel-tabs__actions {
        flex-wrap: wrap;
    }
}

@media screen and (max-width: 992px) {
    .dev-run-editor.dev-editor-split,
    .dev-run-compiler.dev-editor-split,
    .dev-run-editor[class*="dev-split-"],
    .dev-run-compiler[class*="dev-split-"] {
        grid-template-columns: 1fr !important;
        gap: 8px;
    }

    .dev-run-editor .dev-panel,
    .dev-run-compiler .dev-panel,
    .dev-run-compiler .dev-run-compiler__right {
        min-height: 240px;
    }

    .dev-run-editor .dev-ace-host,
    .dev-run-compiler .dev-ace-host,
    .dev-run-output-panel {
        min-height: 220px;
    }

    .dev-run-editor .dev-split-ratio,
    .dev-run-compiler .dev-split-ratio,
    .dev-run-editor label[for="splitRatio"],
    .dev-run-compiler label[for="splitRatio"] {
        display: none;
    }
}

@media screen and (max-width: 960px) {
    .dev-run-page .dev-editor-split {
        min-height: 280px;
    }
}
