/**
 * Six Sigma Tools — reusable UI components
 * Depends on css/theme.css
 */

/* ── Modal ─────────────────────────────────────────────────────────────────── */

/* Modal: backdrop/Escape do not dismiss unless opt-in; close via .modal-close / *-cancel / *-close (js/app-modal.js). */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--shadow-overlay);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.visible {
    display: flex;
}

.modal-dialog {
    background: var(--bg-surface);
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-modal);
    min-width: 320px;
    max-width: 90vw;
    overflow: hidden;
    font-size: var(--font-size-dialog);
    line-height: var(--line-height-ui);
    color: var(--color-text);
}

.modal-dialog-wide {
    min-width: 420px;
    max-width: 560px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--title-bar-padding);
    background-color: var(--title-bar-bg);
    color: var(--title-bar-color);
    font-weight: var(--title-bar-font-weight);
    font-size: var(--title-bar-font-size);
    user-select: none;
    cursor: move;
    touch-action: none;
}

.modal-overlay .modal-header .modal-close,
.modal-overlay .modal-header button,
.modal-overlay .modal-header a,
.modal-overlay .modal-header input,
.modal-overlay .modal-header select {
    cursor: pointer;
    touch-action: auto;
}

.modal-dialog--positioned,
.modal-dialog--dragging {
    z-index: 2001;
}

.modal-dialog--dragging {
    user-select: none;
}

.modal-header h3 {
    margin: 0;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
}

.modal-header h3 .filename-normal {
    color: inherit;
    opacity: 0.92;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 2px;
    color: var(--title-bar-color);
    opacity: 0.85;
}

.modal-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
}

.modal-body {
    padding: var(--space-md);
}

.modal-footer {
    padding: 10px var(--space-md);
    border-top: 1px solid var(--border-default);
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
}

.modal-hint {
    margin: 0 0 10px 0;
    color: var(--color-text-disabled);
}

.modal-hint--primary {
    color: var(--color-primary);
    font-weight: 600;
}

/* Dialog typography — labels, inputs and options inherit .modal-dialog font-size */
.modal-dialog .form-group label,
.modal-dialog .form-input,
.modal-dialog .form-select,
.modal-dialog .form-input-inline,
.modal-dialog .btn,
.modal-dialog .btn-primary,
.modal-dialog .btn-secondary,
.modal-dialog .check-label,
.modal-dialog .form-col,
.modal-dialog .inline-label,
.modal-dialog .radio-label,
.modal-dialog .format-option,
.modal-dialog .form-legend,
.modal-dialog .dialog-hint,
.modal-dialog .dialog-note,
.modal-dialog .modal-hint,
.modal-dialog .nowrap-label,
.modal-dialog .text-heading-sm,
.modal-dialog .text-path,
.modal-dialog .descriptive-column-list label {
    font-size: inherit;
}

.modal-dialog .btn-primary,
.modal-dialog .btn-secondary {
    padding: 6px var(--space-md);
    border-radius: var(--radius-sm);
    font: inherit;
    cursor: pointer;
}

.modal-dialog .form-legend,
.modal-dialog .text-heading-sm,
.modal-dialog .nowrap-label {
    font-weight: 600;
}

.modal-dialog .text-muted-sm {
    font-size: 0.92em;
}

/* ── Forms & buttons ─────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: var(--space-md);
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: var(--space-xs);
}

.form-input {
    width: 100%;
    padding: var(--input-padding-y) var(--input-padding-x);
    min-height: var(--control-height);
    box-sizing: border-box;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    font: inherit;
    line-height: 1.25;
}

select.form-input,
.form-select {
    width: 100%;
    padding: var(--select-padding-y) var(--select-padding-end) var(--select-padding-y) var(--select-padding-x);
    min-height: var(--control-height);
    height: var(--control-height);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    font: inherit;
    line-height: 1.2;
    cursor: pointer;
    box-sizing: border-box;
}

.btn {
    padding: 6px var(--space-md);
    border-radius: var(--radius-sm);
    font: inherit;
    cursor: pointer;
}

.btn-primary {
    background: var(--color-primary);
    color: var(--bg-surface);
    border: 1px solid var(--color-primary-dark);
}

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

.btn-secondary {
    background: var(--bg-app);
    border: 1px solid var(--border-default);
}

.btn-secondary:hover {
    background: var(--bg-app-dark);
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: var(--space-xs) 0;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
}

.radio-label input[type="radio"] {
    margin: 0;
    cursor: pointer;
}

.descriptive-column-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm) var(--space-lg);
    max-height: 280px;
    overflow-y: auto;
    padding: var(--space-sm) 0;
}

.descriptive-column-list label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    white-space: nowrap;
}

/* ── Dialog layout & form controls ───────────────────────────────────────── */

.modal-body-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.modal-row {
    display: flex;
    gap: var(--space-lg);
    flex-wrap: wrap;
}

.modal-row--wide {
    gap: var(--space-xl);
}

.modal-row--center {
    align-items: center;
}

.modal-section {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    padding-top: var(--space-xs);
    border-top: 1px solid var(--border-subtle);
}

.modal-divider {
    border: none;
    border-top: 1px solid var(--border-subtle, #ddd);
    margin: var(--space-sm) 0;
}

.modal-dialog--560 {
    width: min(560px, 96vw);
}

.modal-dialog--620 { width: min(620px, 96vw); }
.modal-dialog--680 { width: min(680px, 96vw); }
.modal-dialog--380 { width: min(380px, 96vw); }
.modal-dialog--400 { width: min(400px, 96vw); }
.modal-dialog--480 { width: min(480px, 96vw); }
.modal-dialog--520 { width: min(520px, 96vw); }
.modal-dialog--820 { width: min(820px, 96vw); max-width: 820px; }
.modal-dialog--860 {
    width: min(860px, 96vw);
    max-width: 860px;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-body-padded {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: var(--space-lg) var(--space-xl);
}

.modal-body-gap14 {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-body-scroll {
    overflow-y: auto;
    max-height: 70vh;
}

.modal-body-export {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: var(--space-md) var(--space-lg);
    gap: var(--space-sm);
}

.modal-row--12 { gap: 12px; }
.modal-row--12-wrap { display: flex; gap: 12px; flex-wrap: wrap; }

.inline-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.inline-label--click {
    cursor: pointer;
}

.check-list--200 {
    max-height: 200px;
}

.calc-pick-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-sm);
    max-height: 180px;
    overflow-y: auto;
    padding: var(--space-xs) 0;
}

.calc-pick-item {
    font: inherit;
    font-size: 0.9em;
    padding: 4px 10px;
    border: 1px solid var(--border-color, #ccc);
    border-radius: 4px;
    background: var(--surface-muted, #f5f5f5);
    cursor: pointer;
}

.calc-pick-item:hover {
    background: var(--accent-soft, #e8f4fc);
    border-color: var(--accent, #3498db);
}

.calc-formula {
    width: 100%;
    min-height: 88px;
    font-family: ui-monospace, monospace;
    font-size: 0.95em;
    resize: vertical;
}

.form-fieldset--grow {
    flex: 1 1 220px;
    min-width: 200px;
}

.form-select--min160 {
    min-width: 160px;
}

.format-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: var(--space-xs);
}

.filename-normal {
    font-weight: normal;
    font-size: 0.9em;
}

.form-select--min130 {
    min-width: 130px;
}

.export-toolbar-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.export-options-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-lg);
    flex-wrap: wrap;
}

.export-col {
    min-width: 140px;
}

.export-scroll-box {
    max-height: 220px;
    overflow-y: auto;
}

.nowrap-label {
    font-weight: 600;
    white-space: nowrap;
}

.btn-xs {
    font-size: 11px;
    padding: 2px var(--space-sm);
}

.export-preview-col {
    flex: 1;
    min-width: 300px;
}

.export-preview-ta {
    width: 100%;
    height: 280px;
    font-family: var(--font-family-mono);
    font-size: 12px;
}

.export-actions {
    margin-top: 6px;
    display: flex;
    gap: var(--space-sm);
}

.form-input--w80 { width: 80px; }
.form-input--w100 { width: 100px; }
.form-input--min120 { min-width: 120px; }

.modal-row--mb {
    margin-bottom: var(--space-md);
}

.modal-row--mt {
    margin-top: var(--space-md);
}

.modal-row--mt-sm {
    margin-top: 6px;
}

.modal-row--gap28 { gap: 28px; }
.modal-row--gap32 { gap: 32px; }

.mt-xs { margin-top: var(--space-xs); }
.mt-lg { margin-top: 18px; }

/* Scrollable dialog region: max N data rows (default 5), then vertical scrollbar. */
.modal-scroll-rows,
.params-scroll {
    --modal-scroll-rows: 5;
    --modal-scroll-row-h: calc(var(--control-height) + 2 * var(--space-xs) + 1px);
    --modal-scroll-head-h: calc(var(--control-height) + 2 * var(--space-xs) + 2px);
    max-height: calc(var(--modal-scroll-head-h) + var(--modal-scroll-row-h) * var(--modal-scroll-rows));
    overflow-y: auto;
    overflow-x: auto;
    margin-top: var(--space-xs);
}

.modal-scroll-rows--body,
.params-scroll--body {
    --modal-scroll-head-h: 0px;
}

.modal-scroll-rows .ttest-table thead th,
.params-scroll .ttest-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    box-shadow: 0 1px 0 var(--border-dark);
}

.form-fieldset {
    border: 1px solid var(--border-input);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
}

.form-legend {
    font-weight: 600;
}

.form-col {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.form-col--grow {
    flex: 1;
    min-width: 160px;
}

.form-col--160 {
    min-width: 160px;
}

.form-input-inline {
    padding: var(--input-padding-y) var(--input-padding-x);
    min-height: var(--control-height);
    box-sizing: border-box;
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    font: inherit;
    line-height: 1.25;
}

select.form-input-inline {
    padding: var(--select-padding-y) var(--select-padding-end) var(--select-padding-y) var(--select-padding-x);
    height: var(--control-height);
    line-height: 1.2;
    cursor: pointer;
    background: var(--bg-surface);
}

.form-input-inline--w80 { width: 80px; }
.form-input-inline--w100 { width: 100px; }
.form-input-inline--w120 { width: 120px; }
.form-input-inline--full { width: 100%; box-sizing: border-box; }

.check-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.check-label--bold {
    font-weight: 600;
}

.check-label--mt {
    margin-top: var(--space-xs);
}

.check-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm) var(--space-xl);
    max-height: 180px;
    overflow-y: auto;
    padding-top: var(--space-xs);
}

.glm-predictor-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
    padding-top: var(--space-xs);
}

.glm-predictor-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.glm-predictor-row label {
    flex: 1 1 160px;
    min-width: 120px;
}

.glm-predictor-row select {
    min-width: 110px;
}

.capability-column-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 240px;
    overflow-y: auto;
    padding-top: var(--space-xs);
}

.capability-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 16px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-light, #eee);
}

.capability-row:last-child {
    border-bottom: none;
}

.capability-row-label {
    flex: 1 1 140px;
    min-width: 120px;
}

.capability-spec-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.92em;
    white-space: nowrap;
}

.capability-spec-label .form-input {
    width: 88px;
    min-width: 72px;
}

.capability-row-poor td {
    background: rgba(231, 76, 60, 0.08);
}

.spc-rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 6px 12px;
    max-height: 120px;
    overflow-y: auto;
}

.check-label--muted {
    opacity: 0.55;
    cursor: not-allowed;
}

.spc-chart-wrap {
    margin-top: 14px;
    overflow-x: auto;
}

.spc-chart-title {
    font-weight: 600;
    font-size: 12px;
    margin: 8px 0 4px;
}

.spc-subgroup-hint {
    flex: 1 1 100%;
    margin: 4px 0 0;
}

.msa-report-grid,
.msa-report-stack {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 16px;
}

.msa-panel {
    border: 1px solid var(--border-color, #ddd);
    border-radius: 6px;
    padding: 12px 14px 16px;
    background: #fafafa;
    width: 100%;
    box-sizing: border-box;
}

.msa-panel-title {
    font-weight: 600;
    font-size: 12px;
    margin-bottom: 8px;
}

.msa-panel-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.msa-chart-host {
    width: 100%;
    min-height: 320px;
    overflow-x: auto;
}

.msa-chart-host svg {
    display: block;
    margin: 0 auto;
    max-width: 100%;
}

.msa-mini-chart {
    display: block;
    max-width: 100%;
}

.format-option {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: var(--space-sm);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
}

.format-option--sm {
    padding: 7px 10px;
}

.dialog-hint {
    margin: 0;
    color: var(--color-text-muted);
}

.dialog-note {
    margin: 0;
    color: var(--color-text-disabled);
}

.text-muted-sm {
    color: var(--color-text-subtle);
    font-weight: normal;
}

.text-path {
    margin: 4px 0 0;
    font-size: 0.83rem;
    color: var(--color-text-muted);
}

.text-heading-sm {
    font-weight: 600;
    margin: 0 0 6px;
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-sm {
    margin-top: 10px;
}

.hidden-panel {
    display: none;
}

.code-textarea {
    width: 100%;
    min-height: 280px;
    font-family: var(--font-family-mono);
    font-size: 0.78rem;
    border: 1px solid var(--border-input);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    white-space: pre;
    overflow: auto;
    background: var(--bg-inset);
    box-sizing: border-box;
    resize: vertical;
}

.code-textarea--readonly {
    background: var(--bg-inset);
    color: var(--color-text);
}

/* JSON viewer tables (dynamic HTML) */
.json-meta {
    color: var(--color-text-muted);
    font-size: 0.85em;
}

.json-meta--saved {
    color: var(--color-text-subtle);
    font-size: 0.82em;
}

.json-table-title {
    font-weight: 600;
    margin: var(--space-md) 0 var(--space-xs);
}

.json-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-family-mono);
    font-size: 0.82em;
}

.json-table th,
.json-table td {
    padding: var(--space-xs) 10px;
    border: 1px solid var(--border-light);
}

.json-table th {
    background: var(--bg-code);
    text-align: left;
}

.json-table tr:nth-child(even) td {
    background: var(--bg-zebra);
}

.json-pre {
    font-size: 0.82em;
    overflow: auto;
}

/* ── Toolbar language selector ───────────────────────────────────────────── */

.toolbar-lang-wrap {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    margin-right: 6px;
}

.toolbar-lang-label {
    font-size: 0.8em;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.toolbar-lang-select {
    height: var(--control-height);
    font-size: inherit;
    padding: var(--select-padding-y) var(--select-padding-end) var(--select-padding-y) var(--select-padding-x);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    cursor: pointer;
    max-width: 110px;
    box-sizing: border-box;
    line-height: 1.2;
}

.toolbar-lang-icon {
    display: block;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
}

/* ── Toolbar help search ─────────────────────────────────────────────────── */

.toolbar-help-search-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
}

.toolbar-help-search-input {
    height: var(--control-height);
    font-size: inherit;
    padding: 0 6px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-input-bg, var(--color-surface));
    color: var(--color-text);
    width: 160px;
    outline: none;
    transition: border-color 0.15s, width 0.2s;
}

.toolbar-help-search-input:focus {
    border-color: var(--color-accent, #4a90d9);
    width: 210px;
}

.toolbar-help-search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 9999;
    background: var(--color-surface, #fff);
    background-color: var(--color-bg, var(--color-surface, #ffffff));
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 6px 20px rgba(0,0,0,0.55);
    min-width: 220px;
    max-height: 260px;
    overflow-y: auto;
    isolation: isolate;
}

.toolbar-help-search-item {
    padding: 5px 10px;
    cursor: pointer;
    font-size: 0.85em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--color-text);
}

.toolbar-help-search-item:hover,
.toolbar-help-search-item.is-active {
    background: var(--color-hover, rgba(74,144,217,0.12));
    color: var(--color-accent, #4a90d9);
}

/* ── Results & statistical output ────────────────────────────────────────── */

.results-content {
    flex: 1;
    overflow: auto;
    padding: var(--space-md);
    background: var(--bg-surface);
}

.results-content:empty::before {
    content: 'No results yet. Run a function (e.g. Descriptive statistics) from the Functions tree.';
    color: var(--color-text-subtle);
    font-style: italic;
}

.descriptive-result {
    margin-bottom: var(--space-xl);
}

.descriptive-result h4 {
    margin: var(--space-lg) 0 var(--space-sm) 0;
    font-size: var(--font-size-base);
    color: var(--color-primary);
    font-weight: 700;
    border-bottom: 1px solid var(--border-default, #ddd);
    padding-bottom: 4px;
}

.descriptive-result h4:first-of-type {
    margin-top: 0;
}

.descriptive-stats-layout {
    margin-bottom: var(--space-md);
    max-width: 100%;
}

.descriptive-stats-main-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    border: 1px solid var(--border-default, #b0b0b0);
    border-radius: 0;
}

.descriptive-stats-section {
    min-width: 0;
    border-right: 1px solid var(--border-default, #b0b0b0);
}

.descriptive-stats-section:last-child {
    border-right: none;
}

.descriptive-stats-section-title {
    margin: 0;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-subtle, #555);
    font-family: var(--font-family-ui);
    background: var(--bg-app, #f4f4f4);
    border-bottom: 1px solid var(--border-default, #b0b0b0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.descriptive-stats-table {
    border-collapse: collapse;
    font-size: 11px;
    width: 100%;
    margin-bottom: 0;
    table-layout: fixed;
}

.descriptive-stats-table th,
.descriptive-stats-table td {
    border: none;
    border-bottom: 1px solid var(--border-default, #d8d8d8);
    padding: 3px 8px;
    text-align: left;
    line-height: 1.35;
    height: 22px;
    box-sizing: border-box;
    vertical-align: middle;
}

.descriptive-stats-table tr:last-child th,
.descriptive-stats-table tr:last-child td {
    border-bottom: none;
}

.descriptive-stats-table th {
    background: transparent;
    font-weight: 600;
    width: 52%;
    white-space: nowrap;
    color: var(--color-text, #222);
}

.descriptive-stats-table td {
    font-variant-numeric: tabular-nums;
    color: var(--color-text, #111);
}

.descriptive-stats-table tr.descriptive-stats-blind th,
.descriptive-stats-table tr.descriptive-stats-blind td {
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.03) 2px,
        rgba(0, 0, 0, 0.03) 4px
    );
    border-bottom: 1px solid var(--border-default, #e0e0e0);
}

.descriptive-stats-percentiles {
    margin-top: var(--space-sm);
    max-width: 220px;
    border: 1px solid var(--border-default, #b0b0b0);
    border-radius: 0;
}

.descriptive-stats-percentiles .descriptive-stats-section-title {
    border-bottom: 1px solid var(--border-default, #b0b0b0);
}

.descriptive-stats-table-compact {
    max-width: 220px;
}

.descriptive-summary-table-wrap {
    margin-bottom: var(--space-md);
    overflow-x: auto;
    max-width: 100%;
}

.descriptive-summary-table {
    border-collapse: collapse;
    font-size: 11px;
    width: auto;
    min-width: 100%;
    table-layout: auto;
    border: 1px solid var(--border-default, #b0b0b0);
}

.descriptive-summary-table th,
.descriptive-summary-table td {
    border: 1px solid var(--border-default, #d8d8d8);
    padding: 3px 10px;
    text-align: right;
    line-height: 1.35;
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}

.descriptive-summary-table thead th {
    background: var(--bg-app, #f4f4f4);
    font-weight: 700;
    color: var(--color-primary, #1a5276);
    white-space: nowrap;
}

.descriptive-summary-table tbody th {
    text-align: left;
    font-weight: 600;
    background: var(--bg-app, #f4f4f4);
    white-space: nowrap;
    color: var(--color-text, #222);
}

.descriptive-summary-table tbody td {
    color: var(--color-text, #111);
}

.descriptive-summary-charts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    margin: var(--space-md) 0 var(--space-lg) 0;
}

.descriptive-summary-charts .descriptive-histogram-wrap {
    flex: 0 1 320px;
    margin: 0;
}

.descriptive-histogram-wrap {
    margin: var(--space-md) 0 var(--space-lg) 0;
    max-width: 480px;
    border: 1px solid #b0b0b0;
    border-radius: 0;
    background: #fff;
    padding: 6px 8px 4px 8px;
}

.descriptive-histogram-title {
    margin: 0 0 2px 0;
    font-size: 12px;
    font-weight: 700;
    color: var(--color-text, #222);
    font-family: var(--font-family-ui);
    text-align: left;
}

.descriptive-histogram-subtitle {
    margin: 0 0 4px 0;
    font-size: 10px;
    color: #777;
    font-family: var(--font-family-ui);
    text-align: left;
}

.descriptive-histogram-host {
    min-height: 200px;
}

.descriptive-histogram-host svg {
    display: block;
}

.graph-result {
    margin-bottom: var(--space-xl);
    max-width: 960px;
}

.graph-title {
    font-weight: 700;
    font-size: var(--font-size-base);
    margin: 0 0 4px 0;
    font-family: var(--font-family-ui);
    color: var(--color-primary);
    border-bottom: 2px solid var(--color-accent, #3498db);
    padding-bottom: 4px;
}

.graph-meta {
    margin: 4px 0 0;
    color: var(--color-text-secondary);
    font-size: var(--font-size-small);
    font-family: var(--font-family-ui);
}

.graph-equation {
    margin: 6px 0 0;
    font-family: var(--font-family-mono);
    font-size: 0.88em;
    color: var(--color-text-secondary);
}

.graph-plot-host {
    margin-top: 10px;
    min-height: 280px;
}

.graph-plot-host svg {
    display: block;
    max-width: 100%;
    height: auto;
    overflow: visible;
}

.ttest-result {
    margin-bottom: var(--space-xl);
    font-family: var(--font-family-mono);
    font-size: var(--font-size-small);
}

.ttest-title {
    font-weight: 700;
    font-size: var(--font-size-base);
    margin: 0 0 2px 0;
    font-family: var(--font-family-ui);
    color: var(--color-primary);
}

.ttest-hypothesis {
    margin: 0 0 var(--space-md) 0;
    color: var(--color-text-secondary);
}

.ttest-table-wrap {
    overflow-x: auto;
}

.ttest-table {
    border-collapse: collapse;
    font-family: var(--font-family-mono);
    font-size: var(--font-size-small);
    white-space: nowrap;
}

.ttest-table th {
    background: var(--bg-app);
    font-weight: 700;
    padding: var(--space-xs) 14px var(--space-xs) 6px;
    border-bottom: 2px solid var(--border-dark);
    text-align: right;
}

.ttest-table th:first-child {
    text-align: left;
}

.ttest-table td {
    padding: var(--space-xs) 14px var(--space-xs) 6px;
    text-align: right;
    border-bottom: 1px solid var(--border-default);
}

.ttest-table .ttest-td-name {
    text-align: left;
    padding-right: var(--space-xl);
}

.ttest-table .ttest-td-ci {
    text-align: center;
}

.ttest-section {
    margin: 14px 0 6px 0;
    font-weight: 600;
    font-family: var(--font-family-ui);
}

.ttest-variance-note {
    margin: var(--space-sm) 0 0 0;
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
    font-family: var(--font-family-ui);
    font-style: italic;
}

.ttest-verdict {
    margin: var(--space-md) 0 0 0;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-small);
    font-weight: 600;
    font-family: var(--font-family-ui);
    border: 1px solid;
}

.ttest-reject {
    background: var(--color-error-bg);
    border-color: var(--color-error-border);
    color: var(--color-error-text);
}

.ttest-accept {
    background: var(--color-success-bg);
    border-color: var(--color-success-border);
    color: var(--color-success-text);
}

.residuals-analysis {
    margin-top: var(--space-xl);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border, #ddd);
}

.residuals-diagnostics-table th {
    text-align: left;
    width: 42%;
    font-weight: 600;
}

.residuals-verdict {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-small);
    font-weight: 600;
    font-family: var(--font-family-ui);
    border: 1px solid;
}

.residuals-verdict-caution {
    background: #fffbeb;
    border-color: #f0c040;
    color: #856404;
}

.residuals-verdict-warning {
    background: #fdecea;
    border-color: #e74c3c;
    color: #922b21;
}

.residuals-chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(280px, 1fr));
    gap: var(--space-lg);
    margin-top: var(--space-lg);
    max-width: 960px;
}

.residuals-chart-cell {
    border: 1px solid var(--color-border, #ddd);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    background: #fff;
}

.residuals-chart-title {
    margin: 0 0 6px;
    font-size: var(--font-size-small);
    font-weight: 600;
    color: var(--color-primary);
    font-family: var(--font-family-ui);
}

.residuals-chart-host {
    min-height: 260px;
    overflow-x: auto;
}

.residuals-chart-fallback {
    margin: 24px 8px;
    font-size: var(--font-size-small);
    color: var(--color-text-secondary);
}

.posthoc-analysis {
    margin-top: var(--space-xl);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border, #ddd);
}

.posthoc-method-title {
    margin: 6px 0 0;
    font-weight: 600;
    font-size: var(--font-size-small);
    color: var(--color-primary);
    font-family: var(--font-family-ui);
}

.posthoc-table tr.posthoc-row-significant td {
    background: #f0f9ff;
}

.posthoc-table td.posthoc-p-significant {
    background: #e8f8e8;
    font-weight: 700;
}

.posthoc-summary {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-small);
    font-weight: 600;
    font-family: var(--font-family-ui);
    border: 1px solid;
    margin-top: 12px;
}

.posthoc-summary-significant {
    background: #fffbeb;
    border-color: #f0c040;
    color: #856404;
}

.posthoc-chart-host {
    margin-top: 14px;
    overflow-x: auto;
    min-height: 120px;
}

.posthoc-skipped .posthoc-summary {
    background: var(--color-success-bg);
    border-color: var(--color-success-border);
    color: var(--color-success-text);
}

@media (max-width: 720px) {
    .residuals-chart-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Markdown / help / info content ──────────────────────────────────────── */

.panel-placeholder.md-content {
    text-align: left;
    color: var(--color-text-body);
}

.md-content {
    padding: var(--space-lg) var(--space-xl);
    overflow-y: auto;
    min-height: 0;
    font-size: var(--font-size-base);
    line-height: var(--line-height-content);
    color: var(--color-text-body);
    text-align: left;
}

.md-content h2,
.md-content > h3:first-child {
    font-size: var(--heading-xl);
    font-weight: 700;
    color: var(--color-heading);
    border-bottom: 3px solid var(--color-accent);
    padding: 6px 0 var(--space-sm) 0;
    margin: 0 0 var(--space-lg) 0;
    text-align: left;
    letter-spacing: 0.01em;
}

.md-content > h3:first-child {
    border-left: none;
    background: none;
}

.md-content h3 {
    font-size: var(--heading-lg);
    font-weight: 700;
    color: var(--color-heading-secondary);
    margin: var(--space-xl) 0 10px 0;
    padding: 6px 0 6px var(--space-md);
    text-align: left;
    border-left: 4px solid var(--color-accent);
    background: linear-gradient(90deg, var(--bg-section) 0%, transparent 100%);
}

.md-content h4 {
    font-size: var(--heading-md);
    font-weight: 700;
    color: var(--color-heading-secondary);
    margin: 18px 0 var(--space-sm) 0;
    padding: 5px 0 5px 10px;
    text-align: left;
    border-left: 3px solid var(--color-accent-light);
    background: linear-gradient(90deg, var(--bg-section-alt) 0%, transparent 100%);
}

.md-content h5 {
    font-size: var(--heading-sm);
    font-weight: 600;
    color: var(--color-text-disabled);
    margin: 10px 0 var(--space-xs) 0;
    text-align: left;
}

.md-content p {
    margin: 6px 0 var(--space-sm) 0;
    text-align: left;
}

.md-content b,
.md-content strong {
    font-weight: 700;
    color: var(--color-heading-secondary);
}

.md-content ul,
.md-content ol {
    margin: 6px 0 10px 0;
    padding-left: 1.5em;
    text-align: left;
    list-style-position: outside;
}

.md-content ul { list-style-type: disc; }
.md-content ol { list-style-type: decimal; }
.md-content li { margin: var(--space-xs) 0; text-align: left; }

.md-content code {
    font-family: var(--font-family-mono);
    background: var(--bg-code);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.92em;
}

.md-content pre {
    background: var(--bg-pre);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 10px var(--space-md);
    overflow-x: auto;
    margin: var(--space-sm) 0;
    text-align: left;
}

.md-content pre code {
    background: none;
    padding: 0;
}

.md-content blockquote {
    border-left: 3px solid var(--color-accent);
    margin: var(--space-sm) 0;
    padding: var(--space-xs) var(--space-md);
    color: var(--color-text-disabled);
    background: var(--bg-blockquote);
    text-align: left;
}

.md-content hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: var(--space-md) 0;
}

.md-content a {
    color: var(--color-link);
}

.md-fallback-note {
    color: var(--color-text-faint);
    font-size: 0.85em;
    margin-top: var(--space-md);
    font-style: italic;
}

.md-content .katex-display {
    margin: 14px 0;
    padding: 10px var(--space-md);
    overflow-x: auto;
    background: var(--bg-math);
    border: 1px solid var(--border-math);
    border-radius: var(--radius-lg);
    text-align: center;
}

.md-content .katex {
    font-size: 1.12em;
}

.md-content .math-fallback {
    font-family: var(--font-family-mono);
    font-size: 0.9em;
    background: var(--bg-code);
    padding: var(--space-sm) 10px;
    border-radius: var(--radius-md);
    overflow-x: auto;
}
