/** Full-HD 16:9 layout for correlation-video & cognitive-video (no page scroll) */
:root {
    --bg: #050a12;
    --surface: #0c1120;
    --surface2: #111a28;
    --border: #253552;
    --text: #eef5ff;
    --muted: #9aaec9;
    --accent: #3b82f6;
    --strong: #4ade80;
    --moderate: #fbbf24;
    --weak: #6d86b0;
    --none: #f87171;
    --top-h: 44px;
    --sidebar-w: 272px;
    --verdict-h: 52px;
    --gap: 6px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, system-ui, sans-serif;
    font-size: 13px;
}

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

.app-top {
    flex-shrink: 0;
    height: var(--top-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
    min-width: 0;
}

.app-top h1 {
    font-size: 0.95rem;
    font-weight: 700;
    white-space: nowrap;
}

.app-top h1 span {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.78rem;
}

.top-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.header-sample {
    border: none;
    min-width: 0;
    flex: 1;
    max-width: 340px;
    position: relative;
}

.header-sample:not([open]) .sample-grid {
    display: none;
}

.header-sample[open] .sample-grid {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 300;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: min(480px, 90vw);
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}

.header-sample > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
}

.header-sample > summary::-webkit-details-marker { display: none; }

.header-sample[open] > summary { margin-bottom: 4px; }

.sample-summary-status {
    font-size: 0.72rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sample-summary-status.loaded { color: #86efac; }
.sample-summary-status.partial { color: #fcd34d; }
.sample-summary-status.missing { color: var(--muted); }

.sample-popover {
    position: absolute;
    z-index: 200;
    margin-top: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    max-width: 480px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}

.sample-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.sample-box {
    background: var(--surface2);
    border-radius: 8px;
    padding: 8px;
    font-size: 0.72rem;
}

.sample-box.bm { border-left: 3px solid #3b82f6; }
.sample-box.muse { border-left: 3px solid #a855f7; }
.sample-box .name { font-weight: 700; margin-bottom: 4px; }

.warn-bar {
    flex-shrink: 0;
    background: #422006;
    border-bottom: 1px solid #92400e;
    color: #fcd34d;
    padding: 4px 10px;
    font-size: 0.75rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    gap: var(--gap);
    padding: var(--gap);
}

.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.sidebar-tabs {
    flex-shrink: 0;
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
}

.sidebar-tab {
    flex: 1;
    min-height: 30px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0 4px;
}

.sidebar-tab:hover { color: var(--text); background: #1a2638; }
.sidebar-tab.active { color: var(--text); background: var(--surface); box-shadow: inset 0 -2px 0 var(--accent); }

.sidebar-panels {
    flex: 1;
    min-height: 0;
    position: relative;
}

.sidebar-panel {
    display: none;
    height: 100%;
    overflow: hidden;
    padding: 8px;
}

.sidebar-panel.active {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.panel-block h2 {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 4px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 0 10px;
    border: none;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    color: #fff;
    background: #263b58;
    white-space: nowrap;
}

.btn-primary { background: var(--accent); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn-sm { min-height: 28px; padding: 0 8px; font-size: 0.72rem; }
.btn-export { background: #15803d; }
.btn-video { background: #6366f1; }

label.field-label {
    display: block;
    font-size: 0.72rem;
    color: var(--muted);
    margin-bottom: 2px;
}

select, input[type=number], input[type=text], textarea {
    width: 100%;
    min-height: 28px;
    background: #0f172a;
    border: 1px solid #3b5282;
    color: #fff;
    border-radius: 6px;
    padding: 0 8px;
    font-size: 0.78rem;
    margin-bottom: 4px;
}

textarea { min-height: 48px; resize: none; padding: 6px 8px; line-height: 1.35; }

input[type=range] {
    width: 100%;
    min-height: 22px;
    margin: 0;
    accent-color: var(--accent);
}

.ctrl-row {
    display: grid;
    grid-template-columns: 1fr 58px;
    gap: 6px;
    align-items: center;
    margin-bottom: 4px;
}

.ctrl-row .range-wrap { min-width: 0; }

.range-val {
    font-size: 0.7rem;
    color: var(--muted);
    line-height: 1.2;
    margin-bottom: 2px;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--surface2);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    margin-bottom: 4px;
}

.toggle-row input { width: 14px; height: 14px; accent-color: var(--accent); flex-shrink: 0; }

.video-status {
    font-size: 0.72rem;
    color: var(--muted);
    line-height: 1.35;
    padding: 6px 8px;
    background: var(--surface2);
    border-radius: 6px;
    border-left: 3px solid #6366f1;
    max-height: 52px;
    overflow: hidden;
}

.video-status.loaded { border-left-color: #86efac; color: #c4e8d0; }
.video-status.missing { border-left-color: #f87171; }

.video-transport { display: flex; gap: 6px; margin-top: 2px; }
.video-transport .btn { flex: 1; }

.formula-box {
    font-family: ui-monospace, monospace;
    font-size: 0.68rem;
    color: #a5b4fc;
    background: #0a1220;
    border-radius: 6px;
    padding: 6px 8px;
    line-height: 1.35;
    border-left: 3px solid #6366f1;
}

.academic-ref {
    margin: 6px 0 4px;
    font-size: 0.68rem;
    color: var(--muted);
    line-height: 1.35;
}
.academic-ref summary {
    cursor: pointer;
    color: #94a3b8;
    user-select: none;
}
.academic-ref summary:hover { color: #cbd5e1; }
.academic-ref dl { margin: 6px 0 0; padding: 0; }
.academic-ref dt {
    color: #a5b4fc;
    font-weight: 600;
    margin-top: 6px;
}
.academic-ref dt:first-child { margin-top: 0; }
.academic-ref dd { margin: 2px 0 0; }

.channel-map {
    font-size: 0.68rem;
    color: var(--muted);
    line-height: 1.3;
}

.main-pane {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) min-content;
    min-height: 0;
    min-width: 0;
    gap: var(--gap);
    flex: 1;
}

.main-top {
    flex-shrink: 0;
    display: flex;
    align-items: stretch;
    gap: var(--gap);
    min-height: var(--verdict-h);
}

.verdict {
    flex: 0 0 auto;
    min-width: 280px;
    max-width: 420px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.verdict.strong { background: #052e16; border-color: var(--strong); }
.verdict.moderate { background: #422006; border-color: var(--moderate); }
.verdict.weak { background: #1a2538; border-color: var(--weak); }
.verdict.none { background: #450a0a; border-color: var(--none); }

.verdict .score {
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.verdict.verdict-prominent {
    min-width: 300px;
    max-width: 480px;
}

.verdict.verdict-prominent .score {
    font-size: 1.65rem;
    min-width: 5.5rem;
    text-align: center;
}

.main-top .matrix-card h2,
.matrix-card h2 {
    font-size: 0.92rem;
}

.verdict .verdict-text { min-width: 0; flex: 1; }

.verdict .label {
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.2;
}

.verdict .hint {
    font-size: 0.68rem;
    color: var(--muted);
    line-height: 1.25;
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tabs-card {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    padding: 4px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    position: relative;
    overflow: visible;
}

.metric-tab-wrap {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

.metric-formula-tip {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 120;
    min-width: 260px;
    max-width: min(380px, 72vw);
    padding: 8px 10px;
    background: #0f172a;
    border: 1px solid #3b5282;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    color: #c7d6ef;
    font-size: 0.68rem;
    line-height: 1.45;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    pointer-events: none;
    text-align: left;
    white-space: normal;
}

.metric-formula-tip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #3b5282;
}

.metric-tab-wrap:hover .metric-formula-tip,
.metric-tab-wrap:focus-within .metric-formula-tip {
    display: block;
}

.metric-formula-tip .tip-title {
    display: block;
    font-family: Inter, system-ui, sans-serif;
    font-weight: 600;
    color: #eef5ff;
    margin-bottom: 4px;
    font-size: 0.72rem;
}

.metric-formula-tip .tip-line {
    display: block;
    color: #93c5fd;
}

.metric-formula-tip .tip-line.bm {
    color: #a5b4fc;
    margin-top: 3px;
}

.band-tabs, .metric-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: visible;
    width: 100%;
}

.band-tab, .metric-tab {
    flex-shrink: 0;
    padding: 5px 10px;
    border-radius: 16px;
    background: var(--surface2);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text);
}

.band-tab.active, .metric-tab.active {
    background: var(--accent);
    border-color: var(--accent);
}

.chart-card {
    height: 80%;
    max-height: 100%;
    align-self: start;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 6px;
    overflow: hidden;
}

.chart-toolbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    min-height: 28px;
}

.legend {
    display: flex;
    gap: 12px;
    font-size: 0.72rem;
    color: var(--muted);
    white-space: nowrap;
}

.legend i {
    display: inline-block;
    width: 18px;
    height: 3px;
    vertical-align: middle;
    margin-right: 4px;
}

.trace-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    font-size: 0.68rem;
    color: var(--muted);
}

.trace-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.trace-toggle input {
    width: 12px;
    height: 12px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.trace-toggle .dot {
    display: inline-block;
    width: 16px;
    height: 3px;
    border-radius: 1px;
    flex-shrink: 0;
}

.trace-toggle .dot.muse { background: #f97316; border-top: 2px dashed #f97316; height: 0; margin-top: 1px; }
.trace-toggle .dot.bm-f7 { background: #3b82f6; }
.trace-toggle .dot.bm-fp { background: #a78bfa; border-top: 2px dashed #a78bfa; height: 0; margin-top: 1px; }

.trace-toggle:not(:has(input:checked)) { opacity: 0.4; }

.legend .bm i { background: #3b82f6; }
.legend .muse i { background: #f97316; border-top: 2px dashed #f97316; height: 0; }

.video-fade-control {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    min-width: 140px;
    max-width: 220px;
    flex: 1;
}

.video-fade-control label {
    font-size: 0.68rem;
    color: var(--muted);
    white-space: nowrap;
}

.video-fade-control input[type=range] { flex: 1; min-width: 60px; }

.video-fade-control .range-val {
    font-size: 0.68rem;
    min-width: 28px;
    text-align: right;
    margin: 0;
}

.chart-click-hint {
    font-size: 0.65rem;
    color: #6d86b0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-box {
    flex: 1;
    min-height: 0;
    position: relative;
    background: #000;
    border-radius: 6px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-box .chart-inner {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    border-radius: 4px;
}

.chart-video-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    opacity: 0.4;
}

.chart-scrim {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(180deg, rgba(5,10,18,.12), rgba(5,10,18,.32));
    pointer-events: none;
}

.chart-inner canvas {
    position: relative;
    z-index: 2;
    background: transparent !important;
    cursor: crosshair;
}

.playhead-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(255,255,255,.85);
    box-shadow: 0 0 8px rgba(59,130,246,.8);
    z-index: 3;
    pointer-events: none;
    transform: translateX(-1px);
    display: none;
}

.playhead-line.visible { display: block; }

.matrix-card {
    height: auto;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px 6px 4px;
    overflow: visible;
    flex-shrink: 0;
}

.matrix-card h2 {
    flex-shrink: 0;
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 2px;
}

.matrix-wrap {
    flex: none;
    overflow: visible;
}

table.matrix {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.65rem;
    table-layout: fixed;
}

table.matrix th, table.matrix td {
    border: 1px solid var(--border);
    padding: 2px 4px;
    text-align: center;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

table.matrix th {
    background: var(--surface2);
    color: var(--muted);
    font-weight: 600;
}

table.matrix td { cursor: pointer; }
table.matrix td:hover { background: #1a2a42; }
table.matrix td.active, table.matrix tr.active td { outline: 1px solid var(--accent); }

.r-strong { color: var(--strong); font-weight: 700; }
.r-moderate { color: var(--moderate); font-weight: 600; }
.r-weak { color: var(--weak); }
.r-none { color: var(--none); }

table.matrix.metric-table th,
table.matrix.metric-table td { text-align: left; }
table.matrix.metric-table td.r-cell { text-align: center; }

.chart-box.chart-fullscreen-active {
    background: #050a12;
    padding: 12px;
}

.panel-hint {
    font-size: 0.65rem;
    color: #6d86b0;
    line-height: 1.3;
}

@media (max-height: 720px) {
    :root {
        --verdict-h: 46px;
        --sidebar-w: 248px;
    }
    .chart-card { height: 78%; }
}
