:root {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #111b2e;
  --surface-raised: #16233a;
  --surface-hover: #1c2b46;
  --border: #2b3b56;
  --border-strong: #405271;
  --text: #f4f7fb;
  --muted: #b6c2d4;
  --subtle: #8fa0b8;
  --primary: #4f83ff;
  --primary-hover: #6b97ff;
  --primary-soft: rgba(79, 131, 255, .14);
  --positive: #43d19e;
  --positive-soft: rgba(67, 209, 158, .12);
  --negative: #ff8a8a;
  --negative-soft: rgba(255, 138, 138, .1);
  --warning: #ffc766;
  --focus: #9db9ff;
  --shadow: 0 16px 48px rgba(0, 0, 0, .24);
  --body-glow: rgba(47, 91, 178, .16);
  --topbar-bg: rgba(11, 18, 32, .92);
  --topbar-border: rgba(64, 82, 113, .72);
  --nav-bg: rgba(17, 27, 46, .8);
  --input-bg: #0c1628;
  --input-focus-bg: #0d192d;
  --card-bg: linear-gradient(145deg, rgba(22, 35, 58, .95), rgba(17, 27, 46, .95));
  --hero-bg: linear-gradient(135deg, rgba(46, 87, 177, .34), rgba(17, 27, 46, .95) 64%);
  --hero-border: rgba(79, 131, 255, .45);
  --hero-orb: rgba(79, 131, 255, .1);
  --panel-bg: rgba(17, 27, 46, .88);
  --panel-header-bg: rgba(22, 35, 58, .65);
  --panel-footer-bg: rgba(11, 18, 32, .25);
  --row-border: rgba(43, 59, 86, .7);
  --row-hover: rgba(28, 43, 70, .48);
  --badge-bg: rgba(143, 160, 184, .11);
  --linked-border: rgba(67, 209, 158, .24);
  --help-border: rgba(79, 131, 255, .26);
  --toast-bg: #351b26;
  --toast-text: #ffd9dd;
  --toast-border: rgba(255, 138, 138, .45);
  --modal-scrim: rgba(2, 7, 16, .78);
  --warning-soft: rgba(255, 199, 102, .08);
  --danger: #bd3f4b;
  --danger-hover: #d34c58;
  --skip-text: #08101f;
  --radius: 16px;
  --radius-sm: 10px;
  --speed: 180ms;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-raised: #f9fbff;
  --surface-hover: #e9eff8;
  --border: #d5dfea;
  --border-strong: #a9b8cc;
  --text: #101828;
  --muted: #475467;
  --subtle: #667085;
  --primary: #285fd1;
  --primary-hover: #1e4fac;
  --primary-soft: rgba(40, 95, 209, .09);
  --positive: #047857;
  --positive-soft: rgba(4, 120, 87, .09);
  --negative: #b4233a;
  --negative-soft: rgba(180, 35, 58, .08);
  --warning: #9a6700;
  --focus: #1d4ed8;
  --shadow: 0 16px 44px rgba(31, 50, 81, .13);
  --body-glow: rgba(79, 131, 255, .1);
  --topbar-bg: rgba(248, 250, 253, .94);
  --topbar-border: rgba(180, 193, 211, .78);
  --nav-bg: rgba(255, 255, 255, .82);
  --input-bg: #ffffff;
  --input-focus-bg: #f9fbff;
  --card-bg: linear-gradient(145deg, #ffffff, #f9fbff);
  --hero-bg: linear-gradient(135deg, rgba(40, 95, 209, .13), #ffffff 68%);
  --hero-border: rgba(40, 95, 209, .3);
  --hero-orb: rgba(40, 95, 209, .08);
  --panel-bg: rgba(255, 255, 255, .95);
  --panel-header-bg: #f7f9fc;
  --panel-footer-bg: #fbfcfe;
  --row-border: rgba(213, 223, 234, .88);
  --row-hover: rgba(233, 239, 248, .65);
  --badge-bg: #e9eef5;
  --linked-border: rgba(4, 120, 87, .22);
  --help-border: rgba(40, 95, 209, .2);
  --toast-bg: #fff1f3;
  --toast-text: #7a1a2c;
  --toast-border: rgba(180, 35, 58, .28);
  --modal-scrim: rgba(16, 24, 40, .54);
  --warning-soft: rgba(154, 103, 0, .08);
  --danger: #b4233a;
  --danger-hover: #941b30;
  --skip-text: #ffffff;
}

* { box-sizing: border-box; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 80% 0%, var(--body-glow), transparent 34rem), var(--bg); color: var(--text); transition: background-color var(--speed), color var(--speed); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:active { opacity: .82; }
button:disabled { cursor: not-allowed; opacity: .45; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: fixed; left: 12px; top: -100px; z-index: 100; padding: 10px 14px; color: var(--skip-text); background: var(--focus); border-radius: 8px; }
.skip-link:focus { top: 12px; }

.app-shell { min-height: 100vh; }
.auth-shell { min-height:100vh; display:grid; place-items:center; padding:24px; }
.auth-card { width:min(440px, 100%); padding:clamp(24px, 5vw, 38px); border:1px solid var(--border); border-radius:18px; background:var(--surface); box-shadow:var(--shadow-lg); }
.auth-brand { margin-bottom:34px; }
.auth-card h1 { margin-bottom:8px; font-size:clamp(1.7rem, 5vw, 2.25rem); }
.auth-card > p:not(.eyebrow) { color:var(--muted); line-height:1.55; }
.auth-tabs { display:grid; grid-template-columns:1fr 1fr; gap:4px; margin:24px 0 18px; padding:4px; border:1px solid var(--border); border-radius:11px; background:var(--nav-bg); }
.auth-tab { min-height:44px; border:0; border-radius:8px; background:transparent; color:var(--muted); font-weight:750; }
.auth-tab.active { background:var(--surface); color:var(--text); box-shadow:var(--shadow-sm); }
.auth-card .dialog-field { margin-top:14px; }
.auth-show-password { margin-top:12px; }
.auth-submit { width:100%; margin-top:22px; }
.auth-error { margin-bottom:14px; padding:11px 12px; border:1px solid color-mix(in srgb, var(--negative) 45%, var(--border)); border-radius:9px; background:var(--negative-soft); color:var(--negative); font-size:.84rem; line-height:1.45; }
.account-control { display:flex; align-items:center; gap:8px; }
.account-name { max-width:130px; overflow:hidden; color:var(--muted); font-size:.78rem; font-weight:700; text-overflow:ellipsis; white-space:nowrap; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; min-height: 76px; align-items: center; justify-content: space-between; gap: 24px; padding: 12px clamp(16px, 4vw, 56px); border-bottom: 1px solid var(--topbar-border); background: var(--topbar-bg); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 12px; min-width: max-content; }
.brand-mark { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 12px; background: linear-gradient(145deg, #5d8dff, #315fce); color: white; box-shadow: 0 8px 20px rgba(49, 95, 206, .3); font-size: .78rem; font-weight: 800; letter-spacing: .04em; }
.brand strong { display: block; font-size: 1rem; }
.brand span { display: block; color: var(--subtle); font-size: .78rem; }
.primary-nav { display: flex; align-self: stretch; gap: 6px; padding: 4px; border: 1px solid var(--border); border-radius: 12px; background: var(--nav-bg); }
.nav-button { display: flex; min-height: 44px; align-items: center; gap: 8px; padding: 8px 14px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 650; transition: color var(--speed), background var(--speed); }
.nav-button:hover { color: var(--text); background: var(--surface-hover); }
.nav-button.active { color: white; background: var(--primary); box-shadow: 0 5px 16px rgba(79, 131, 255, .24); }
.nav-button svg, .button svg, .icon-button svg { width: 18px; height: 18px; flex: 0 0 auto; }
.header-status { display: flex; min-width: max-content; align-items: center; justify-content: flex-end; gap: 10px; }
.theme-toggle { display: inline-flex; min-height: 44px; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--muted); font-size: .8rem; font-weight: 700; transition: background var(--speed), border-color var(--speed), color var(--speed); }
.theme-toggle:hover { border-color: var(--border-strong); background: var(--surface-hover); color: var(--text); }
.theme-toggle svg { width: 18px; height: 18px; }
.save-indicator { display: flex; min-width: 92px; align-items: center; justify-content: flex-end; gap: 7px; color: var(--muted); font-size: .84rem; }
.save-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--positive); box-shadow: 0 0 0 4px var(--positive-soft); }
.save-indicator.saving .save-dot { background: var(--warning); animation: pulse 1s infinite; }
.save-indicator.error .save-dot { background: var(--negative); }

.page { width: min(1480px, 100%); margin: 0 auto; padding: 30px clamp(16px, 4vw, 56px) 64px; }
.context-bar { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 4px; color: var(--primary-hover); font-size: .76rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(1.75rem, 4vw, 2.55rem); line-height: 1.15; letter-spacing: -.035em; }
.page-intro { max-width: 670px; margin-bottom: 0; color: var(--muted); }
.scenario-tools { display: flex; flex-wrap: wrap; align-items: end; justify-content: flex-end; gap: 8px; }
.select-field { display: grid; gap: 5px; }
.select-field label { color: var(--muted); font-size: .76rem; font-weight: 700; }

input, select, textarea { min-height: 44px; border: 1px solid var(--border); border-radius: 9px; background: var(--input-bg); color: var(--text); transition: border-color var(--speed), background var(--speed), box-shadow var(--speed); }
input, textarea { width: 100%; padding: 8px 11px; }
textarea { resize: vertical; }
select { padding: 8px 34px 8px 11px; }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); background: var(--input-focus-bg); }
input[aria-invalid="true"] { border-color: var(--negative); box-shadow: 0 0 0 3px var(--negative-soft); }
.scenario-select { min-width: 210px; }
.button, .icon-button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 9px; font-weight: 700; transition: background var(--speed), border-color var(--speed), color var(--speed); }
.button { padding: 9px 14px; }
.button.primary { background: var(--primary); color: white; }
.button.primary:hover { background: var(--primary-hover); }
.button.secondary { border-color: var(--border); background: var(--surface); color: var(--text); }
.button.secondary:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.button.ghost { background: transparent; color: var(--muted); }
.button.ghost:hover { background: var(--surface-hover); color: var(--text); }
.button.danger { background: var(--danger); color: white; }
.button.danger:hover { background: var(--danger-hover); }
.button.small { min-height: 40px; padding: 7px 11px; font-size: .84rem; }
.icon-button { width: 44px; padding: 0; border-color: transparent; background: transparent; color: var(--subtle); }
.icon-button:hover { background: var(--surface-hover); color: var(--text); }
.icon-button.danger:hover { background: var(--negative-soft); color: var(--negative); }
.icon-button[draggable="true"] { cursor: grab; }
.icon-button[draggable="true"]:active { cursor: grabbing; }

.summary-grid { display: grid; grid-template-columns: minmax(280px, 1.35fr) repeat(2, minmax(190px, .8fr)); gap: 14px; margin-bottom: 24px; }
.summary-card { position: relative; overflow: hidden; min-height: 148px; padding: 22px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); box-shadow: 0 10px 28px rgba(0, 0, 0, .12); }
.summary-card.hero { border-color: var(--hero-border); background: var(--hero-bg); }
.summary-card.hero::after { position: absolute; right: -28px; bottom: -58px; width: 160px; height: 160px; border-radius: 50%; background: var(--hero-orb); content: ""; }
.summary-label { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; color: var(--muted); font-size: .84rem; font-weight: 700; }
.summary-label svg { width: 18px; height: 18px; }
.summary-value { margin: 0; font-size: clamp(1.55rem, 3vw, 2.35rem); font-variant-numeric: tabular-nums; letter-spacing: -.035em; }
.summary-note { margin: 7px 0 0; color: var(--subtle); font-size: .8rem; }
.positive { color: var(--positive) !important; }
.negative { color: var(--negative) !important; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: 30px 0 14px; }
.section-heading h2 { margin: 0; font-size: 1.15rem; }
.section-heading p { margin: 3px 0 0; color: var(--subtle); font-size: .84rem; }
.stage-list, .category-list { display: grid; gap: 16px; }
.panel { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-bg); box-shadow: 0 10px 24px rgba(0, 0, 0, .08); }
.panel.drag-over { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.panel[data-drop-category].drag-over { border-color: var(--primary); background: var(--primary-soft); }
.panel-header { display: flex; min-height: 70px; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 16px; border-bottom: 1px solid var(--border); background: var(--panel-header-bg); }
.panel-title-group { display: flex; min-width: 0; flex: 1; align-items: center; gap: 6px; }
.panel-number { display: grid; width: 30px; height: 30px; flex: 0 0 auto; place-items: center; border-radius: 9px; background: var(--primary-soft); color: var(--primary-hover); font-size: .78rem; font-weight: 850; }
.title-input { min-width: 100px; max-width: 470px; border-color: transparent; background: transparent; font-size: 1rem; font-weight: 760; }
.title-input:hover, .title-input:focus { border-color: var(--border-strong); background: var(--input-bg); }
.panel-actions { display: flex; align-items: center; gap: 2px; }
.panel-summary { min-width: 150px; margin-right: 8px; text-align: right; }
.panel-summary strong { display: block; font-size: 1rem; font-variant-numeric: tabular-nums; }
.panel-summary span { display: block; color: var(--subtle); font-size: .72rem; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--subtle); font-size: .7rem; font-weight: 800; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
.data-table td { padding: 10px 8px; border-bottom: 1px solid var(--row-border); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background var(--speed); }
.data-table tbody tr:hover { background: var(--row-hover); }
.data-table .name-col { width: 30%; padding-left: 16px; }
.data-table .enabled-col { width: 72px; padding-inline: 8px; text-align: center; }
.data-table .amount-col { width: 170px; }
.data-table .type-col { width: 145px; }
.data-table .actions-col { width: 142px; text-align: right; }
.money-wrap, .percent-wrap { position: relative; }
.money-wrap::before { position: absolute; left: 11px; top: 10px; z-index: 1; color: var(--subtle); content: "$"; }
.money-wrap input { padding-left: 25px; text-align: right; font-variant-numeric: tabular-nums; }
.percent-wrap::after { position: absolute; right: 11px; top: 10px; color: var(--subtle); content: "%"; }
.percent-wrap input { padding-right: 28px; text-align: right; }
.calculated-value { display: flex; min-height: 44px; align-items: center; justify-content: flex-end; padding: 8px 11px; color: var(--text); font-weight: 730; font-variant-numeric: tabular-nums; }
.calculated-value.linked { border: 1px solid var(--linked-border); border-radius: 9px; background: var(--positive-soft); color: var(--positive); }
.type-badge { display: inline-flex; min-height: 30px; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 999px; background: var(--badge-bg); color: var(--muted); font-size: .74rem; font-weight: 750; white-space: nowrap; }
.type-badge.link { background: var(--positive-soft); color: var(--positive); }
.row-actions { display: flex; justify-content: flex-end; gap: 1px; }
.row-actions .icon-button { width: 44px; min-height: 44px; }
.item-enabled-toggle { display: inline-grid; width: 44px; min-height: 44px; place-items: center; border-radius: 9px; cursor: pointer; }
.item-enabled-toggle:hover { background: var(--primary-soft); }
.item-enabled-toggle input, .estimator-grid .item-enabled-toggle input { width: 20px; height: 20px; min-height: 20px; margin: 0; accent-color: var(--primary); cursor: pointer; }
.data-table tr.item-disabled > td:not(.enabled-col):not(.actions-col) { opacity: .52; }
.data-table tr.item-disabled .name-col input { text-decoration: line-through; }
.data-table tr.item-disabled .calculated-value { color: var(--subtle); font-weight: 650; }
.summary-value-suffix { color: var(--subtle); font-size: .48em; font-weight: 650; }
.source-select { width: 100%; margin-top: 6px; color: var(--muted); font-size: .78rem; }
.field-error { min-height: 18px; margin: 3px 3px 0; color: var(--negative); font-size: .72rem; }
.calculation-select, .field-mode { width: 100%; margin-bottom: 6px; font-size: .78rem; }
.formula-editor { display: grid; grid-template-columns: minmax(150px, 1fr) auto; gap: 6px; min-width: 260px; }
.formula-editor .field-error { grid-column: 1 / -1; margin-top: -2px; }
.formula-input { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .8rem; }
.formula-insert { flex:0 0 28px; width:28px; min-height:28px; padding:0; border:1px solid var(--border); border-radius:6px; background:var(--surface); color:var(--primary); cursor:pointer; }
.formula-suggestions { position:fixed; z-index:10001; width:min(320px,calc(100vw - 16px)); max-height:240px; overflow-y:auto; padding:4px; border:1px solid var(--border); border-radius:8px; background:var(--surface); box-shadow:var(--shadow); }
.formula-suggestions [role="option"] { padding:7px 9px; border-radius:4px; cursor:pointer; }
.formula-suggestions [aria-selected="true"], .formula-suggestions [role="option"]:hover { background:var(--primary-soft); }
.formula-suggestions strong, .formula-suggestions small { display:block; overflow-wrap:anywhere; }
.formula-suggestions strong { color:var(--text); font-size:.8rem; }
.formula-suggestions small, .formula-no-match { color:var(--muted); font-size:.72rem; }
.insert-variable { max-width: 150px; font-size: .75rem; }
.resolved-hint, .field-hint, .status-note, .unit-label { display: block; margin-top: 3px; color: var(--subtle); font-size: .72rem; }
.calculated-value.has-error, .inline-error { color: var(--negative); }
.incomplete-badge { display: inline-flex; align-items: center; margin-left: 6px; padding: 3px 7px; border: 1px solid color-mix(in srgb, var(--warning) 38%, transparent); border-radius: 999px; background: var(--warning-soft); color: var(--warning); font-size: .68rem; font-weight: 800; white-space: nowrap; }
.summary-card.incomplete { border-color: color-mix(in srgb, var(--warning) 45%, var(--border)); }
.panel-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--panel-footer-bg); }
.footer-spacer { flex: 1; }
.running-balance { color: var(--muted); font-size: .82rem; }
.running-balance strong { margin-left: 8px; color: var(--text); font-size: .95rem; font-variant-numeric: tabular-nums; }
.empty-state { padding: 34px 20px; color: var(--muted); text-align: center; }
.empty-state p { margin-bottom: 12px; }

.estimator-table-scroll { overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-gutter: stable; }
.estimator-grid { table-layout: fixed; }
.estimator-grid th { position: relative; }
.estimator-grid th > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.column-resizer { position: absolute; top: 0; right: -5px; z-index: 2; width: 10px; height: 100%; border: 0; background: transparent; cursor: col-resize; touch-action: none; }
.column-resizer::after { position: absolute; top: 25%; right: 4px; width: 1px; height: 50%; background: var(--border-strong); content: ""; opacity: .45; }
.column-resizer:hover::after, .column-resizer:focus-visible::after { width: 2px; background: var(--primary); opacity: 1; }
.resizing-column, .resizing-column * { cursor: col-resize !important; user-select: none !important; }
.estimator-grid td { height: 52px; padding: 6px; vertical-align: middle; }
.estimator-grid tbody tr.drag-over { background: var(--primary-soft); box-shadow: inset 0 2px 0 var(--primary); }
.estimator-grid .labour-component-row > td { height: 72px; border-bottom: 1px solid var(--row-border); background: color-mix(in srgb, var(--primary-soft) 17%, var(--panel-bg)); }
.estimator-grid .labour-component-row:hover > td { background: var(--row-hover); }
.labour-branch-cell { text-align: center; }
.labour-branch { display: inline-block; width: 15px; height: 17px; margin-top: -8px; border-bottom: 1.5px solid var(--subtle); border-left: 1.5px solid var(--subtle); border-radius: 0 0 0 5px; }
.labour-name { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.labour-name strong { font-size: .79rem; font-weight: 750; }
.labour-kind { padding: 2px 6px; border-radius: 999px; background: var(--badge-bg); color: var(--muted); font-size: .66rem; font-weight: 700; }
.labour-comment { display: flex; min-width: 0; align-items: center; gap: 4px; color: var(--subtle); font-size: .66rem; }
.labour-comment input { min-width: 0; min-height: 28px; flex: 1; padding: 2px 4px; font-size: .72rem; }
.labour-line-field { display: grid; min-width: 0; gap: 2px; }
.labour-line-field > span { color: var(--subtle); font-size: .64rem; font-weight: 750; white-space: nowrap; }
.labour-line-field input, .labour-line-field select { width: 100%; min-width: 0; min-height: 32px; padding: 3px 5px; font-size: .76rem; font-variant-numeric: tabular-nums; }
.labour-line-field select { padding-right: 18px; }
.labour-unit, .labour-not-used { color: var(--muted); font-size: .77rem; }
.labour-diy-toggle { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.estimator-grid .labour-diy-toggle input { width: 18px; height: 18px; min-height: 18px; margin: 0; accent-color: var(--primary); }
.labour-diy-toggle span { color: var(--muted); font-size: .7rem; white-space: nowrap; }
.estimator-grid .labour-total { font-variant-numeric: tabular-nums; }
.labour-total strong { display: block; color: var(--text); font-size: .82rem; white-space: nowrap; }
.labour-total small { display: block; color: var(--muted); font-size: .63rem; white-space: nowrap; }
.labour-remove { width: 34px; min-height: 40px; }
.estimator-grid input, .estimator-grid select { min-height: 40px; border-color: transparent; border-radius: 6px; background: transparent; }
.estimator-grid input:hover, .estimator-grid select:hover { border-color: var(--border); background: var(--input-bg); }
.estimator-grid input:focus, .estimator-grid select:focus { border-color: var(--primary); background: var(--input-focus-bg); }
.estimator-grid .description { min-width: 0; padding-left: 10px; }
.estimator-grid .enabled-col { padding-inline: 8px; }
.estimate-description-wrap { display: flex; align-items: center; gap: 6px; }
.estimate-description-wrap input { min-width: 0; flex: 1; }
.research-match-button { position: relative; display: inline-grid; width: 36px; min-width: 36px; height: 36px; place-items: center; border: 1px solid transparent; border-radius: 50%; background: var(--primary-soft); color: var(--primary-hover); }
.research-match-button svg { width: 18px; height: 18px; }
.research-tooltip { position: fixed; z-index: 10000; max-width: 260px; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow); font-size: .72rem; line-height: 1.35; pointer-events: none; }
.estimator-grid .total { text-align: right; }
.estimator-grid .calculated-value { min-height: 40px; padding-inline: 5px; white-space: nowrap; }
.estimator-grid .row-actions .icon-button { width: 28px; min-height: 40px; }
.estimator-grid .field-error:empty { display: none; }
.estimator-field { display: flex; min-width: 0; align-items: center; gap: 4px; }
.estimator-field > .field-mode { width: 68px; flex: 0 0 68px; margin: 0; padding: 6px 22px 6px 6px; }
.estimator-field > input { min-width: 0; }
.estimator-field > .field-error { display: none; }
.estimator-field.formula-mode .formula-editor { display: flex; min-width: 0; flex: 1; gap: 4px; }
.estimator-field.formula-mode .formula-editor input { min-width: 105px; }
.estimator-field.formula-mode .insert-variable { width: 38px; padding: 4px; color: transparent; }
.estimator-field.formula-mode .resolved-hint { display: none; }
.contingency-input { text-align: right; font-variant-numeric: tabular-nums; }
.estimate-help { display: flex; align-items: start; gap: 12px; margin-bottom: 20px; padding: 14px 16px; border: 1px solid var(--help-border); border-radius: 12px; background: var(--primary-soft); color: var(--muted); }
.estimate-help svg { width: 20px; height: 20px; flex: 0 0 auto; color: var(--primary-hover); }
.estimate-help p { margin: 0; font-size: .86rem; }

.calculator-summary { display: grid; grid-template-columns: repeat(4, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.calculator-summary .summary-card { min-height: 138px; }
.calculator-layout { display: grid; grid-template-columns: minmax(390px, 520px) minmax(0, 1fr); align-items: start; gap: 18px; }
.calculator-controls { overflow: visible; }
.calculator-panel-header { display: flex; min-height: 72px; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 18px; border-bottom: 1px solid var(--border); background: var(--panel-header-bg); }
.calculator-panel-header h2 { margin: 0; font-size: 1.08rem; }
.calculator-panel-header .eyebrow { margin-bottom: 3px; }
.calculator-controls fieldset { min-width: 0; margin: 0; padding: 19px 18px 20px; border: 0; border-bottom: 1px solid var(--border); }
.calculator-controls fieldset:last-child { border-bottom: 0; }
.calculator-controls legend { padding: 0; color: var(--text); font-size: .88rem; font-weight: 800; }
.calculator-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px 14px; margin-top: 14px; }
.calculator-field { display: grid; grid-template-columns: minmax(105px, .8fr) minmax(125px, 1fr); align-items: start; gap: 10px; }
.calculator-field > span { padding-top: 12px; color: var(--muted); font-size: .77rem; font-weight: 730; }
.calculator-input { min-width: 0; }
.calculator-input input, .calculator-input select { width: 100%; }
.calculator-input small, .calculator-toggle small { display: block; margin-top: 4px; color: var(--subtle); font-size: .68rem; line-height: 1.35; }
.fieldset-help { margin: 10px 0 0; padding: 10px 12px; border-left: 3px solid var(--primary); background: var(--primary-soft); color: var(--muted); font-size: .75rem; line-height: 1.45; }
.override-fieldset .calculator-input input:not([value="0"]) { border-color: var(--primary); background: var(--primary-soft); }
.calculator-toggles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 14px; }
.calculator-toggle { display: flex; min-height: 54px; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; transition: border-color var(--speed), background var(--speed); }
.calculator-toggle:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.calculator-toggle input { width: 20px; min-height: 20px; margin-top: 2px; accent-color: var(--primary); }
.calculator-toggle strong { display: block; font-size: .78rem; }
.calculator-results { display: grid; min-width: 0; gap: 16px; }
.calculator-callout { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 20px; border-color: var(--hero-border); background: var(--hero-bg); }
.calculator-callout h2 { margin-bottom: 7px; font-size: clamp(1.35rem, 3vw, 2rem); }
.calculator-callout p:not(.eyebrow) { max-width: 760px; margin: 0; color: var(--muted); font-size: .84rem; }
.calculator-actions { display: flex; flex: 0 0 auto; flex-direction: column; gap: 8px; }
.stage-breakdown { display: grid; gap: 13px; padding: 18px; }
.stage-breakdown-row > div:first-child { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; font-size: .82rem; }
.stage-breakdown-row span { color: var(--muted); font-variant-numeric: tabular-nums; }
.stage-bar { overflow: hidden; height: 8px; border-radius: 999px; background: var(--badge-bg); }
.stage-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--positive)); }
.calculator-line-list details { border-bottom: 1px solid var(--row-border); }
.calculator-line-list details:last-child { border-bottom: 0; }
.calculator-line-list summary { display: flex; min-height: 62px; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 18px; cursor: pointer; list-style-position: inside; transition: background var(--speed); }
.calculator-line-list summary:hover { background: var(--row-hover); }
.calculator-line-list summary span { min-width: 0; flex: 1; }
.calculator-line-list summary strong, .calculator-line-list summary small { display: block; }
.calculator-line-list summary small { margin-top: 3px; color: var(--subtle); font-size: .72rem; }
.calculator-line-list summary b { flex: 0 0 auto; font-size: .9rem; font-variant-numeric: tabular-nums; }
.calculator-line-list details > p { margin: 0; padding: 0 18px 10px 38px; color: var(--muted); font-size: .79rem; }
.calculation-disclosure { margin: 0 18px 12px 38px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.calculation-disclosure p { margin: 0; color: var(--muted); font-size: .73rem; line-height: 1.5; }
.calculation-disclosure p + p { margin-top: 5px; }
.calculation-disclosure .override-note { color: var(--primary-hover); }
.line-override-editor { margin: 0 18px 14px 38px; padding: 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-footer-bg); }
.line-override-editor.enabled { border-color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
.line-override-switch { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.line-override-switch input { width: 20px; min-height: 20px; margin-top: 1px; accent-color: var(--primary); }
.line-override-switch strong, .line-override-switch small { display: block; }
.line-override-switch strong { font-size: .8rem; }
.line-override-switch small { margin-top: 2px; color: var(--subtle); font-size: .68rem; }
.line-override-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; margin-top: 12px; }
.line-override-grid label { min-width: 0; }
.line-override-grid label > span, .custom-item-fields label > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .7rem; font-weight: 760; }
.line-override-grid input, .line-override-grid select { width: 100%; min-height: 40px; }
.line-override-grid small { display: block; margin-top: 4px; color: var(--subtle); font-size: .65rem; line-height: 1.3; }
.line-override-grid :disabled { cursor: not-allowed; opacity: .55; }
.line-override-editor .danger-text { margin-top: 11px; color: var(--negative); }
.calculator-line-list details.excluded > summary { background: var(--panel-footer-bg); }
.calculator-line-list details.excluded > summary strong { text-decoration: line-through; }
.line-meta { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 18px 14px 38px; }
.line-meta span { padding: 4px 7px; border-radius: 999px; background: var(--badge-bg); color: var(--subtle); font-size: .67rem; font-weight: 700; }
.calculator-disclaimer { margin: 0; padding: 4px 4px 0; color: var(--subtle); font-size: .74rem; line-height: 1.5; }
.all-cost-lines > summary { display: flex; min-height: 78px; align-items: center; justify-content: space-between; gap: 14px; padding: 16px 18px; cursor: pointer; background: var(--panel-header-bg); }
.all-cost-lines > summary strong { display: block; margin-top: 3px; font-size: 1.02rem; }
.all-cost-lines[open] > summary { border-bottom: 1px solid var(--border); }
.custom-item-builder { display: grid; grid-template-columns: minmax(190px,.65fr) minmax(360px,1.35fr) auto; align-items: end; gap: 16px; padding: 18px; border-bottom: 1px solid var(--border); background: var(--primary-soft); }
.custom-item-builder h3 { margin: 2px 0 5px; font-size: 1rem; }
.custom-item-builder p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: .73rem; line-height: 1.45; }
.custom-item-fields { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; }
.custom-item-fields input, .custom-item-fields select { width: 100%; min-height: 40px; }
.custom-item-fields small { display: block; margin-top: 3px; color: var(--subtle); font-size: .65rem; }
.custom-item-fields .custom-scope { grid-column: span 2; }

.variable-toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) 190px auto; gap: 14px; padding: 16px; overflow: visible; align-items: end; }
.search-field { display: grid; gap: 5px; }
.search-field label { color: var(--muted); font-size: .76rem; font-weight: 700; }
.tag-filters { display: flex; grid-column: 1 / -1; flex-wrap: wrap; align-items: center; gap: 7px; color: var(--subtle); font-size: .78rem; }
.tag-chip { min-height: 34px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--muted); }
.tag-chip.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-hover); }
.variable-intro { display: flex; gap: 10px; margin: 14px 0; padding: 12px 14px; border: 1px solid var(--help-border); border-radius: 12px; background: var(--primary-soft); color: var(--muted); }
.variable-intro svg { width: 20px; flex: 0 0 auto; }
.variable-intro p { margin: 0; }
.variable-intro code { color: var(--text); }
.variables-list { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-bg); }
.variables-table { table-layout: fixed; }
.variables-table th { padding: 8px 7px; }
.variables-table td { padding: 7px; vertical-align: middle; }
.variables-table input, .variables-table select { min-height: 40px; padding-top: 6px; padding-bottom: 6px; }
.variables-table .variable-key { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-weight: 750; }
.variables-table .variable-description { color: var(--muted); font-size: .78rem; }
.variables-table th:nth-child(1) { width: 11%; }
.variables-table th:nth-child(2) { width: 14%; }
.variables-table th:nth-child(3) { width: 9%; }
.variables-table th:nth-child(4) { width: 8%; }
.variables-table th:nth-child(5) { width: 25%; }
.variables-table th:nth-child(6) { width: 8%; }
.variables-table th:nth-child(7) { width: 11%; }
.variables-table th:nth-child(8) { width: 10%; }
.variables-table th:nth-child(9) { width: 4%; }
.variables-table .field-mode { margin-bottom: 0; padding-right: 24px; }
.variables-table .formula-editor { grid-template-columns: minmax(110px, 1fr) 112px; min-width: 0; }
.variables-table .insert-variable { max-width: 112px; padding-right: 24px; }
.variables-table .field-error:empty { display: none; }
.variables-table .unit-label { display: inline; margin: 0; }
.variables-table .actions-col { width: auto; padding-inline: 2px; }
.scope-toggle, .check-field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .8rem; }
.scope-toggle input, .check-field input { width: 20px; min-height: 20px; accent-color: var(--primary); }
.resolved-value { display: inline-block; font-variant-numeric: tabular-nums; }
.inline-error { display: block; max-width: 240px; margin-top: 4px; font-size: .72rem; }
.row-incomplete { background: var(--warning-soft); }

.utility-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.utility-bar .button { color: var(--muted); }
.loading-screen { display: grid; min-height: 100vh; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.loading-screen .brand-mark { width: 54px; height: 54px; }
.toast { position: fixed; right: 22px; bottom: 82px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); padding: 13px 16px; border: 1px solid var(--toast-border); border-radius: 10px; background: var(--toast-bg); color: var(--toast-text); box-shadow: var(--shadow); }
.research-launcher { position: fixed; right: 22px; bottom: 22px; z-index: 55; display: grid; width: 50px; height: 50px; place-items: center; border: 1px solid var(--hero-border); border-radius: 50%; background: var(--primary); color: white; box-shadow: 0 10px 28px rgba(40, 95, 209, .34); font-size: 1.25rem; font-weight: 850; }
.research-launcher:hover { background: var(--primary-hover); transform: translateY(-1px); }
.research-drawer { position: fixed; inset: 0 0 0 auto; width: min(620px, 100%); max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0; border: 0; border-left: 1px solid var(--border-strong); background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
.research-drawer::backdrop { background: var(--modal-scrim); backdrop-filter: blur(3px); }
.research-drawer-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 22px 17px; border-bottom: 1px solid var(--border); background: var(--topbar-bg); }
.research-drawer-header h2 { margin: 0 0 3px; }
.research-drawer-header p { margin-bottom: 0; color: var(--muted); font-size: .84rem; }
.research-drawer-header .eyebrow { margin-bottom: 3px; color: var(--primary-hover); }
.research-drawer-header #close-research { font-size: 1.5rem; }
.research-toolbar { display: grid; gap: 6px; padding: 17px 22px; border-bottom: 1px solid var(--border); }
.research-toolbar > label { color: var(--muted); font-size: .76rem; font-weight: 750; }
.research-toolbar > div { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.research-results { display: grid; align-content: start; gap: 12px; height: calc(100dvh - 178px); overflow-y: auto; padding: 17px 22px 30px; }
.research-card { padding: 16px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); }
.research-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.research-card > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.research-card h3 { margin: 2px 0 0; font-size: 1rem; }
.research-card-meta { color: var(--subtle); font-size: .7rem; font-weight: 700; text-transform: uppercase; }
.research-cost { color: var(--positive); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.research-cost strong, .research-cost span { display: block; }
.research-cost span { margin-top: 2px; color: var(--subtle); font-size: .72rem; font-weight: 650; }
.research-card > p, .research-card details p { margin: 12px 0 0; color: var(--muted); font-size: .84rem; white-space: pre-line; }
.research-card details { margin-top: 11px; color: var(--muted); font-size: .8rem; }
.research-card summary { cursor: pointer; font-weight: 700; }
.research-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }
.research-tags span { padding: 3px 7px; border-radius: 999px; background: var(--badge-bg); color: var(--muted); font-size: .7rem; }
.research-card footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 13px; padding-top: 11px; border-top: 1px solid var(--row-border); color: var(--subtle); font-size: .78rem; }
.research-card footer > div { display: flex; align-items: center; }
.research-card footer a { color: var(--primary-hover); }
.research-source-links { display: grid !important; gap: 4px; min-width: 0; }
.research-source-links a, .research-source-links span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.research-empty { padding: 48px 20px; color: var(--muted); text-align: center; }
.research-editor-dialog { width: min(720px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; }
.cost-range-grid { grid-template-columns: repeat(3, 1fr); }
.dialog { width: min(480px, calc(100% - 32px)); padding: 28px; border: 1px solid var(--border-strong); border-radius: 18px; background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: var(--modal-scrim); backdrop-filter: blur(3px); }
.dialog h2 { margin-bottom: 8px; }
.dialog-field { display: grid; gap: 6px; margin-top: 20px; }
.dialog-field label { color: var(--muted); font-size: .82rem; font-weight: 750; }
.dialog-field select { width: 100%; }
.dialog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-field { margin-top: 20px; }
.dialog-warning { padding: 12px; border-left: 3px solid var(--warning); background: var(--warning-soft); color: var(--muted); font-size: .86rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

.audit-kind-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.scope-intro, .scope-context, .scope-run, .scope-history { margin-bottom: 16px; padding: 18px 20px; }
.scope-intro { background: var(--hero-bg); }
.scope-intro h2, .scope-context h2, .scope-run h2 { margin: 2px 0 5px; font-size: 1.15rem; }
.scope-intro p, .scope-context p, .scope-run p { max-width: 75ch; margin: 0; color: var(--muted); font-size: .86rem; }
.scope-context { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.scope-run-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.scope-history { display: flex; align-items: center; gap: 12px; }
.scope-history label { color: var(--muted); font-size: .8rem; font-weight: 750; }
.scope-history select { max-width: 520px; flex: 1; }
.scope-results { display: grid; gap: 10px; }
.scope-results .section-heading { margin: 2px 0 4px; }
.scope-finding { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 15px 18px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--panel-bg); }
.scope-finding h3 { margin: 5px 0 3px; font-size: .96rem; }
.scope-finding p { margin: 0; color: var(--muted); font-size: .82rem; }
.scope-finding .scope-matches { margin-top: 5px; color: var(--subtle); }
.scope-finding-main { min-width: 0; flex: 1; }
.scope-suggested-match { display: grid; gap: 2px; max-width: 520px; margin-top: 10px; padding: 9px 11px; border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border)); border-radius: 8px; background: var(--primary-soft); }
.scope-suggested-match span { color: var(--primary-hover); font-size: .68rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.scope-suggested-match strong { color: var(--text); font-size: .85rem; overflow-wrap: anywhere; }
.scope-suggested-match small { color: var(--muted); font-size: .74rem; }
.scope-finding .scope-stale-match { margin-top: 8px; color: var(--warning); }
.scope-decision { display: inline-block; margin-top: 8px; color: var(--positive); font-size: .76rem; font-weight: 750; }
.scope-decided { opacity: .76; }
.scope-finding-actions { display: flex; min-width: 220px; align-items: flex-end; flex-direction: column; gap: 8px; }
.scope-finding-actions details { width: 100%; }
.scope-finding-actions details summary { color: var(--primary-hover); font-size: .78rem; cursor: pointer; text-align: right; }
.scope-finding-actions details label { display: grid; gap: 3px; margin-top: 8px; color: var(--muted); font-size: .72rem; }
.scope-finding-actions details select, .scope-finding-actions details input { width: 100%; min-height: 38px; }
.scope-finding-actions details > div { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; margin-top: 8px; }
.scope-covered { margin-top: 8px; }
.scope-covered > summary { padding: 14px 18px; color: var(--muted); font-weight: 750; cursor: pointer; }
.scope-covered .scope-finding { border-radius: 0; border-right: 0; border-bottom: 0; border-left: 0; }
.scope-fallback { padding: 12px 16px; color: var(--warning); font-size: .83rem; }
.scope-dialog { width: min(720px, calc(100vw - 32px)); }
.scope-dialog .scope-step h3 { margin-top: 20px; font-size: 1rem; }
.scope-step[hidden] { display: none; }
.needs-pricing { color: var(--warning); font-size: .74rem; font-weight: 800; }

@keyframes pulse { 50% { opacity: .4; } }
@media (max-width: 1200px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .primary-nav { order: 3; width: 100%; }
  .nav-button { flex: 1; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-card.hero { grid-column: 1 / -1; }
  .calculator-summary { grid-template-columns: 1fr 1fr; }
  .calculator-summary .summary-card.hero { grid-column: auto; }
  .calculator-layout { grid-template-columns: 1fr; }
  .custom-item-builder { grid-template-columns: 1fr; align-items: stretch; }
  .custom-item-builder > .button { justify-self: start; }
  .context-bar { align-items: flex-start; flex-direction: column; }
  .scenario-tools { justify-content: flex-start; }
  .variable-toolbar { grid-template-columns: 1fr 180px; }
  .variable-toolbar > .button { grid-column: 1 / -1; }
  .data-table { display: block; }
  .estimator-table-scroll { overflow: visible; }
  .estimator-grid { width: 100% !important; }
  .estimator-grid colgroup { display: none; }
  .data-table thead { display: none; }
  .data-table tbody { display: grid; }
  .data-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 10px; border-bottom: 1px solid var(--border); }
  .data-table tr:last-child { border-bottom: 0; }
  .data-table td, .data-table .enabled-col, .data-table .name-col, .data-table .amount-col, .data-table .type-col, .data-table .actions-col, .estimator-grid .description, .estimator-grid .quantity, .estimator-grid .unit, .estimator-grid .rate, .estimator-grid .contingency, .estimator-grid .total { width: auto; padding: 7px; border: 0; text-align: left; }
  .variables-table { table-layout: auto; }
  .variables-table td { min-width: 0; }
  .data-table td::before { display: block; margin-bottom: 4px; color: var(--subtle); content: attr(data-label); font-size: .66rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
  .data-table .name-col { grid-column: 1 / -1; }
  .data-table .actions-col { grid-column: 1 / -1; }
  .row-actions { justify-content: flex-start; }
  .estimator-grid .row-actions .icon-button { width: 44px; }
  .calculated-value { justify-content: flex-start; }
  .labour-component-row { padding-left: 18px !important; box-shadow: inset 3px 0 var(--primary); }
  .estimator-grid .labour-component-row > td { height: auto; background: transparent; }
  .labour-branch-cell { display: none; }
  .data-table .labour-description { grid-column: 1 / -1; }
  .labour-comment { max-width: 460px; }
  .labour-component-row .tags, .labour-component-row .quantity, .labour-component-row .unit, .labour-component-row .rate, .labour-component-row .contingency, .labour-component-row .total { min-width: 0; }
  .labour-component-row .labour-line-field > span { display: none; }
  .labour-component-row .actions-col { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .scope-context, .scope-finding { align-items: stretch; flex-direction: column; }
  .scope-finding-actions { min-width: 0; align-items: stretch; }
  .scope-finding-actions details summary { text-align: left; }
  .scope-history { align-items: stretch; flex-direction: column; }
  .topbar { padding: 10px 14px; }
  .brand span, .save-indicator span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  .save-indicator { min-width: 24px; }
  .theme-toggle { width: 44px; padding: 0; }
  .theme-toggle span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  .page { padding: 22px 12px 48px; }
  .scenario-tools, .select-field { width: 100%; }
  .scenario-select { width: 100%; }
  .scenario-tools .button { flex: 1; }
  .summary-grid { grid-template-columns: 1fr; }
  .calculator-summary { grid-template-columns: 1fr; }
  .summary-card.hero { grid-column: auto; }
  .panel-header { align-items: flex-start; flex-wrap: wrap; }
  .panel-title-group { width: 100%; }
  .panel-summary { order: 3; min-width: 0; margin-left: 42px; text-align: left; }
  .panel-actions { margin-left: auto; }
  .data-table tr { grid-template-columns: 1fr; }
  .data-table .name-col, .data-table .actions-col { grid-column: auto; }
  .panel-footer .button { flex: 1 1 calc(50% - 8px); }
  .footer-spacer { display: none; }
  .running-balance { width: 100%; padding-top: 5px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading .button { width: 100%; }
  .primary-nav { overflow-x: auto; gap: 3px; padding: 3px; }
  .nav-button { min-width: 72px; flex:0 0 auto; flex-direction: column; gap: 2px; padding: 5px 4px; font-size: .68rem; line-height: 1.15; text-align: center; }
  .nav-button svg { width: 16px; height: 16px; }
  .variable-toolbar, .dialog-grid { grid-template-columns: 1fr; }
  .variable-toolbar > .button, .tag-filters { grid-column: auto; }
  .formula-editor { grid-template-columns: 1fr; min-width: 0; }
  .calculator-fields, .calculator-toggles { grid-template-columns: 1fr; }
  .calculator-field { grid-template-columns: 1fr; gap: 4px; }
  .calculator-field > span { padding-top: 0; }
  .calculator-callout { align-items: stretch; flex-direction: column; }
  .calculator-actions { width: 100%; }
  .calculator-actions .button { width: 100%; }
  .calculation-disclosure { margin-left: 18px; }
  .calculator-line-list details > p, .line-meta { padding-left: 18px; }
  .line-override-editor { margin-left: 18px; }
  .line-override-grid, .custom-item-fields { grid-template-columns: 1fr; }
  .custom-item-fields .custom-scope { grid-column: auto; }
  .custom-item-builder > .button { width: 100%; }
  .formula-editor .field-error { grid-column: auto; }
  .insert-variable { max-width: none; width: 100%; }
  .research-launcher { right: 14px; bottom: 14px; }
  .research-drawer-header, .research-toolbar { padding-inline: 16px; }
  .research-results { padding-inline: 16px; }
  .research-toolbar > div, .cost-range-grid { grid-template-columns: 1fr; }
  .research-card > header, .research-card footer { align-items: flex-start; flex-direction: column; }
  .research-cost { text-align: left; white-space: normal; }
  .labour-comment { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
