/* Ballerina Playground — Monaco editor + Run/Debug (v2 compact) */

/* ── Hide raw code blocks before JS upgrades them ── */
.bal-code-block pre {
    position: relative;
    overflow: hidden;
}

/* ── Container ─────────────────────────────────────── */
.bal-playground {
    position: relative;
    border: 1px solid var(--md-default-fg-color--lightest);
    border-radius: 4px;
    margin: 0.5em 0 0.8em;
    overflow: hidden;
    background: var(--md-code-bg-color);
    font-family: var(--md-code-font-family, "Fira Code", monospace);
    contain: layout style;
}

/* ── Editor area ───────────────────────────────────── */
.bal-playground .bal-editor {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 50px;
    overflow: hidden;
}

/* ── Middle row (editor + debug side panel) ─────────── */
.bal-middle-row {
    display: flex;
    flex-direction: row;
    width: 100%;
    position: relative;
}

/* ── Toolbar (icon-only, single line) ──────────────── */
.bal-toolbar {
    display: flex;
    align-items: center;
    gap: 1px;
    padding: 0 2px;
    background: var(--md-code-bg-color);
    border-bottom: 1px solid var(--md-default-fg-color--lightest);
    height: 22px;
}

.bal-toolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: none;
    border-radius: 2px;
    background: transparent;
    color: var(--md-default-fg-color);
    font-size: 0.72rem;
    cursor: pointer;
    transition: background 0.1s;
    white-space: nowrap;
    line-height: 20px;
    height: 20px;
}

.bal-toolbar button:hover {
    background: var(--md-default-fg-color--lightest);
}

.bal-toolbar button:disabled {
    opacity: 0.25;
    cursor: default;
    pointer-events: none;
}

.bal-toolbar .bal-btn-run {
    color: #16a34a;
}

.bal-toolbar .bal-btn-run:hover {
    background: #16a34a18;
}

.bal-toolbar .bal-btn-debug {
    color: #d97706;
}

.bal-toolbar .bal-btn-debug:hover {
    background: #d9770618;
}

.bal-toolbar .bal-btn-stop {
    color: #dc2626;
}

.bal-toolbar .bal-btn-stop:hover {
    background: #dc262618;
}

.bal-toolbar .bal-btn-maximize {
    color: var(--md-default-fg-color--light);
}

.bal-toolbar .bal-btn-maximize:hover {
    background: var(--md-default-fg-color--lightest);
    color: var(--md-default-fg-color);
}

.bal-toolbar .bal-btn-close {
    color: #dc2626;
}

.bal-toolbar .bal-btn-close:hover {
    background: #dc262618;
}

.bal-toolbar .bal-btn-slow-run {
    color: #0891b2;
}

.bal-toolbar .bal-btn-slow-run:hover {
    background: #0891b218;
}

.bal-toolbar .bal-speed-select {
    font-size: 0.62rem;
    height: 18px;
    padding: 0 2px;
    border: 1px solid var(--md-default-fg-color--lightest);
    border-radius: 2px;
    background: var(--md-code-bg-color);
    color: var(--md-default-fg-color);
    cursor: pointer;
}

.bal-toolbar .bal-sep {
    width: 1px;
    height: 12px;
    background: var(--md-default-fg-color--lightest);
    margin: 0 2px;
}

.bal-toolbar .bal-spacer {
    flex: 1;
}

/* ── Debug toolbar (compact) ───────────────────────── */
.bal-debug-toolbar {
    display: none;
    align-items: center;
    gap: 1px;
    padding: 0 2px;
    background: #fef3c7;
    border-bottom: 1px solid #fbbf2480;
    height: 22px;
}

[data-md-color-scheme="slate"] .bal-debug-toolbar {
    background: #422006;
    border-bottom-color: #92400e;
}

.bal-debug-toolbar.active {
    display: flex;
}

.bal-debug-toolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: none;
    border-radius: 2px;
    background: transparent;
    color: var(--md-default-fg-color);
    font-size: 0.72rem;
    cursor: pointer;
    line-height: 20px;
    height: 20px;
}

.bal-debug-toolbar button:hover {
    background: #d9770620;
}

.bal-debug-toolbar .bal-speed-select {
    font-size: 0.62rem;
    height: 18px;
    padding: 0 2px;
    border: 1px solid var(--md-default-fg-color--lightest);
    border-radius: 2px;
    background: var(--md-code-bg-color);
    color: var(--md-default-fg-color);
    margin-left: auto;
    cursor: pointer;
}

/* ── Bottom panel: output only, full width ─── */
.bal-bottom-panel {
    display: none;
    border-top: 1px solid var(--md-default-fg-color--lightest);
    background: var(--md-code-bg-color);
    max-height: 200px;
}

.bal-bottom-panel.active {
    display: flex;
}

/* ── Output (console) ─────────────────────────────── */
.bal-output {
    flex: 1;
    min-width: 0;
    max-height: 200px;
    overflow-y: auto;
    padding: 3px 6px;
    font-size: 0.72rem;
    line-height: 1.35;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--md-default-fg-color);
}

.bal-output .bal-out-line {
    margin: 0;
}

.bal-output .bal-out-error {
    color: #dc2626;
}

.bal-output .bal-out-success {
    color: #16a34a;
}

.bal-output .bal-out-info {
    color: var(--md-default-fg-color--light);
    font-style: italic;
}

.bal-output .bal-out-warning {
    color: #d97706;
}

.bal-output .bal-out-hint {
    color: var(--md-default-fg-color--light);
    font-style: italic;
    padding-left: 0.5em;
}

/* Trace annotations emitted at function call boundaries during debug stepping */
.bal-output .bal-out-call-enter {
    color: #2563eb;   /* blue */
    font-style: italic;
    opacity: 0.85;
}

.bal-output .bal-out-call-return {
    color: #7c3aed;   /* purple */
    font-style: italic;
    opacity: 0.85;
}

/* ── Maximized overlay ─────────────────────────────── */
.bal-playground.bal-maximized {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    z-index: 9999;
    margin: 0;
    border-radius: 0;
    border: none;
    display: flex;
    flex-direction: column;
}

.bal-maximized .bal-middle-row {
    flex: 1;
    min-height: 0;
}

.bal-maximized .bal-editor {
    height: 100% !important;
    max-height: none !important;
    min-height: 0;
}

.bal-maximized .bal-side-panel,
.bal-maximized .bal-side-panel.active {
    flex: 0 0 40%;
    max-width: 40%;
}

.bal-maximized .bal-bottom-panel {
    max-height: 30vh;
}

.bal-maximized .bal-output {
    max-height: 30vh;
}

/* ── Side panel (call stack top, variables bottom — debug only) ─ */
.bal-side-panel {
    display: none;
    flex: 0 0 200px;
    min-width: 0;
    max-width: 200px;
    border-left: 1px solid var(--md-default-fg-color--lightest);
    flex-direction: column;
    background: var(--md-code-bg-color);
    position: relative;
    overflow: hidden;
    transition: flex-basis 0.15s ease, max-width 0.15s ease;
}

.bal-side-panel.active {
    display: flex;
}

.bal-side-panel.folded {
    flex: 0 0 18px;
    max-width: 18px;
}

.bal-side-panel.folded .bal-callstack,
.bal-side-panel.folded .bal-variables {
    display: none !important;
}

/* ── Fold toggle button ────────────────────────────── */
.bal-fold-toggle {
    position: absolute;
    top: 2px;
    left: 2px;
    z-index: 10;
    width: 14px;
    height: 14px;
    padding: 0;
    border: none;
    border-radius: 2px;
    background: transparent;
    color: var(--md-default-fg-color--light);
    font-size: 0.6rem;
    line-height: 14px;
    text-align: center;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bal-fold-toggle:hover {
    background: var(--md-default-fg-color--lightest);
    color: var(--md-default-fg-color);
}

/* ── Variables panel (bottom of side panel in debug mode) ── */
.bal-variables {
    display: none;
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    overflow-x: auto;
    padding: 2px 4px;
    font-size: 0.62rem;
    background: var(--md-code-bg-color);
}

.bal-variables.active {
    display: block;
}

.bal-variables-title {
    font-size: 0.56rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--md-default-fg-color--light);
    margin-bottom: 1px;
    padding: 1px 2px;
}

.bal-variables table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.62rem;
    min-width: max-content;
}

.bal-variables th {
    text-align: left;
    font-weight: 600;
    padding: 0 2px;
    border-bottom: 1px solid var(--md-default-fg-color--lightest);
    color: var(--md-default-fg-color--light);
    font-size: 0.56rem;
}

.bal-variables td {
    padding: 0 2px;
    border-bottom: 1px solid var(--md-default-fg-color--lightest);
    line-height: 1.4;
    vertical-align: top;
}

/* Primary: variable name */
.bal-variables .bal-var-name-cell {
    white-space: nowrap;
    padding-right: 6px;
}

.bal-variables .bal-var-name {
    color: #2563eb;
    font-weight: 600;
    font-size: 0.65rem;
    line-height: 1.2;
}

[data-md-color-scheme="slate"] .bal-variables .bal-var-name {
    color: #60a5fa;
}

/* Secondary: type shown below the name */
.bal-variables .bal-var-type-hint {
    color: var(--md-default-fg-color--light);
    font-size: 0.54rem;
    font-style: italic;
    line-height: 1.1;
    display: block;
}

.bal-variables td.bal-var-value {
    font-family: var(--md-code-font-family, monospace);
    word-break: break-all;
    white-space: nowrap;
}

/* ── Call Stack panel (top of side panel in debug mode) ── */
.bal-callstack {
    display: none;
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 2px 4px;
    padding-top: 18px; /* room for fold toggle button */
    font-size: 0.62rem;
    border-bottom: 1px solid var(--md-default-fg-color--lightest);
    background: var(--md-code-bg-color);
}

.bal-callstack.active {
    display: block;
}

.bal-stack-frame {
    padding: 1px 3px;
    font-family: var(--md-code-font-family, monospace);
    color: var(--md-default-fg-color);
    border-bottom: 1px solid var(--md-default-fg-color--lightest);
    line-height: 1.4;
    white-space: nowrap;
    cursor: pointer;
}

.bal-stack-frame:hover {
    background: var(--md-default-fg-color--lightest);
}

.bal-stack-frame.bal-stack-active {
    color: #2563eb;
    font-weight: 500;
    background: #2563eb10;
}

/* ── Current line highlight ────────────────────────── */
.bal-current-line-decoration {
    background: #fef08a80 !important;
}

[data-md-color-scheme="slate"] .bal-current-line-decoration {
    background: #854d0e40 !important;
}

/* ── Breakpoint gutter ─────────────────────────────── */
.bal-breakpoint-glyph {
    background: #dc2626;
    border-radius: 50%;
    width: 8px !important;
    height: 8px !important;
    margin-left: 4px;
    margin-top: 4px;
}

/* ── Compile-error examples ────────────────────────── */
.bal-playground.has-error {
    border-left: 3px solid #dc2626;
}

/* ── Dark theme overrides (MkDocs Material "slate" scheme) ─── */

/* Toolbar icon colours — lighter variants so they're visible on dark bg */
[data-md-color-scheme="slate"] .bal-toolbar .bal-btn-run         { color: #4ade80; }
[data-md-color-scheme="slate"] .bal-toolbar .bal-btn-run:hover   { background: #4ade8018; }
[data-md-color-scheme="slate"] .bal-toolbar .bal-btn-debug       { color: #fbbf24; }
[data-md-color-scheme="slate"] .bal-toolbar .bal-btn-debug:hover { background: #fbbf2418; }
[data-md-color-scheme="slate"] .bal-toolbar .bal-btn-stop        { color: #f87171; }
[data-md-color-scheme="slate"] .bal-toolbar .bal-btn-stop:hover  { background: #f8717118; }
[data-md-color-scheme="slate"] .bal-toolbar .bal-btn-close       { color: #f87171; }
[data-md-color-scheme="slate"] .bal-toolbar .bal-btn-close:hover { background: #f8717118; }
[data-md-color-scheme="slate"] .bal-toolbar .bal-btn-slow-run        { color: #22d3ee; }
[data-md-color-scheme="slate"] .bal-toolbar .bal-btn-slow-run:hover  { background: #22d3ee18; }

/* Output panel text — lighter variants for dark backgrounds */
[data-md-color-scheme="slate"] .bal-output .bal-out-error   { color: #f87171; }
[data-md-color-scheme="slate"] .bal-output .bal-out-success { color: #4ade80; }
[data-md-color-scheme="slate"] .bal-output .bal-out-warning { color: #fbbf24; }
[data-md-color-scheme="slate"] .bal-output .bal-out-call-enter  { color: #60a5fa; }
[data-md-color-scheme="slate"] .bal-output .bal-out-call-return { color: #a78bfa; }

/* Active call-stack frame */
[data-md-color-scheme="slate"] .bal-stack-frame.bal-stack-active {
    color: #60a5fa;
    background: #60a5fa18;
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 600px) {
    .bal-middle-row {
        flex-direction: column;
    }

    .bal-side-panel {
        flex: 0 0 auto;
        max-width: none;
        border-left: none;
        border-top: 1px solid var(--md-default-fg-color--lightest);
        flex-direction: row;
    }

    .bal-side-panel.folded {
        flex: 0 0 18px;
        max-width: none;
    }

    .bal-callstack {
        border-bottom: none;
        border-right: 1px solid var(--md-default-fg-color--lightest);
        padding-top: 2px;
    }
}