/* ═══════════════════════════════════════════════════════════════
   TeachCode — Base Stylesheet
   VS Code-inspired dark theme, plain CSS, no framework
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
    /* Core palette */
    --bg-base:         #1e1e1e;
    --bg-surface:      #252526;
    --bg-elevated:     #2d2d30;
    --bg-input:        #3c3c3c;
    --bg-hover:        #2a2d2e;

    /* Borders */
    --border:          #3e3e42;
    --border-focus:    #007acc;

    /* Text */
    --text-primary:    #d4d4d4;
    --text-secondary:  #9d9d9d;
    --text-muted:      #6a6a6a;
    --text-heading:    #ffffff;

    /* Accent */
    --accent:          #007acc;
    --accent-hover:    #1a8ad4;
    --accent-dim:      #0e4f7a;

    /* Status */
    --success:         #4ec9b0;
    --success-bg:      rgba(78,201,176,.12);
    --warning:         #dcdcaa;
    --error:           #f48771;
    --error-bg:        rgba(244,135,113,.12);
    --locked:          #6a6a6a;

    /* Sizes */
    --topbar-h:        48px;
    --radius:          4px;
    --radius-lg:       8px;

    /* Fonts */
    --font-ui:         -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-code:       'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

/* ── Light theme override ───────────────────────────────────── */
[data-theme="light"] {
    --bg-base:         #f3f3f3;
    --bg-surface:      #ffffff;
    --bg-elevated:     #e8e8e8;
    --bg-input:        #f5f5f5;
    --bg-hover:        #e0e0e0;
    --border:          #c6c6c6;
    --border-focus:    #0078d4;
    --text-primary:    #1e1e1e;
    --text-secondary:  #616161;
    --text-muted:      #999999;
    --text-heading:    #000000;
    --accent:          #0078d4;
    --accent-hover:    #106ebe;
    --accent-dim:      #daedfb;
    --success:         #107c10;
    --success-bg:      rgba(16,124,16,.1);
    --warning:         #8a6914;
    --error:           #c0392b;
    --error-bg:        rgba(192,57,43,.1);
    --locked:          #999999;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

h1, h2, h3, h4 {
    color: var(--text-heading);
    font-weight: 600;
    margin: 0 0 .75rem;
}
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

p  { margin: 0 0 .75rem; }
ul, ol { margin: 0 0 .75rem; padding-left: 1.5rem; }
li { margin-bottom: .25rem; }

pre {
    background: #0d0d0d;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
    font-family: var(--font-code);
    font-size: 13px;
    line-height: 1.5;
}

code {
    font-family: var(--font-code);
    font-size: 13px;
    background: var(--bg-elevated);
    padding: .1em .3em;
    border-radius: 3px;
}

pre code {
    background: none;
    padding: 0;
}

/* ── App Shell ──────────────────────────────────────────────── */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.main-content {
    flex: 1;
    overflow-y: auto;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1.5rem;
    flex-shrink: 0;
    z-index: 100;
}

.topbar-brand {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: .03em;
    text-decoration: none;
}

.topbar-nav {
    display: flex;
    gap: .25rem;
    flex: 1;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
}

.nav-username {
    color: var(--text-secondary);
    font-size: 13px;
}

.nav-link {
    color: var(--text-secondary);
    padding: .25rem .6rem;
    border-radius: var(--radius);
    font-size: 13px;
    text-decoration: none;
    transition: background .15s, color .15s;
}

.nav-link:hover,
.nav-link.active {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-link--logout {
    color: var(--error);
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .4rem .9rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-ui);
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
    text-decoration: none;
}

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

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

.btn--secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border);
}
.btn--secondary:hover:not(:disabled) { background: var(--bg-hover); }

.btn--danger {
    background: transparent;
    color: var(--error);
    border-color: var(--error);
}
.btn--danger:hover:not(:disabled) { background: var(--error-bg); }

.btn--full { width: 100%; justify-content: center; }
.btn--sm   { padding: .2rem .6rem; font-size: 12px; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    margin-bottom: .75rem;
}

.form-group--checkbox {
    flex-direction: row;
    align-items: center;
    margin-top: 1.2rem;
}

.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.form-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 14px;
    padding: .45rem .7rem;
    width: 100%;
    transition: border-color .15s;
    outline: none;
}

.form-input:focus {
    border-color: var(--border-focus);
}

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
    padding: .6rem 1rem;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 1rem;
    border-left: 3px solid;
}
.alert--error   { background: var(--error-bg);   border-color: var(--error);   color: var(--error); }
.alert--success { background: var(--success-bg);  border-color: var(--success); color: var(--success); }

/* ── Auth page ──────────────────────────────────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--topbar-h));
    padding: 2rem;
}

.auth-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
}

.auth-logo {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-heading);
}

.auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.auth-tab {
    flex: 1;
    padding: .6rem 0;
    text-align: center;
    font-size: .9rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color .15s, border-color .15s;
}
.auth-tab:hover { color: var(--text-primary); }
.auth-tab--active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.auth-title {
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.auth-form { display: flex; flex-direction: column; }

/* ── Syllabus page ──────────────────────────────────────────── */
.syllabus-page {
    max-width: 860px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.syllabus-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.lang-tabs {
    display: flex;
    gap: .5rem;
}

.lang-tab {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: 13px;
    padding: .35rem .9rem;
    transition: background .15s, color .15s, border-color .15s;
}

.lang-tab:hover { background: var(--bg-hover); color: var(--text-primary); }

.lang-tab--active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: #fff;
}

.module-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.module-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.module-card--locked {
    opacity: .6;
}

.module-card__header {
    padding: 1rem 1.25rem .75rem;
    border-bottom: 1px solid var(--border);
}

.module-card__number {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--accent);
}

.module-card__title {
    font-size: 1.1rem;
    margin: .25rem 0 .35rem;
}

.module-card__description {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: .6rem;
}

.module-card__progress-bar {
    height: 3px;
    background: var(--bg-elevated);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: .3rem;
}

.module-card__progress-fill {
    height: 100%;
    background: var(--success);
    transition: width .3s;
}

.module-card__progress-text {
    font-size: 11px;
    color: var(--text-muted);
}

.module-lock-badge, .module-complete-badge {
    float: right;
    font-size: 1rem;
}

.module-lock-hint {
    font-size: 12px;
    color: var(--text-muted);
    padding: .5rem 1.25rem;
    background: var(--bg-elevated);
}

.exercise-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.exercise-item {
    border-bottom: 1px solid var(--border);
}

.exercise-item:last-child { border-bottom: none; }

.exercise-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .6rem 1.25rem;
    color: var(--text-primary);
    font-size: 13px;
    text-decoration: none;
    transition: background .12s;
}

.exercise-item--clickable .exercise-link:hover {
    background: var(--bg-hover);
}

.exercise-link--locked {
    color: var(--text-muted);
    cursor: default;
}

.exercise-link--inactive {
    color: var(--text-muted);
    cursor: default;
    opacity: .7;
}

.exercise-link--active {
    font-weight: 600;
    color: var(--accent);
}

.exercise-link--active:hover {
    background: var(--bg-hover);
}

.exercise-status { width: 1.2em; text-align: center; flex-shrink: 0; }
.exercise-title  { flex: 1; }
.exercise-attempts { font-size: 11px; color: var(--text-muted); }

/* ── Lesson page ────────────────────────────────────────────── */
.lesson-shell {
    display: flex;
    height: calc(100vh - var(--topbar-h));
    overflow: hidden;
}

.lesson-content-panel {
    width: 420px;
    min-width: 220px;
    max-width: 700px;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--bg-surface);
    flex-shrink: 0;
}

.lesson-resize-handle {
    width: 5px;
    cursor: col-resize;
    background: var(--border);
    flex-shrink: 0;
    transition: background .15s;
}
.lesson-resize-handle:hover,
.lesson-resize-handle.dragging {
    background: var(--accent);
}

.lesson-editor-panel {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
}

.lesson-breadcrumb {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 1rem;
    display: flex;
    gap: .4rem;
    align-items: center;
    flex-wrap: wrap;
}

.lesson-concept-badge {
    display: inline-block;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 100px;
    font-size: 11px;
    padding: .1em .7em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: .6rem;
}

.lesson-title {
    font-size: 1.3rem;
    margin-bottom: 1.25rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--border);
}

.lesson-body { font-size: 14px; line-height: 1.75; }
.lesson-body h2 { font-size: 1rem; margin-top: 1.5rem; }
.lesson-body h3 { font-size: .95rem; color: var(--text-secondary); margin-top: 1rem; }
.lesson-body blockquote {
    border-left: 3px solid var(--accent);
    margin: .75rem 0;
    padding: .4rem .8rem;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.lesson-nav {
    display: flex;
    gap: .75rem;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.lesson-locked {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: calc(100vh - var(--topbar-h));
    gap: 1rem;
    color: var(--text-secondary);
}

/* ── Monaco Editor component ────────────────────────────────── */
.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

.editor-init-overlay {
    position: absolute;
    inset: 0;
    background: var(--bg-base);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.editor-init-message {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: var(--text-secondary);
    font-size: 13px;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 .75rem;
    height: 32px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.editor-filename {
    font-family: var(--font-code);
    font-size: 12px;
    color: var(--text-secondary);
}

.editor-lang-badge {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-elevated);
    padding: .1em .5em;
    border-radius: var(--radius);
}

/* ── Multi-file tab bar ─────────────────────────────────────────────────── */
.editor-tabs {
    display: flex;
    align-items: center;
    height: 32px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}
.editor-tabs::-webkit-scrollbar { display: none; }

.editor-tab {
    padding: 0 .75rem;
    height: 100%;
    border: none;
    border-right: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-code);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background .1s, color .1s;
}
.editor-tab:hover { background: var(--bg-elevated); color: var(--text-primary); }
.editor-tab--active {
    background: var(--bg-elevated);
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
}
.editor-tab:disabled { cursor: not-allowed; opacity: .5; }

.editor-tab-spacer { flex: 1; }

/* badge sits on the right inside the tab bar */
.editor-tabs .editor-lang-badge {
    margin-right: .5rem;
    flex-shrink: 0;
}

.monaco-container {
    flex: 1;
    min-height: 0;
}

/* xterm.js overrides so it fills its container */
.monaco-container .xterm,
.monaco-container .xterm-viewport,
.monaco-container .xterm-screen {
    height: 100%;
}

.editor-statusbar {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 0 .75rem;
    height: 22px;
    background: var(--accent-dim);
    border-top: 1px solid var(--border);
    font-size: 11px;
    flex-shrink: 0;
    overflow: hidden;
}

.statusbar-status   { color: var(--text-secondary); }
.status-saved       { color: var(--success); }
.status-saving      { color: var(--warning); }
.status-unsaved     { color: var(--text-secondary); }
.statusbar-separator { color: var(--text-muted); }
.statusbar-checkpoint { color: var(--text-muted); font-family: var(--font-code); }
.statusbar-container  { color: var(--text-muted); }
.container-running    { color: var(--success); }
.container-stopped    { color: var(--error); }

/* ── Run toolbar ─────────────────────────────────────────────── */
.run-toolbar {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .35rem .6rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.btn--run {
    background: #1a7340;
    color: #fff;
    border-color: #1a7340;
}
.btn--run:hover:not(:disabled) { background: #1e8a4c; border-color: #1e8a4c; }

.btn--stop {
    background: var(--error-bg);
    color: var(--error);
    border-color: var(--error);
}
.btn--stop:hover:not(:disabled) { background: rgba(244,135,113,.25); }

.run-status {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: 12px;
    color: var(--text-secondary);
}

/* ── Spinner ─────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,.25);
    border-top-color: rgba(255,255,255,.85);
    border-radius: 50%;
    animation: spin .65s linear infinite;
    flex-shrink: 0;
}

.spinner--sm {
    width: 11px;
    height: 11px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Terminal panel ──────────────────────────────────────────── */
.terminal-panel {
    display: flex;
    flex-direction: column;
    height: 240px;
    min-height: 160px;
    background: #0d0d0d;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.terminal-toolbar {
    display: flex;
    align-items: center;
    padding: 0 .6rem;
    height: 26px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.terminal-toolbar__label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .06em;
    flex: 1;
}

.terminal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: .1rem .3rem;
    border-radius: var(--radius);
    line-height: 1;
}
.terminal-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.terminal-container {
    flex: 1;
    overflow: hidden;
    padding: 2px 4px;
}

/* Make xterm.js fill the terminal container */
.terminal-container .xterm {
    height: 100%;
}
.terminal-container .xterm-viewport {
    overflow-y: auto !important;
}

/* ── Editor placeholder (Phase 1 only) ─────────────────────── */
.editor-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.editor-placeholder__inner {
    max-width: 480px;
    text-align: center;
    color: var(--text-secondary);
}

.editor-placeholder__hint {
    font-size: 13px;
    margin: 1rem 0 .5rem;
}

.starter-preview {
    text-align: left;
    font-size: 12px;
    max-height: 300px;
    overflow-y: auto;
}

/* ── Admin page ─────────────────────────────────────────────── */
.admin-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.admin-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.admin-card h2 {
    margin-bottom: 1rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--border);
}

/* ── Data table ─────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    padding: .5rem .75rem;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: .6rem .75rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }

/* ── Misc ───────────────────────────────────────────────────── */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-muted);
    font-size: 13px;
}

.not-found {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 50vh;
    gap: .5rem;
    color: var(--text-secondary);
}

.not-found h1 { font-size: 4rem; color: var(--text-muted); }

/* ── Blazor error UI ────────────────────────────────────────── */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--error-bg);
    border-top: 2px solid var(--error);
    color: var(--error);
    padding: .6rem 1rem;
    font-size: 13px;
    z-index: 1000;
    gap: 1rem;
}

#blazor-error-ui .reload { color: var(--error); text-decoration: underline; cursor: pointer; margin-left: 1rem; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

/* ── Test button ─────────────────────────────────────────────── */
.btn--test {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border);
}
.btn--test:hover:not(:disabled) { background: var(--bg-hover); }

/* ── Test results panel ──────────────────────────────────────── */
.test-panel {
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
    max-height: 280px;
    overflow-y: auto;
}

.test-panel__running {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .6rem .75rem;
    color: var(--text-secondary);
    font-size: 13px;
}

.test-panel__header {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    font-size: 13px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}

.test-panel__header--pass {
    background: var(--success-bg);
    color: var(--success);
}

.test-panel__header--fail {
    background: var(--error-bg);
    color: var(--error);
}

.test-icon { font-size: 14px; font-weight: 700; }
.test-icon--pass { color: var(--success); }
.test-icon--fail { color: var(--error); }

.test-summary-text { flex: 1; }

.test-unlock-badge {
    font-size: 12px;
    background: rgba(78,201,176,.2);
    color: var(--success);
    padding: .1rem .5rem;
    border-radius: 99px;
    border: 1px solid var(--success);
}

.test-list {
    list-style: none;
    margin: 0;
    padding: .25rem 0;
}

.test-item {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    padding: .3rem .75rem;
    font-size: 12px;
    border-bottom: 1px solid var(--border);
}
.test-item:last-child { border-bottom: none; }

.test-item--pass { color: var(--text-primary); }
.test-item--fail { color: var(--text-primary); }

.test-item__icon {
    flex-shrink: 0;
    font-weight: 700;
    width: 14px;
    margin-top: 1px;
}
.test-item--pass .test-item__icon { color: var(--success); }
.test-item--fail .test-item__icon { color: var(--error); }

.test-item__body {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    min-width: 0;
}

.test-item__desc {
    color: var(--text-primary);
    line-height: 1.4;
}

.test-item__hint {
    color: var(--text-secondary);
    font-size: 11px;
    line-height: 1.4;
}

.test-panel__compile-error {
    padding: .5rem .75rem;
}

.test-panel__compile-error-header {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: 12px;
    font-weight: 600;
    color: var(--error);
    margin-bottom: .4rem;
}

.test-compile-output {
    font-size: 11px;
    max-height: 180px;
    overflow-y: auto;
    color: var(--error);
    background: var(--error-bg);
    border: 1px solid rgba(244,135,113,.3);
    border-radius: var(--radius);
    padding: .5rem;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ── Scrollbar styling ──────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-input); }

/* ── Tutor button ────────────────────────────────────────────── */
.btn--tutor {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border-color: var(--border);
    margin-left: auto;  /* push to right side of toolbar */
}
.btn--tutor:hover:not(:disabled) {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
}

/* ── Tutor drawer ────────────────────────────────────────────── */
.tutor-drawer {
    position: absolute;
    top: 0;
    right: 0;
    width: 380px;
    height: 100%;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform .22s ease;
    z-index: 50;
    overflow: hidden;
}

.tutor-drawer--open {
    transform: translateX(0);
    box-shadow: -4px 0 16px rgba(0,0,0,.35);
}

.tutor-drawer__header {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 0 .75rem;
    height: 36px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tutor-drawer__title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-heading);
    flex: 1;
}

.tutor-model-select {
    font-size: 11px;
    padding: .15rem .4rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    max-width: 120px;
}

.tutor-online-dot {
    font-size: 10px;
    line-height: 1;
}
.tutor-online-dot--on  { color: var(--success); }
.tutor-online-dot--off { color: var(--error); }

.tutor-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    padding: .1rem .3rem;
    border-radius: var(--radius);
    line-height: 1;
}
.tutor-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.tutor-offline-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .4rem .75rem;
    background: var(--error-bg);
    border-bottom: 1px solid rgba(244,135,113,.3);
    font-size: 12px;
    color: var(--error);
    flex-shrink: 0;
}

/* ── Chat messages area ──────────────────────────────────────── */
.tutor-messages {
    flex: 1;
    overflow-y: auto;
    padding: .5rem;
    display: flex;
    flex-direction: column;
    gap: .4rem;
    min-height: 0;
}

.tutor-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: .4rem;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 1.5rem;
}
.tutor-empty__sub { font-size: 11px; }

/* ── Chat message bubbles ────────────────────────────────────── */
.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 92%;
}

.chat-msg--user {
    align-self: flex-end;
}

.chat-msg--assistant {
    align-self: flex-start;
}

.chat-msg__bubble {
    padding: .45rem .65rem;
    border-radius: var(--radius-lg);
    font-size: 13px;
    line-height: 1.55;
    word-break: break-word;
}

.chat-msg--user .chat-msg__bubble {
    background: var(--accent-dim);
    color: var(--text-primary);
    border: 1px solid var(--accent);
    border-bottom-right-radius: 2px;
}

.chat-msg--assistant .chat-msg__bubble {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
}

.chat-msg__text {
    white-space: pre-wrap;
}

/* Markdown rendered inside assistant bubbles */
.chat-msg__markdown { line-height: 1.6; }
.chat-msg__markdown > *:first-child { margin-top: 0; }
.chat-msg__markdown > *:last-child  { margin-bottom: 0; }
.chat-msg__markdown p               { margin: .4em 0; }
.chat-msg__markdown h1,.chat-msg__markdown h2,.chat-msg__markdown h3 {
    font-size: 13px; font-weight: 700; margin: .6em 0 .2em;
}
.chat-msg__markdown ul,.chat-msg__markdown ol {
    padding-left: 1.2em; margin: .3em 0;
}
.chat-msg__markdown li { margin: .15em 0; }
.chat-msg__markdown code {
    font-family: var(--font-code);
    font-size: 12px;
    background: var(--bg-base);
    padding: .1em .35em;
    border-radius: 3px;
    border: 1px solid var(--border);
}
.chat-msg__markdown pre {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .6em .8em;
    margin: .4em 0;
    overflow-x: auto;
}
.chat-msg__markdown pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 12px;
}
.chat-msg__markdown blockquote {
    border-left: 3px solid var(--accent);
    margin: .4em 0;
    padding: .2em .6em;
    color: var(--text-secondary);
}
.chat-msg__markdown strong { font-weight: 700; }
.chat-msg__markdown em     { font-style: italic; }

.chat-cursor {
    animation: blink .85s step-end infinite;
    color: var(--accent);
    font-size: 14px;
    vertical-align: -1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Input area ──────────────────────────────────────────────── */
.tutor-input-area {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    padding: .5rem;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.tutor-input-row {
    display: flex;
    gap: .4rem;
    align-items: flex-end;
}

.tutor-textarea {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 13px;
    padding: .4rem .6rem;
    resize: none;
    outline: none;
    line-height: 1.4;
    transition: border-color .15s;
}
.tutor-textarea:focus    { border-color: var(--border-focus); }
.tutor-textarea:disabled { opacity: .5; }

.tutor-send-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
    flex-shrink: 0;
}

.tutor-clear-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    text-align: left;
    font-family: var(--font-ui);
}
.tutor-clear-btn:hover:not(:disabled) { color: var(--text-secondary); text-decoration: underline; }
.tutor-clear-btn:disabled             { opacity: .4; cursor: not-allowed; }

/* ── Context indicator ───────────────────────────────────────── */
.tutor-context-indicator {
    display: flex;
    align-items: center;
    gap: .3rem;
    flex-wrap: wrap;
    font-size: 10px;
    padding: .2rem 0;
}

.tutor-ctx-label { color: var(--text-muted); }
.tutor-ctx-item  { color: var(--text-secondary); }
.tutor-ctx-sep   { color: var(--text-muted); }
.tutor-ctx-code  { color: var(--success); }
.tutor-ctx-pass  { color: var(--success); }
.tutor-ctx-fail  { color: var(--error); }

/* ── Theme toggle button ─────────────────────────────────────── */
.nav-btn-theme {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: .2rem .45rem;
    border-radius: var(--radius);
    line-height: 1;
    transition: background .15s, color .15s;
}
.nav-btn-theme:hover { background: var(--bg-hover); color: var(--text-primary); }

/* CSS-driven icon: sun in dark mode (to switch to light), moon in light mode */
.nav-btn-theme::before { content: '☀'; }
[data-theme="light"] .nav-btn-theme::before { content: '☾'; }

/* ── Checkpoint dropdown ─────────────────────────────────────── */
.checkpoint-wrapper {
    position: relative;
}

.checkpoint-dropdown {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    min-width: 320px;
    max-width: 440px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 16px rgba(0,0,0,.35);
    z-index: 200;
    overflow: hidden;
}

.checkpoint-dropdown__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem .75rem;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-heading);
}

.checkpoint-dropdown__close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    padding: .1rem .3rem;
    border-radius: var(--radius);
}
.checkpoint-dropdown__close:hover { background: var(--bg-hover); color: var(--text-primary); }

.checkpoint-list {
    list-style: none;
    margin: 0;
    padding: .25rem 0;
    max-height: 260px;
    overflow-y: auto;
}

.checkpoint-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem .75rem;
    cursor: pointer;
    transition: background .1s;
    border-bottom: 1px solid var(--border);
}
.checkpoint-item:last-child { border-bottom: none; }
.checkpoint-item:hover { background: var(--bg-hover); }
.checkpoint-item--special { border-bottom: 2px solid var(--border); }

.checkpoint-item__icon { font-size: 12px; flex-shrink: 0; }
.checkpoint-item__body { flex: 1; min-width: 0; }
.checkpoint-item__msg  { font-size: 12px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.checkpoint-item__date { font-size: 10px; color: var(--text-muted); font-family: var(--font-code); }

.checkpoint-empty {
    padding: .75rem;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

.checkpoint-loading {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .75rem;
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Admin progress page ─────────────────────────────────────── */
.progress-grid {
    display: grid;
    gap: 1.5rem;
}

.progress-user-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.progress-user-card__header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .75rem 1.25rem;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
}

.progress-user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-heading);
    flex: 1;
}

.progress-user-login {
    font-size: 11px;
    color: var(--text-muted);
}

.progress-lang-section {
    padding: .75rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.progress-lang-section:last-child { border-bottom: none; }

.progress-lang-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-secondary);
    margin-bottom: .5rem;
}

.progress-module-row {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: 12px;
    margin-bottom: .25rem;
}

.progress-module-label {
    color: var(--text-secondary);
    width: 180px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-ex-dots {
    display: flex;
    gap: 3px;
    flex: 1;
}

.progress-ex-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
}

.progress-ex-dot--passed     { background: var(--success); border-color: var(--success); }
.progress-ex-dot--inprogress { background: var(--warning); border-color: var(--warning); }

.progress-count {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 3.5rem;
    text-align: right;
}

.progress-no-activity {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

/* ── Tutor auto-analysis panel ───────────────────────────────── */
.tutor-analysis {
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
    max-height: 180px;
    overflow-y: auto;
}

.tutor-analysis__header {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .4rem .75rem;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
}

.tutor-analysis__icon  { font-size: 13px; }
.tutor-analysis__title { flex: 1; }

.tutor-analysis__body {
    padding: .5rem .75rem;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.tutor-analysis__footer {
    padding: .35rem .75rem .5rem;
    display: flex;
    justify-content: flex-end;
}
