/* ================================================================
   DataLab 数据工坊 — 专业数据工作台设计系统
   Neutral surfaces, restrained color, flat borders, compact density.
   ================================================================ */

/* ---------- Tokens ---------- */
:root {
    --bg: #F5F6F8;
    --surface: #FFFFFF;
    --surface-subtle: #FAFAFB;
    --surface-muted: #F2F4F7;

    --text: #20242B;
    --text-secondary: #667085;
    --text-muted: #98A2B3;

    --border: #E5E7EB;
    --border-strong: #D0D5DD;

    --brand: #356AE6;
    --brand-hover: #2858C7;
    --brand-soft: #EEF3FE;

    --success: #16A36A;
    --success-soft: #ECFDF3;
    --warning: #D99525;
    --warning-soft: #FFFAEB;
    --danger: #D94848;
    --danger-soft: #FEF3F2;

    --radius-lg: 8px;
    --radius-md: 6px;
    --radius-sm: 5px;
    --radius-xs: 3px;

    --sidebar-w: 232px;
    --topbar-h: 60px;

    --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI",
            "PingFang SC", "Microsoft YaHei", "Noto Sans SC", Arial, sans-serif;
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }
h1, h2, h3, h4 { font-weight: 600; color: var(--text); }
ul, ol { list-style: none; }

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }

/* ---------- Icons ---------- */
.icon {
    width: 16px; height: 16px;
    stroke: currentColor; fill: none;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
    flex: 0 0 auto; vertical-align: -2px;
}
.icon-sm { width: 14px; height: 14px; }
.icon-btn {
    width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    background: transparent; color: var(--text-secondary); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-muted); color: var(--text); }

/* ---------- App shell ---------- */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    height: 100vh; background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 14px 10px;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px 20px;
}
.brand-mark {
    width: 30px; height: 30px; border-radius: var(--radius-md);
    background: var(--brand); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; letter-spacing: .02em;
    flex: 0 0 auto;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-size: 14px; font-weight: 650; color: var(--text); }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
    font-size: 11px; color: var(--text-muted); font-weight: 500;
    padding: 8px 10px 6px;
}
.nav-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 8px 10px;
    border: none; border-radius: var(--radius-md);
    background: transparent; color: #475467;
    font-size: 13px; font-weight: 500; text-align: left; cursor: pointer;
    transition: background-color .12s ease, color .12s ease;
}
.nav-item .icon { color: var(--text-secondary); }
.nav-item:hover { background: var(--surface-muted); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-hover); font-weight: 600; }
.nav-item.active .icon { color: var(--brand); }
.nav-item-chat { color: var(--text-secondary); }
.tab-btn { background: none; border: none; }

.sidebar-footer {
    margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border);
}

.app-body {
    flex: 1; min-width: 0; height: 100vh;
    display: flex; flex-direction: column;
}

.topbar {
    height: var(--topbar-h); flex: 0 0 var(--topbar-h);
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; padding: 0 28px;
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-heading { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.topbar-heading h1 { font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.topbar-subtitle { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }
.user-area { display: flex; align-items: center; gap: 14px; font-size: 12.5px; }
.user-name { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-weight: 500; }
.user-link { display: inline-flex; align-items: center; gap: 5px; color: var(--text-secondary); }
.user-link:hover { color: var(--brand); }

.app-main {
    flex: 1; overflow-y: auto;
    padding: 24px 28px 40px;
}
.tab-content { display: none; }
.tab-content.active { display: block; animation: tab-in .14s ease-out; }
@keyframes tab-in { from { opacity: .4; } to { opacity: 1; } }

.status-bar {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    min-height: 32px; padding: 6px 28px;
    background: var(--surface); border-top: 1px solid var(--border);
    font-size: 11.5px; color: var(--text-muted);
}
.status-version { font-variant-numeric: tabular-nums; }

/* ---------- Typography helpers ---------- */
.section-heading {
    font-size: 13px; font-weight: 600; color: var(--text-secondary);
    margin: 28px 0 10px; padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.stats-content > .section-heading:first-of-type { margin-top: 0; }
.section-intro { margin-bottom: 16px; }
.section-intro h3 { font-size: 15px; margin-bottom: 4px; }
.section-intro p { font-size: 12.5px; color: var(--text-secondary); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 34px; padding: 0 14px;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; line-height: 1;
    cursor: pointer; white-space: nowrap;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible, .nav-item:focus-visible, .icon-btn:focus-visible {
    outline: 2px solid rgba(53, 106, 230, .45); outline-offset: 1px;
}
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: #344054; }
.btn-secondary:hover:not(:disabled) { background: var(--surface-subtle); border-color: #98A2B3; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #11865A; border-color: #11865A; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-warning:hover:not(:disabled) { background: #B57D1C; border-color: #B57D1C; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #B93B3B; border-color: #B93B3B; }
.btn-neutral { background: var(--surface); border-color: var(--border-strong); color: #344054; }
.btn-neutral:hover { background: var(--surface-subtle); }
.btn-warn { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: 12px; font-weight: 500; }
.btn-block { width: 100%; }
.btn-link {
    background: none; border: none; color: var(--brand);
    font-size: 12.5px; cursor: pointer; padding: 0;
}
.btn-link:hover { color: var(--brand-hover); text-decoration: underline; }
.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; padding: 0;
    background: transparent; border: none; border-radius: var(--radius-sm);
    color: var(--text-secondary); cursor: pointer;
}
.btn-icon:hover { background: var(--surface-muted); color: var(--text); }
.btn-add { background: var(--surface); border: 1px solid var(--border-strong); color: #344054; }
.btn-remove { background: var(--danger-soft); border: 1px solid #FDA29B; color: var(--danger); }
.btn-remove:hover { background: #FEE4E2; }

/* ---------- Form controls ---------- */
.input-text, .input-select, .input-number, .input-number-sm,
.wjx-url-input, .q-text, .q-scale-input, .q-type-select, .opt-input,
.dim-name-input, .chat-input-area textarea {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    transition: border-color .12s ease, box-shadow .12s ease;
}
.input-text, .input-select { height: 34px; padding: 0 11px; width: 100%; }
.input-number { width: 100px; height: 34px; padding: 0 10px; }
.input-number-sm { width: 84px; height: 30px; padding: 0 8px; font-size: 12.5px; }
.input-select-xs { height: 26px; padding: 0 6px; font-size: 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-xs); background: var(--surface); }
.input-text:focus, .input-select:focus, .input-number:focus, .input-number-sm:focus,
.wjx-url-input:focus, .q-text:focus, .q-scale-input:focus, .q-type-select:focus,
.opt-input:focus, .dim-name-input:focus, .chat-input-area textarea:focus,
.input-select-xs:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(53, 106, 230, .12);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input[type="checkbox"] { accent-color: var(--brand); cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }

/* ---------- Badges & status ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    height: 22px; padding: 0 8px;
    border-radius: var(--radius-xs);
    font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-neutral { background: var(--surface-muted); color: #475467; }
.badge-info { background: var(--brand-soft); color: var(--brand-hover); }
.badge-success, .badge-ok { background: #DCFAE6; color: #067647; }
.badge-warning { background: #FEF0C7; color: #B54708; }
.badge-danger, .badge-disabled { background: #FEE4E2; color: #B42318; }
.badge-admin { background: var(--brand-soft); color: var(--brand-hover); }

.status-label, .req-status-text {
    display: inline-flex; align-items: center; flex: 0 0 auto;
    height: 20px; padding: 0 7px; margin-right: 8px;
    border-radius: var(--radius-xs);
    background: var(--surface-muted); color: #475467;
    font-size: 11px; font-weight: 600;
}
.req-status-item.met .status-label, .gen-req-item.met .status-label,
.req-status-item.met .req-status-text, .gen-req-item.met .req-status-text { background: #DCFAE6; color: #067647; }
.req-status-item.unmet .status-label, .gen-req-item.unmet .status-label,
.req-status-item.unmet .req-status-text, .gen-req-item.unmet .req-status-text { background: #FEF0C7; color: #B54708; }

.metric-tag {
    display: inline-flex; align-items: center;
    height: 20px; padding: 0 7px; border-radius: var(--radius-xs);
    font-size: 11px; font-weight: 600;
}
.metric-tag.alpha-good { background: #DCFAE6; color: #067647; }
.metric-tag.alpha-ok { background: #FEF0C7; color: #B54708; }
.metric-tag.alpha-bad { background: #FEE4E2; color: #B42318; }

.alpha-good { color: var(--success); }
.alpha-ok { color: var(--warning); }
.alpha-bad { color: var(--danger); }

/* ---------- Panels ---------- */
.panel-heading {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; margin-bottom: 16px;
}
.panel-heading h3 { font-size: 15px; margin-bottom: 4px; }
.panel-hint { font-size: 12.5px; color: var(--text-secondary); line-height: 1.65; max-width: 760px; }

/* ---------- Upload ---------- */
.upload-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr);
    gap: 16px; margin-bottom: 20px;
}
.upload-zone {
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 40px 24px; text-align: center; cursor: pointer;
    transition: border-color .12s ease, background-color .12s ease;
}
.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--brand); background: #FAFCFF;
}
.upload-icon { width: 30px; height: 30px; color: var(--text-muted); stroke-width: 1.5; margin-bottom: 12px; }
.upload-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.upload-desc { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 16px; }

.wjx-input-section {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px;
    display: flex; flex-direction: column; justify-content: center;
}
.wjx-input-row { display: flex; align-items: center; gap: 8px; }
.wjx-input-icon { color: var(--text-muted); }
.wjx-url-input {
    flex: 1; min-width: 0; height: 34px; padding: 0 11px; font-size: 12.5px;
}
.wjx-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 10px; line-height: 1.5; }

.upload-info {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 16px 18px;
    margin-bottom: 20px;
}
.upload-info.hidden { display: none; }
.file-card {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; margin-bottom: 12px;
    background: var(--surface-subtle);
    border: 1px solid var(--border); border-radius: var(--radius-md);
}
.file-icon { color: var(--text-secondary); }
.file-name { font-size: 13px; font-weight: 500; color: var(--text); }

.parse-summary { display: flex; gap: 8px; flex-wrap: wrap; }
.parse-summary .stat-item {
    padding: 7px 10px; background: var(--surface-subtle);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 12px; color: var(--text-secondary);
}
.parse-summary .stat-item strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.dim-tag {
    display: inline-flex; align-items: center;
    padding: 1px 6px; margin-left: 4px;
    background: var(--surface-muted); border-radius: var(--radius-xs);
    font-size: 11px; color: #475467;
}
.quality-info {
    margin-top: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
    font-size: 12px; border: 1px solid var(--border);
}

/* ---------- Review / questionnaire editor ---------- */
.review-panel, .requirements-panel, .baby-panel, .requirements-status {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px;
    margin-bottom: 20px;
}
.review-panel.hidden, .requirements-panel.hidden, .baby-panel.hidden,
.requirements-status.hidden { display: none; }
.review-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.review-hint { font-size: 12.5px; color: var(--text-secondary); line-height: 1.6; }
.review-save-status { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; padding-top: 2px; }
.review-save-status.saved { color: var(--success); }
.review-save-status.error { color: var(--danger); }
.review-footer {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border);
}
.review-confirm-hint { font-size: 12px; color: var(--text-muted); }
.review-confirm-hint.warn { color: var(--warning); font-weight: 600; }
.btn-confirmed { background: var(--success-soft) !important; color: #067647 !important; border-color: #A6F4C5 !important; }

.questionnaire-preview { margin-top: 18px; }
.q-section { margin-bottom: 22px; }
.q-section-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 10px; padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.q-section-title {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 13px; font-weight: 600; color: var(--text);
}
.q-section-title .icon { color: var(--text-muted); }
.q-section-title small { color: var(--text-muted); font-weight: 500; margin-left: 2px; }

.q-dim {
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px; margin-bottom: 12px;
}
.q-dim-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.q-dim-label { font-size: 11.5px; color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.dim-name-input {
    flex: 1; min-width: 180px; height: 32px; padding: 0 10px;
    font-size: 13px; font-weight: 600; color: var(--text); background: var(--surface);
}
.q-dim-count { font-size: 11.5px; color: var(--text-muted); }

.q-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px; margin-bottom: 8px;
}
.q-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.q-num {
    display: inline-flex; align-items: center; justify-content: center;
    height: 20px; padding: 0 7px;
    background: var(--surface-muted); color: #475467;
    border-radius: var(--radius-xs);
    font-size: 11px; font-weight: 600;
}
.q-type-badge {
    display: inline-flex; align-items: center; height: 20px; padding: 0 7px;
    border: 1px solid var(--border); border-radius: var(--radius-xs);
    background: var(--surface-subtle); color: var(--text-secondary);
    font-size: 11px; font-weight: 500;
}
.q-type-badge.demo { background: #FFFAEB; border-color: #FEDF89; color: #B54708; }
.q-type-badge.other { background: #ECFDF3; border-color: #A6F4C5; color: #067647; }
.q-type-badge.likert { background: var(--brand-soft); border-color: #C7D7FE; color: var(--brand-hover); }
.q-head-spacer { flex: 1; }

.q-del, .opt-del, .q-add-item, .q-add-dim, .q-add-question {
    display: inline-flex; align-items: center; justify-content: center;
    height: 24px; padding: 0 8px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-xs);
    background: var(--surface); color: var(--text-secondary);
    font-size: 11.5px; cursor: pointer;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
.q-del:hover, .opt-del:hover { background: var(--danger-soft); border-color: #FDA29B; color: var(--danger); }
.q-add-item:hover, .q-add-dim:hover, .q-add-question:hover {
    background: var(--brand-soft); border-color: #C7D7FE; color: var(--brand-hover);
}
.q-text {
    width: 100%; min-height: 40px; padding: 8px 10px;
    font-size: 13px; line-height: 1.55; resize: vertical;
}
.q-meta-row {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    margin-top: 8px; font-size: 12px; color: var(--text-secondary);
}
.q-meta-row label { display: inline-flex; align-items: center; gap: 5px; font-weight: 500; }
.q-scale-input { width: 54px; height: 26px; padding: 0 6px; font-size: 12px; }
.q-type-select { height: 26px; padding: 0 6px; font-size: 11.5px; color: #475467; }
.q-move-wrap { display: inline-flex; align-items: center; gap: 4px; }
.q-move-label { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.q-move-select { max-width: 170px; color: var(--text-secondary); border-color: var(--border-strong); }
.q-options { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.opt-row { display: flex; align-items: center; gap: 6px; }
.opt-letter { width: 18px; text-align: center; font-size: 11px; color: var(--text-muted); font-weight: 600; }
.opt-input { flex: 1; height: 28px; padding: 0 8px; font-size: 12.5px; }
.opt-del { width: 24px; padding: 0; }
.q-empty { color: var(--text-muted); font-size: 12px; padding: 8px 2px; }

.debug-panel {
    margin-top: 16px; border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 10px 12px;
    background: var(--surface-subtle);
}
.debug-summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.debug-warn { color: var(--danger); font-size: 12px; }

/* ---------- Requirements ---------- */
.requirements-layout {
    display: grid; grid-template-columns: minmax(0, 1fr) 300px;
    gap: 28px; align-items: start;
}
.requirements-form { min-width: 0; }
.form-block { padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.form-block:last-child { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
.form-block-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.form-block-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
.form-block-head .form-block-title { margin-bottom: 0; }
.optional { margin-left: 8px; font-size: 11px; font-weight: 500; color: var(--text-muted); }

.req-row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.req-row:last-child { margin-bottom: 0; }
.req-row-3col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.req-row-3col .field { min-width: 0; }
.req-row-3col .input-number-sm { width: 100%; }
.req-dynamic-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.req-item {
    background: var(--surface-subtle); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 12px;
}
.req-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.req-item-title { font-size: 12.5px; font-weight: 600; color: var(--text); }
.req-hint-text { color: var(--text-muted); font-size: 12px; margin-top: 8px; }
.regression-ivs, .regression-ivs-mini {
    border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 10px 12px; margin: 8px 0 10px;
}
.regression-ivs legend, .regression-ivs-mini legend {
    font-size: 12px; color: var(--text-secondary); font-weight: 500; padding: 0 6px;
}
.iv-item-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; }
.iv-item-row .checkbox-label { flex: 1; }
.iv-sig-label { font-size: 11.5px; color: var(--text-secondary); display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.iv-sign-select { font-size: 11.5px; padding: 1px 5px; margin: 0 4px; width: auto; border: 1px solid var(--border-strong); border-radius: var(--radius-xs); background: var(--surface); }
.iv-list { max-height: 220px; overflow-y: auto; }
.checkbox-group {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 2px; max-height: 220px; overflow-y: auto;
}
.checkbox-label {
    display: flex; align-items: center; gap: 7px;
    padding: 5px 7px; border-radius: var(--radius-xs);
    font-size: 12.5px; color: #344054; cursor: pointer;
}
.checkbox-label:hover { background: var(--surface-muted); }
.var-tag {
    margin-left: auto; padding: 0 5px; height: 18px; display: inline-flex; align-items: center;
    background: var(--surface-muted); color: var(--text-muted);
    border-radius: var(--radius-xs); font-size: 10px;
}

.requirements-summary {
    position: sticky; top: 8px;
    background: var(--surface-subtle);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 16px;
}
.summary-title { font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.summary-list div {
    display: flex; align-items: center; justify-content: space-between;
    padding: 7px 0; border-bottom: 1px solid var(--border);
    font-size: 12px;
}
.summary-list div:last-child { border-bottom: none; }
.summary-list dt { color: var(--text-secondary); }
.summary-list dd { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.summary-note { font-size: 11.5px; color: var(--text-muted); line-height: 1.6; margin: 12px 0; }
.generate-controls { display: flex; align-items: center; gap: 12px; }
.progress { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin-top: 10px; }
.progress-bar { height: 100%; width: 0; background: var(--brand); transition: width .3s; }

/* ---------- Data page ---------- */
.data-page { display: flex; flex-direction: column; min-height: 0; }
.data-toolbar {
    display: flex; justify-content: space-between; align-items: center;
    gap: 16px; margin-bottom: 12px;
}
.data-info { font-size: 12.5px; color: var(--text-secondary); }
.data-info strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.data-search { position: relative; }
.data-search .icon {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); pointer-events: none;
}
.data-search .input-text { width: 240px; padding-left: 32px; }

.table-wrapper {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); overflow: auto; max-height: 68vh;
}
.table-empty, .stats-empty, .export-empty {
    text-align: center; padding: 72px 24px;
    color: var(--text-muted); font-size: 13px;
}
table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
thead { position: sticky; top: 0; z-index: 2; }
th {
    background: var(--surface-subtle); color: var(--text-secondary);
    padding: 9px 12px; text-align: left; white-space: nowrap;
    font-weight: 600; font-size: 11.5px;
    border-bottom: 1px solid var(--border);
}
td { padding: 8px 12px; border-bottom: 1px solid #F2F4F7; white-space: nowrap; color: #344054; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #FAFBFC; }
.row-num { width: 48px; color: var(--text-muted); }
.col-name { font-weight: 600; }
.col-type {
    margin-left: 6px; padding: 0 4px;
    background: var(--surface-muted); color: var(--text-muted);
    border-radius: var(--radius-xs); font-size: 10px; font-weight: 500;
}
.pagination { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 14px; }
.pagination.hidden { display: none; }
.pagination button {
    height: 30px; padding: 0 11px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: #344054;
    font-size: 12px; cursor: pointer;
}
.pagination button:hover:not(:disabled) { background: var(--surface-subtle); }
.pagination button:disabled { opacity: .45; cursor: not-allowed; }
.pagination .page-info { font-size: 12px; color: var(--text-secondary); }

/* ---------- Stats ---------- */
.stats-content.hidden, .export-content.hidden { display: none; }

.quality-bar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; padding: 11px 14px; margin-bottom: 20px;
    border: 1px solid var(--border); border-radius: var(--radius-md);
    font-size: 12.5px; line-height: 1.6;
}
.quality-bar.passed { background: var(--success-soft); border-color: #A6F4C5; color: #067647; }
.quality-bar.failed { background: var(--warning-soft); border-color: #FEDF89; color: #B54708; }
.quality-bar .status-label { background: rgba(255,255,255,.7); color: inherit; }

.requirements-status { margin-bottom: 20px; }
.requirements-status h3 { font-size: 14px; margin-bottom: 12px; }
.requirements-status h4 { font-size: 12px; color: var(--text-secondary); margin: 12px 0 6px; font-weight: 600; }
.req-status-group { margin-bottom: 8px; }
.req-status-group ul, .req-status-list { margin: 4px 0; }
.req-status-item {
    display: flex; align-items: center; flex-wrap: wrap;
    padding: 7px 10px; margin: 4px 0;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); font-size: 12px;
}
.req-status-item.met { border-color: #A6F4C5; background: #F6FEF9; }
.req-status-item.unmet { border-color: #FEDF89; background: #FFFCF5; }

.dimension-cards {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px; margin-bottom: 8px;
}
.dim-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 14px 16px;
}
.dim-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.dim-card h4 { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.dim-card .alpha-value {
    font-size: 24px; font-weight: 650; letter-spacing: -.01em;
    font-variant-numeric: tabular-nums; line-height: 1.3;
}
.overall-card .alpha-value { font-size: 28px; }
.dim-card .dim-detail { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
.overall-alpha { margin-bottom: 8px; }

.kmo-card, .correlation-matrix, .regression-section {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 16px;
}
.kmo-card p { font-size: 12.5px; color: var(--text-secondary); line-height: 1.9; }
.kmo-card strong { color: var(--text); font-weight: 600; }
.correlation-matrix { overflow-x: auto; }
.correlation-matrix table { margin-top: 4px; }
.correlation-matrix th { text-align: center; }
.correlation-matrix td { text-align: center; }
.corr-cell-wrap { text-align: center; }
.corr-cell {
    display: inline-block; min-width: 58px; padding: 2px 6px;
    border-radius: var(--radius-xs); color: var(--text); font-weight: 500;
}
.corr-diagonal { color: var(--text-muted); background: var(--surface-subtle); }
.table-note { font-size: 11px; color: var(--text-muted); margin-top: 8px; }

.regression-hint { color: var(--text-muted); font-size: 12.5px; margin-bottom: 14px; }
.regression-controls { display: flex; flex-direction: column; gap: 14px; }
.regression-controls > .field { max-width: 360px; }
.regression-results { margin-top: 18px; }
.regression-summary {
    background: var(--surface-subtle); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 11px 14px;
    margin-bottom: 14px; font-size: 12.5px; line-height: 1.8; color: #344054;
}
.regression-summary strong { color: var(--text); }
.regression-error {
    margin-top: 14px; padding: 10px 12px;
    background: var(--danger-soft); border: 1px solid #FDA29B;
    border-radius: var(--radius-sm); color: #B42318; font-size: 12.5px;
}
.regression-error .status-label { background: #FEE4E2; color: #B42318; }
.regression-table { font-size: 12.5px; }
.regression-table th { background: var(--surface-subtle); }
.regression-table td { padding: 7px 10px; }

/* ---------- Export ---------- */
.export-cards { display: flex; flex-direction: column; gap: 10px; }
.export-card {
    display: flex; align-items: center; gap: 16px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 16px 18px;
}
.export-icon { width: 20px; height: 20px; color: var(--text-secondary); }
.export-body { flex: 1; min-width: 0; }
.export-card h4 { font-size: 13px; margin-bottom: 3px; }
.export-card p { font-size: 12px; color: var(--text-muted); }

/* ---------- Chat panel ---------- */
.chat-panel {
    position: fixed; right: 0; top: 0; bottom: 0; width: 400px;
    background: var(--surface); border-left: 1px solid var(--border);
    box-shadow: -8px 0 24px rgba(16, 24, 40, .06);
    z-index: 100; display: flex; flex-direction: column;
    transition: transform .2s ease;
}
.chat-panel.hidden { transform: translateX(100%); }
.chat-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 12px; padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.chat-header h3 { font-size: 14px; margin-bottom: 2px; }
.chat-header p { font-size: 11.5px; color: var(--text-muted); }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-welcome { color: var(--text-secondary); font-size: 12.5px; line-height: 1.7; }
.chat-welcome-title { font-weight: 600; color: var(--text); margin-bottom: 6px; }
.chat-welcome li {
    padding: 6px 8px; margin: 3px 0;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface-subtle); cursor: pointer;
}
.chat-welcome li:hover { border-color: #C7D7FE; background: var(--brand-soft); color: var(--brand-hover); }

.chat-message {
    max-width: 88%; padding: 9px 12px;
    border-radius: var(--radius-md);
    font-size: 12.5px; line-height: 1.65; word-break: break-word;
}
.chat-message.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 2px; }
.chat-message.assistant { align-self: flex-start; background: var(--surface-muted); color: #344054; border-bottom-left-radius: 2px; }
.chat-message.system {
    align-self: stretch; background: var(--warning-soft);
    border: 1px solid #FEDF89; border-radius: var(--radius-sm);
    font-size: 12px; color: #B54708;
}
.chat-message.system summary { cursor: pointer; font-weight: 600; }

.chat-input-area { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); }
.chat-input-area textarea {
    flex: 1; min-height: 38px; max-height: 120px; padding: 8px 10px;
    resize: none; font-size: 12.5px; line-height: 1.5;
}
.typing-indicator { display: flex; gap: 4px; padding: 10px 12px; }
.typing-indicator span {
    width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted);
    animation: typing 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

/* ---------- Modal ---------- */
.modal {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(16, 24, 40, .45);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: modal-in .12s ease-out;
}
.modal.hidden { display: none; }
@keyframes modal-in { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
    background: var(--surface); border-radius: var(--radius-lg);
    width: 92%; max-width: 500px;
    box-shadow: 0 16px 40px rgba(16, 24, 40, .18);
    animation: modal-rise .16s ease-out;
}
@keyframes modal-rise { from { transform: translateY(6px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-body .btn-block { margin-top: 2px; }
.modal-close { font-size: 14px; }
.auth-content { max-width: 380px; }
.auth-brand {
    display: flex; align-items: center; gap: 8px;
    padding: 18px 20px 0;
}
.auth-brand .brand-name { font-size: 14px; }
.auth-brand .brand-sub { font-size: 11px; }
.auth-sub { font-size: 12.5px; color: var(--text-muted); margin-top: -4px; }
.auth-error { color: var(--danger); font-size: 12px; min-height: 1em; }
.auth-content .btn-link { align-self: center; }

/* ---------- Generation progress ---------- */
.gen-progress-content { max-width: 560px; }
.gen-spinner {
    width: 32px; height: 32px; margin: 2px auto 16px;
    border: 3px solid var(--border); border-top-color: var(--brand);
    border-radius: 50%; animation: gen-spin .8s linear infinite;
}
@keyframes gen-spin { to { transform: rotate(360deg); } }
.gen-status-text { text-align: center; font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; }
.gen-stats {
    background: var(--surface-subtle); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 12px 14px;
    margin-bottom: 14px; font-size: 12.5px;
}
.gen-stat-row { display: flex; justify-content: space-between; padding: 3px 0; }
.gen-stat-row span { color: var(--text-secondary); }
.gen-stat-row strong { color: var(--text); font-variant-numeric: tabular-nums; }
.gen-requirements { margin-bottom: 14px; }
.gen-section-title { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); margin: 10px 0 4px; }
.gen-req-item {
    display: flex; align-items: flex-start; gap: 2px;
    padding: 6px 8px; margin: 3px 0;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); font-size: 12px; line-height: 1.6;
}
.gen-req-item.met { border-color: #A6F4C5; background: #F6FEF9; color: #067647; }
.gen-req-item.unmet { border-color: #FEDF89; background: #FFFCF5; color: #B54708; }
.gen-progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.gen-progress-fill { height: 100%; width: 0; background: var(--brand); border-radius: 3px; transition: width .3s; }
.gen-timeout-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.timeout-title { font-size: 13.5px; color: var(--warning); margin-bottom: 10px; }

/* ---------- Data adjustment model ---------- */
.baby-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.baby-stats { margin-bottom: 14px; }
.baby-stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.baby-stat-card {
    background: var(--surface-subtle); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 12px 14px;
}
.baby-stat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.baby-stat-value { font-size: 14px; font-weight: 600; color: var(--text); }
.baby-stat-detail { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.baby-rules-details {
    background: var(--surface-subtle); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 12px 14px;
}
.baby-rules-details summary { cursor: pointer; font-weight: 600; font-size: 12.5px; color: var(--text-secondary); user-select: none; }
.baby-rules-content { margin-top: 12px; }
.baby-rule-count { margin-bottom: 8px; font-size: 12.5px; color: var(--text-secondary); }
.baby-rules-list { display: flex; flex-direction: column; gap: 8px; max-height: 400px; overflow-y: auto; }
.baby-rule-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.baby-rule-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 5px; }
.baby-rule-num { font-size: 10.5px; color: var(--text-muted); background: var(--surface-muted); padding: 1px 6px; border-radius: var(--radius-xs); }
.baby-rule-action { font-weight: 600; font-size: 12.5px; color: var(--text); }
.baby-rule-confidence { font-size: 10.5px; padding: 1px 7px; border-radius: var(--radius-xs); font-weight: 600; }
.baby-rule-support { font-size: 10.5px; color: var(--text-muted); }
.confidence-high { background: #DCFAE6; color: #067647; }
.confidence-medium { background: #FEF0C7; color: #B54708; }
.confidence-low { background: #FEE4E2; color: #B42318; }
.baby-rule-condition { font-size: 12px; color: #475467; line-height: 1.6; }
.baby-rule-method { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.baby-empty-state { text-align: center; padding: 20px; color: var(--text-muted); font-size: 12.5px; }
.baby-empty-state p { margin-bottom: 4px; }
.baby-recent-logs { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin-top: 10px; }
.baby-log-entry { font-size: 11.5px; padding: 4px 0; border-bottom: 1px solid var(--border); color: var(--text-secondary); }
.baby-log-entry:last-child { border-bottom: none; }
.log-ok { color: var(--success); font-weight: 600; }
.log-fail { color: var(--danger); font-weight: 600; }

/* ---------- Admin ---------- */
.admin-body { background: var(--bg); min-height: 100vh; }
.admin-shell { max-width: 1180px; margin: 0 auto; padding: 24px; }
.admin-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; margin-bottom: 20px;
}
.admin-brand { display: flex; align-items: center; gap: 10px; }
.admin-brand h1 { font-size: 16px; font-weight: 600; }
.admin-header .actions { display: flex; gap: 8px; }
.stat-cards {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px; margin-bottom: 20px;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 14px 16px;
}
.stat-card .num { font-size: 24px; font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-card .label { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.admin-section {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); margin-bottom: 16px; overflow: hidden;
}
.admin-section h2 {
    font-size: 13px; font-weight: 600;
    padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.admin-section table { font-size: 12.5px; }
.admin-section th { padding: 9px 16px; }
.admin-section td { padding: 8px 16px; }
.admin-section .btn { height: 26px; padding: 0 8px; font-size: 11.5px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .requirements-layout { grid-template-columns: minmax(0, 1fr) 260px; gap: 20px; }
}
@media (max-width: 960px) {
    .upload-layout { grid-template-columns: 1fr; }
    .requirements-layout { grid-template-columns: 1fr; }
    .requirements-summary { position: static; }
}
@media (max-width: 860px) {
    .app-shell { flex-direction: column; height: auto; min-height: 100vh; overflow: visible; }
    .sidebar {
        width: 100%; height: auto; flex: 0 0 auto; flex-direction: row; align-items: center;
        gap: 10px; padding: 8px 12px;
        border-right: none; border-bottom: 1px solid var(--border);
        position: sticky; top: 0; z-index: 60;
    }
    .sidebar-brand { padding: 2px 6px; }
    .brand-sub { display: none; }
    .side-nav { flex-direction: row; flex: 1 1 auto; min-width: 0; overflow-x: auto; gap: 2px; }
    .nav-label { display: none; }
    .nav-item { width: auto; flex: 0 0 auto; white-space: nowrap; padding: 7px 10px; }
    .sidebar-footer { margin: 0; padding: 0; border: none; flex: 0 0 auto; }
    .app-body { height: auto; min-height: 0; }
    .topbar { padding: 0 16px; height: 52px; flex-basis: 52px; }
    .topbar-subtitle { display: none; }
    .app-main { overflow: visible; padding: 16px; }
    .status-bar { padding: 6px 16px; }
    .chat-panel { width: 100%; }
}
@media (max-width: 640px) {
    .brand-text { display: none; }
    .nav-item > span { display: none; }
    .nav-item { padding: 8px; }
    .topbar-heading h1 { white-space: nowrap; font-size: 15px; }
    .topbar-actions { gap: 6px; }
    .user-name span, .user-link span, #btnLogout span { display: none; }
    .user-area { gap: 8px; }
    .req-row-3col { grid-template-columns: 1fr; }
    .data-toolbar { flex-direction: column; align-items: stretch; }
    .data-search .input-text { width: 100%; }
    .export-card { flex-wrap: wrap; }
    .export-card .btn { width: 100%; }
    .wjx-input-row { flex-wrap: wrap; }
    .wjx-url-input { flex-basis: 100%; }
    .summary-list div { font-size: 12px; }
}
