/* Python Live Lab v9 — ProgressiveKids Theme, Fullscreen, Light/Dark */

/* ── CSS Variables ── */
.pylab-root {
    --pk-blue:    #00a1ff;
    --pk-orange:  darkorange;
    --pk-dark:    #275372;
    --pk-bg:      #e8edf2;
    --pk-white:   #ffffff;
    --pk-font:    'Roboto', sans-serif;

    /* Light mode defaults */
    --bg-app:       #f0f4f8;
    --bg-topbar:    #e8edf2;
    --bg-sidebar:   #dce6ef;
    --bg-editor:    #ffffff;
    --bg-console:   #f8fafc;
    --bg-cin:       #eef4fa;
    --bg-tab-active:#ffffff;
    --bg-tab:       #dce6ef;
    --bg-tab-hover: #cfe0ef;
    --bg-file-active:#c8dff0;
    --bg-file-hover: #dce9f5;
    --bg-gutter:    #e8edf2;
    --bg-hint:      #ffffff;

    --txt-primary:  #275372;
    --txt-secondary:#4a7090;
    --txt-muted:    #7a9ab0;
    --txt-gutter:   #8aaac0;
    --txt-tab:      #4a7090;
    --txt-tab-active:#00a1ff;

    --border:       #c5d8e8;
    --border-strong:#aac4d8;

    --run-bg:       #00a1ff;
    --run-hover:    #0090e0;
    --stop-bg:      #e05252;
    --tool-bg:      transparent;
    --tool-hover:   #cfe0ef;
    --tool-border:  #b0ccd8;
    --tool-txt:     #275372;

    --cm-keyword:   #7c3aed;
    --cm-string:    #15803d;
    --cm-comment:   #6b7280;
    --cm-number:    #b45309;
    --cm-operator:  #0369a1;
    --cm-builtin:   #0284c7;
    --cm-def:       #1d4ed8;
    --cm-variable:  #275372;
    --cm-atom:      #be123c;

    --console-out:  #1a3a52;
    --console-prompt:#b45309;
    --console-in:   #15803d;
    --console-err:  #dc2626;
    --console-info: #94a3b8;
    --inline-prompt:#b45309;
    --inline-in:    #15803d;

    --dot-idle:    #c0ccd8;
    --dot-loading: #f0c040;
    --dot-running: #22c55e;
    --dot-waiting: #f97316;
    --dot-error:   #ef4444;
    --dot-done:    #00a1ff;
}

/* ── Dark mode overrides ── */
.pylab-root.pylab-dark {
    --bg-app:       #0d1b2a;
    --bg-topbar:    #0a1520;
    --bg-sidebar:   #0f1e2e;
    --bg-editor:    #1a2a3a;
    --bg-console:   #0a1520;
    --bg-cin:       #0f1e2e;
    --bg-tab-active:#1a2a3a;
    --bg-tab:       #0f1e2e;
    --bg-tab-hover: #162535;
    --bg-file-active:#1a3a55;
    --bg-file-hover: #152535;
    --bg-gutter:    #0f1e2e;
    --bg-hint:      #0f1e2e;

    --txt-primary:  #b8d4e8;
    --txt-secondary:#7aa8c8;
    --txt-muted:    #4a7090;
    --txt-gutter:   #3a6080;
    --txt-tab:      #5a8ab0;
    --txt-tab-active:#00a1ff;

    --border:       #1e3a52;
    --border-strong:#254a66;

    --tool-hover:   #1a3a55;
    --tool-border:  #1e3a52;
    --tool-txt:     #7aa8c8;

    --cm-keyword:   #c792ea;
    --cm-string:    #c3e88d;
    --cm-comment:   #4a6a7a;
    --cm-number:    #f78c6c;
    --cm-operator:  #89ddff;
    --cm-builtin:   #82aaff;
    --cm-def:       #82aaff;
    --cm-variable:  #b8d4e8;
    --cm-atom:      #ff5370;

    --console-out:  #b8d4e8;
    --console-prompt:#f9e2af;
    --console-in:   #50c878;
    --console-err:  #ff6b6b;
    --console-info: #3a6080;
    --inline-prompt:#f9e2af;
    --inline-in:    #50c878;
}


/* ── Reset & Base ── */
.pylab-root *, .pylab-root *::before, .pylab-root *::after {
    box-sizing: border-box; margin: 0; padding: 0;
}
.pylab-root {
    font-family: var(--pk-font);
    font-size: 13px;
    background: var(--bg-app);
    color: var(--txt-primary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background .2s, color .2s;
}
.pylab-root.pylab-fullscreen {
    position: fixed;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 99999;
    border-radius: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
}
body.admin-bar .pylab-root.pylab-fullscreen {
    top: 32px !important;
    height: calc(100vh - 32px) !important;
}
.pylab-root:not(.pylab-fullscreen) {
    border-radius: 10px;
    border: 1px solid var(--border);
}

/* ── Topbar ── */
.pylab-topbar {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px;
    background: var(--bg-topbar);
    border-bottom: 2px solid var(--pk-blue);
    flex-shrink: 0;
}
.pylab-brand {
    display: flex; align-items: center; gap: 8px;
    font-family: var(--pk-font); font-weight: 700;
    font-size: 15px; color: var(--pk-blue);
    margin-right: 6px; text-decoration: none;
}
.pylab-brand-dot { color: var(--pk-orange); }

.pylab-run-btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 20px; border-radius: 22px; border: none;
    background: var(--pk-blue); color: #fff;
    font-size: 14px; font-weight: 700; cursor: pointer;
    font-family: var(--pk-font); transition: background .2s, transform .1s;
    box-shadow: 0 2px 8px rgba(0,161,255,.3);
}
.pylab-run-btn:hover  { background: var(--run-hover); transform: translateY(-1px); }
.pylab-run-btn:active { transform: translateY(0); }
.pylab-run-btn.stop   { background: var(--stop-bg); box-shadow: 0 2px 8px rgba(224,82,82,.3); }
.pylab-run-btn.stop:hover { background: #c43c3c; }
.pylab-run-btn:disabled { background: #aac4d8; cursor: not-allowed; box-shadow: none; transform: none; }
.pylab-run-icon { width: 14px; height: 14px; fill: currentColor; }

.pylab-toolbar-sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; flex-shrink: 0; }

.pylab-tool-btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 6px 11px; border-radius: 6px; border: 1px solid var(--tool-border);
    background: var(--tool-bg); color: var(--tool-txt);
    font-size: 12px; font-weight: 600; cursor: pointer;
    font-family: var(--pk-font); transition: all .15s; white-space: nowrap;
}
.pylab-tool-btn:hover { background: var(--tool-hover); border-color: var(--pk-blue); color: var(--pk-blue); }

/* Dark/Light + Fullscreen toggles */
.pylab-icon-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 50%;
    border: 1px solid var(--tool-border); background: var(--tool-bg);
    color: var(--tool-txt); font-size: 16px; cursor: pointer;
    transition: all .15s; flex-shrink: 0;
}
.pylab-icon-toggle:hover { background: var(--tool-hover); border-color: var(--pk-blue); color: var(--pk-blue); }

.pylab-status {
    display: flex; align-items: center; gap: 7px;
    font-size: 12px; color: var(--txt-muted);
    font-family: var(--pk-font);
}
.pylab-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--dot-idle); flex-shrink: 0;
}
.pylab-dot.loading { background: var(--dot-loading); animation: pk-pulse 1.2s infinite; }
.pylab-dot.running { background: var(--dot-running); animation: pk-pulse .9s infinite; }
.pylab-dot.waiting { background: var(--dot-waiting); animation: pk-pulse .5s infinite; }
.pylab-dot.error   { background: var(--dot-error); }
.pylab-dot.done    { background: var(--dot-done); }
@keyframes pk-pulse { 0%,100%{opacity:1;} 50%{opacity:.2;} }

.pylab-loading-bar { height: 3px; background: var(--border); flex-shrink: 0; }
.pylab-loading-inner { height: 100%; width: 0; background: var(--pk-blue); transition: width .4s ease; }

/* ── IDE body ── */
.pylab-ide { display: flex; flex: 1; overflow: hidden; flex-direction: column; min-height: 0; }
.pylab-ide-main { display: flex; flex: 1; overflow: hidden; min-height: 0; }

/* ── Sidebar ── */
.pylab-sidebar {
    width: 178px; background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; flex-shrink: 0;
    transition: background .2s;
}
.pylab-sidebar-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px;
    font-size: 11px; font-weight: 700; color: var(--txt-muted);
    text-transform: uppercase; letter-spacing: .08em;
    border-bottom: 1px solid var(--border);
    font-family: var(--pk-font);
}
.pylab-icon-btn {
    background: none; border: none; cursor: pointer;
    color: var(--txt-muted); padding: 2px 5px; border-radius: 4px;
    font-size: 18px; line-height: 1; transition: color .15s, background .15s;
    font-family: var(--pk-font);
}
.pylab-icon-btn:hover { color: var(--pk-blue); background: var(--tool-hover); }

.pylab-file-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.pylab-file-item {
    display: flex; align-items: center; gap: 7px;
    padding: 6px 10px; cursor: pointer;
    color: var(--txt-secondary); font-size: 13px;
    transition: background .1s; user-select: none;
    font-family: var(--pk-font);
}
.pylab-file-item:hover { background: var(--bg-file-hover); }
.pylab-file-item.active { background: var(--bg-file-active); color: var(--pk-blue); font-weight: 600; }
.pylab-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pylab-file-del {
    opacity: 0; font-size: 12px; color: var(--txt-muted);
    background: none; border: none; cursor: pointer; padding: 0 2px;
    transition: color .15s;
}
.pylab-file-item:hover .pylab-file-del { opacity: 1; }
.pylab-file-del:hover { color: var(--stop-bg) !important; }
.pylab-new-file-row {
    display: flex; align-items: center; gap: 4px; padding: 5px 8px;
    background: var(--bg-file-hover); border-top: 1px solid var(--border);
}
.pylab-new-file-input {
    flex: 1; background: var(--bg-editor); border: 1px solid var(--pk-blue);
    color: var(--txt-primary); font-size: 12px; padding: 4px 7px;
    border-radius: 4px; outline: none; font-family: var(--pk-font);
}
.pylab-new-file-ok {
    background: var(--pk-blue); border: none; color: #fff;
    font-size: 12px; font-weight: 700; padding: 4px 10px;
    border-radius: 4px; cursor: pointer; font-family: var(--pk-font);
}
.pylab-new-file-ok:hover { background: var(--run-hover); }

/* ── Editor ── */
.pylab-editor-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.pylab-tabs {
    display: flex; align-items: center;
    background: var(--bg-topbar); border-bottom: 1px solid var(--border);
    overflow-x: auto; flex-shrink: 0; scrollbar-width: none;
}
.pylab-tabs::-webkit-scrollbar { display: none; }
.pylab-tab {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 14px; font-size: 13px; color: var(--txt-tab);
    cursor: pointer; white-space: nowrap; border-right: 1px solid var(--border);
    transition: background .1s, color .1s; user-select: none; flex-shrink: 0;
    font-family: var(--pk-font); background: var(--bg-tab);
}
.pylab-tab:hover { background: var(--bg-tab-hover); }
.pylab-tab.active { background: var(--bg-tab-active); color: var(--pk-blue); font-weight: 600; border-bottom: 2px solid var(--pk-blue); }
.pylab-tab-close {
    font-size: 12px; line-height: 1; background: none; border: none;
    color: var(--txt-muted); cursor: pointer; padding: 0 2px; opacity: 0;
}
.pylab-tab:hover .pylab-tab-close { opacity: 1; }
.pylab-tab-close:hover { color: var(--stop-bg); }

.pylab-cm-wrap { flex: 1; overflow: hidden; position: relative; min-height: 0; }
.pylab-cm-wrap .CodeMirror {
    height: 100% !important;
    background: var(--bg-editor) !important;
    color: var(--txt-primary) !important;
    font-family: "JetBrains Mono","Fira Code",Consolas,Monaco,monospace !important;
    font-size: 14px !important; line-height: 1.65 !important;
    transition: background .2s;
}
.pylab-cm-wrap .CodeMirror-gutters { background: var(--bg-gutter) !important; border-right: 1px solid var(--border) !important; transition: background .2s; }
.pylab-cm-wrap .CodeMirror-linenumber { color: var(--txt-gutter) !important; padding: 0 10px 0 8px !important; }
.pylab-cm-wrap .CodeMirror-activeline-background { background: rgba(0,161,255,.06) !important; }
.pylab-cm-wrap .CodeMirror-selected { background: rgba(0,161,255,.18) !important; }
.pylab-cm-wrap .CodeMirror-cursor { border-left: 2px solid var(--pk-blue) !important; }
.pylab-cm-wrap .CodeMirror-matchingbracket { background: rgba(0,161,255,.25) !important; color: var(--pk-blue) !important; outline: none; font-weight: 700; }
.pylab-cm-wrap .CodeMirror-scroll { padding-bottom: 30px; }
.pylab-cm-wrap .CodeMirror-foldgutter-open:after  { content:"▾"; color: var(--txt-muted); }
.pylab-cm-wrap .CodeMirror-foldgutter-folded:after { content:"▸"; color: var(--txt-muted); }

/* Syntax colors */
.pylab-cm-wrap .cm-keyword   { color: var(--cm-keyword) !important; font-weight: 600; }
.pylab-cm-wrap .cm-builtin   { color: var(--cm-builtin) !important; }
.pylab-cm-wrap .cm-string,
.pylab-cm-wrap .cm-string-2  { color: var(--cm-string) !important; }
.pylab-cm-wrap .cm-comment   { color: var(--cm-comment) !important; font-style: italic; }
.pylab-cm-wrap .cm-number    { color: var(--cm-number) !important; }
.pylab-cm-wrap .cm-operator  { color: var(--cm-operator) !important; }
.pylab-cm-wrap .cm-def       { color: var(--cm-def) !important; font-weight: 600; }
.pylab-cm-wrap .cm-variable  { color: var(--cm-variable) !important; }
.pylab-cm-wrap .cm-variable-2{ color: var(--cm-atom) !important; }
.pylab-cm-wrap .cm-atom      { color: var(--cm-atom) !important; }
.pylab-cm-wrap .cm-error     { background: rgba(220,38,38,.12) !important; color: var(--dot-error) !important; }

/* Autocomplete */
.CodeMirror-hints {
    background: var(--bg-hint) !important;
    border: 1px solid var(--pk-blue) !important;
    border-radius: 6px !important;
    font-family: "JetBrains Mono",Consolas,monospace !important;
    font-size: 13px !important;
    box-shadow: 0 4px 16px rgba(0,161,255,.15) !important;
}
.CodeMirror-hint { color: var(--txt-primary) !important; padding: 4px 12px !important; }
.CodeMirror-hint-active { background: var(--pk-blue) !important; color: #fff !important; border-radius: 4px; }

/* ── Console ── */
.pylab-console-panel {
    border-top: 2px solid var(--pk-blue);
    display: flex; flex-direction: column; flex-shrink: 0; min-height: 120px;
    background: var(--bg-console); transition: background .2s;
}
.pylab-console-head {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 14px; background: var(--bg-topbar);
    border-bottom: 1px solid var(--border);
    font-size: 11px; font-weight: 700; color: var(--txt-muted);
    text-transform: uppercase; letter-spacing: .08em;
    cursor: ns-resize; flex-shrink: 0; user-select: none;
    font-family: var(--pk-font);
}
.pylab-console-clear-btn {
    margin-left: auto; background: none; border: 1px solid var(--tool-border);
    cursor: pointer; color: var(--txt-muted); font-size: 12px;
    padding: 2px 10px; border-radius: 12px; font-family: var(--pk-font);
    transition: all .15s;
}
.pylab-console-clear-btn:hover { border-color: var(--pk-orange); color: var(--pk-orange); }

.pylab-console-body {
    flex: 1; overflow-y: auto; padding: 10px 16px;
    font-family: "JetBrains Mono","Fira Code",Consolas,monospace;
    font-size: 13px; line-height: 1.8;
    background: var(--bg-console); color: var(--console-out);
    cursor: text; transition: background .2s;
}
.l-out    { color: var(--console-out);    white-space: pre-wrap; word-break: break-all; }
.l-prompt { color: var(--console-prompt); white-space: pre-wrap; font-weight: 600; }
.l-in     { color: var(--console-in);     white-space: pre-wrap; }
.l-err    { color: var(--console-err);    white-space: pre-wrap; }
.l-info   { color: var(--console-info);   font-style: italic; }
.l-warn   { color: var(--pk-orange);      font-style: italic; }

/* Inline input */
.pylab-inline-input-row {
    display: flex; align-items: center; gap: 4px; padding: 2px 0;
}
.pylab-inline-prompt { color: var(--pk-blue); font-weight: 700; white-space: pre; }
.pylab-inline-cin {
    flex: 1; background: transparent; border: none;
    border-bottom: 2px solid var(--pk-blue); outline: none;
    color: var(--console-in); caret-color: var(--pk-orange);
    font-family: "JetBrains Mono","Fira Code",Consolas,monospace;
    font-size: 13px; padding: 2px 4px; min-width: 0;
}
.pylab-inline-cin::placeholder { color: var(--console-info); }

@media (max-width:600px) { .pylab-sidebar { display: none; } }

/* ── Course mode additions ── */
.pylab-student-badge {
    display: flex; align-items: center; gap: 5px;
    padding: 5px 12px; border-radius: 20px;
    background: rgba(0,161,255,.12);
    border: 1px solid rgba(0,161,255,.3);
    color: var(--pk-blue); font-size: 12px;
    font-family: var(--pk-font); white-space: nowrap;
}
.pylab-save-btn {
    border-color: #22c55e !important; color: #22c55e !important;
}
.pylab-save-btn:hover { background: rgba(34,197,94,.12) !important; }

.pylab-submit-btn {
    border-color: var(--pk-orange) !important; color: var(--pk-orange) !important;
}
.pylab-submit-btn:hover { background: rgba(255,140,0,.12) !important; }

.pylab-save-status {
    font-size: 12px; font-family: var(--pk-font);
    font-weight: 600; white-space: nowrap;
    transition: opacity .3s;
}

/* ── Restore banner ── */
.pylab-restore-banner {
    display: flex; align-items: center; justify-content: space-between;
    padding: 7px 14px;
    background: rgba(0,161,255,.1);
    border-bottom: 1px solid rgba(0,161,255,.25);
    font-size: 12px; font-family: var(--pk-font);
    color: var(--pk-blue); flex-shrink: 0; gap: 10px;
}
.pylab-restore-clear {
    padding: 3px 10px; border-radius: 12px;
    border: 1px solid rgba(0,161,255,.4);
    background: transparent; color: var(--pk-blue);
    font-size: 11px; cursor: pointer; font-family: var(--pk-font);
    white-space: nowrap; transition: all .15s;
}
.pylab-restore-clear:hover {
    background: var(--pk-blue); color: #fff;
}

/* ── My Assignments panel ── */
.pylab-myfiles-btn {
    border-color: #a78bfa !important;
    color: #7c3aed !important;
}
.pylab-root.pylab-dark .pylab-myfiles-btn {
    border-color: #7c3aed !important;
    color: #a78bfa !important;
}
.pylab-myfiles-btn:hover {
    background: rgba(124,58,237,.1) !important;
}

/* Slide-in panel from the right */
.pylab-myfiles-panel {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 340px;
    background: var(--bg-sidebar);
    border-left: 2px solid var(--pk-blue);
    display: flex; flex-direction: column;
    z-index: 200;
    transform: translateX(100%);
    transition: transform .25s ease;
    box-shadow: -4px 0 20px rgba(0,0,0,.15);
}
.pylab-myfiles-panel.open {
    transform: translateX(0);
}
.pylab-root { position: relative; } /* ensure panel is contained */

.pylab-myfiles-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border);
    font-size: 13px; font-weight: 700;
    color: var(--pk-blue); font-family: var(--pk-font);
    flex-shrink: 0;
}
.pylab-myfiles-close {
    background: none; border: none; cursor: pointer;
    color: var(--txt-muted); font-size: 15px;
    padding: 2px 6px; border-radius: 4px;
    transition: all .15s;
}
.pylab-myfiles-close:hover { color: var(--stop-bg); background: var(--tool-hover); }

.pylab-myfiles-body {
    flex: 1; overflow-y: auto; padding: 12px;
    display: flex; flex-direction: column; gap: 10px;
}
.pylab-myfiles-loading,
.pylab-myfiles-empty {
    color: var(--txt-muted); font-size: 13px;
    font-family: var(--pk-font); font-style: italic;
    padding: 20px; text-align: center;
}

/* Assignment card */
.pylab-myfiles-card {
    background: var(--bg-editor);
    border: 1px solid var(--border);
    border-radius: 8px; padding: 12px;
    display: flex; flex-direction: column; gap: 6px;
    transition: border-color .15s;
}
.pylab-myfiles-card:hover { border-color: var(--pk-blue); }
.pylab-myfiles-card.current {
    border-color: var(--pk-blue);
    background: rgba(0,161,255,.06);
}

.pylab-myfiles-card-top {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.pylab-myfiles-aid {
    font-size: 13px; font-weight: 700;
    color: var(--txt-primary); font-family: var(--pk-font);
    flex: 1;
}
.pylab-myfiles-card-meta {
    font-size: 11px; color: var(--txt-muted);
    font-family: var(--pk-font);
}

/* Badges */
.pylab-myfiles-badge {
    font-size: 10px; font-weight: 700; padding: 2px 8px;
    border-radius: 10px; white-space: nowrap;
    font-family: var(--pk-font);
}
.pylab-myfiles-badge.submitted {
    background: rgba(34,197,94,.15); color: #16a34a;
    border: 1px solid rgba(34,197,94,.3);
}
.pylab-myfiles-badge.draft {
    background: rgba(249,115,22,.12); color: #ea580c;
    border: 1px solid rgba(249,115,22,.25);
}
.pylab-myfiles-badge.current-badge {
    background: rgba(0,161,255,.15); color: var(--pk-blue);
    border: 1px solid rgba(0,161,255,.3);
}

.pylab-myfiles-load-btn {
    margin-top: 4px; padding: 6px 14px;
    border-radius: 6px; border: 1px solid var(--pk-blue);
    background: transparent; color: var(--pk-blue);
    font-size: 12px; font-weight: 600; cursor: pointer;
    font-family: var(--pk-font); transition: all .15s;
    align-self: flex-start;
}
.pylab-myfiles-load-btn:hover {
    background: var(--pk-blue); color: #fff;
}
.pylab-myfiles-load-btn:disabled {
    opacity: .5; cursor: not-allowed;
}
