:root {
    --ink: #15231c;
    --muted: #66736c;
    --paper: #f4f2eb;
    --surface: #fffefa;
    --line: #d7dbd5;
    --green: #176b45;
    --green-light: #e4f0e9;
    --amber: #a96918;
    --amber-light: #f8edd9;
    --blue: #235f77;
    --red: #a34335;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    color: var(--ink);
    font-family: "Avenir Next", "Gill Sans", sans-serif;
    background: var(--paper);
}

button, input, select, textarea { font: inherit; }
button, select, input[type="range"] { cursor: pointer; }

.topbar {
    height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 clamp(18px, 3vw, 44px);
    border-bottom: 1px solid #293b32;
    background: #13231b;
    color: white;
}

.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark { width: 36px; aspect-ratio: 1; display: grid; place-items: center; border: 1px solid #718078; border-radius: 6px; font: 1rem Georgia, serif; }
.brand > span:last-child { display: grid; }
.brand strong { font: 1rem Georgia, serif; }
.brand small { color: #aab6b0; font-size: 0.61rem; letter-spacing: 0.12em; text-transform: uppercase; }
.run-status { display: flex; align-items: center; gap: 8px; color: #c9d2cd; font-size: 0.72rem; }
.run-status span { width: 7px; height: 7px; border-radius: 50%; background: #65c391; box-shadow: 0 0 0 4px rgba(101, 195, 145, 0.12); }
.run-status strong { color: white; }
.topbar-actions, .review-page-actions { display: flex; align-items: center; gap: 14px; }
.topbar-actions > a { color: white; font-size: 0.72rem; font-weight: 800; }
.review-page-actions .button { display: inline-grid; place-items: center; text-decoration: none; }

.experimental-notice { display: grid; grid-template-columns: 120px 1fr; gap: 18px; padding: 13px clamp(18px, 3vw, 44px); border-bottom: 2px solid var(--amber); background: #fff5df; }
.experimental-notice strong { color: #70470f; font-size: 0.72rem; text-transform: uppercase; }
.experimental-notice p { margin: 0; color: #5d4a2d; font-size: 0.72rem; line-height: 1.5; }

.app-shell { min-height: calc(100vh - 68px); display: grid; grid-template-columns: 252px minmax(0, 1fr); }
.workflow { display: flex; flex-direction: column; padding: 34px 18px 22px; border-right: 1px solid var(--line); background: #eae9e2; }
.workflow-heading { padding: 0 10px 28px; }
.workflow-heading p, .eyebrow { margin: 0 0 6px; color: var(--green); font-size: 0.64rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.workflow-heading h1 { margin: 0 0 2px; font: 1.65rem Georgia, serif; }
.workflow-heading > span { color: var(--muted); font-size: 0.74rem; }
.steps { display: grid; gap: 5px; }
.step { width: 100%; min-height: 62px; display: grid; grid-template-columns: 34px 1fr; grid-template-rows: auto auto; align-items: center; padding: 9px 10px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted); text-align: left; }
.step:hover { background: rgba(255, 255, 255, 0.5); }
.step.is-active { border-color: #cbd2cc; background: var(--surface); color: var(--ink); box-shadow: 0 4px 14px rgba(25, 39, 31, 0.05); }
.step > span { grid-row: 1 / 3; width: 25px; height: 25px; display: grid; place-items: center; border: 1px solid #aeb8b2; border-radius: 50%; font-size: 0.6rem; font-weight: 800; }
.step.is-active > span { border-color: var(--green); background: var(--green); color: white; }
.step strong { font-size: 0.76rem; }
.step small { font-size: 0.65rem; }
.accountability-note { margin-top: auto; padding: 15px; border-top: 2px solid var(--green); background: #dde6df; }
.accountability-note strong { font-size: 0.72rem; }
.accountability-note p { margin: 5px 0 0; color: #55635c; font-size: 0.68rem; line-height: 1.45; }

.workspace { min-width: 0; }
.workspace-header { min-height: 100px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px clamp(22px, 4vw, 58px); border-bottom: 1px solid var(--line); background: rgba(255, 254, 250, 0.74); }
.workspace-header h2 { margin: 0; font: 1.65rem Georgia, serif; }
.header-actions { display: flex; gap: 8px; }
.button { min-height: 40px; padding: 0 15px; border: 1px solid var(--line); border-radius: 6px; font-size: 0.76rem; font-weight: 800; }
.button-quiet { background: transparent; color: var(--muted); }
.button-primary { border-color: var(--green); background: var(--green); color: white; }
.button-primary:hover { background: #0e5636; }
.button-review { border-color: #85958c; background: white; color: var(--ink); }
.button:disabled { cursor: not-allowed; opacity: 0.45; }

.step-panel { display: none; padding: clamp(22px, 4vw, 48px) clamp(22px, 4vw, 58px) 52px; animation: reveal 0.28s ease both; }
.step-panel.is-active { display: block; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.setup-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(340px, 1.1fr); gap: 18px; }
.form-section, .table-section, .stress-controls, .decision-form, .brief-preview { border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.form-section { padding: clamp(20px, 3vw, 30px); }
.section-heading, .comparison-summary { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
h3 { margin: 0; font: 1.28rem Georgia, serif; }
.evidence-badge { padding: 5px 8px; border-radius: 4px; font-size: 0.6rem; font-weight: 800; text-transform: uppercase; }
.evidence-badge.verified { background: var(--green-light); color: var(--green); }
.evidence-badge.caution { background: var(--amber-light); color: var(--amber); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 14px; margin-top: 28px; }
label { display: grid; gap: 7px; color: #55625b; font-size: 0.68rem; font-weight: 800; }
input, select, textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #cbd1cc; border-radius: 5px; outline: none; background: white; color: var(--ink); }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 107, 69, 0.1); }
input[readonly] { cursor: default; background: #f0f1ed; color: var(--muted); }
.baseline-list { display: grid; margin-top: 18px; border-top: 1px solid var(--line); }
.baseline-list label { grid-template-columns: 1fr 142px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.baseline-list label > span:first-child { display: grid; gap: 2px; color: var(--ink); }
.baseline-list small { color: var(--amber); font-size: 0.6rem; font-weight: 700; }
.baseline-list label:first-child small { color: var(--green); }
.unit-input { position: relative; }
.unit-input input { padding-right: 38px; text-align: right; }
.unit-input em { position: absolute; right: 10px; top: 14px; color: var(--muted); font-size: 0.65rem; font-style: normal; }
.source-link { display: inline-block; margin-top: 16px; color: var(--blue); font-size: 0.67rem; font-weight: 800; }
.assumption-strip { display: grid; grid-template-columns: minmax(180px, 0.5fr) minmax(300px, 1fr) auto; align-items: center; gap: 28px; margin-top: 18px; padding: 18px 22px; border-left: 3px solid var(--amber); background: #edece5; }
.assumption-strip p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: 0.72rem; line-height: 1.55; }
.text-button { padding: 0; border: 0; border-bottom: 1px solid currentColor; background: none; color: var(--green); font-size: 0.7rem; font-weight: 800; }

.comparison-summary { align-items: center; margin-bottom: 22px; }
.comparison-summary h3 { font-size: 1.55rem; }
.budget-lock { display: grid; gap: 2px; padding-left: 18px; border-left: 2px solid var(--green); }
.budget-lock span { color: var(--muted); font-size: 0.62rem; text-transform: uppercase; }
.budget-lock strong { font-size: 0.9rem; }
.scenario-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.scenario-card { position: relative; min-height: 210px; padding: 20px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); overflow: hidden; }
.scenario-card.is-recommended { border-color: var(--green); box-shadow: inset 0 3px 0 var(--green); }
.scenario-rank { position: absolute; right: 16px; top: 15px; color: #c9cec9; font: 2.2rem Georgia, serif; }
.scenario-card h4 { margin: 28px 0 7px; font: 1.16rem Georgia, serif; }
.scenario-card > p { min-height: 46px; margin: 0; color: var(--muted); font-size: 0.68rem; line-height: 1.5; }
.recommend-label { color: var(--green); font-size: 0.58rem; font-weight: 900; letter-spacing: 0.1em; text-transform: uppercase; }
.allocation-bar { height: 8px; display: flex; margin: 17px 0 9px; overflow: hidden; border-radius: 2px; }
.allocation-bar span:nth-child(1) { background: var(--green); }
.allocation-bar span:nth-child(2) { background: var(--blue); }
.allocation-bar span:nth-child(3) { background: #b8a47b; }
.allocation-key { display: flex; flex-wrap: wrap; gap: 5px 10px; color: var(--muted); font-size: 0.58rem; }
.allocation-key b { color: var(--ink); }
.table-section { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.72rem; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { background: #ecece6; color: #4e5c55; font-size: 0.62rem; text-transform: uppercase; }
th:first-child, td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
td strong { color: var(--green); }

.stress-controls { display: grid; grid-template-columns: 0.8fr 1fr 1fr; align-items: center; gap: 35px; padding: 24px 28px; }
.stress-controls-four { grid-template-columns: minmax(160px, 0.8fr) repeat(2, minmax(150px, 1fr)); gap: 20px; }
.stress-controls label span { display: flex; justify-content: space-between; }
input[type="range"] { min-height: 0; padding: 0; accent-color: var(--green); box-shadow: none; }
.stress-callout { margin: 16px 0; padding: 14px 18px; border-left: 3px solid var(--green); background: var(--green-light); color: #375448; font-size: 0.72rem; }
.stress-callout.is-warning { border-color: var(--amber); background: var(--amber-light); color: #654a26; }
.rank-pill { display: inline-grid; min-width: 26px; height: 22px; place-items: center; border-radius: 4px; background: var(--green-light); color: var(--green); font-weight: 900; }
.preset-section { margin-top: 24px; }
.preset-checks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.preset-check { padding: 15px; border: 1px solid var(--line); background: rgba(255,255,255,0.48); }
.preset-check strong { display: block; margin-bottom: 4px; font-size: 0.74rem; }
.preset-check span { color: var(--muted); font-size: 0.65rem; }

.record-grid { display: grid; grid-template-columns: minmax(300px, 0.72fr) minmax(420px, 1.28fr); gap: 18px; }
.decision-form, .brief-preview { padding: clamp(22px, 3vw, 32px); }
.decision-form { display: grid; align-content: start; gap: 18px; }
.decision-form h3 { margin-bottom: 7px; font-size: 1.5rem; }
textarea { resize: vertical; line-height: 1.45; }
.check-field { grid-template-columns: 18px 1fr; align-items: start; font-weight: 600; line-height: 1.45; }
.check-field input { width: 16px; min-height: 16px; margin: 1px 0 0; accent-color: var(--green); }
.brief-preview { min-height: 520px; border-top: 4px solid var(--green); }
.brief-preview .brief-meta { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.6rem; text-transform: uppercase; }
.brief-preview h2 { margin: 25px 0 8px; font: 1.75rem Georgia, serif; }
.brief-preview h3 { margin: 24px 0 7px; padding-top: 16px; border-top: 1px solid var(--line); font: 1rem Georgia, serif; }
.brief-preview h4 { margin: 18px 0 7px; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.brief-preview p, .brief-preview li { color: #46544d; font-size: 0.72rem; line-height: 1.55; }
.brief-preview ul { padding-left: 18px; }
.brief-preview a { color: var(--blue); }
.brief-preview .experimental-notice, .review-content .experimental-notice { display: block; padding: 12px 15px; border: 2px solid var(--amber); }
.brief-preview .experimental-notice p, .review-content .experimental-notice p { margin: 4px 0 0; }
.brief-table-wrap { max-width: 100%; overflow-x: auto; }
.brief-table { width: 100%; border-collapse: collapse; font-size: 0.62rem; }
.brief-table th, .brief-table td { padding: 8px; border: 1px solid var(--line); text-align: left; vertical-align: top; white-space: normal; }
.brief-table th { background: #ecece6; }
.provenance-table { min-width: 820px; font-size: 0.58rem; }
.export-bar { display: flex; align-items: center; justify-content: space-between; gap: 25px; margin-top: 16px; padding: 15px 18px; background: #24372d; color: white; }
.export-bar p { margin: 0; color: #bec9c3; font-size: 0.68rem; }
.export-bar strong { color: white; }
.export-actions, .review-toolbar-actions { display: flex; gap: 8px; }

dialog { width: min(720px, calc(100vw - 30px)); padding: 0; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--surface); box-shadow: 0 24px 70px rgba(0,0,0,0.25); }
dialog::backdrop { background: rgba(18, 30, 24, 0.62); }
.dialog-heading { display: flex; justify-content: space-between; padding: 24px 28px 18px; border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin: 0; font: 1.5rem Georgia, serif; }
.dialog-heading button { border: 0; background: none; color: var(--muted); font-size: 1.5rem; }
.rules-content { padding: 24px 28px 30px; }
.review-dialog { width: min(1080px, calc(100vw - 30px)); max-height: calc(100vh - 30px); }
.review-toolbar { position: sticky; top: 0; z-index: 2; align-items: center; background: var(--surface); }
.review-toolbar-actions { align-items: center; }
.review-content { padding: 24px clamp(18px, 4vw, 48px) 48px; }
.review-content .decision-brief-document { max-width: 900px; margin: 0 auto; }
.rule { padding: 13px 0; border-bottom: 1px solid var(--line); }
.rule:last-child { border: 0; }
.rule strong { display: block; font-size: 0.72rem; }
.rule code { display: block; margin-top: 5px; color: var(--muted); font-size: 0.67rem; white-space: normal; }

.evidence-review-shell { width: min(1180px, calc(100% - 36px)); margin: 0 auto; padding: 30px 0 60px; }
.evidence-review-shell > .experimental-notice { margin-bottom: 26px; border: 2px solid var(--amber); }
.evidence-review-heading { display: flex; justify-content: space-between; gap: 30px; margin-bottom: 20px; }
.evidence-review-heading h1 { margin: 0 0 8px; font: 2rem Georgia, serif; }
.evidence-review-heading > div > p:not(.eyebrow) { max-width: 680px; margin: 0; color: var(--muted); font-size: 0.78rem; line-height: 1.55; }
.evidence-review-summary { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; max-width: 420px; }
.evidence-review-summary div { min-width: 112px; padding: 9px 11px; border: 1px solid var(--line); background: var(--surface); }
.evidence-review-summary strong { display: block; color: var(--green); font-size: 1rem; }
.evidence-review-summary span { color: var(--muted); font-size: 0.58rem; text-transform: uppercase; }
.version-control-notice { margin-bottom: 18px; padding: 15px 18px; border-left: 4px solid var(--red); background: #f6e8e4; }
.version-control-notice strong { font-size: 0.78rem; }
.version-control-notice p { margin: 4px 0 0; color: #6b4a43; font-size: 0.7rem; line-height: 1.5; }
.evidence-records { display: grid; gap: 14px; }
.labs-index-shell { width: min(1080px, calc(100% - 36px)); margin: 0 auto; padding: 54px 0; }
.labs-index-heading { max-width: 760px; margin-bottom: 30px; }
.labs-index-heading h1 { margin: 0 0 10px; font: 2.3rem Georgia, serif; }
.labs-index-heading > p:last-child { color: var(--muted); line-height: 1.6; }
.labs-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.lab-entry { min-width: 0; padding: 28px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface); }
.lab-entry h2 { margin: 0 0 10px; font: 1.45rem Georgia, serif; }
.lab-entry > p:not(.eyebrow) { min-height: 70px; color: var(--muted); font-size: 0.78rem; line-height: 1.55; }
.lab-entry .button { display: inline-grid; place-items: center; text-decoration: none; }
.evidence-record { border: 1px solid var(--line); background: var(--surface); }
.evidence-record > header { display: flex; justify-content: space-between; gap: 20px; padding: 11px 16px; border-bottom: 1px solid var(--line); background: #e8e9e3; }
.evidence-record > header span { color: var(--green); font-size: 0.65rem; font-weight: 900; text-transform: uppercase; }
.evidence-record > header code { color: var(--muted); font-size: 0.68rem; }
.evidence-record-facts { display: grid; grid-template-columns: repeat(4, 1fr); }
.evidence-record-facts > div { min-width: 0; padding: 12px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.evidence-record-facts > div:nth-child(4n), .evidence-record-facts > div.wide { border-right: 0; }
.evidence-record-facts .wide { grid-column: 1 / -1; }
.evidence-record-facts span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 0.56rem; font-weight: 800; text-transform: uppercase; }
.evidence-record-facts strong { display: block; overflow-wrap: anywhere; font-size: 0.7rem; line-height: 1.45; }
.reviewer-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; margin: 0; padding: 15px; border: 0; }
.reviewer-fields legend { padding: 15px 0 0; color: var(--green); font-size: 0.62rem; font-weight: 900; text-transform: uppercase; }
.reviewer-fields .wide { grid-column: 1 / -1; }

@media (max-width: 920px) {
    .app-shell { grid-template-columns: 1fr; }
    .workflow { padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
    .workflow-heading, .accountability-note { display: none; }
    .steps { grid-template-columns: repeat(4, 1fr); }
    .step { min-height: 45px; grid-template-columns: 26px 1fr; padding: 6px; }
    .step small { display: none; }
    .setup-grid, .record-grid { grid-template-columns: 1fr; }
    .stress-controls { grid-template-columns: 1fr 1fr; }
    .stress-controls > div { grid-column: 1 / -1; }
}

@media (max-width: 650px) {
    .topbar { height: 58px; }
    .run-status { font-size: 0; }
    .run-status strong { font-size: 0.68rem; }
    .topbar-actions > a { display: none; }
    .experimental-notice { grid-template-columns: 1fr; gap: 4px; }
    .app-shell { min-height: calc(100vh - 58px); }
    .steps { gap: 2px; }
    .step { display: flex; justify-content: center; }
    .step strong { display: none; }
    .workspace-header { align-items: flex-end; padding: 16px 18px; }
    .workspace-header h2 { font-size: 1.2rem; }
    .header-actions .button-quiet { display: none; }
    .step-panel { padding: 20px 16px 38px; }
    .field-grid, .scenario-cards, .preset-checks, .stress-controls { grid-template-columns: 1fr; }
    .baseline-list label { grid-template-columns: 1fr 120px; }
    .assumption-strip { grid-template-columns: 1fr; gap: 10px; }
    .scenario-card { min-height: 190px; }
    .comparison-summary { align-items: flex-start; }
    .record-grid { grid-template-columns: minmax(0, 1fr); }
    .brief-preview { min-height: 0; }
    .export-bar { align-items: stretch; flex-direction: column; }
    .export-actions { flex-direction: column; }
    .review-toolbar { align-items: flex-start; }
    .review-toolbar-actions { flex-direction: column-reverse; align-items: flex-end; }
    .review-page-actions .button-review { display: none; }
    .evidence-review-heading { display: block; }
    .evidence-review-summary { justify-content: flex-start; margin-top: 18px; }
    .evidence-record-facts, .reviewer-fields { grid-template-columns: 1fr; }
    .evidence-record-facts > div, .evidence-record-facts > div:nth-child(4n) { border-right: 0; }
    .reviewer-fields .wide { grid-column: auto; }
    .labs-grid { grid-template-columns: 1fr; }
    .lab-entry > p:not(.eyebrow) { min-height: 0; }
}

@media print {
    .topbar, .workflow, .workspace-header, .decision-form, .export-bar, .review-toolbar, .review-page-actions { display: none !important; }
    .app-shell, .record-grid { display: block; }
    .step-panel { padding: 0; }
    .step-panel:not([data-panel="record"]) { display: none; }
    .step-panel[data-panel="record"] { display: block; }
    .brief-preview { border: 0; }
    dialog.review-dialog[open] { position: static; width: auto; max-height: none; border: 0; }
    dialog.review-dialog[open] .review-content { padding: 0; }
    .evidence-review-shell { width: auto; padding: 0; }
    .evidence-review-heading h1 { font-size: 22px; }
    .evidence-review-summary { display: none; }
    .evidence-record { break-inside: avoid; }
    .evidence-record-facts { grid-template-columns: repeat(4, 1fr); }
    .reviewer-fields { grid-template-columns: 1fr 1fr; }
    .reviewer-fields .wide { grid-column: 1 / -1; }
    input, select, textarea { border-color: #999; }
}