/* Theory WHERE page - twh- prefix, page-design skill */
/* Uses var() from themes.css */

#_dash-app-content .twh-page,
#_pages_content .twh-page {
    width: 100% !important;
    max-width: none !important;
}

.twh-page {
    flex: 1 1 0;
    min-height: 0;
    padding: 8px 12px;
    width: 100%;
    max-width: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#_dash-app-content .twh-page {
    min-height: 60vh;
}

.twh-split-outer {
    flex: 1 1 0;
    min-height: 400px;
    width: 100%;
    display: flex;
    overflow: hidden;
    gap: 0;
}

.twh-panel-left {
    flex: 0 0 auto;
    width: 20%;
    min-width: 200px;
    max-width: 280px;
    background: var(--background-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.twh-panel-left .twh-page-header {
    flex-shrink: 0;
    padding: 8px 8px 0 8px;
}

.twh-panel-left .twh-panel-content {
    flex: 1 1 0;
    min-height: 0;
    padding: 8px;
    overflow-y: auto;
    scrollbar-gutter: stable;
    min-width: 0;
}

.twh-panel-right {
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    background: var(--background-color);
    overflow: hidden;
}

/* Intro and tasks wrappers must fill the panel when visible (display toggled by callback) */
.twh-panel-right > div {
    flex: 1 1 0;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
}

.twh-panel-right .twh-intro-block {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.twh-panel-right .twh-panel-content {
    flex: 1 1 0;
    min-height: 0;
    padding: 8px 12px;
    overflow-y: auto;
    scrollbar-gutter: stable;
    display: flex;
    flex-direction: column;
}

.twh-stages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.twh-stage-item {
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    min-width: 0;
}

.twh-stage-item:hover {
    background: var(--accent-color);
    border-color: var(--primary-color);
}

.twh-stage-item.twh-current {
    background: #e7f1ff;
    border: 2px solid var(--primary-color);
}

.twh-stage-item.twh-correct {
    background: #d1e7dd;
    border-left: 4px solid var(--success-color);
}

.twh-stage-item.twh-stage-pending .twh-stage-num {
    background: #bfdbfe;
    color: #1d4ed8;
}

.twh-stage-num {
    background: #9ca3af;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: var(--font-size-secondary);
    font-weight: 600;
    flex-shrink: 0;
}

.twh-stage-text {
    font-size: var(--font-size-label);
}

.twh-stage-item.twh-current .twh-stage-num {
    background: var(--primary-color);
}

.twh-stage-item.twh-correct .twh-stage-num {
    background: var(--success-color);
}

.twh-stage-content {
    display: none;
    flex: 1 1 0;
    min-height: 200px;
    min-width: 0;
    flex-direction: column;
}

.twh-stage-content.twh-active {
    display: flex;
}

.twh-stage-tasks {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.twh-task-block {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    background: var(--background-color);
}

.twh-task-block.twh-task-solved {
    border-left: 4px solid var(--success-color);
    background: #f0f9f4;
}

.twh-task-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

.twh-table-pair {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 64px;
    margin-bottom: 8px;
}

.twh-table-pair .twh-table-wrap {
    flex: 0 0 auto;
    width: max-content;
}

/* Lightweight source tables - portal-like styling, no DataTable (avoids CPU freeze) */
.twh-src-table {
    /* Join/Where share common theory-src-table styles */
}

.twh-src-table th.twh-cell-right,
.twh-src-table td.twh-cell-right {
    text-align: right;
}

.twh-src-table tbody tr td {
    background: #ffffff;
}

.twh-src-table tr.twh-row-odd td {
    background: var(--accent-color);
}

/* Higher specificity so NULL cells keep yellow even in zebra rows */
.twh-src-table tbody tr td.twh-cell-null {
    background: #fffacd;
    color: #999;
    font-style: italic;
}

.twh-query-template {
    font-size: 12px;
    margin-bottom: 4px;
    color: var(--text-secondary);
    font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Monaco, Consolas, monospace;
}

.twh-query-template .twh-sql-kw {
    color: var(--primary-color);
    font-weight: 600;
}

.twh-expected-row {
    font-size: 12px;
}

.twh-expected-value {
    font-size: 12px;
}

/* Answer row: class theory-answer-row on the flex row; Dash input rules below */

.twh-result {
    font-size: 13px;
}

.twh-result-ok {
    color: var(--success-color, #198754);
    font-weight: 600;
}

.twh-result-err {
    color: var(--danger-color, #dc3545);
    font-weight: 500;
}

/* Intro block (stage 0) — same structure as theory/join, theory/data-types */
.twh-intro-block {
    max-width: 720px;
    padding: 8px 0 8px 16px;
}

.twh-intro-hero {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.twh-intro-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.4;
}

.twh-intro-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.twh-intro-card {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    background: var(--accent-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.twh-intro-icon {
    font-size: 20px;
    color: var(--primary-color);
    flex-shrink: 0;
}

.twh-intro-card-body {
    flex: 1 1 0;
    min-width: 0;
}

.twh-intro-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 6px;
}

.twh-intro-order-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-style: italic;
}

.twh-intro-note {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 12px 0 0 0;
    line-height: 1.45;
}

.twh-intro-list {
    margin: 0;
    padding-left: 18px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
}

.twh-intro-list li {
    margin-bottom: 4px;
}

.twh-intro-list li:last-child {
    margin-bottom: 0;
}

.twh-intro-block a.twh-intro-link,
.twh-intro-block a[href].twh-intro-link {
    color: var(--primary-color);
    font-weight: 500;
    text-decoration: underline;
}

.twh-intro-block a.twh-intro-link:hover,
.twh-intro-block a[href].twh-intro-link:hover {
    text-decoration: none;
}

.twh-intro-btn {
    font-size: 15px;
    padding: 10px 20px;
}

.twh-intro-reread-btn {
    padding: 4px 8px;
    border-radius: 6px;
}

/* Answer row: same pattern as theory_groupby (twh-task-block) */
.twh-task-block > .d-flex.gap-2.flex-wrap {
    width: 100%;
}
.twh-task-block > .d-flex.gap-2.flex-wrap > :first-child {
    flex: 0 1 auto;
    min-width: 15rem;
    max-width: min(100%, 25rem);
}
.twh-task-block > .d-flex.gap-2.flex-wrap > input.form-control,
.twh-task-block > .d-flex.gap-2.flex-wrap > textarea.form-control {
    width: 100%;
    min-width: 15rem;
    max-width: none;
    box-sizing: border-box;
}
.twh-task-block > .d-flex.gap-2.flex-wrap > div:first-child input.form-control,
.twh-task-block > .d-flex.gap-2.flex-wrap > div:first-child textarea.form-control {
    width: 100%;
    min-width: 15rem;
    max-width: none;
    box-sizing: border-box;
}
/* Dash: className is on .dash-input-container; inner field is .dash-input-element */
.twh-task-block .dash-input-container.twh-where-input,
.twh-task-block .dash-input-container.form-control.twh-where-input {
    flex: 0 1 auto;
    min-width: 15rem !important;
    max-width: min(100%, 25rem) !important;
    box-sizing: border-box !important;
}
.twh-task-block .dash-input-container input.dash-input-element {
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box !important;
}
