/* Theory Data Types page - tdt- prefix, page-design skill */
/* Uses var() from themes.css */

/* Full-width: override any parent container constraint */
#_dash-app-content .tdt-page,
#_pages_content .tdt-page {
    width: 100% !important;
    max-width: none !important;
}

.tdt-page {
    flex: 1 1 0;
    min-height: 0;
    padding: 8px 12px;
    width: 100%;
    max-width: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Ensure page has height when parent is flex without defined height */
#_dash-app-content .tdt-page {
    min-height: 60vh;
}

.tdt-split-outer {
    flex: 1 1 0;
    min-height: 400px;
    width: 100%;
    display: flex;
    overflow: hidden;
    gap: 0;
}

.tdt-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;
}

.tdt-panel-left .tdt-page-header {
    flex-shrink: 0;
    flex-direction: column;
    align-items: flex-start;
    padding: 8px 8px 0 8px;
}

.tdt-panel-left .tdt-panel-content {
    flex: 1 1 0;
    min-height: 0;
    padding: 8px;
    overflow-y: auto;
    scrollbar-gutter: stable;
    min-width: 0;
}

.tdt-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) */
.tdt-panel-right > div {
    flex: 1 1 0;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
}

.tdt-panel-right .tdt-intro-block {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.tdt-panel-right .tdt-panel-content {
    flex: 1 1 0;
    min-height: 0;
    padding: 8px 12px;
    overflow-y: auto;
    scrollbar-gutter: stable;
    display: flex;
    flex-direction: column;
}

.tdt-stages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tdt-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;
}

.tdt-stage-item:hover {
    background: var(--accent-color);
    border-color: var(--primary-color);
}

.tdt-stage-item.tdt-current {
    background: #e7f1ff;
    border: 2px solid var(--primary-color);
}

.tdt-stage-item.tdt-correct {
    background: #d1e7dd;
    border-left: 4px solid var(--success-color);
}

.tdt-stage-num {
    background: #9ca3af;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: var(--font-size-secondary);
    font-weight: 600;
    flex-shrink: 0;
}

/* Not selected, not finished yet: still clickable — avoid gray "disabled" badge */
.tdt-stage-item.tdt-stage-pending .tdt-stage-num {
    background: #bfdbfe;
    color: #1d4ed8;
}

.tdt-stage-text {
    font-size: var(--font-size-label);
}

.tdt-stage-item.tdt-current .tdt-stage-num {
    background: var(--primary-color);
}

.tdt-stage-item.tdt-correct .tdt-stage-num {
    background: var(--success-color);
}

.tdt-stage-content {
    display: none;
    flex: 1 1 0;
    min-height: 200px;
    min-width: 0;
    flex-direction: column;
}

.tdt-stage-content.tdt-active {
    display: flex;
}

/* Stages 8, 9: scrollable content + fixed actions (button always visible) */
.tdt-stage-with-actions {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
}

.tdt-stage-with-actions .tdt-stage-scrollable {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.tdt-stage-with-actions .tdt-stage-actions {
    flex-shrink: 0;
    padding-top: 8px;
    padding-bottom: 4px;
    border-top: 1px solid var(--border-color);
    background: var(--background-color);
}

.tdt-page-header {
    flex-shrink: 0;
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.tdt-page-title {
    font-size: var(--font-size-page-title);
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0;
}

.tdt-hint {
    font-size: var(--font-size-secondary);
    color: var(--text-secondary);
    margin-top: 8px;
}

.tdt-page-header .tdt-hint {
    margin-top: 0;
}

.tdt-hint a {
    color: var(--primary-color);
}

/* Stage 1: reference block and hints (from prototype) */
.tdt-op-hint {
    font-size: var(--font-size-body);
    color: var(--text-primary);
    margin: 0;
    line-height: 1.4;
}

.tdt-op-hint code {
    background: var(--accent-color);
    color: var(--text-primary);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
    border: 1px solid var(--border-color);
}

/* Stage 1: task text in 2 columns, narrow width, left-aligned */
.tdt-op-task-block {
    column-count: 2;
    column-gap: 24px;
    column-fill: balance;
    max-width: 800px;
}

@media (max-width: 768px) {
    .tdt-op-task-block {
        column-count: 1;
        max-width: 100%;
    }
}

.tdt-op-ref-label {
    font-size: var(--font-size-secondary);
    color: var(--text-secondary);
    font-weight: 500;
    margin: 0;
}

.tdt-op-ref-query {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.8125rem;
    background: #f6f8fa;
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--primary-color);
    border-radius: 4px;
    padding: 10px 12px;
    margin: 0 0 8px 0;
    overflow-x: auto;
    white-space: pre;
    color: var(--text-primary);
    line-height: 1.4;
    break-inside: avoid;
}

.tdt-op-ref-query .tdt-sql-kw { color: #0550ae; font-weight: 600; }
.tdt-op-ref-query .tdt-sql-type { color: #0a6f47; }
.tdt-op-ref-query .tdt-sql-str { color: #0a6f47; }
.tdt-op-ref-query .tdt-sql-null { color: #6e40c9; font-style: italic; }

/* Stage 1: operators x types table (from prototype op-*) */
.tdt-op-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.tdt-op-tab {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--background-color);
    cursor: pointer;
    font-size: var(--font-size-secondary);
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s;
}

.tdt-op-tab:hover {
    background: var(--accent-color);
    border-color: var(--primary-color);
}

.tdt-op-tab.tdt-op-active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.tdt-op-section {
    display: none;
    background: var(--background-color);
    border-radius: 6px;
    padding: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.tdt-op-section.tdt-op-active {
    display: block;
}

.tdt-op-section-title {
    font-size: var(--font-size-section-title);
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.tdt-op-section-title span {
    font-family: monospace;
}

/* Colored section titles by type (prototype) */
.tdt-op-section[data-type="integer"] .tdt-op-section-title span,
.tdt-op-section[data-type="numeric"] .tdt-op-section-title span { color: #0550ae; }
.tdt-op-section[data-type="text"] .tdt-op-section-title span { color: #0a6f47; }
.tdt-op-section[data-type="boolean"] .tdt-op-section-title span { color: #953800; }
.tdt-op-section[data-type="date"] .tdt-op-section-title span,
.tdt-op-section[data-type="interval"] .tdt-op-section-title span { color: #6e40c9; }
.tdt-op-section[data-type="null"] .tdt-op-section-title span { color: var(--text-secondary); }

.tdt-op-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-secondary);
    line-height: 1.25;
}

.tdt-op-table th,
.tdt-op-table td {
    border: 1px solid var(--border-color);
    padding: 4px 6px;
    text-align: left;
    vertical-align: middle;
}

.tdt-op-table th {
    background: var(--accent-color);
    font-weight: 600;
    font-size: 0.6875rem;
}

.tdt-op-table th.tdt-op-col-type {
    min-width: 100px;
}

/* Colored column headers by type (prototype) - override Bootstrap */
.tdt-op-table th.tdt-op-col-type[data-type="integer"],
.tdt-op-table th.tdt-op-col-type[data-type="numeric"] {
    color: #0550ae !important;
    font-weight: 600;
}
.tdt-op-table th.tdt-op-col-type[data-type="text"] {
    color: #0a6f47 !important;
    font-weight: 600;
}
.tdt-op-table th.tdt-op-col-type[data-type="boolean"] {
    color: #953800 !important;
    font-weight: 600;
}
.tdt-op-table th.tdt-op-col-type[data-type="date"],
.tdt-op-table th.tdt-op-col-type[data-type="interval"] {
    color: #6e40c9 !important;
    font-weight: 600;
}
.tdt-op-table th.tdt-op-col-type[data-type="null"] {
    color: var(--text-secondary) !important;
    font-weight: 600;
}

.tdt-op-table th.tdt-op-col-unary {
    min-width: 0;
    font-style: italic;
    color: var(--text-secondary);
}

.tdt-op-table th.tdt-op-row-op {
    min-width: 32px;
    font-family: monospace;
}

.tdt-op-table .tdt-op-cell-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    width: 100%;
}

.tdt-op-table .tdt-op-cell-btn {
    flex: 0 0 20px;
    width: 20px;
    height: 22px;
    padding: 0;
    margin: 0;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    cursor: pointer;
    font-size: 0;
    box-sizing: border-box;
}

.tdt-op-table .tdt-op-cell-btn:hover {
    opacity: 0.9;
}

.tdt-op-table .tdt-op-cell-btn-null {
    background: #fff3cd;
}

.tdt-op-table .tdt-op-cell-btn-err {
    background: #f8d7da;
}

.tdt-op-table .tdt-op-cell-select,
.tdt-op-table .tdt-op-cell-wrap .Select,
.tdt-op-table .tdt-op-cell-wrap [class*="Select"] {
    flex: 1;
    min-width: 60px;
    font-size: 0.6875rem;
}

/* Stage 11: match iframe fills available space */
.tdt-stage-content-wrap {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
}

.tdt-stage-content-wrap iframe#tdt-match-iframe {
    flex: 1 1 0;
    min-height: 500px;
}

.tdt-op-verify-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.tdt-op-verify-row .btn-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

#tdt-results-type.text-success,
.tdt-results .text-success { color: var(--success-color) !important; }
#tdt-results-type .text-danger,
.tdt-results .text-danger { color: var(--error-color) !important; }
.tdt-results .text-warning {
    color: var(--warning-color, #e0a020) !important;
}

.tdt-schema-block {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.75rem;
    background: var(--accent-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 8px 10px;
    overflow-x: auto;
    white-space: pre;
}

/* Stage 10 pgops: [panel] -> [input] row layout */
.tdt-pgops-rows {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.tdt-pgops-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.tdt-pgops-expr-panel {
    flex: 0 0 auto;
    width: 200px;
    min-width: 200px;
    margin: 0;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.75rem;
    background: var(--accent-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 6px 10px;
    white-space: pre;
    line-height: 1.5;
    height: 31px;
    display: flex;
    align-items: center;
    overflow: hidden;
}
.tdt-pgops-arrow {
    flex: 0 0 auto;
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
    color: var(--text-color-secondary);
}
.tdt-pgops-input {
    flex: 0 0 auto;
    width: 220px;
    max-width: 220px;
}
.tdt-pgops-equals {
    flex: 0 0 auto;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    color: var(--text-color-secondary);
}

.tdt-sql-editor-wrap {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    min-width: 0;
}

.tdt-sql-editor-wrap > div {
    max-width: 100%;
    min-width: 0;
}

.tdt-sql-editor-wrap .ace_editor {
    width: 100% !important;
    max-width: 100%;
    min-width: 0;
}

.tdt-results {
    font-size: var(--font-size-secondary);
    padding: 8px;
    border-radius: 4px;
    min-height: 2em;
}

/* Intro block (stage 0) — same structure as theory/join */
.tdt-intro-block {
    max-width: 720px;
    padding: 8px 0 8px 16px;
}

.tdt-intro-hero {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.tdt-intro-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.4;
}

.tdt-intro-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.tdt-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;
}

.tdt-intro-icon {
    font-size: 20px;
    color: var(--primary-color);
    flex-shrink: 0;
}

.tdt-intro-card-body {
    flex: 1 1 0;
    min-width: 0;
}

.tdt-intro-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 6px;
}

.tdt-intro-order-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-style: italic;
}

.tdt-intro-note {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 12px 0 0 0;
    line-height: 1.45;
}

.tdt-intro-list {
    margin: 0;
    padding-left: 18px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
}

.tdt-intro-list li {
    margin-bottom: 4px;
}

.tdt-intro-list li:last-child {
    margin-bottom: 0;
}

.tdt-intro-block a.tdt-intro-link,
.tdt-intro-block a[href].tdt-intro-link {
    color: var(--primary-color);
    font-weight: 500;
    text-decoration: underline;
}

.tdt-intro-block a.tdt-intro-link:hover,
.tdt-intro-block a[href].tdt-intro-link:hover {
    text-decoration: none;
}

.tdt-intro-btn {
    font-size: 15px;
    padding: 10px 20px;
}

.tdt-intro-reread-btn {
    padding: 4px 8px;
    border-radius: 6px;
}

@media (max-width: 992px) {
    .tdt-panel-left {
        width: 100%;
        max-width: none;
    }
    .tdt-split-outer {
        flex-direction: column;
    }
}
