* {
    box-sizing: border-box;
}

:root {
    --background: #f5f7fb;
    --panel: #ffffff;
    --border: #dfe5ee;
    --border-strong: #cbd5e1;
    --text: #172033;
    --muted: #667085;
    --soft: #f8fafc;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #15803d;
    --success-bg: #f0fdf4;
    --danger: #b42318;
    --danger-bg: #fef3f2;
    --warning-bg: #fff8e7;
    --warning: #9a6700;
    --code-bg: #101827;
    --code-text: #e5edf8;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--background);
    color: var(--text);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

button,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.lab-header {
    min-height: 64px;
    padding: 10px 24px;
    background: #172033;
    color: white;
    display: flex;
    align-items: center;
    gap: 18px;
    border-bottom: 1px solid #2b3549;
}

.lab-brand {
    display: flex;
    align-items: center;
}

.lab-brand img {
    height: 38px;
    width: auto;
}

.lab-header-copy {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding-left: 18px;
    border-left: 1px solid #3b4558;
}

.lab-header-copy strong {
    font-size: 15px;
}

.lab-header-copy span {
    color: #aeb8c9;
    font-size: 12px;
}

.lab-header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.engine-pill {
    padding: 5px 9px;
    border: 1px solid #475569;
    border-radius: 999px;
    color: #dbe4f0;
    font-size: 12px;
}

.home-link {
    color: #dbe4f0;
    text-decoration: none;
    font-size: 13px;
}

.home-link:hover {
    color: white;
}

.lab-shell {
    width: min(1800px, 100%);
    margin: 0 auto;
    padding: 18px;
}

.lab-toolbar {
    margin-bottom: 14px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
}

.eyebrow,
.panel-kicker {
    color: #7b8494;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .12em;
}

.lab-toolbar h1 {
    margin: 3px 0 0;
    font-size: 26px;
    line-height: 1.1;
}

.challenge-navigation {
    display: flex;
    align-items: center;
    gap: 12px;
}

.challenge-navigation span {
    min-width: 110px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.workspace {
    display: grid;
    grid-template-columns: 250px minmax(420px, 1fr) 340px;
    gap: 12px;
    min-height: calc(100vh - 135px);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
}

.database-panel,
.challenge-panel {
    min-width: 0;
}

.database-panel {
    padding: 16px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-heading h2 {
    margin: 4px 0 0;
    font-size: 16px;
}

.database-help {
    margin: 10px 0 14px;
    color: var(--muted);
    font-size: 12px;
}

.schema-browser {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.loading-state {
    padding: 20px 8px;
    color: var(--muted);
    font-size: 13px;
}

.schema-table {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 7px;
}

.schema-table-button {
    width: 100%;
    padding: 9px 10px;
    border: 0;
    background: var(--soft);
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
    font-size: 13px;
    font-weight: 700;
}

.schema-table-button:hover {
    background: #f0f4f8;
}

.schema-arrow {
    width: 12px;
    color: var(--muted);
}

.schema-columns {
    display: none;
    padding: 5px 0;
    border-top: 1px solid var(--border);
}

.schema-table.open .schema-columns {
    display: block;
}

.schema-column {
    padding: 5px 10px 5px 30px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 11px;
}

.schema-column span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
}

.schema-column span:last-child {
    color: #98a2b3;
    font-size: 10px;
}

.relationship-card {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.relationship {
    margin-top: 9px;
    padding: 8px;
    background: var(--soft);
    border-radius: 6px;
    font-size: 11px;
}

.relationship span {
    display: block;
    margin: 2px 0;
    color: var(--muted);
    font-size: 9px;
}

.query-panel {
    min-width: 0;
    display: grid;
    grid-template-rows: minmax(330px, 44%) minmax(300px, 56%);
    gap: 12px;
}

.editor-card,
.results-card {
    min-height: 0;
    overflow: hidden;
}

.editor-card {
    display: flex;
    flex-direction: column;
}

.editor-toolbar,
.results-toolbar {
    min-height: 48px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.keyboard-hint {
    margin-left: 8px;
    color: #98a2b3;
    font-size: 10px;
}

.editor-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.primary-button,
.secondary-button,
.check-button,
.solution-button {
    border-radius: 6px;
    font-weight: 700;
}

.primary-button {
    padding: 8px 13px;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: white;
}

.primary-button:hover {
    background: var(--primary-hover);
}

.secondary-button {
    padding: 7px 11px;
    border: 1px solid var(--border-strong);
    background: white;
    color: #344054;
}

.secondary-button:hover {
    background: var(--soft);
}

.editor-wrap {
    min-height: 0;
    flex: 1;
    display: grid;
    grid-template-columns: 42px 1fr;
    background: var(--code-bg);
}

.line-numbers {
    padding: 16px 10px;
    overflow: hidden;
    border-right: 1px solid #263244;
    color: #64748b;
    font-family: Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.65;
    text-align: right;
    white-space: pre;
    user-select: none;
}

#sqlEditor {
    width: 100%;
    height: 100%;
    min-height: 280px;
    padding: 16px;
    resize: none;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--code-text);
    caret-color: white;
    font-family: Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.65;
    tab-size: 4;
}

.results-card {
    display: flex;
    flex-direction: column;
}

.results-toolbar {
    padding: 0 12px;
}

.results-tabs {
    height: 100%;
    display: flex;
    align-items: stretch;
}

.result-tab {
    padding: 0 12px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.result-tab.active {
    border-bottom-color: var(--primary);
    color: var(--primary);
}

.query-meta {
    color: var(--muted);
    font-size: 11px;
}

.result-view {
    display: none;
    min-height: 0;
    flex: 1;
    overflow: auto;
}

.result-view.active {
    display: block;
}

.query-message {
    margin: 12px;
    padding: 9px 11px;
    border-radius: 6px;
    font-size: 12px;
}

.query-message.neutral {
    background: var(--soft);
    color: var(--muted);
}

.query-message.error {
    background: var(--danger-bg);
    color: var(--danger);
}

.query-message.success {
    background: var(--success-bg);
    color: var(--success);
}

.table-wrap {
    max-width: 100%;
    overflow: auto;
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    white-space: nowrap;
}

.result-table th {
    position: sticky;
    top: 0;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-strong);
    background: #f8fafc;
    color: #475467;
    text-align: left;
    font-weight: 800;
}

.result-table td {
    padding: 7px 10px;
    border-bottom: 1px solid #edf0f4;
}

.result-table tbody tr:hover {
    background: #fafcff;
}

.expected-copy {
    margin: 16px 16px 10px;
    color: var(--muted);
    font-size: 12px;
}

.required-columns {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

#requiredColumns {
    padding: 0 16px 16px;
}

.column-chip,
.skill-chip {
    padding: 4px 7px;
    border-radius: 5px;
    font-family: Consolas, Monaco, monospace;
    font-size: 10px;
}

.column-chip {
    border: 1px solid #d9e2f0;
    background: #f7f9fc;
    color: #344054;
}

.skill-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.skill-chip {
    background: #eef4ff;
    color: #3538cd;
}

.challenge-panel {
    padding: 17px;
    overflow-y: auto;
}

.challenge-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-size: 11px;
}

.difficulty-badge {
    padding: 4px 7px;
    border-radius: 999px;
    background: #ecfdf3;
    color: #027a48;
    font-size: 10px;
    font-weight: 800;
}

.difficulty-badge.intermediate {
    background: #fff8e7;
    color: #9a6700;
}

.difficulty-badge.advanced {
    background: #fef3f2;
    color: #b42318;
}

.challenge-top h2 {
    margin: 10px 0 0;
    font-size: 20px;
    line-height: 1.25;
}

.challenge-section {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.challenge-section p {
    margin: 8px 0 0;
    color: #475467;
    font-size: 13px;
    line-height: 1.55;
}

.task-section p {
    color: var(--text);
    font-weight: 600;
}

.hint-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.hint-heading span:last-child {
    color: var(--muted);
    font-size: 10px;
}

.hint-box {
    margin: 9px 0;
    padding: 10px;
    border: 1px solid #f2dfae;
    border-radius: 6px;
    background: var(--warning-bg);
    color: #765500;
    font-size: 12px;
    line-height: 1.5;
}

.full-button {
    width: 100%;
    margin-top: 2px;
}

.challenge-actions {
    margin-top: 18px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.check-button,
.solution-button {
    padding: 10px 8px;
}

.check-button {
    border: 1px solid #15803d;
    background: #15803d;
    color: white;
}

.check-button:hover {
    background: #116b33;
}

.solution-button {
    border: 1px solid var(--border-strong);
    background: white;
    color: #344054;
}

.solution-button:hover {
    background: var(--soft);
}

.validation-message {
    display: none;
    margin-top: 12px;
    padding: 10px;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.45;
}

.validation-message.success {
    display: block;
    background: var(--success-bg);
    color: var(--success);
}

.validation-message.error {
    display: block;
    background: var(--danger-bg);
    color: var(--danger);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .58);
}

.modal-card {
    position: relative;
    width: min(720px, 100%);
    overflow: hidden;
    border-radius: 10px;
    background: white;
    box-shadow: 0 20px 60px rgba(15, 23, 42, .3);
}

.modal-header {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
}

.modal-header h2 {
    margin: 3px 0 0;
    font-size: 18px;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 5px;
    background: var(--soft);
    color: #475467;
    font-size: 22px;
}

#solutionCode {
    margin: 0;
    max-height: 55vh;
    padding: 18px;
    overflow: auto;
    background: var(--code-bg);
    color: var(--code-text);
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    line-height: 1.6;
}

.modal-actions {
    padding: 12px 18px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

@media (max-width: 1180px) {
    .workspace {
        grid-template-columns: 220px minmax(400px, 1fr);
    }

    .challenge-panel {
        grid-column: 1 / -1;
    }
}

@media (max-width: 780px) {
    .lab-header {
        padding: 9px 12px;
    }

    .lab-header-copy {
        display: none;
    }

    .lab-shell {
        padding: 10px;
    }

    .lab-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .challenge-navigation {
        width: 100%;
        justify-content: space-between;
    }

    .workspace {
        display: flex;
        flex-direction: column;
    }

    .database-panel {
        order: 2;
    }

    .query-panel {
        order: 1;
        display: flex;
        flex-direction: column;
    }

    .challenge-panel {
        order: 0;
    }

    .editor-card {
        min-height: 400px;
    }

    .results-card {
        min-height: 320px;
    }

    .challenge-actions {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================
   SQL LAB MODES
   ========================================================== */

.workspace-heading {
    min-width: 0;
}

.mode-switch {
    display: inline-flex;
    margin-top: 12px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #eef2f7;
}

.mode-button {
    min-width: 88px;
    padding: 7px 14px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.mode-button:hover {
    color: var(--text);
}

.mode-button.active {
    background: white;
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(16, 24, 40, .10);
}

.mode-description {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 11px;
}

.workspace.explore-mode {
    grid-template-columns: 250px minmax(0, 1fr);
}

.workspace.explore-mode .query-panel {
    grid-column: 2;
}

.workspace.explore-mode .challenge-panel {
    display: none;
}

.workspace.practice-mode .challenge-panel {
    display: block;
}

.challenge-navigation[hidden],
.result-tab[hidden],
.challenge-panel[hidden] {
    display: none !important;
}

/*
Keep the side panels inside the available viewport.
This prevents the task controls from being pushed unnecessarily
far below the visible workspace on desktop.
*/
@media (min-width: 1181px) {
    .database-panel,
    .challenge-panel {
        max-height: calc(100vh - 190px);
        overflow-y: auto;
    }

    .workspace {
        min-height: calc(100vh - 190px);
    }

    .query-panel {
        min-height: calc(100vh - 190px);
    }
}

@media (max-width: 780px) {
    .mode-switch {
        width: 100%;
    }

    .mode-button {
        flex: 1;
    }

    .mode-description {
        max-width: 520px;
    }

    .workspace.explore-mode {
        display: flex;
    }

    .workspace.explore-mode .query-panel {
        order: 1;
    }
}


/* ==========================================================
   SQL LAB DATABASE SELECTOR
   ========================================================== */

.database-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.database-select-label {
    display: block;
    margin-top: 12px;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
}

.database-selector {
    width: 100%;
    padding: 8px 30px 8px 9px;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    outline: none;
    background: white;
    color: var(--text);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
}

.database-selector:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .10);
}

.database-selector:disabled {
    opacity: .65;
    cursor: wait;
}


/* ==========================================================
   SQL LAB ROBUSTNESS TEST
   ========================================================== */

.robustness-panel {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: #f8fbff;
}

.robustness-panel[hidden] {
    display: none !important;
}

.robustness-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.robustness-heading > div {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.robustness-heading strong {
    font-size: 13px;
}

.robustness-copy {
    margin: 9px 0 10px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.55;
}

.robustness-button {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #2563eb;
    border-radius: 7px;
    background: white;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 800;
}

.robustness-button:hover {
    background: #eff6ff;
}

.robustness-button:disabled {
    opacity: .65;
    cursor: wait;
}

.robustness-badge {
    flex: 0 0 auto;
    padding: 4px 7px;
    border-radius: 999px;
    background: #eef2f7;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
}

.robustness-badge.testing {
    background: #fff8e7;
    color: var(--warning);
}

.robustness-badge.success {
    background: var(--success-bg);
    color: var(--success);
}

.robustness-badge.error {
    background: var(--danger-bg);
    color: var(--danger);
}

.robustness-results {
    margin-top: 10px;
}

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

.robustness-test-list {
    display: grid;
    gap: 5px;
}

.robustness-test {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
}

.robustness-test.passed {
    background: var(--success-bg);
    color: var(--success);
}

.robustness-test.failed {
    background: var(--danger-bg);
    color: var(--danger);
}

.robustness-message {
    margin-top: 8px;
    padding: 8px;
    border-radius: 6px;
    font-size: 11px;
    line-height: 1.5;
}

.robustness-message.success {
    background: var(--success-bg);
    color: var(--success);
}

.robustness-message.error {
    background: var(--danger-bg);
    color: var(--danger);
}


/* ==========================================================
   SQL LAB PHASE 4A — PRACTICE PROGRESS + TASK BROWSER
   ========================================================== */

.task-progress-summary {
    min-width: 125px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.challenge-navigation .task-progress-summary #challengeProgress {
    min-width: 0;
}

.completion-progress {
    color: #98a2b3 !important;
    font-size: 10px !important;
}

.browse-tasks-button {
    white-space: nowrap;
}

.task-drawer {
    position: fixed;
    inset: 0;
    z-index: 90;
    visibility: hidden;
    pointer-events: none;
}

.task-drawer.open {
    visibility: visible;
    pointer-events: auto;
}

.task-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .38);
    opacity: 0;
    transition: opacity .18s ease;
}

.task-drawer.open .task-drawer-backdrop {
    opacity: 1;
}

.task-drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: min(470px, 94vw);
    height: 100%;
    padding: 20px;
    overflow-y: auto;
    background: white;
    box-shadow: -16px 0 45px rgba(15, 23, 42, .18);
    transform: translateX(100%);
    transition: transform .2s ease;
}

.task-drawer.open .task-drawer-panel {
    transform: translateX(0);
}

body.task-drawer-open {
    overflow: hidden;
}

.task-drawer-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.task-drawer-header h2 {
    margin: 4px 0 2px;
    font-size: 21px;
}

.task-drawer-header p {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.task-filters {
    padding: 16px 0;
    display: grid;
    gap: 14px;
    border-bottom: 1px solid var(--border);
}

.task-filter-label {
    display: block;
    margin-bottom: 7px;
    color: #7b8494;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
}

.difficulty-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.task-filter {
    padding: 6px 9px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: white;
    color: #475467;
    font-size: 11px;
    font-weight: 700;
}

.task-filter:hover {
    background: var(--soft);
}

.task-filter.active {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: var(--primary);
}

.task-skill-filter {
    width: 100%;
    padding: 8px 30px 8px 9px;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    outline: none;
    background: white;
    color: var(--text);
    font: inherit;
    font-size: 12px;
}

.task-skill-filter:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .10);
}

.task-status-legend {
    padding: 12px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    color: var(--muted);
    font-size: 10px;
}

.task-list {
    display: grid;
    gap: 7px;
}

.task-list-item {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    display: grid;
    grid-template-columns: 22px 28px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    color: var(--text);
    text-align: left;
}

.task-list-item:hover {
    border-color: #bfdbfe;
    background: #f8fbff;
}

.task-list-item.current {
    border-color: #93c5fd;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, .08);
}

.task-status-symbol {
    font-size: 15px;
    font-weight: 900;
    text-align: center;
}

.status-not_started .task-status-symbol {
    color: #98a2b3;
}

.status-attempted .task-status-symbol {
    color: #d97706;
}

.status-correct .task-status-symbol {
    color: var(--success);
}

.status-robust .task-status-symbol {
    color: #7c3aed;
}

.task-list-number {
    color: #98a2b3;
    font-family: Consolas, Monaco, monospace;
    font-size: 11px;
}

.task-list-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.task-list-copy strong {
    overflow: hidden;
    color: var(--text);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-list-copy small {
    overflow: hidden;
    color: var(--muted);
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-list-empty {
    padding: 28px 12px;
    border: 1px dashed var(--border-strong);
    border-radius: 8px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

/*
Keep the final robustness explanation visible after a test.
*/
.robustness-results {
    scroll-margin-block: 16px;
}

.robustness-message.error {
    font-weight: 600;
}

@media (max-width: 900px) {
    .challenge-navigation {
        flex-wrap: wrap;
    }

    .task-progress-summary {
        order: -1;
        width: 100%;
    }
}

@media (max-width: 520px) {
    .task-drawer-panel {
        width: 100%;
        padding: 16px;
    }

    .difficulty-filters {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .task-filter {
        border-radius: 7px;
    }
}


/* ==========================================================
   SQL LAB PHASE 4B — DIAGNOSTIC ANSWER FEEDBACK
   ========================================================== */

.validation-diagnostics {
    margin-top: 12px;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #fbfcfe;
}

.validation-diagnostics[hidden] {
    display: none;
}

.diagnostic-heading {
    margin-bottom: 8px;
    color: #667085;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.diagnostic-grid {
    display: grid;
    gap: 5px;
}

.diagnostic-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: #475467;
    font-size: 11px;
}

.diagnostic-row strong {
    min-width: 24px;
    text-align: center;
    font-size: 12px;
}

.diagnostic-row strong.pass {
    color: var(--success);
}

.diagnostic-row strong.fail {
    color: var(--danger);
}

.diagnostic-row strong.neutral {
    color: #98a2b3;
}


/* ==========================================================
   SQL LAB PHASE 4C — WORKSPACE POLISH
   ========================================================== */

.task-drawer-footer {
    padding: 14px 20px 20px;
    border-top: 1px solid var(--border);
}

.reset-progress-button {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: #667085;
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition:
        background .15s ease,
        border-color .15s ease,
        color .15s ease;
}

.reset-progress-button:hover {
    border-color: #fda29b;
    background: var(--danger-bg);
    color: var(--danger);
}

/* ==========================================================
   PHASE 11C-1-R2 WORKSPACE REDESIGN START

   Phase 11 SQL Lab visual workspace layer.
   CSS ONLY.
   Existing DOM IDs, JavaScript behavior, SQL execution,
   challenges, progress and database contracts are preserved.
   ========================================================== */


/* ==========================================================
   DESKTOP APPLICATION WORKSPACE
   ========================================================== */

@media (min-width: 1181px) {

    /*
     * Reduce the page-like feeling and give the working
     * environment substantially more horizontal space.
     */

    .sql-lab-shell {
        width: min(1680px, calc(100% - 40px));
        max-width: none;
        margin-left: auto;
        margin-right: auto;
    }


    /*
     * The hero should identify the workspace, not consume a
     * large portion of the screen before the editor begins.
     */

    .sql-lab-hero {
        padding-top: 22px;
        padding-bottom: 16px;
    }

    .sql-lab-hero-copy {
        max-width: 820px;
    }

    .sql-lab-hero h1 {
        margin-top: 4px;
        margin-bottom: 8px;
    }

    .sql-lab-hero p {
        margin-top: 6px;
        margin-bottom: 0;
    }


    /*
     * Compact mode/database controls.
     */

    .sql-lab-controls {
        margin-top: 14px;
        margin-bottom: 14px;
    }

    .sql-mode-switch {
        gap: 6px;
    }


    /*
     * EXPLORE WORKSPACE
     *
     * Narrow schema navigation + dominant editor workspace.
     */

    .sql-workspace {
        grid-template-columns:
            minmax(225px, 0.68fr)
            minmax(0, 2.7fr);
        gap: 16px;
        align-items: stretch;
    }


    /*
     * Database/schema panel.
     */

    .schema-panel {
        min-width: 0;
    }

    .schema-panel-header {
        padding-top: 16px;
        padding-bottom: 14px;
    }

    .schema-list {
        max-height: calc(100vh - 315px);
        overflow-y: auto;
        overscroll-behavior: contain;
    }


    /*
     * Main editor.
     */

    .editor-panel {
        min-width: 0;
    }

    .editor-toolbar {
        min-height: 56px;
        padding-top: 9px;
        padding-bottom: 9px;
    }

    .editor-shell {
        min-height: 315px;
    }

    #sqlEditor {
        min-height: 300px;
    }


    /*
     * Results remain visually connected to the editor instead
     * of feeling like a distant card below the workspace.
     */

    .results-panel {
        margin-top: 14px;
        min-width: 0;
    }

    .results-table-wrap {
        max-height: 340px;
        overflow: auto;
        overscroll-behavior: contain;
    }


    /* ======================================================
       PRACTICE MODE
       ======================================================

       Database | SQL workspace | learning task

       Existing DOM is preserved; this layer only changes
       visual proportions when the body/root has practice-mode.
       ====================================================== */

    .practice-mode .sql-workspace {
        grid-template-columns:
            minmax(210px, 0.60fr)
            minmax(500px, 1.95fr)
            minmax(320px, 0.88fr);
        gap: 16px;
        align-items: stretch;
    }


    /*
     * Challenge/task panel gets enough width to read naturally.
     */

    .practice-mode .challenge-panel {
        min-width: 0;
        max-height: calc(100vh - 285px);
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .challenge-card {
        padding: 20px;
    }

    .challenge-card h2,
    .challenge-card h3 {
        margin-top: 0;
    }


    /*
     * Reduce the amount of vertical space consumed by task
     * navigation/progress controls.
     */

    .challenge-navigation {
        gap: 10px;
        margin-top: 8px;
        margin-bottom: 12px;
    }

    .challenge-progress {
        min-width: 0;
    }


    /*
     * Hint/solution controls should remain secondary to the
     * actual task and editor.
     */

    .challenge-actions {
        gap: 8px;
    }


    /*
     * Prevent any individual workspace card from forcing the
     * application wider than the viewport.
     */

    .sql-workspace > *,
    .editor-panel,
    .results-panel,
    .challenge-panel,
    .schema-panel {
        min-width: 0;
    }
}


/* ==========================================================
   MID-SIZE DESKTOP / TABLET LANDSCAPE
   ========================================================== */

@media (min-width: 781px) and (max-width: 1180px) {

    .sql-lab-shell {
        width: calc(100% - 28px);
    }

    .sql-lab-hero {
        padding-bottom: 14px;
    }

    .sql-workspace {
        gap: 14px;
    }

    .editor-shell {
        min-height: 290px;
    }

    #sqlEditor {
        min-height: 275px;
    }
}


/* ==========================================================
   MOBILE SAFETY
   ==========================================================

   Existing SQL Lab responsive stacking remains authoritative.
   We only remove desktop scrolling constraints.
   ========================================================== */

@media (max-width: 780px) {

    .schema-list,
    .challenge-panel,
    .results-table-wrap {
        max-height: none;
    }

    .sql-workspace > * {
        min-width: 0;
    }
}


/* ==========================================================
   PHASE 11C-1-R2 WORKSPACE REDESIGN END
   ========================================================== */

/* ==========================================================
   PHASE 11C-2 DENSITY POLISH START

   Visual-density refinement only.
   No DOM, JavaScript, SQL or challenge behavior changes.
   ========================================================== */


/* ==========================================================
   DESKTOP
   ========================================================== */

@media (min-width: 1181px) {

    /*
     * Reduce the amount of vertical space between the global
     * navigation and the actual SQL workspace.
     */

    .sql-lab-shell {
        padding-top: 0;
    }

    .sql-lab-hero {
        padding-top: 14px;
        padding-bottom: 8px;
    }

    .sql-lab-hero h1 {
        margin-top: 2px;
        margin-bottom: 5px;
        line-height: 1.08;
    }

    .sql-lab-hero p {
        margin-top: 4px;
        margin-bottom: 0;
        line-height: 1.45;
    }

    /*
     * Keep the workspace label useful without allowing it to
     * become a large header region.
     */

    .sql-lab-hero .eyebrow,
    .sql-lab-hero .section-kicker,
    .sql-lab-hero .workspace-label {
        margin-bottom: 5px;
    }


    /*
     * Compact Explore / Practice mode control.
     */

    .sql-mode-switch,
    .mode-switch {
        margin-top: 8px;
        margin-bottom: 6px;
    }


    /*
     * Pull any explanatory copy closer to the workspace.
     */

    .mode-description,
    .workspace-description {
        margin-top: 5px;
        margin-bottom: 10px;
    }


    /*
     * Slightly reclaim width from schema navigation.
     */

    .sql-workspace {
        grid-template-columns:
            minmax(205px, 0.56fr)
            minmax(0, 2.85fr);
        gap: 14px;
    }


    /*
     * Reduce schema-card visual bulk.
     */

    .schema-panel {
        min-width: 0;
    }

    .schema-panel-header {
        padding-top: 13px;
        padding-bottom: 11px;
    }

    .schema-list {
        max-height: calc(100vh - 270px);
    }


    /*
     * Slightly reduce editor height so Results appears higher
     * while preserving a comfortable coding surface.
     */

    .editor-shell {
        min-height: 285px;
    }

    #sqlEditor {
        min-height: 270px;
    }

    .editor-toolbar {
        min-height: 52px;
        padding-top: 7px;
        padding-bottom: 7px;
    }


    /*
     * Bring Results closer to the editor.
     */

    .results-panel {
        margin-top: 10px;
    }

    .results-table-wrap {
        max-height: 300px;
    }


    /* ======================================================
       PRACTICE MODE
       ====================================================== */

    .practice-mode .sql-workspace {
        grid-template-columns:
            minmax(195px, 0.52fr)
            minmax(500px, 2.08fr)
            minmax(315px, 0.90fr);
        gap: 14px;
    }


    /*
     * Pull task navigation toward the working area.
     */

    .practice-mode .challenge-navigation,
    .practice-mode .task-navigation {
        margin-top: 4px;
        margin-bottom: 8px;
        gap: 8px;
    }


    /*
     * Reduce unnecessary vertical bulk in navigation buttons.
     */

    .practice-mode .challenge-navigation button,
    .practice-mode .task-navigation button,
    .practice-mode .challenge-navigation a,
    .practice-mode .task-navigation a {
        min-height: 42px;
    }


    /*
     * Task content gets slightly more usable vertical space.
     */

    .practice-mode .challenge-panel,
    .practice-mode .task-panel {
        max-height: calc(100vh - 250px);
    }

    .challenge-card,
    .task-card {
        padding: 18px;
    }


    /*
     * Keep major challenge sections readable while reducing
     * large gaps between them.
     */

    .challenge-card section,
    .task-card section {
        margin-top: 14px;
        margin-bottom: 14px;
    }


    /*
     * Ensure all three working columns remain shrink-safe.
     */

    .practice-mode .sql-workspace > *,
    .sql-workspace > * {
        min-width: 0;
    }
}


/* ==========================================================
   MEDIUM WIDTH
   ========================================================== */

@media (min-width: 901px) and (max-width: 1180px) {

    .sql-lab-hero {
        padding-top: 14px;
        padding-bottom: 10px;
    }

    .sql-lab-hero h1 {
        margin-bottom: 6px;
    }

    .mode-description,
    .workspace-description {
        margin-bottom: 10px;
    }

    .sql-workspace {
        gap: 12px;
    }

    .editor-shell {
        min-height: 270px;
    }

    #sqlEditor {
        min-height: 255px;
    }

    .results-panel {
        margin-top: 10px;
    }
}


/* ==========================================================
   TABLET / NARROW WORKSPACE
   ========================================================== */

@media (min-width: 781px) and (max-width: 900px) {

    /*
     * At this width the existing responsive system remains
     * authoritative. Only density is adjusted.
     */

    .sql-lab-hero {
        padding-top: 12px;
        padding-bottom: 8px;
    }

    .editor-shell {
        min-height: 250px;
    }

    #sqlEditor {
        min-height: 235px;
    }

    .results-panel {
        margin-top: 10px;
    }
}


/* ==========================================================
   MOBILE
   ========================================================== */

@media (max-width: 780px) {

    .sql-lab-hero {
        padding-top: 12px;
        padding-bottom: 8px;
    }

    .sql-lab-hero h1 {
        margin-bottom: 6px;
    }

    .mode-description,
    .workspace-description {
        margin-bottom: 10px;
    }

    /*
     * Mobile should scroll naturally as a page rather than
     * introducing additional constrained vertical regions.
     */

    .schema-list,
    .challenge-panel,
    .task-panel,
    .results-table-wrap {
        max-height: none;
    }
}


/* ==========================================================
   PHASE 11C-2 DENSITY POLISH END
   ========================================================== */
/* PHASE 11D-2B: WORKFLOW CONTEXT */

.workflow-context {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.55rem;
    width: fit-content;
    max-width: 100%;
    padding: 0.4rem 0.65rem;
    border: 1px solid var(--border-color, #d8dee8);
    border-radius: 0.55rem;
    background: var(--surface-soft, #f8fafc);
    font-size: 0.78rem;
    line-height: 1.35;
}

.workflow-context[hidden] {
    display: none;
}

.workflow-context-label {
    font-weight: 700;
}

#workflowDataset,
#workflowScenario,
#workflowQuality {
    overflow-wrap: anywhere;
}

/* POST-11 BATCH 3A: SQL PLAYGROUND PUBLIC HEADER */

.lab-header {
    padding: 0;
}

.lab-header-inner {
    width: 100%;
    min-height: 76px;
    padding: 0 32px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.lab-brand {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    padding-right: 24px;
    border-right: 1px solid rgba(255, 255, 255, 0.14);
}

.lab-brand img {
    display: block;
}

.lab-product-title {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 155px;
}

.lab-product-title strong {
    color: #ffffff;
    font-size: 1.05rem;
    line-height: 1.2;
}

.lab-product-title span {
    color: rgba(255, 255, 255, 0.68);
    font-size: 0.78rem;
    line-height: 1.3;
}

.lab-site-nav {
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.lab-site-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.78);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    transition:
        color 0.15s ease,
        background-color 0.15s ease;
}

.lab-site-nav a:hover,
.lab-site-nav a:focus-visible {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

.lab-site-nav a[aria-current="page"] {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.workspace-database-context {
    margin-top: 5px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    color: var(--muted, #64748b);
    font-size: 0.82rem;
}

.workspace-database-context #headerDatabaseName {
    font-weight: 600;
}

@media (max-width: 900px) {
    .lab-header-inner {
        padding: 12px 20px;
        flex-wrap: wrap;
        gap: 12px 18px;
    }

    .lab-brand {
        padding-right: 18px;
    }

    .lab-site-nav {
        width: 100%;
        margin-left: 0;
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 2px;
    }
}

@media (max-width: 560px) {
    .lab-header-inner {
        padding: 10px 14px;
    }

    .lab-brand {
        padding-right: 14px;
    }

    .lab-product-title span {
        display: none;
    }

    .lab-site-nav {
        gap: 2px;
    }

    .lab-site-nav a {
        min-height: 34px;
        padding: 7px 9px;
        font-size: 0.82rem;
    }
}
