/* ═══════════════════════════════════════════════════════════════
   HTML IDE — stylesheet
   Ported from the Python IDE CSS with HTML-specific additions
   ═══════════════════════════════════════════════════════════════ */

* {
    box-sizing: border-box
}

#ide-root {
    font-family: system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    padding: 8px 0;
    visibility: hidden
}

/* ── Toolbar ──────────────────────────────────────────────────── */

#toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px
}

.toolbar-sep {
    width: 1px;
    height: 22px;
    background: var(--color-border-secondary, #555);
    margin: 0 2px
}

button.tb {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 2.2em;
    padding: 0 12px;
    font-size: 1rem;
    font-weight: 600;
    border: 1px solid #fff0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    color: #fff
}

button.tb:hover:not(:disabled) {
    filter: brightness(1.08)
}

button.tb:active:not(:disabled) {
    transform: scale(.97)
}

button.tb:disabled {
    background: #6b7280 !important;
    border-color: #6b7280 !important;
    color: #d1d5db !important;
    opacity: .6;
    cursor: not-allowed;
    transform: none
}

button.tb.primary {
    background: #15803d;
    border-color: #15803d
}

button.tb.primary:hover:not(:disabled) {
    background: #166534;
    border-color: #166534
}

button.tb.success {
    background: #2563eb;
    border-color: #2563eb
}

button.tb.success:hover:not(:disabled) {
    background: #1d4ed8;
    border-color: #1d4ed8
}

button.tb.danger {
    background: #b91c1c;
    border-color: #b91c1c
}

button.tb.danger:hover:not(:disabled) {
    background: #991b1b;
    border-color: #991b1b
}

button.tb:not(.primary):not(.danger):not(.success) {
    background: #2563eb;
    border-color: #2563eb
}

button.tb:not(.primary):not(.danger):not(.success):hover:not(:disabled) {
    background: #1d4ed8;
    border-color: #1d4ed8
}

button.tb.icon-only {
    width: 2.2em;
    justify-content: center;
    padding: 0
}

#dbSaveBtn {
    background: #7c3aed;
    border-color: #7c3aed
}

#dbSaveBtn:hover:not(:disabled) {
    background: #6d28d9;
    border-color: #6d28d9
}

#programsBtn {
    background: #0e7490;
    border-color: #0e7490
}

#programsBtn:hover:not(:disabled) {
    background: #0c6175;
    border-color: #0c6175
}

select.tb {
    height: 2.2em;
    padding: 0 8px;
    font-size: 1rem;
    font-weight: 600;
    border: 1px solid #444;
    border-radius: 6px;
    background: #2a2a2a;
    color: #e8e8e8;
    cursor: pointer
}

.select-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center
}

.select-icon {
    display: none;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    color: #fff;
    font-size: 1rem
}

@media (max-width: 900px) {
    .select-wrapper select.tb {
        width: 2.2em;
        padding: 0;
        color: #fff0;
        text-indent: -9999px
    }

    .select-wrapper select.tb option {
        color: #e8e8e8;
        text-indent: 0
    }

    .select-icon {
        display: block;
        pointer-events: none
    }
}

/* ── Active program badge ─────────────────────────────────────── */

#activeProgramBadge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
    color: #a78bfa;
    background: rgb(124 58 237 / .15);
    border: 1px solid rgb(124 58 237 / .3);
    border-radius: 4px;
    padding: 1px 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    margin-left: 6px
}

#activeProgramBadge.unsaved {
    color: #f59e0b;
    border-color: rgb(245 158 11 / .4);
    background: rgb(245 158 11 / .08)
}

#activeProgramBadge .badge-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0
}

/* ── IDE layout ───────────────────────────────────────────────── */

#ide-layout {
    display: flex;
    flex-direction: row;
    min-height: 220px;
    margin-top: 6px;
    z-index: 2;
    border-radius: 6px 6px 0 0;
    overflow: hidden
}

.outline-23 #ide-layout { height: calc(100vh - 300px) }
.outline-12 #ide-layout { height: calc(100vh - 200px) }
.outline-18 #ide-layout { height: calc(100vh - 100px) }

#editor-wrapper,
#console-wrapper {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0
}

#splitter {
    flex: 0 0 6px;
    background: var(--color-border-secondary, #444);
    cursor: col-resize;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center
}

#splitter:hover { background: #666 }

#swapBtn {
    position: relative;
    z-index: 5;
    width: 20px;
    height: 32px;
    padding: 0;
    font-size: 13px;
    background: #555;
    border: 1px solid #777;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    line-height: 1
}

#swapBtn i {
    transition: transform 0.3s ease
}

#swapBtn.vertical i {
    transform: rotate(90deg)
}

#swapBtn:hover {
    background: #7c3aed;
    border-color: #7c3aed
}

#heightSplitter {
    height: 8px;
    cursor: row-resize;
    background: var(--color-border-secondary, #444);
    border-radius: 0 0 4px 4px
}

#heightSplitter:hover {
    background: #666
}

#editor-wrapper,
#console-wrapper {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column
}

@media (max-width: 700px) {
    #ide-layout {
        flex-direction: column
    }

    #splitter {
        display: none
    }
}

/* ── Pane tabs ────────────────────────────────────────────────── */

.pane-tabs {
    display: flex;
    align-items: stretch;
    background: var(--color-background-secondary, #1a1a1a);
    border: .5px solid var(--color-border-secondary, #444);
    border-bottom: none;
    min-height: 26px
}

.pane-tab {
    font-size: 11px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--color-text-secondary, #888);
    padding: 4px 12px;
    cursor: pointer;
    border-bottom: 2px solid #fff0;
    transition: color 0.15s, border-color 0.15s;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 5px
}

.pane-tab:hover {
    color: #ccc
}

.pane-tab.active {
    color: #e8e8e8;
    border-bottom-color: #7c3aed
}

.pane-tab .tab-badge {
    font-size: 10px;
    background: #7c3aed;
    color: #fff;
    border-radius: 9px;
    padding: 0 5px;
    line-height: 16px
}

.pane-label-right {
    margin-left: auto;
    font-size: 11px;
    letter-spacing: .06em;
    color: var(--color-text-secondary, #888);
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 8px
}

/* ── Sub-tabs: colour dots + dirty indicator ──────────────────── */

.tab-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0
}

.tab-dot.html-dot { background: #f38ba8 }
.tab-dot.css-dot  { background: #89dceb }
.tab-dot.js-dot   { background: #f9e2af }

.pane-tab .tab-dirty {
    display: none;
    font-size: 10px;
    color: #f59e0b;
    margin-left: 2px
}

.pane-tab.dirty .tab-dirty {
    display: inline
}

/* ── Editor pane ──────────────────────────────────────────────── */

#editor-pane {
    position: relative;
    display: flex;
    flex-direction: column;
    border: .5px solid var(--color-border-secondary, #444);
    overflow: hidden;
    flex: 1;
    min-height: 0
}

/* cm-panel: only the active sub-editor is visible */
.cm-panel {
    display: none;
    flex: 1;
    overflow: hidden;
    flex-direction: column
}

.cm-panel.active {
    display: flex
}

.CodeMirror {
    width: 100%;
    height: 100%;
    font-size: 14px;
    font-family: Consolas, "Courier New", monospace;
    line-height: 1.2
}

.CodeMirror-lines {
    padding-bottom: 75px
}

.CodeMirror pre {
    line-height: 1.2;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere
}

/* ── Console / preview pane ───────────────────────────────────── */

#console-pane {
    display: flex;
    flex-direction: column;
    border: .5px solid var(--color-border-secondary, #444);
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
    background: #fff
}

#preview-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: #888;
    font-size: 14px;
    pointer-events: none;
    background: var(--color-background-secondary, #1a1a1a)
}

#preview-placeholder svg {
    opacity: .25
}

#preview-placeholder strong {
    color: #e8e8e8
}

/* ── Status bar ───────────────────────────────────────────────── */

#statusBar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--color-text-secondary, #888);
    padding: 4px 0
}

#statusControls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap
}

@media (max-width: 700px) {
    #statusBar { row-gap: 6px }

    #statusControls {
        width: 100%;
        margin-left: 0;
        justify-content: space-between
    }

    #statusControls > span { flex: 1 1 220px }

    #statusControls input[type="range"] {
        width: 100%;
        min-width: 80px
    }
}

#statusDot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #555;
    flex-shrink: 0;
    transition: background 0.2s
}

#statusDot.running {
    background: #56d364;
    animation: pulse 1s ease-in-out infinite
}

#statusDot.error { background: #ff7b72 }
#statusDot.ok    { background: #56d364 }

@keyframes pulse {
    0%, 100% { opacity: 1 }
    50%       { opacity: .4 }
}

#autosaveIndicator,
#dbSaveIndicator {
    font-size: 11px;
    opacity: 0;
    transition: opacity 0.4s;
    white-space: nowrap
}

#autosaveIndicator         { color: #56d364 }
#dbSaveIndicator           { color: #a78bfa }
#autosaveIndicator.visible,
#dbSaveIndicator.visible   { opacity: 1 }

#autosaveIndicator i,
#dbSaveIndicator i { margin-right: 4px }

/* ── Examples modal ───────────────────────────────────────────── */

#examplesModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgb(0 0 0 / .55);
    align-items: center;
    justify-content: center
}

#examplesDialog {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 10px;
    width: min(700px, 95vw);
    height: min(85vh, 800px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgb(0 0 0 / .5)
}

#examplesHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: #1c2230;
    border-bottom: 1px solid #30363d
}

#examplesTitle {
    font-size: 15px;
    font-weight: 600;
    color: #e8e8e8
}

#examplesClose {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    color: #888
}

#examplesClose:hover { color: #e8e8e8 }

#examplesList {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: #0d1117
}

/* category header row */
.ex-category-header {
    padding: 8px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: #888;
    background: #161b22;
    border-bottom: 1px solid #21262d;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none
}

.ex-category-header:hover { background: #1c2230 }

.ex-category-arrow {
    transition: transform .2s;
    font-size: 10px;
    color: #555
}

/* individual example row */
.ex-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 13px;
    color: #e8e8e8;
    border-bottom: 1px solid #21262d;
    transition: background 0.12s
}

.ex-item-header:hover { background: #161b22 }

.ex-item-arrow {
    transition: transform .2s;
    font-size: 10px;
    color: #555
}

/* code preview block (hidden until item opened) */
.ex-item-code {
    display: none;
    flex-direction: column;
    border-bottom: 1px solid #21262d
}

.ex-item-code.open { display: flex }

/* mini tab bar inside code preview */
.ex-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 10px;
    background: #1c2230;
    border-bottom: 1px solid #21262d
}

.ex-tab-btn {
    padding: 2px 10px;
    border-radius: 4px;
    border: none;
    background: #21262d;
    color: #888;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s
}

.ex-tab-btn.active {
    background: #7c3aed;
    color: #fff
}

.ex-tab-btn:not(.active):hover {
    background: #2d333b;
    color: #ccc
}

/* code preview pre */
.ex-pre {
    margin: 0;
    padding: 10px 14px;
    font-size: 12px;
    font-family: Consolas, "Courier New", monospace;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    background: #0d1117;
    color: #e8e8e8
}

/* action buttons row */
.ex-copy-row {
    display: flex;
    justify-content: flex-end;
    padding: 6px 10px 8px;
    gap: 6px;
    background: #0d1117
}

.ex-copy-btn {
    padding: 3px 10px;
    border-radius: 5px;
    border: 1px solid #30363d;
    background: #21262d;
    color: #ccc;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.12s
}

.ex-copy-btn:hover { background: #2d333b }

.ex-copy-btn.copied {
    background: #7c3aed;
    border-color: #7c3aed;
    color: #fff
}

.ex-load-btn {
    padding: 3px 10px;
    border-radius: 5px;
    border: none;
    background: #15803d;
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.12s
}

.ex-load-btn:hover { background: #166534 }

/* ── Programs modal ───────────────────────────────────────────── */

#programsModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgb(0 0 0 / .6);
    align-items: center;
    justify-content: center
}

#programsDialog {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 10px;
    width: min(640px, 95vw);
    max-height: min(85vh, 700px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgb(0 0 0 / .5)
}

#programsHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: #1c2230;
    border-bottom: 1px solid #30363d
}

#programsTitle {
    font-size: 15px;
    font-weight: 600;
    color: #e8e8e8
}

#programsClose {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    color: #888
}

#programsClose:hover { color: #e8e8e8 }

#programsNewRow {
    display: flex;
    gap: 8px;
    padding: 12px 18px;
    border-bottom: 1px solid #21262d;
    background: #0d1117
}

#programsNewName {
    flex: 1;
    padding: 6px 10px;
    font-size: 13px;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 6px;
    color: #e8e8e8;
    outline: none
}

#programsNewName:focus { border-color: #7c3aed }

#programsSaveNewBtn {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    background: #7c3aed;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    white-space: nowrap
}

#programsSaveNewBtn:hover { background: #6d28d9 }

#programsSearchRow {
    padding: 8px 18px;
    background: #0d1117;
    border-bottom: 1px solid #21262d
}

#programsSearch {
    width: 100%;
    padding: 5px 10px;
    font-size: 12px;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 5px;
    color: #e8e8e8;
    outline: none
}

#programsSearch:focus { border-color: #7c3aed }

#programsList {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0
}

#programsEmpty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    color: #555;
    font-size: 13px
}

.program-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid #1c2230;
    transition: background 0.12s
}

.program-item:hover { background: #1c2230 }

.program-item.active-prog {
    background: rgb(124 58 237 / .08);
    border-left: 3px solid #7c3aed;
    padding-left: 15px
}

.program-item-info { flex: 1; min-width: 0 }

.program-item-name {
    font-size: 13px;
    font-weight: 600;
    color: #e8e8e8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap
}

.program-item-meta {
    font-size: 11px;
    color: #555;
    margin-top: 2px
}

.program-item-actions {
    display: flex;
    gap: 5px;
    flex-shrink: 0
}

.prog-btn {
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 4px;
    border: 1px solid #30363d;
    background: #21262d;
    color: #ccc;
    cursor: pointer;
    transition: background 0.12s
}

.prog-btn:hover { background: #2d333b }

.prog-btn.load {
    background: #1a3a5c;
    border-color: #2563eb;
    color: #79c0ff
}

.prog-btn.load:hover { background: #1e4a7a }

.prog-btn.del {
    background: #2a1a1a;
    border-color: #7f1d1d;
    color: #fca5a5
}

.prog-btn.del:hover { background: #3d1f1f }

/* ── Confirm modal ────────────────────────────────────────────── */

#confirmModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgb(0 0 0 / .65);
    align-items: center;
    justify-content: center
}

#confirmDialog {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 10px;
    width: min(400px, 92vw);
    padding: 24px 24px 20px;
    box-shadow: 0 8px 32px rgb(0 0 0 / .5)
}

#confirmMsg {
    font-size: 14px;
    color: #e8e8e8;
    margin-bottom: 20px;
    line-height: 1.5
}

#confirmActions {
    display: flex;
    gap: 10px;
    justify-content: flex-end
}

.confirm-btn {
    padding: 6px 18px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    border: none;
    cursor: pointer
}

.confirm-btn.ok {
    background: #b91c1c;
    color: #fff
}

.confirm-btn.ok:hover { background: #991b1b }

.confirm-btn.cancel {
    background: #21262d;
    color: #ccc;
    border: 1px solid #30363d
}

.confirm-btn.cancel:hover { background: #2d333b }

/* ── Toast ────────────────────────────────────────────────────── */

#ideToast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #1c2230;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 13px;
    color: #e8e8e8;
    box-shadow: 0 4px 16px rgb(0 0 0 / .4);
    opacity: 0;
    pointer-events: none;
    z-index: 11000;
    transition: opacity 0.2s, transform 0.2s;
    white-space: nowrap
}

#ideToast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0)
}

#ideToast.toast-ok    { border-color: #15803d; color: #56d364 }
#ideToast.toast-error { border-color: #7f1d1d; color: #fca5a5 }
#ideToast.toast-info  { border-color: #2563eb; color: #79c0ff }

/* ── Misc ─────────────────────────────────────────────────────── */

.tb i {
    width: 1em;
    text-align: center;
    flex-shrink: 0
}

.tb.locked {
    opacity: .45;
    cursor: not-allowed;
    filter: grayscale(.6)
}

@media (max-width: 900px) {
    #toolbar { gap: 4px }

    .toolbar-sep { display: none }

    button.tb .btn-text { display: none }

    button.tb {
        padding: 0;
        width: 2.2em;
        justify-content: center
    }

    button.tb.has-text-only {
        width: auto;
        padding: 0 12px
    }
}

/* ── Mascot ───────────────────────────────────────────────────── */

#editorMascot {
    position: absolute;
    left: 10px;
    bottom: -40px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    z-index: 50;
    transition: bottom .35s ease, opacity .25s ease;
    pointer-events: none
}

#editorMascotImg {
    width: 90px;
    height: auto;
    display: block
}

#editorMascotBubble {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity .25s ease, transform .25s ease;
    background: rgb(255 255 255 / .97);
    color: #222;
    border-radius: 16px;
    padding: 10px 14px;
    max-width: min(450px, calc(100% - 110px));
    box-shadow: 0 2px 8px rgb(0 0 0 / .2);
    align-self: flex-start;
    line-height: 1.4;
    font-size: 13px
}

#editorMascot.active {
    bottom: 0
}

#editorMascot.active #editorMascotBubble {
    opacity: 1;
    transform: translateY(0)
}

@media (max-width: 900px) {
    #editorMascotImg { width: 60px }
    #editorMascot    { bottom: -30px }
}

@media (max-width: 600px) {
    #editorMascotImg { width: 40px }
    #editorMascot    { bottom: -20px }

    #editorMascotBubble {
        font-size: .9rem;
        border-radius: 8px;
        padding: 5px 10px
    }
}