/* ══════════════════════════════════════════════════════════════════════
   Wangscape Stats Lab — app-shell v3
   Slim, results-first layout inspired by JASP / jamovi / Hex / Observable.
   All `data-*` hooks from the previous version are preserved.
   ══════════════════════════════════════════════════════════════════════ */


/* ── 1. Tokens ───────────────────────────────────────────────────── */
:root {
    /* Surfaces */
    --bg:              #ffffff;
    --bg-soft:         #fafaf7;
    --surface:         #ffffff;
    --surface-muted:   #f6f6f2;
    --surface-sunken:  #eeeeea;

    /* Borders */
    --line:            rgba(15, 23, 42, 0.08);
    --line-strong:     rgba(15, 23, 42, 0.15);

    /* Text */
    --ink:             #0f172a;
    --ink-soft:        #1f2937;
    --muted:           #5b6472;
    --muted-strong:    #3a4453;
    --faint:           #8b94a3;

    /* Accent — academic ink-blue with warm note */
    --accent:          #2563eb;
    --accent-strong:   #1d4ed8;
    --accent-soft:     #eef4ff;
    --accent-line:     rgba(37, 99, 235, 0.22);

    --warm:            #b45309;
    --warm-soft:       #fdf6ec;

    --ok:              #047857;
    --ok-soft:         #ecfdf5;

    --danger:          #b91c1c;

    /* Typography */
    --font-serif:      "Source Serif 4", "Source Serif Pro", "Noto Serif SC", Georgia, serif;
    --font-sans:       "Inter", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono:       "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

    /* Shadows */
    --shadow-xs:       0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm:       0 2px 8px rgba(15, 23, 42, 0.06);

    /* Layout */
    --topbar-h:        56px;
    --subtop-h:        48px;
    --rail-w:          300px;
    --radius-sm:       6px;
    --radius:          9px;
    --gap:             12px;
}


/* ── 2. Reset & base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body.app-shell {
    min-height: 100vh;
    color: var(--ink);
    background: var(--bg-soft);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.55;
    font-feature-settings: "kern", "liga", "calt";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 3px; }

button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; background: transparent; cursor: pointer; }

::selection { color: #fff; background: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

img, svg { display: block; max-width: 100%; }

code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    padding: 0.1em 0.35em;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: 4px;
    color: var(--ink-soft);
}


/* ── 3. App shell layout ─────────────────────────────────────────── */
.app {
    display: grid;
    grid-template-rows: var(--topbar-h) var(--subtop-h) 1fr auto;
    grid-template-columns: minmax(0, 1fr);
    min-height: 100vh;
    max-width: 100vw;
    overflow-x: hidden;
}


/* ── 4. Top bar ──────────────────────────────────────────────────── */
.app-topbar {
    grid-row: 1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 1.2rem;
    padding: 0 1.1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 40;
    min-width: 0;
    max-width: 100vw;
}

.app-brand { display: flex; align-items: center; gap: 0.5rem; color: var(--ink); }
.app-brand:hover { color: var(--ink); text-decoration: none; }

.app-brand-mark {
    font-family: var(--font-serif);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.app-brand::before {
    content: "";
    display: inline-block;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--ink) 100%);
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.35);
}


/* Case switcher in top bar */
.app-case-switcher {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
}
.app-case-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    flex-shrink: 0;
}
.app-case-chips {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 4px;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    scrollbar-width: thin;
    min-width: 0;
    flex: 1 1 0;
}

/* Override stats-chip inside the case switcher to be segmented pills */
.app-case-chip.stats-chip {
    padding: 0.3rem 0.75rem;
    background: transparent;
    border: 0;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--muted-strong);
    white-space: nowrap;
    transition: all 0.15s ease;
}
.app-case-chip.stats-chip:hover {
    background: var(--surface);
    color: var(--ink);
}
.app-case-chip.stats-chip.active {
    background: var(--ink);
    color: #fff;
    box-shadow: var(--shadow-xs);
}


/* Topbar actions */
.app-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.app-iconlink {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--ink-soft);
    background: var(--surface);
}
.app-iconlink:hover {
    border-color: var(--accent);
    color: var(--accent);
    text-decoration: none;
}

.lang-switch {
    display: inline-flex;
    padding: 2px;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: 999px;
}
.lang-button {
    padding: 0.22rem 0.65rem;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--muted);
    border-radius: 999px;
    letter-spacing: 0.04em;
    transition: all 0.15s ease;
}
.lang-button[aria-pressed="true"] {
    background: var(--ink);
    color: #fff;
}


/* ── 5. Subtop bar (task tabs + metrics strip) ────────────────────── */
.app-subtop {
    grid-row: 2;
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 1.5rem;
    padding: 0 1.1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: var(--topbar-h);
    z-index: 30;
    min-width: 0;
    max-width: 100vw;
}

.task-tabs {
    display: flex;
    align-items: stretch;
    gap: 0;
    overflow-x: auto;
    scrollbar-width: none;
    min-width: 0;
    flex: 1 1 0;
}
.task-tabs::-webkit-scrollbar { display: none; }

.task-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1rem;
    border: 0;
    background: transparent;
    color: var(--muted-strong);
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    position: relative;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.task-tab:hover { color: var(--ink); }
.task-tab.active {
    color: var(--ink);
    font-weight: 600;
    border-bottom-color: var(--accent);
}
.task-tab .task-tab-num {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--faint);
    letter-spacing: 0.04em;
}
.task-tab.active .task-tab-num { color: var(--accent); }


/* Metric strip — right-aligned, numbers-first */
.metric-strip {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    overflow-x: auto;
    scrollbar-width: none;
    max-width: 62%;
}
.metric-strip::-webkit-scrollbar { display: none; }

.metric-pill {
    display: inline-flex;
    align-items: baseline;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    white-space: nowrap;
    font-size: 0.78rem;
}
.metric-pill em {
    font-style: normal;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.metric-pill b {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--ink);
    letter-spacing: -0.01em;
}
.metric-pill.hidden-metric { display: none; }


/* ── 6. Main workspace ───────────────────────────────────────────── */
.app-main {
    grid-row: 3;
    display: grid;
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    min-height: 0;
    min-width: 0;
    max-width: 100vw;
}


/* ── 7. Left side rail ───────────────────────────────────────────── */
.side-rail {
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 0.5rem 0;
    overflow-y: auto;
    max-height: calc(100vh - var(--topbar-h) - var(--subtop-h));
    position: sticky;
    top: calc(var(--topbar-h) + var(--subtop-h));
    align-self: start;
}

.side-block {
    border-bottom: 1px solid var(--line);
    padding: 0.9rem 1.1rem 1rem;
}
.side-block:last-child { border-bottom: 0; }
.side-block[open] { padding-bottom: 1.1rem; }

.side-block > summary {
    list-style: none;
    cursor: pointer;
    padding: 0 0 0.55rem;
    margin-bottom: 0.25rem;
    position: relative;
}
.side-block > summary::-webkit-details-marker { display: none; }
.side-block > summary::after {
    content: "›";
    position: absolute;
    right: 0;
    top: -2px;
    color: var(--faint);
    font-size: 1.1rem;
    transition: transform 0.2s ease;
}
.side-block[open] > summary::after { transform: rotate(90deg); }

.side-eyebrow {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
}

.side-title {
    font-family: var(--font-serif);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.3;
    margin-top: 0.2rem;
}

.side-text {
    color: var(--muted-strong);
    font-size: 0.85rem;
    line-height: 1.55;
}

.side-question {
    margin-top: 0.55rem;
    padding: 0.55rem 0.7rem;
    border-left: 3px solid var(--accent);
    background: var(--accent-soft);
    font-size: 0.82rem;
    font-style: italic;
    color: var(--ink-soft);
    border-radius: 0 4px 4px 0;
}

.side-list {
    list-style: none;
    margin-top: 0.6rem;
}
.side-list li {
    position: relative;
    padding: 0.3rem 0 0.3rem 0.95rem;
    color: var(--muted-strong);
    font-size: 0.8rem;
    line-height: 1.45;
    border-top: 1px dashed var(--line);
}
.side-list li:first-child { border-top: 0; }
.side-list li::before {
    content: "▸";
    position: absolute;
    left: 0;
    top: 0.35rem;
    color: var(--accent);
    font-size: 0.7rem;
}

.case-block > summary .side-title {
    font-size: 0.95rem;
    margin-top: 0.1rem;
}

.side-hint {
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 0.4rem;
}

.side-status {
    margin-top: 0.7rem;
    padding: 0.5rem 0.65rem;
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
    border-radius: 0 4px 4px 0;
    font-size: 0.78rem;
    color: var(--ink-soft);
}


/* ── 8. Form fields (same hooks, slimmer) ─────────────────────────── */
.stats-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-top: 0.65rem;
}
.stats-field span {
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--muted-strong);
    letter-spacing: 0.02em;
}

.stats-field input[type="file"],
.stats-field input[type="text"],
.stats-field input[type="number"],
.stats-field select,
.stats-field textarea {
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--ink);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.stats-field select {
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 1.8rem;
}

.stats-field input[type="file"] {
    padding: 0.35rem;
    font-size: 0.78rem;
    background: var(--surface-muted);
}

.stats-field textarea {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.5;
    resize: vertical;
    min-height: 70px;
}

.stats-field input:focus,
.stats-field select:focus,
.stats-field textarea:focus {
    outline: 0;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-line);
}

.stats-check {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.55rem;
    font-size: 0.82rem;
    color: var(--ink-soft);
    cursor: pointer;
}
.stats-check input[type="checkbox"] {
    width: 15px; height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
}


/* ── 9. Buttons ───────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.48rem 0.9rem;
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
}
.btn-solid   { background: var(--ink); color: #fff; }
.btn-solid:hover   { background: var(--accent); color: #fff; text-decoration: none; }

.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.btn-ghost {
    background: transparent;
    color: var(--muted-strong);
    border-color: var(--line);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.stats-inline-btn { padding: 0.42rem 0.75rem; font-size: 0.8rem; }

.stats-action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.6rem;
    align-items: center;
}
.preset-row { gap: 4px; }


/* ── 10. Stats chips (chart presets) ──────────────────────────────── */
.stats-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.32rem 0.7rem;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 500;
    color: var(--ink-soft);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.stats-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
    text-decoration: none;
}
.stats-chip.active {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
}
.stats-chip-link::after { content: " ↓"; }


/* ── 11. Correlation column checklist ─────────────────────────────── */
.check-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.3rem;
    margin-top: 0.55rem;
    max-height: 200px;
    overflow-y: auto;
    padding: 0.5rem 0.6rem;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}
.check-grid .stats-check {
    margin-top: 0;
    font-size: 0.78rem;
}


/* ── 12. Canvas ──────────────────────────────────────────────────── */
.app-canvas {
    padding: var(--gap);
    display: grid;
    gap: var(--gap);
    align-content: start;
    min-width: 0;
}

.canvas-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem 1.15rem;
    box-shadow: var(--shadow-xs);
    min-width: 0;
}

.canvas-head {
    margin-bottom: 0.6rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--line);
}

.canvas-head h3 {
    font-family: var(--font-serif);
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.1rem;
}

.canvas-sub {
    font-size: 0.78rem;
    color: var(--muted);
}


/* Hero plot card */
.canvas-plot { padding: 0.9rem 1.1rem 1rem; }
.canvas-plot .plot-surface {
    width: 100%;
    min-height: 420px;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.4rem;
}
.canvas-plot .plot-surface:empty::before {
    content: "Chart will render here once you load data and click Draw Chart.";
    display: flex;
    align-items: center;
    justify-content: center;
    height: 420px;
    color: var(--faint);
    font-size: 0.85rem;
    font-style: italic;
}


/* Split: output + preview */
.canvas-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--gap);
}
.canvas-row .canvas-card { min-height: 260px; }


/* Audit <details> card */
.canvas-audit {
    padding: 0;
    overflow: hidden;
}
.canvas-audit > summary {
    list-style: none;
    cursor: pointer;
    padding: 0.8rem 1.15rem;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    background: var(--surface);
    position: relative;
}
.canvas-audit > summary::-webkit-details-marker { display: none; }
.canvas-audit > summary h3 {
    font-family: var(--font-serif);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
}
.canvas-audit > summary::after {
    content: "▾";
    color: var(--faint);
    font-size: 0.75rem;
    margin-left: auto;
    transition: transform 0.2s ease;
}
.canvas-audit[open] > summary::after { transform: rotate(180deg); }
.canvas-audit[open] > summary {
    border-bottom: 1px solid var(--line);
}
.canvas-audit > *:not(summary) {
    padding: 0.9rem 1.15rem 1rem;
}


/* Notes card */
.canvas-notes-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.canvas-notes-actions { margin-top: 0; }

.stats-interpretation {
    font-size: 0.88rem;
    color: var(--ink-soft);
    line-height: 1.65;
    padding: 0.55rem 0.75rem;
    background: var(--warm-soft);
    border: 1px solid rgba(180, 83, 9, 0.16);
    border-radius: var(--radius-sm);
    margin-bottom: 0.8rem;
}
.stats-interpretation > * + * { margin-top: 0.55rem; }
.stats-interpretation h4 {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--warm);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.25rem;
}
.stats-interpretation ul { list-style: none; padding-left: 0; }
.stats-interpretation ul li {
    position: relative;
    padding: 0.2rem 0 0.2rem 1rem;
}
.stats-interpretation ul li::before {
    content: "•";
    position: absolute;
    left: 0.2rem;
    color: var(--warm);
}

.lab-notes-input {
    width: 100%;
    padding: 0.7rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--ink);
    resize: vertical;
    min-height: 110px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.lab-notes-input:focus {
    outline: 0;
    border-color: var(--warm);
    box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.15);
}
.lab-notes-input::placeholder {
    color: var(--faint);
    font-family: var(--font-sans);
    font-style: italic;
}

.lab-notes-status {
    font-size: 0.74rem;
    color: var(--muted);
    font-style: italic;
    margin-left: 0.4rem;
    transition: opacity 0.4s ease;
}
.lab-notes-status[data-state="ok"] { color: var(--ok); font-style: normal; }
.lab-notes-status[data-state="warn"] { color: var(--warm); }


/* ── 13. Task output + audit lists ────────────────────────────────── */
.stats-output {
    font-size: 0.86rem;
    color: var(--ink-soft);
    line-height: 1.6;
    max-height: 480px;
    overflow: auto;
}

.stats-output > * + * { margin-top: 0.65rem; }

.stats-output h4 {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted-strong);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0.8rem 0 0.35rem;
}

.stats-output ul {
    list-style: none;
    padding-left: 0;
}
.stats-output ul li {
    position: relative;
    padding: 0.25rem 0 0.25rem 1rem;
    border-bottom: 1px dashed var(--line);
}
.stats-output ul li:last-child { border-bottom: 0; }
.stats-output ul li::before {
    content: "•";
    position: absolute;
    left: 0.2rem;
    color: var(--accent);
}

.stats-output table,
.stats-table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}
.stats-output table th,
.stats-output table td {
    padding: 0.35rem 0.55rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
}
.stats-output table th {
    background: var(--surface-muted);
    color: var(--ink);
    font-weight: 600;
    font-size: 0.75rem;
    position: sticky;
    top: 0;
}


/* ── 14. Table preview ────────────────────────────────────────────── */
.stats-table-wrap {
    overflow: auto;
    max-height: 380px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.stats-table-wrap table {
    width: 100%;
    border-collapse: collapse;
}
.stats-table-wrap th,
.stats-table-wrap td {
    padding: 0.4rem 0.65rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    font-size: 0.78rem;
}
.stats-table-wrap thead th {
    position: sticky;
    top: 0;
    background: var(--surface-muted);
    color: var(--ink);
    font-weight: 600;
    font-size: 0.74rem;
    letter-spacing: 0.02em;
    border-bottom: 1px solid var(--line-strong);
    z-index: 1;
}
.stats-table-wrap tbody tr:hover { background: var(--accent-soft); }
.stats-table-wrap tbody tr:last-child td { border-bottom: 0; }


/* ── 15. Empty state ──────────────────────────────────────────────── */
.stats-empty {
    padding: 1rem 0.8rem;
    color: var(--faint);
    font-style: italic;
    font-size: 0.82rem;
    text-align: center;
    background: var(--surface-muted);
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-sm);
}


/* ── 16. Footer ──────────────────────────────────────────────────── */
.app-footer {
    grid-row: 4;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.6rem 1.1rem;
    border-top: 1px solid var(--line);
    background: var(--surface);
    font-size: 0.78rem;
    color: var(--muted);
}
.app-footer-links { display: inline-flex; gap: 1rem; }
.app-footer-links a { color: var(--ink-soft); }
.app-footer-links a:hover { color: var(--accent); }


/* ── 17. Plotly tweaks ────────────────────────────────────────────── */
.js-plotly-plot .plotly .modebar { background: transparent !important; }
.js-plotly-plot .plotly .modebar-btn path { fill: var(--muted) !important; }
.js-plotly-plot .plotly .modebar-btn.active path,
.js-plotly-plot .plotly .modebar-btn:hover path { fill: var(--accent) !important; }


/* ── 18. Hide legacy bits still present in DOM but unused ────────── */
.stats-mode-bar,
.workflow-stepper,
.task-compass,
.lab-cockpit,
.hero,
.site-header,
.site-footer { display: none !important; }


/* ── 18b. Stats form spacing inside multi-form configure block ───── */
.stats-form + .stats-form { margin-top: 0.7rem; padding-top: 0.7rem; border-top: 1px dashed var(--line); }
.stats-form .check-grid { max-height: 160px; }


/* ── 18c. Output table polish for new analyses ───────────────────── */
.stats-callout { margin-bottom: 0.7rem; }
.stats-callout h4 + table,
.stats-callout p + table { margin-top: 0.4rem; }
.stats-callout table td:nth-child(2),
.stats-callout table td:nth-child(3),
.stats-callout table td:nth-child(4) { text-align: right; font-variant-numeric: tabular-nums; }


/* Keep the plot card tall when a multi-panel chart is shown */
.canvas-plot .plot-surface .js-plotly-plot { min-height: 420px; }


/* ── 19. Responsive ──────────────────────────────────────────────── */
@media (max-width: 1100px) {
    :root { --rail-w: 260px; }
    .metric-strip { max-width: 50%; }
    .canvas-row { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .app {
        grid-template-rows: var(--topbar-h) var(--subtop-h) auto 1fr auto;
    }
    .app-topbar {
        grid-template-columns: auto auto;
        gap: 0.7rem;
    }
    .app-case-switcher {
        grid-column: 1 / -1;
        grid-row: 2;
        padding-bottom: 0.5rem;
    }
    .app-topbar { padding-top: 0.5rem; padding-bottom: 0.5rem; }
    .app-main {
        grid-row: 3 / 5;
        grid-template-columns: 1fr;
    }
    .side-rail {
        position: static;
        max-height: none;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }
    .metric-strip { max-width: 100%; }
    .app-brand-mark { font-size: 0.9rem; }
    .canvas-plot .plot-surface { min-height: 320px; }
    .canvas-plot .plot-surface:empty::before { height: 320px; }
}

@media (max-width: 560px) {
    :root { --topbar-h: auto; --subtop-h: auto; }
    .app-topbar {
        position: static;
        flex-wrap: wrap;
    }
    .app-subtop {
        position: static;
        flex-direction: column;
        padding: 0.5rem 1rem;
    }
    .metric-strip { justify-content: flex-start; }
    .canvas-notes-head { flex-direction: column; }
}


/* ── 20. Print ───────────────────────────────────────────────────── */
@media print {
    .app-topbar, .app-subtop, .side-rail, .app-footer, .canvas-notes-actions { display: none !important; }
    .app { grid-template-columns: 1fr; grid-template-rows: none; }
    .app-main { grid-template-columns: 1fr; }
    .canvas-card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
    body.app-shell { background: #fff; }
}
