/* =========================================================================
   Analysis extras: the mission envelope (envelope.js), the condensation
   requirement (analysis.js), view factors from geometry (physics.js) and
   the impedance and CFD tools (exporting.js).

   Loaded after builder.css. Colours are tokens.css variables only, so the
   light and dark themes both follow from the tokens.
   ========================================================================= */

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- requirements: kind first */

.req-row.req-v2 { grid-template-columns: minmax(190px, 1.25fr) repeat(3, minmax(0, 1fr)) minmax(130px, 1.1fr) 28px; }
.req-row.req-v2 > * { grid-column: auto; grid-row: auto; }
.req-row.req-v2 > .req-kind { grid-column: 1; grid-row: 1; }
.req-row.req-v2 > .req-name { grid-column: 2; grid-row: 1; }
.req-row.req-v2 > .req-target { grid-column: 3 / 5; grid-row: 1; }
.req-row.req-v2 > :nth-child(4) { grid-column: 1; grid-row: 2; }
.req-row.req-v2 > :nth-child(5) { grid-column: 2; grid-row: 2; }
.req-row.req-v2 > :nth-child(6) { grid-column: 3; grid-row: 2; }
.req-row.req-v2 > :nth-child(7) { grid-column: 4; grid-row: 2; }
.req-row.req-v2.dew > .req-dew { grid-column: 1 / 3; grid-row: 2; }
.req-row.req-v2.dew > :nth-child(5) { grid-column: 3; grid-row: 2; }
.req-row.req-v2.dew > :nth-child(6) { grid-column: 4; grid-row: 2; }
.req-row.req-v2 > .req-now { grid-column: 5; grid-row: 1 / 3; align-self: center; }
.req-row.req-v2 > [data-rq-del] { grid-column: 6; grid-row: 1; align-self: start; margin-top: 4px; }
.req-row.req-v2 > .req-notes { grid-column: 1 / -1; grid-row: 3; }
.req-dew-value { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 6px 0 7px; }
.req-dew-value b { font-family: var(--mono); font-weight: 600; color: var(--ink); font-size: 13px; }
.req-dew-value span { font-size: 12px; color: var(--ink-soft); }
.req-notes li .linkish { margin-left: 6px; font-weight: 600; }
@media (max-width: 1100px) {
    .req-row.req-v2 > *, .req-row.req-v2.dew > * { grid-column: auto; grid-row: auto; }
    .req-row.req-v2 > .req-notes { grid-column: 1 / -1; }
}

/* ---------------------------------------------------------------- inputs: "also sets" picker */

.in-also { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.in-also select { max-width: 320px; }

/* ---------------------------------------------------------------- envelope: analysis and mission */

.env-analysis { margin-bottom: 8px; }
.role-tag.msn-tag { background: var(--cool-pale); color: var(--cool-deep); border-color: var(--cool-line); }
.msn-held { color: var(--cool-deep); }
.msn-sub { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); }

.msn-drives { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.msn-drives .msn-sub { margin-bottom: 4px; }
.msn-drive {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center;
    padding: 5px 8px; border: 1px solid var(--rule); border-radius: var(--radius);
    background: var(--field); font-size: 13px; cursor: pointer;
}
.msn-drive.on { border-color: var(--cool-line); background: var(--cool-pale); }
.msn-drive small { color: var(--ink-soft); font-size: 11.5px; }
.msn-drive span small { font-family: var(--mono); margin-left: 4px; }

.msn-scroll { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--field); }
.msn-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.msn-table th, .msn-table td { padding: 4px 6px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: middle; }
.msn-table thead th {
    font-size: 11px; font-weight: 600; color: var(--ink-soft); background: var(--panel);
    white-space: nowrap; border-bottom: 1px solid var(--rule-firm);
}
.msn-table thead th small { display: block; font-family: var(--mono); font-weight: 400; color: var(--ink-faint); }
.msn-table th.num, .msn-table td.num { text-align: right; }
.msn-table .msn-n { width: 26px; text-align: center; font-family: var(--mono); color: var(--ink-soft); font-weight: 500; }
.msn-dur-head label { margin-right: 6px; }
.msn-dur-head select { padding: 1px 22px 1px 6px; font-size: 11.5px; height: auto; min-height: 0; width: auto; }
.msn-cell {
    width: 100%; min-width: 64px; box-sizing: border-box; font-family: var(--mono); font-size: 12.5px;
    text-align: right; padding: 4px 6px;
}
.msn-cell::placeholder { color: var(--ink-faint); font-family: var(--sans); font-style: italic; }
.msn-cell[aria-invalid="true"] { border-color: var(--danger); background: var(--bad-pale); color: var(--danger-deep); }
.msn-act { white-space: nowrap; width: 1%; text-align: right; }
.msn-act .icon-btn { margin: 0; }
.msn-act .icon-btn:disabled { opacity: .3; }
.msn-table tbody tr:hover td, .msn-table tbody tr:hover th { background: var(--panel); }
.msn-table tfoot td { border-bottom: 0; padding: 6px 8px; }
.msn-total { float: right; font-size: 12px; color: var(--ink-soft); font-family: var(--mono); }
.msn-errors {
    list-style: none; margin: 8px 0 0; padding: 6px 10px; font-size: 12px; color: var(--danger);
    border: 1px solid var(--bad-line); background: var(--bad-pale); border-radius: var(--radius);
}
.msn-errors li::before { content: "✕"; margin-right: 6px; }
.msn-preview-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 14px 0 4px; }
.msn-preview-head .hint { margin: 0; font-size: 11.5px; }
.msn-preview { width: 100%; height: auto; display: block; background: var(--field); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 12px; }
.msn-preview .msn-line { fill: none; stroke: var(--trace-1); stroke-width: 2; stroke-linejoin: round; }
.msn-preview .msn-line.point { stroke: var(--ink-faint); stroke-dasharray: 4 3; stroke-width: 1.5; }
.msn-preview .msn-lane-label { font-size: 10.5px; font-weight: 600; fill: var(--ink-mid); }
.msn-band { fill: var(--ink); opacity: .045; }
.msn-seg-label { font-family: var(--mono); font-size: 9.5px; fill: var(--ink-faint); }
.msn-preview .tick, .msn-when .tick { font-family: var(--mono); font-size: 9.5px; fill: var(--ink-faint); }
.msn-preview .axis, .msn-when .axis { stroke: var(--rule-firm); }
.msn-preview .grid, .msn-when .grid { stroke: var(--rule); stroke-width: .7; }
.msn-preview .axis-label { font-size: 10.5px; fill: var(--ink-soft); }

.msn-results td b { font-family: var(--mono); font-weight: 600; }
.msn-results th small { display: block; font-weight: 400; color: var(--ink-faint); font-size: 10.5px; }
.msn-at { display: block; font-size: 10.5px; color: var(--ink-soft); font-family: var(--sans); font-weight: 400; white-space: nowrap; }
.env-kv .msn-at { text-align: right; }
.msn-when .limit { stroke: var(--danger); stroke-dasharray: 4 3; stroke-width: 1.5; }
.msn-when .limit-label { font-size: 10.5px; fill: var(--danger); }
.msn-when .axis-label { font-size: 11px; fill: var(--ink-mid); }
.env-dot.bad { fill: var(--danger); }

/* ---------------------------------------------------------------- view factors from geometry (physics.js) */

.vf-wrap { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.vf-top { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; }
.vf-top .field { margin: 0; min-width: 120px; }
.vf-top .vf-close { margin-left: auto; padding-bottom: 7px; }
.vf-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
@media (max-width: 900px) { .vf-grid { grid-template-columns: minmax(0, 1fr); } }
.vf-surfaces { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.vf-surface { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--field); padding: 8px 10px; }
.vf-surface.invalid { border-color: var(--bad-line); background: var(--bad-pale); }
.vf-surface .field { margin-bottom: 6px; }
.vf-surface-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 6px; font-size: 13px; }
.vf-surface-head select { width: auto; min-width: 150px; }
.vf-surface-head .check { font-size: 12px; display: inline-flex; gap: 4px; align-items: center; }
.vf-swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.vf-area { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--ink-soft); }
.vf-xyz { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.vf-xyz-label { font-size: 12px; color: var(--ink-mid); min-width: 92px; }
.vf-xyz label { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--ink-soft); }
.vf-xyz input, .vf-verts input { width: 76px; font-family: var(--mono); font-size: 12px; text-align: right; padding: 3px 5px; }
.vf-verts { border-collapse: collapse; font-size: 12px; }
.vf-verts th { font-size: 11px; font-weight: 600; color: var(--ink-soft); text-align: left; padding: 2px 4px; }
.vf-verts td { padding: 2px 4px; }
.vf-verts td.num { font-family: var(--mono); color: var(--ink-soft); }
.vf-row-tools { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: baseline; margin-top: 4px; }
.vf-row-tools .hint { margin: 0; font-size: 11.5px; }
.vf-faces { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px; max-height: 180px; overflow: auto; }
.vf-face { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 6px; font-size: 12px; align-items: center;
           padding: 3px 6px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--panel); }
.vf-face small { grid-column: 2; color: var(--ink-soft); font-size: 11px; }
.vf-err { color: var(--danger); font-size: 12px; margin: 4px 0 0; }
.vf-problems { list-style: none; margin: 0; padding: 6px 10px; font-size: 12px; color: var(--danger);
               border: 1px solid var(--bad-line); background: var(--bad-pale); border-radius: var(--radius); }
.vf-problems li::before { content: "✕"; margin-right: 6px; }
.vf-preview { margin: 0; position: sticky; top: 0; }
.vf-preview svg { width: 100%; height: auto; display: block; background: var(--canvas); border: 1px solid var(--rule); border-radius: var(--radius); }
.vf-preview figcaption { font-size: 11px; color: var(--ink-soft); margin-top: 4px; line-height: 1.4; }
.vf-poly { fill-opacity: .28; stroke-width: 1.2; stroke-linejoin: round; }
.vf-normal { stroke-width: 1.6; }
.vf-head { fill: var(--ink-mid); }
.vf-label { font-family: var(--mono); font-size: 11px; font-weight: 700; fill: var(--ink); paint-order: stroke; stroke: var(--canvas); stroke-width: 3px; }
.vf-axis { stroke: var(--ink-faint); stroke-width: 1; }
.vf-axis-label { font-family: var(--mono); font-size: 9.5px; fill: var(--ink-soft); }
.vf-preview .tick { font-family: var(--mono); font-size: 9.5px; fill: var(--ink-faint); }

.vf-result { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--rule); padding-top: 10px; }
.vf-mats { display: flex; flex-wrap: wrap; gap: 18px; }
.vf-mats > div { min-width: 0; overflow-x: auto; }
.vf-matrix, .vf-areas { border-collapse: collapse; font-size: 12px; }
.vf-matrix th, .vf-matrix td, .vf-areas th, .vf-areas td { padding: 3px 8px; border-bottom: 1px solid var(--rule); text-align: left; white-space: nowrap; }
.vf-matrix thead th, .vf-areas thead th { font-size: 11px; color: var(--ink-soft); font-weight: 600; border-bottom-color: var(--rule-firm); }
.vf-matrix th.num, .vf-matrix td.num, .vf-areas .num { text-align: right; font-family: var(--mono); }
.vf-matrix td small { display: block; color: var(--ink-faint); font-size: 10px; }
.vf-matrix td.diag { color: var(--ink-faint); }
.vf-matrix td.sum { font-weight: 600; background: var(--panel); }
.vf-matrix td.sum.open { color: var(--amber-deep); background: var(--amber-pale); }
.vf-checks { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.vf-checks .ok { color: var(--ok); }
.vf-checks .ok::before { content: "✓ "; }
.vf-checks .warn { color: var(--amber-deep); }
.vf-checks .warn::before { content: "⚠ "; }
.vf-matrix thead th.num, .vf-areas thead th.num { font-family: var(--sans); }

/* ---------------------------------------------------------------- impedance and CFD (exporting.js) */

.tools-modal { width: min(940px, 100%); height: min(860px, 100%); display: flex; flex-direction: column; }
.tools-modal .modal-body { flex: 1; min-height: 0; }
.tools-tabs { display: flex; gap: 0; padding: 0 18px; border-bottom: 1px solid var(--rule); background: var(--panel); }
.tools-tabs .mode { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 9px 14px; font-size: 13px; color: var(--ink-soft); }
.tools-tabs .mode.active { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.tools-modal .pgroup { margin-bottom: 18px; }
.tools-modal .run-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin: 8px 0; }
.tools-modal .run-row .hint { margin: 0; }
.zth-kpis { margin: 12px 0 8px; }
.zth-figure { margin: 0; }
.zth-chart { width: 100%; height: auto; display: block; background: var(--field); border: 1px solid var(--rule); border-radius: var(--radius); }
.zth-chart .grid { stroke: var(--rule); stroke-width: .8; }
.zth-chart .grid.minor { stroke-width: .4; opacity: .7; }
.zth-chart .axis { stroke: var(--rule-firm); }
.zth-chart .tick { font-family: var(--mono); font-size: 10px; fill: var(--ink-faint); }
.zth-chart .axis-label { font-size: 11px; fill: var(--ink-soft); }
.zth-chart .zth-dot { fill: var(--warm); }
.zth-chart .zth-fit { fill: none; stroke: var(--trace-1); stroke-width: 1.8; }
.zth-chart .zth-rth { stroke: var(--ink-faint); stroke-dasharray: 4 3; }
.zth-chart .zth-rth-label { font-size: 10px; fill: var(--ink-soft); }
.zth-figure figcaption { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; }
.zth-key { display: inline-block; width: 14px; height: 0; margin-right: -8px; vertical-align: middle; }
.zth-key.computed { height: 7px; width: 7px; border-radius: 50%; background: var(--warm); }
.zth-key.fit { border-top: 2px solid var(--trace-1); }
.zth-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) { .zth-pair { grid-template-columns: 1fr; } }
.zth-table { border-collapse: collapse; font-size: 12px; margin: 4px 0; }
.zth-table th, .zth-table td { padding: 2px 4px; border-bottom: 1px solid var(--rule); }
.zth-table thead th { font-size: 11px; color: var(--ink-soft); font-weight: 600; text-align: left; border-bottom-color: var(--rule-firm); }
.zth-table th.num { text-align: right; }
.zth-table tbody th { font-family: var(--mono); color: var(--ink-soft); font-weight: 500; }
.zth-table input { width: 110px; font-family: var(--mono); font-size: 12px; text-align: right; padding: 3px 6px; }
.zth-table input[aria-invalid="true"], .cfd-table input[aria-invalid="true"] { border-color: var(--danger); background: var(--bad-pale); }
.zth-problems { list-style: none; margin: 6px 0; padding: 0; font-size: 12px; color: var(--danger); }
.zth-problems li::before { content: "✕"; margin-right: 6px; }
.tools-modal .chart-title { font-size: 12px; font-weight: 600; color: var(--ink-mid); margin-bottom: 4px; }

.tools-modal textarea.mono { width: 100%; box-sizing: border-box; font-family: var(--mono); font-size: 12px; min-height: 84px; resize: vertical; }
.cfd-map { margin-bottom: 8px; }
.cfd-scroll { border: 1px solid var(--rule); border-radius: var(--radius); max-height: 340px; overflow: auto; }
.cfd-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.cfd-table th, .cfd-table td { padding: 3px 6px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: middle; }
.cfd-table thead th { position: sticky; top: 0; background: var(--panel); font-size: 11px; color: var(--ink-soft); font-weight: 600; z-index: 1; }
.cfd-table .num { text-align: right; font-family: var(--mono); }
.cfd-table select { width: 100%; min-width: 120px; font-size: 12px; }
.cfd-table input[type=number] { width: 96px; font-family: var(--mono); font-size: 12px; text-align: right; }
.cfd-table tr.bad td { background: var(--bad-pale); }
.cfd-table tr.off td { opacity: .5; }
.cfd-table.compact { width: auto; margin: 4px 0 6px; }
.cfd-check { font-size: 11.5px; min-width: 150px; }
.cfd-bad { color: var(--danger); }
.cfd-ok { color: var(--ok); }
.cfd-ok::before { content: "✓ "; }
.tools-modal .run-row > button, .tools-modal .run-row > .file-btn { flex: 0 0 auto; width: auto; }
.cfd-table thead th.num { font-family: var(--sans); }
