:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --sidebar: #172033;
    --sidebar-hover: #202c44;
    --sidebar-text: #d9e1ef;
    --text: #172033;
    --muted: #667085;
    --muted-2: #98a2b3;
    --border: #e2e7ef;
    --border-strong: #d0d7e2;
    --primary: #315efb;
    --primary-hover: #244bd7;
    --primary-soft: #edf2ff;
    --success: #16865b;
    --success-soft: #eaf8f2;
    --warning: #a96800;
    --warning-soft: #fff7e6;
    --danger: #c43636;
    --danger-soft: #fff0f0;
    --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.04);
    --radius: 14px;
    --radius-sm: 9px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.45;
}
button, input, select, textarea { font: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .35rem; font-size: clamp(1.8rem, 3vw, 2.45rem); line-height: 1.12; letter-spacing: -.035em; }
h2 { margin-bottom: .25rem; font-size: 1.08rem; letter-spacing: -.01em; }

.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    background: var(--sidebar);
    color: var(--sidebar-text);
}
.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 6px 9px 22px;
    color: white;
    text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 37px;
    height: 37px;
    border-radius: 10px;
    background: linear-gradient(145deg, #4a73ff, #294fd8);
    color: white;
    font-weight: 800;
    letter-spacing: -.04em;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.2);
}
.brand strong { display: block; font-size: .98rem; letter-spacing: -.01em; }
.brand small { display: block; margin-top: 1px; color: #8fa0bc; font-size: .72rem; }
.main-nav { display: flex; flex-direction: column; gap: 4px; }
.main-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 43px;
    padding: 8px 10px;
    border-radius: 9px;
    color: #b9c5d7;
    font-weight: 550;
    text-decoration: none;
    transition: background .15s ease, color .15s ease;
}
.main-nav a:hover { background: var(--sidebar-hover); color: white; text-decoration: none; }
.main-nav a.active { background: #263552; color: white; }
.nav-glyph {
    display: grid;
    place-items: center;
    flex: 0 0 25px;
    width: 25px;
    height: 25px;
    border: 1px solid #4b5871;
    border-radius: 7px;
    color: #9eb0cd;
    font-size: .7rem;
    font-weight: 800;
}
.main-nav a.active .nav-glyph { background: #315efb; border-color: #315efb; color: white; }
.nav-count {
    margin-left: auto;
    min-width: 22px;
    padding: 1px 6px;
    border-radius: 20px;
    background: #315efb;
    color: white;
    font-size: .72rem;
    text-align: center;
}
.sidebar-footer { margin-top: auto; padding: 16px 10px 2px; border-top: 1px solid #2b3850; color: #aab7ca; }
.sidebar-footer span, .sidebar-footer small { display: block; }
.sidebar-footer small { margin-top: 2px; color: #74849e; }

.main-content {
    min-height: 100vh;
    margin-left: 240px;
    padding: 34px clamp(22px, 3vw, 46px) 70px;
}
.main-content > * { max-width: 1540px; margin-left: auto; margin-right: auto; }

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}
.page-header p { margin-bottom: 0; max-width: 850px; color: var(--muted); font-size: .96rem; }
.detail-header { align-items: flex-start; }
.eyebrow { margin-bottom: 5px; color: var(--primary); font-size: .73rem; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; }
.breadcrumbs { display: flex; gap: 7px; margin-bottom: 10px; color: var(--muted-2); font-size: .78rem; }
.breadcrumbs a { color: var(--muted); }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 650;
    white-space: nowrap;
    text-decoration: none;
    transition: all .15s ease;
}
.button:hover { text-decoration: none; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.button.primary { background: var(--primary); color: white; box-shadow: 0 1px 2px rgba(49,94,251,.2); }
.button.primary:hover:not(:disabled) { background: var(--primary-hover); }
.button.secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.button.secondary:hover { background: var(--surface-muted); }
.button.ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.button.ghost:hover:not(:disabled) { background: var(--surface-muted); color: var(--text); }
.button.danger-ghost { background: transparent; border-color: #efcccc; color: var(--danger); }
.button.danger-ghost:hover { background: var(--danger-soft); }
.button.full { width: 100%; }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; }

.metrics-grid { display: grid; gap: 14px; margin-bottom: 18px; }
.metrics-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-card {
    min-height: 116px;
    padding: 18px 19px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.metric-label { color: var(--muted); font-size: .78rem; font-weight: 650; }
.metric-value { margin-top: 7px; font-size: clamp(1.35rem, 2.2vw, 1.85rem); line-height: 1.15; font-weight: 760; letter-spacing: -.035em; }
.metric-hint { margin-top: 7px; color: var(--muted-2); font-size: .73rem; }
.metric-card.metric-good { border-color: #c5eadb; }
.metric-card.metric-bad { border-color: #f0caca; }
.metric-card.metric-up .metric-value { color: var(--warning); }
.metric-card.metric-down .metric-value { color: var(--success); }

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}
.dashboard-grid .span-2 { grid-column: span 2; }
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel:not(.table-panel) { padding: 19px; }
.panel + .panel { }
.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 15px;
}
.panel-header h2 { margin-bottom: 3px; }
.panel-header p { margin-bottom: 0; color: var(--muted); font-size: .78rem; }
.panel-header > a { font-size: .78rem; font-weight: 650; white-space: nowrap; }
.table-panel { margin-top: 18px; }
.table-panel > .panel-header { padding: 18px 19px 0; }
.loading-card, .empty-state {
    padding: 42px 28px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
}
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-state strong { color: var(--text); font-size: 1rem; }
.empty-state.large-empty { max-width: 760px; margin-top: 28px; padding: 65px 35px; }
.empty-state.large-empty span { max-width: 570px; margin-bottom: 10px; }
.empty-inline { padding: 20px 8px; color: var(--muted); font-size: .84rem; }

.quality-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quality-summary > div { padding: 15px 10px; border-radius: 10px; background: var(--surface-muted); text-align: center; }
.quality-summary strong { display: block; font-size: 1.5rem; }
.quality-summary span { color: var(--muted); font-size: .69rem; }
.quality-badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px; font-size: .69rem; font-weight: 700; white-space: nowrap; }
.quality-valid { color: #0c6f4a; background: var(--success-soft); }
.quality-warning { color: #8c5700; background: var(--warning-soft); }
.quality-invalid { color: #a72929; background: var(--danger-soft); }

.horizontal-bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 1.05fr) minmax(90px, 2fr) minmax(82px, auto); align-items: center; gap: 12px; }
.bar-row-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: .78rem; }
.bar-row-label a { color: var(--text); font-weight: 600; }
.bar-track { height: 8px; border-radius: 99px; background: #eef1f6; overflow: hidden; }
.bar-fill { height: 100%; min-width: 2px; border-radius: inherit; background: linear-gradient(90deg, #315efb, #6d8aff); }
.bar-value { display: flex; flex-direction: column; align-items: flex-end; font-size: .74rem; }
.bar-value small { color: var(--muted-2); font-size: .65rem; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #fbfcfd; color: #667085; font-size: .68rem; font-weight: 760; text-transform: uppercase; letter-spacing: .035em; white-space: nowrap; }
td { font-size: .79rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfe; }
td strong { font-weight: 650; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.break-word { word-break: break-word; }
.cell-subtitle { display: block; margin-top: 3px; max-width: 520px; color: var(--muted-2); font-size: .68rem; font-weight: 400; }
.basis-cell { max-width: 190px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .72rem; font-weight: 650; }
.basis-cell a, .basis-link { color: #274dcc; }
.description-link { color: var(--text); font-weight: 600; }
.description-link:hover { color: var(--primary); }
.price-cell { font-weight: 700; color: #1f3e95; }
.actions { text-align: right; white-space: nowrap; }
.actions-wide { min-width: 138px; }
.table-link { font-size: .73rem; font-weight: 700; }
.table-action-button {
    margin-left: 7px;
    padding: 4px 7px;
    border: 1px solid #cad4f8;
    border-radius: 6px;
    background: #f4f7ff;
    color: #274dcc;
    cursor: pointer;
    font-size: .69rem;
    font-weight: 700;
}
.table-action-button:hover { background: #eaf0ff; }
.muted-row { opacity: .55; }
.tiny-warning { display: inline-grid; place-items: center; width: 15px; height: 15px; margin-left: 4px; border-radius: 50%; background: var(--warning-soft); color: var(--warning); font-weight: 800; font-size: .6rem; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.grow { flex: 1; }
.field.grow-two { grid-column: span 2; }
.field label, .checkbox-field { color: #556074; font-size: .71rem; font-weight: 700; }
input, select, textarea {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: white;
    color: var(--text);
    outline: none;
    transition: border .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: #7b98ff; box-shadow: 0 0 0 3px rgba(49,94,251,.11); }
input::placeholder { color: #a4acb8; }
.search-panel { padding: 17px 18px !important; margin-bottom: 18px; }
.search-main-row { display: flex; align-items: flex-end; gap: 10px; }
.search-button { min-width: 105px; }
.advanced-filters { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 11px; }
.advanced-filters summary { cursor: pointer; color: var(--muted); font-size: .74rem; font-weight: 700; user-select: none; }
.filter-grid { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 12px; margin-top: 14px; align-items: end; }
.filters-panel { padding: 17px 18px !important; margin-bottom: 18px; }
.estimates-filter-grid { grid-template-columns: 2fr repeat(4, 1fr); margin-top: 0; }
.checkbox-field { display: flex; align-items: center; gap: 7px; min-height: 38px; }
.checkbox-field input { width: 16px; height: 16px; min-height: auto; accent-color: var(--primary); }
.filter-actions { display: flex; align-items: end; }
.inline-search { width: min(340px, 100%); }
.estimate-items-header { align-items: center; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 15px; border-top: 1px solid var(--border); color: var(--muted); font-size: .76rem; }
.notice { margin: 0 18px 15px; padding: 10px 12px; border-radius: 8px; font-size: .76rem; }
.notice.warning { background: var(--warning-soft); color: #805000; border: 1px solid #f2dfb8; }

.details-list, .compact-details { display: grid; grid-template-columns: minmax(115px, .8fr) minmax(0, 1.4fr); gap: 10px 13px; margin: 0; }
.details-list dt, .compact-details dt { color: var(--muted); font-size: .73rem; }
.details-list dd, .compact-details dd { margin: 0; font-size: .78rem; font-weight: 570; }
.overheads-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.overhead-card { display: flex; flex-direction: column; gap: 3px; padding: 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-muted); }
.overhead-card span, .overhead-card small { color: var(--muted); font-size: .69rem; }
.overhead-card b { margin-top: 4px; font-size: 1.1rem; }
.warning-panel { margin-top: 18px; }
.warning-list { display: flex; flex-direction: column; gap: 7px; }
.warning-row { display: grid; grid-template-columns: minmax(160px, .5fr) 2fr; gap: 13px; padding: 9px 11px; border-radius: 8px; background: var(--surface-muted); font-size: .74rem; }
.warning-row strong { font-size: .7rem; }
.warning-row span { color: var(--muted); }
.warning-row.severity-error { background: var(--danger-soft); }
.warning-row.severity-warning { background: var(--warning-soft); }

.chart-scroll { width: 100%; overflow-x: auto; }
.price-chart { display: block; width: 100%; min-width: 620px; height: auto; }
.chart-grid { stroke: #e8ecf2; stroke-width: 1; }
.chart-axis { stroke: #bcc5d2; stroke-width: 1; }
.chart-line { fill: none; stroke: #315efb; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-point { fill: white; stroke: #315efb; stroke-width: 3; cursor: help; }
.chart-axis-label { fill: #7b8494; font-size: 11px; font-family: ui-sans-serif, system-ui, sans-serif; }
.price-history-grid { grid-template-columns: minmax(0, 2fr) minmax(270px, .75fr); }
.suggestion-panel { display: flex; flex-direction: column; }
.suggested-price { margin: 4px 0 10px; font-size: 2rem; font-weight: 800; letter-spacing: -.04em; color: #2348c8; }
.suggested-price small { margin-left: 4px; color: var(--muted); font-size: .8rem; font-weight: 600; }
.suggestion-panel > p { color: var(--muted); font-size: .77rem; }
.suggestion-panel .compact-details { margin: 8px 0 18px; }

.trend-pill { display: inline-flex; justify-content: flex-end; min-width: 68px; padding: 3px 7px; border-radius: 999px; font-weight: 750; }
.trend-pill.up { color: #a04f00; background: #fff2e2; }
.trend-pill.down { color: #08734c; background: #e8f8f1; }
.trend-pill.neutral { color: #566174; background: #f0f2f5; }

.takeoff-import-panel { margin-bottom: 18px; }
.takeoff-import-panel .panel-header { align-items: center; }
.takeoff-import-panel .panel-header p { max-width: 850px; margin-bottom: 0; color: var(--muted); font-size: .76rem; }
.file-upload-button { position: relative; overflow: hidden; white-space: nowrap; cursor: pointer; }
.file-upload-button input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-upload-button.disabled { opacity: .65; pointer-events: none; }
.takeoff-import-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
.takeoff-import-summary span { padding: 6px 9px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-muted); color: var(--muted); font-size: .7rem; }
.takeoff-import-summary strong { color: var(--text); }
.inline-warning, .inline-error { margin-top: 11px; padding: 9px 11px; border-radius: 8px; font-size: .72rem; }
.inline-warning { color: #8a5a00; background: var(--warning-soft); }
.inline-error { color: var(--danger); background: var(--danger-soft); }
.warning-text { color: #a05b00 !important; }
.muted-link { color: var(--muted-2); text-decoration: none; }
.section-path { color: var(--muted) !important; }
.price-reference { margin-top: 2px !important; }
.manual-price-hint { color: var(--muted-2); font-size: .68rem; }

.builder-meta { padding: 17px 18px !important; margin-bottom: 18px; }
.builder-meta-grid { grid-template-columns: 2fr 2fr 1fr; margin-top: 0; }
.input-with-suffix { position: relative; }
.input-with-suffix input { padding-right: 30px; }
.input-with-suffix span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.builder-table-panel { margin-top: 0; }
.builder-table .builder-description { min-width: 350px; }
.builder-description > strong, .builder-description > small, .builder-description > a { display: block; }
.builder-description > strong { margin-top: 3px; }
.builder-description > small { margin-top: 3px; color: var(--muted-2); font-size: .67rem; }
.numeric-input { width: 100px; min-height: 32px; padding: 5px 7px; text-align: right; }
.money-input { width: 110px; }
.price-presets { display: flex; flex-direction: column; gap: 4px; min-width: 145px; }
.price-presets button { padding: 2px 0; border: 0; background: transparent; color: var(--primary); cursor: pointer; text-align: left; font-size: .66rem; }
.price-presets button:hover { text-decoration: underline; }
.icon-button { width: 29px; height: 29px; border: 0; border-radius: 7px; cursor: pointer; font-size: 1.05rem; }
.icon-button.danger { color: var(--danger); background: var(--danger-soft); }
.builder-summary-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, .55fr); gap: 16px; margin-top: 18px; }
.builder-notes p { max-width: 850px; color: var(--muted); font-size: .78rem; }
.totals-card { padding: 0 !important; }
.total-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 14px 17px; border-bottom: 1px solid var(--border); }
.total-row:last-child { border-bottom: 0; }
.total-row span { color: var(--muted); }
.total-row strong { font-size: 1rem; }
.total-row.grand { background: #f5f8ff; }
.total-row.grand span, .total-row.grand strong { color: #2348c8; font-weight: 800; }
.total-row.grand strong { font-size: 1.35rem; }
.inline-success { margin-top: 11px; color: var(--success); font-size: .74rem; font-weight: 650; }

.quality-page-grid { grid-template-columns: minmax(260px, .7fr) minmax(0, 2fr); }
.warning-code-list { display: flex; flex-direction: column; gap: 4px; }
.warning-code-row { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--border); }
.warning-code-row:last-child { border-bottom: 0; }
.warning-code-row strong, .warning-code-row small { display: block; }
.warning-code-row strong { font-size: .73rem; }
.warning-code-row small { color: var(--muted-2); font-size: .63rem; }
.severity-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); }
.severity-dot.severity-warning { background: #e09a25; }
.severity-dot.severity-error { background: #d14b4b; }
.severity-dot.severity-info { background: #5d80e8; }

.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; }
.blazor-error-boundary { padding: 1rem; background: var(--danger); color: white; }

@media (max-width: 1200px) {
    .metrics-grid.four { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid, .price-history-grid, .quality-page-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid .span-2 { grid-column: span 1; }
    .price-history-grid .span-2, .quality-page-grid .span-2 { grid-column: span 2; }
    .filter-grid { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
    .estimates-filter-grid { grid-template-columns: 2fr 1fr 1fr; }
    .builder-meta-grid { grid-template-columns: 1fr 1fr 140px; }
}

@media (max-width: 820px) {
    .sidebar {
        position: static;
        width: 100%;
        padding: 10px 12px;
    }
    .brand { padding: 3px 5px 10px; }
    .brand small, .sidebar-footer { display: none; }
    .main-nav { flex-direction: row; overflow-x: auto; padding-bottom: 2px; }
    .main-nav a { flex: 0 0 auto; min-height: 38px; padding: 6px 9px; }
    .nav-glyph { display: none; }
    .main-content { margin-left: 0; padding: 24px 14px 55px; }
    .page-header { align-items: flex-start; flex-direction: column; }
    .page-header .button { width: 100%; }
    .metrics-grid.four, .dashboard-grid, .price-history-grid, .quality-page-grid, .builder-summary-grid { grid-template-columns: 1fr; }
    .dashboard-grid .span-2, .price-history-grid .span-2, .quality-page-grid .span-2 { grid-column: span 1; }
    .filter-grid, .estimates-filter-grid, .builder-meta-grid { grid-template-columns: 1fr 1fr; }
    .field.grow-two { grid-column: span 1; }
    .bar-row { grid-template-columns: minmax(100px, 1fr) minmax(70px, 1.4fr) auto; }
    .warning-row { grid-template-columns: 1fr; gap: 3px; }
}

@media (max-width: 560px) {
    .metrics-grid.four, .filter-grid, .estimates-filter-grid, .builder-meta-grid { grid-template-columns: 1fr; }
    .search-main-row { flex-direction: column; align-items: stretch; }
    .search-button { width: 100%; }
    .quality-summary { grid-template-columns: 1fr; }
    .bar-row { grid-template-columns: 1fr auto; gap: 5px 8px; }
    .bar-track { grid-column: 1 / -1; grid-row: 2; }
    .bar-value { grid-column: 2; grid-row: 1; }
    .panel:not(.table-panel) { padding: 15px; }
    .details-list, .compact-details { grid-template-columns: 1fr; gap: 2px; }
    .details-list dd, .compact-details dd { margin-bottom: 8px; }
}

/* Source PDF links and wide-table ergonomics -------------------------------- */
.source-pdf-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 26px;
    padding: 3px 8px;
    border: 1px solid #d7dde8;
    border-radius: 6px;
    background: #fff;
    color: #45546b;
    font-size: .68rem;
    font-weight: 750;
    text-decoration: none;
    white-space: nowrap;
}
.source-pdf-link:hover {
    border-color: #aebbd1;
    background: #f7f9fc;
    color: var(--text);
    text-decoration: none;
}
.source-pdf-missing {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 8px;
    border: 1px dashed var(--border-strong);
    border-radius: 6px;
    color: var(--muted-2);
    font-size: .66rem;
    white-space: nowrap;
}
.detail-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}
.table-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 7px;
}
.table-actions .table-action-button { margin-left: 0; }
.table-wrap {
    max-width: 100%;
    scrollbar-gutter: stable;
    overscroll-behavior-x: contain;
}
table.data-table { min-width: 920px; }
.search-results-table { min-width: 1180px !important; }
.search-results-table th:nth-child(2),
.search-results-table td:nth-child(2) { min-width: 340px; }
.search-results-table th:last-child,
.search-results-table td:last-child { min-width: 210px; }
.estimates-table { min-width: 1060px !important; }
.estimates-table th:nth-child(2),
.estimates-table td:nth-child(2) { min-width: 350px; }
.price-observations-table { min-width: 1040px !important; }
.price-observations-table th:nth-child(2),
.price-observations-table td:nth-child(2) { min-width: 350px; }
.estimate-items-table { min-width: 1260px !important; }
.estimate-items-table th:nth-child(3),
.estimate-items-table td:nth-child(3) { min-width: 430px; }
.estimate-items-table th:nth-child(2),
.estimate-items-table td:nth-child(2) { min-width: 150px; }
.builder-table { min-width: 1180px !important; }
.analytics-table { min-width: 1040px !important; }
.recent-estimates-table { min-width: 900px !important; }
.quality-estimates-table { min-width: 900px !important; }
.basis-cell {
    min-width: 130px;
    max-width: 230px;
    white-space: normal;
    overflow-wrap: anywhere;
}
.cell-subtitle,
td {
    overflow-wrap: break-word;
}
.description-link {
    white-space: normal;
    overflow-wrap: break-word;
}

@media (min-width: 1500px) {
    .main-content {
        padding-left: 28px;
        padding-right: 28px;
    }
    .main-content > * { max-width: 1680px; }
}

@media (max-width: 820px) {
    .detail-header-actions {
        width: 100%;
        justify-content: stretch;
    }
    .detail-header-actions > * { flex: 1 1 auto; }
}

/* Prevent long imported names/descriptions from forcing or clipping layouts. */
.page-header > div:first-child,
.panel,
.dashboard-grid > *,
.metrics-grid > * { min-width: 0; }
.page-header h1,
.panel-header h2,
.metric-value,
.details-list dd,
.warning-row span { overflow-wrap: anywhere; }
.details-list dd { min-width: 0; }

@media (max-width: 1499px) and (min-width: 821px) {
    .main-content { padding-left: 20px; padding-right: 20px; }
    th, td { padding-left: 10px; padding-right: 10px; }
}

/* Authentication */
.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #2b3850;
}
.sidebar-user-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #eef3fb;
    font-weight: 700;
}
.sidebar-logout {
    flex: 0 0 auto;
    color: #9fb2d0;
    font-size: .72rem;
    font-weight: 650;
}
.sidebar-logout:hover { color: white; }

.login-page-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    background:
        radial-gradient(circle at 15% 15%, rgba(49,94,251,.12), transparent 28rem),
        radial-gradient(circle at 85% 80%, rgba(22,134,91,.08), transparent 30rem),
        var(--bg);
}
.login-card {
    width: min(100%, 430px);
    padding: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 24px 70px rgba(23,32,51,.12);
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 30px;
}
.login-brand strong { display: block; font-size: 1rem; }
.login-brand small { display: block; margin-top: 1px; color: var(--muted); font-size: .74rem; }
.login-heading { margin-bottom: 22px; }
.login-heading h1 { margin-bottom: 8px; font-size: 2rem; }
.login-heading p:last-child { margin-bottom: 0; color: var(--muted); }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 7px; }
.login-form label > span { color: var(--text); font-size: .78rem; font-weight: 700; }
.login-form input {
    width: 100%;
    min-height: 44px;
    padding: 9px 11px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    outline: none;
    background: white;
    color: var(--text);
}
.login-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(49,94,251,.12);
}
.login-error {
    margin-bottom: 17px;
    padding: 10px 12px;
    border: 1px solid #efcccc;
    border-radius: 8px;
    background: var(--danger-soft);
    color: var(--danger);
    font-size: .8rem;
    font-weight: 650;
}

@media (max-width: 820px) {
    .login-page-shell { padding: 16px; }
    .login-card { padding: 24px 20px; }
}

.builder-overheads { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.builder-overheads-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.builder-overheads-heading strong { display: block; font-size: .8rem; }
.builder-overheads-heading small { display: block; max-width: 820px; margin-top: 3px; color: var(--muted); font-size: .68rem; line-height: 1.45; }
.builder-overheads-grid { grid-template-columns: repeat(3, minmax(170px, 1fr)); margin-top: 0; }
.labor-rate-input input { padding-right: 58px; }
.total-words { padding: 13px 17px 15px; background: var(--surface-muted); }
.total-words span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; }
.total-words strong { display: block; font-size: .78rem; line-height: 1.45; }

@media (max-width: 760px) {
    .builder-overheads-grid { grid-template-columns: 1fr; }
}

/* Builder pricing strategy / overhead controls */
.historical-price-panel { padding-top: 14px; padding-bottom: 14px; }
.historical-price-copy { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.historical-price-copy > div:first-child { min-width: 0; }
.historical-price-copy strong { display: block; font-size: .84rem; }
.historical-price-copy small { display: block; max-width: 760px; margin-top: 4px; color: var(--muted); font-size: .69rem; line-height: 1.45; }
.historical-price-select { flex: 0 0 min(320px, 100%); }
.historical-price-select select { min-width: 260px; }

.builder-toggle { display: flex; align-items: flex-start; gap: 11px; margin-top: 15px; padding: 12px 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-muted); cursor: pointer; }
.builder-toggle > input { position: absolute; opacity: 0; pointer-events: none; }
.builder-toggle-track { position: relative; flex: 0 0 38px; width: 38px; height: 22px; margin-top: 1px; border-radius: 999px; background: #aeb6c4; transition: background .15s ease; }
.builder-toggle-track > span { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.22); transition: transform .15s ease; }
.builder-toggle > input:checked + .builder-toggle-track { background: var(--primary); }
.builder-toggle > input:checked + .builder-toggle-track > span { transform: translateX(16px); }
.builder-toggle > input:focus-visible + .builder-toggle-track { outline: 3px solid rgba(49,94,251,.18); outline-offset: 2px; }
.builder-toggle-copy { min-width: 0; }
.builder-toggle-copy strong { display: block; font-size: .76rem; }
.builder-toggle-copy small { display: block; margin-top: 3px; color: var(--muted); font-size: .66rem; line-height: 1.4; }

@media (max-width: 760px) {
    .historical-price-copy { align-items: stretch; flex-direction: column; }
    .historical-price-select { flex-basis: auto; }
    .historical-price-select select { min-width: 0; width: 100%; }
}

/* 2026 Builder visual refresh ------------------------------------------------ */
.tabler-icon {
    display: inline-block;
    flex: 0 0 auto;
    vertical-align: middle;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.button-with-icon {
    gap: 7px;
}
.button-with-icon > .tabler-icon { margin-left: -1px; }

.section-heading {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}
.section-heading.compact { gap: 10px; }
.section-heading > div { min-width: 0; }
.section-heading h2,
.section-heading p { margin-bottom: 0; }
.section-heading p { margin-top: 3px; }
.section-icon {
    display: grid;
    place-items: center;
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--primary-soft);
    color: var(--primary);
}
.section-icon.subtle {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: #536174;
}
.section-icon.accent {
    background: linear-gradient(145deg, #eef3ff, #e5ecff);
    color: #244bd7;
    box-shadow: inset 0 0 0 1px #dce5ff;
}

.builder-page-header { margin-bottom: 20px; }
.builder-page-header h1 { margin-bottom: .42rem; }
.builder-page-header .button { min-height: 42px; }
.builder-section-panel { margin-bottom: 14px; }
.builder-section-title { margin-bottom: 14px; }
.builder-section-title p { color: var(--muted); font-size: .72rem; }

.takeoff-import-panel .panel-header { margin-bottom: 0; }
.takeoff-import-summary {
    padding-top: 13px;
    border-top: 1px solid var(--border);
}
.takeoff-import-summary span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #fbfcfe;
}

.historical-price-panel {
    background: linear-gradient(180deg, #fff, #fcfdff);
}
.historical-price-copy { align-items: center; }
.historical-price-copy .eyebrow { margin-bottom: 3px; }
.historical-price-select select { font-weight: 650; }

.builder-meta {
    padding: 18px !important;
}
.builder-meta-grid { margin-top: 0; }
.builder-meta .field label {
    display: flex;
    align-items: center;
    gap: 5px;
}
.builder-overheads {
    margin-top: 18px;
    padding-top: 17px;
}
.builder-overheads-heading { align-items: flex-start; }
.builder-toggle {
    position: relative;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.builder-toggle:hover {
    border-color: #cbd6ef;
    background: #f6f8fc;
}
.builder-toggle:has(input:checked) {
    border-color: #c8d5ff;
    background: #f4f7ff;
    box-shadow: inset 3px 0 0 var(--primary);
}

.builder-command-center {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(330px, .62fr);
    gap: 14px;
    margin: 4px 0 18px;
    align-items: stretch;
}
.builder-export-card {
    display: flex;
    flex-direction: column;
    padding: 18px !important;
    border-color: #dce3ef;
}
.builder-command-header {
    align-items: center;
    margin-bottom: 14px;
}
.builder-items-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    padding: 6px 9px;
    border: 1px solid #dce3ef;
    border-radius: 999px;
    background: #fafcff;
    color: #536174;
    font-size: .69rem;
    font-weight: 700;
    white-space: nowrap;
}
.builder-quick-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
    margin-bottom: 14px;
}
.quick-stat {
    min-width: 0;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-muted);
}
.quick-stat span,
.quick-stat strong { display: block; }
.quick-stat span {
    margin-bottom: 3px;
    color: var(--muted);
    font-size: .67rem;
    font-weight: 650;
}
.quick-stat strong {
    overflow: hidden;
    color: var(--text);
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.quick-stat.featured {
    border-color: #cdd9ff;
    background: var(--primary-soft);
}
.quick-stat.featured span { color: #5d6eaa; }
.quick-stat.featured strong { color: #2348c8; }
.builder-export-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.builder-export-actions .button { min-height: 39px; }
.builder-guidance {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: auto;
    padding-top: 14px;
    color: var(--muted);
    font-size: .7rem;
    line-height: 1.48;
}
.builder-guidance .tabler-icon { margin-top: 1px; color: #75839a; }

.builder-totals-card {
    border-color: #d8e0ee;
    box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 10px 30px rgba(16,24,40,.05);
}
.totals-card-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 17px 13px;
    border-bottom: 1px solid var(--border);
}
.totals-card-heading > div:last-child { min-width: 0; }
.totals-card-heading strong,
.totals-card-heading small { display: block; }
.totals-card-heading strong { font-size: .8rem; }
.totals-card-heading small { margin-top: 2px; color: var(--muted); font-size: .65rem; }
.builder-totals-card .total-row { padding: 10px 17px; }
.builder-totals-card .total-row span { font-size: .72rem; }
.builder-totals-card .total-row strong { font-size: .88rem; font-variant-numeric: tabular-nums; }
.builder-totals-card .total-row.grand { padding-top: 13px; padding-bottom: 13px; }
.builder-totals-card .total-row.grand strong { font-size: 1.28rem; }
.builder-totals-card .total-words { padding-top: 11px; }

.status-message {
    display: flex;
    align-items: flex-start;
    gap: 7px;
}
.status-message .tabler-icon { margin-top: 1px; }

.builder-table-panel {
    margin-top: 0;
    overflow: hidden;
}
.builder-table-header {
    align-items: center;
    padding-bottom: 15px !important;
    margin-bottom: 0 !important;
}
.heading-count {
    display: inline-grid;
    place-items: center;
    min-width: 24px;
    margin-left: 5px;
    padding: 2px 6px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: #3151b7;
    font-size: .68rem;
    vertical-align: 2px;
}
.builder-table-wrap {
    max-height: min(72vh, 900px);
    overflow: auto;
    border-top: 1px solid var(--border);
    scrollbar-gutter: stable both-edges;
}
.builder-table thead th {
    position: sticky;
    top: 0;
    z-index: 4;
    border-bottom: 1px solid #d6deea;
    background: #f7f9fc;
    box-shadow: 0 1px 0 rgba(16,24,40,.02);
}
.builder-table tbody tr:nth-child(even) { background: #fcfdff; }
.builder-table tbody tr:hover { background: #f5f8ff; }
.builder-table th,
.builder-table td { padding-top: 10px; padding-bottom: 10px; }
.builder-description > strong { line-height: 1.35; }
.builder-description .basis-link { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .7rem; font-weight: 750; }
.numeric-input {
    border-color: #d9e0ea;
    background: #fff;
    font-variant-numeric: tabular-nums;
}
.numeric-input:hover { border-color: #bcc8da; }
.numeric-input:focus { background: #fff; }
.price-presets {
    min-width: 180px;
    gap: 5px;
}
.price-presets button {
    display: grid;
    grid-template-columns: 14px minmax(52px, auto) 1fr;
    align-items: center;
    gap: 5px;
    width: 100%;
    padding: 4px 7px;
    border: 1px solid transparent;
    border-radius: 7px;
    color: #46566f;
    background: transparent;
    text-decoration: none;
    transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.price-presets button span { font-size: .63rem; }
.price-presets button strong {
    justify-self: end;
    color: #274dcc;
    font-size: .65rem;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
}
.price-presets button:hover {
    border-color: #d9e2ff;
    background: #f4f7ff;
    color: #274dcc;
    text-decoration: none;
}
.icon-button {
    display: inline-grid;
    place-items: center;
    border: 1px solid transparent;
    transition: background .12s ease, border-color .12s ease, transform .12s ease;
}
.icon-button:hover { transform: translateY(-1px); }
.icon-button.danger { border-color: #f3d4d4; }
.icon-button.danger:hover { border-color: #ebbbbb; background: #ffe7e7; }
.manual-price-hint {
    display: inline-flex;
    padding: 4px 7px;
    border-radius: 999px;
    background: #f1f3f6;
    color: #778195;
    font-size: .64rem;
    font-weight: 650;
}

.builder-empty-state .empty-state-icon {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    margin-bottom: 4px;
    border-radius: 15px;
    background: var(--primary-soft);
    color: var(--primary);
}

.sidebar-logout {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.main-nav .nav-glyph .tabler-icon { stroke-width: 1.8; }

@media (max-width: 1100px) {
    .builder-command-center { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
    .nav-glyph { display: grid; border: 0; width: 20px; height: 20px; flex-basis: 20px; }
    .main-nav a.active .nav-glyph { background: transparent; color: white; }
    .builder-command-header,
    .builder-table-header { align-items: flex-start; flex-direction: column; }
    .builder-table-header .button { width: 100%; }
    .builder-totals-card { display: block; }
    .builder-totals-card .totals-card-heading { border-right: 0; border-bottom: 1px solid var(--border); }
}

@media (max-width: 620px) {
    .builder-quick-stats { grid-template-columns: 1fr; }
    .builder-export-actions { display: grid; grid-template-columns: 1fr; }
    .builder-export-actions .button { width: 100%; }
    .builder-items-pill { align-self: flex-start; }
    .builder-table-wrap { max-height: 68vh; }
}

/* Builder compact density -------------------------------------------------- */
.builder-page-header {
    margin-bottom: 14px;
}
.builder-page-header h1 {
    margin-bottom: .25rem;
    font-size: clamp(1.55rem, 2.25vw, 2rem);
}
.builder-page-header p {
    max-width: 780px;
    font-size: .84rem;
}
.builder-page-header .eyebrow {
    margin-bottom: 3px;
    font-size: .67rem;
}
.builder-page-header .button {
    min-height: 35px;
    padding: 6px 11px;
}

.builder-top-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(300px, .72fr);
    gap: 12px;
    margin-bottom: 12px;
    align-items: stretch;
}
.builder-top-grid .builder-section-panel {
    height: 100%;
    margin-bottom: 0;
}
.builder-top-grid .takeoff-import-panel,
.builder-top-grid .historical-price-panel {
    padding: 14px 15px !important;
}
.builder-top-grid .panel-header {
    gap: 12px;
}
.builder-top-grid .takeoff-import-panel .panel-header p {
    max-width: 760px;
    font-size: .7rem;
    line-height: 1.42;
}
.builder-top-grid .historical-price-copy {
    height: 100%;
    align-items: stretch;
    flex-direction: column;
    justify-content: space-between;
    gap: 11px;
}
.builder-top-grid .historical-price-copy small {
    max-width: none;
    font-size: .66rem;
    line-height: 1.4;
}
.builder-top-grid .historical-price-select {
    width: 100%;
}
.builder-top-grid .takeoff-import-summary {
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
}
.builder-top-grid .takeoff-import-summary span {
    padding: 4px 7px;
    font-size: .66rem;
}

.builder-section-panel {
    margin-bottom: 12px;
}
.builder-section-panel .section-icon {
    flex-basis: 32px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
}
.builder-section-panel .section-icon.subtle {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
}
.builder-section-panel .section-heading {
    gap: 9px;
}
.builder-section-panel h2 {
    font-size: 1rem;
}
.builder-section-panel input,
.builder-section-panel select {
    min-height: 34px;
    padding: 6px 9px;
}
.builder-section-panel .field {
    gap: 4px;
}
.builder-section-panel .field label {
    font-size: .68rem;
}

.builder-meta {
    padding: 14px 15px !important;
}
.builder-section-title {
    margin-bottom: 10px;
}
.builder-section-title p {
    font-size: .68rem;
}
.builder-meta-grid {
    gap: 9px 10px;
}
.builder-overheads {
    margin-top: 13px;
    padding-top: 12px;
}
.builder-overheads-heading {
    margin-bottom: 8px;
}
.builder-overheads-heading strong {
    font-size: .77rem;
}
.builder-overheads-heading small {
    margin-top: 2px;
    font-size: .65rem;
    line-height: 1.35;
}
.builder-overheads-grid {
    gap: 9px;
}
.builder-toggle {
    gap: 9px;
    margin-top: 10px;
    padding: 9px 10px;
    border-radius: 8px;
}
.builder-toggle-track {
    flex-basis: 36px;
    width: 36px;
    height: 20px;
}
.builder-toggle-track > span {
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
}
.builder-toggle > input:checked + .builder-toggle-track > span {
    transform: translateX(16px);
}
.builder-toggle-copy strong {
    font-size: .72rem;
}
.builder-toggle-copy small {
    margin-top: 2px;
    font-size: .63rem;
    line-height: 1.35;
}

.builder-command-center {
    grid-template-columns: minmax(0, 1.5fr) minmax(300px, .58fr);
    gap: 12px;
    margin: 2px 0 12px;
}
.builder-export-card {
    padding: 14px 15px !important;
}
.builder-command-header {
    margin-bottom: 10px;
}
.builder-command-header .section-icon {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
    border-radius: 9px;
}
.builder-command-header h2 {
    font-size: 1rem;
}
.builder-command-header p {
    font-size: .69rem;
}
.builder-items-pill {
    gap: 4px;
    padding: 4px 7px;
    font-size: .65rem;
}
.builder-quick-stats {
    gap: 7px;
    margin-bottom: 10px;
}
.quick-stat {
    padding: 8px 10px;
    border-radius: 8px;
}
.quick-stat span {
    margin-bottom: 2px;
    font-size: .63rem;
}
.quick-stat strong {
    font-size: .94rem;
}
.builder-export-actions {
    gap: 6px;
}
.builder-export-actions .button {
    min-height: 34px;
    padding: 6px 10px;
    font-size: .76rem;
}
.builder-guidance {
    gap: 6px;
    padding-top: 10px;
    font-size: .65rem;
    line-height: 1.4;
}
.builder-export-card .inline-success,
.builder-export-card .inline-error {
    margin-top: 8px;
    padding: 7px 9px;
    font-size: .68rem;
}

.builder-totals-card {
    box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 6px 18px rgba(16,24,40,.04);
}
.totals-card-heading {
    gap: 8px;
    padding: 11px 13px 10px;
}
.totals-card-heading .section-icon {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
    border-radius: 8px;
}
.totals-card-heading strong {
    font-size: .76rem;
}
.totals-card-heading small {
    font-size: .62rem;
}
.builder-totals-card .total-row {
    padding: 7px 13px;
}
.builder-totals-card .total-row span {
    font-size: .68rem;
}
.builder-totals-card .total-row strong {
    font-size: .82rem;
}
.builder-totals-card .total-row.grand {
    padding-top: 9px;
    padding-bottom: 9px;
}
.builder-totals-card .total-row.grand strong {
    font-size: 1.1rem;
}
.builder-totals-card .total-words {
    padding: 8px 13px 10px;
}
.builder-totals-card .total-words span {
    margin-bottom: 3px;
    font-size: .62rem;
}
.builder-totals-card .total-words strong {
    font-size: .72rem;
    line-height: 1.35;
}

.builder-table-header {
    padding: 11px 14px 10px !important;
}
.builder-table-header .section-icon {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
    border-radius: 8px;
}
.builder-table-header h2 {
    font-size: .98rem;
}
.builder-table-header p {
    font-size: .67rem;
}
.builder-table-header .button {
    min-height: 33px;
    padding: 5px 9px;
    font-size: .72rem;
}
.heading-count {
    min-width: 21px;
    padding: 1px 5px;
    font-size: .63rem;
}
.builder-table-wrap {
    max-height: min(76vh, 980px);
}
.builder-table th,
.builder-table td {
    padding-top: 7px;
    padding-bottom: 7px;
}
.builder-table th {
    font-size: .64rem;
}
.builder-table td {
    font-size: .75rem;
}
.builder-table .builder-description {
    min-width: 320px;
}
.builder-description > strong {
    margin-top: 2px;
    line-height: 1.28;
}
.builder-description > small {
    margin-top: 2px;
    font-size: .63rem;
}
.builder-description .basis-link {
    font-size: .66rem;
}
.numeric-input {
    min-height: 29px;
    padding: 4px 6px;
    border-radius: 7px;
    font-size: .73rem;
}
.price-presets {
    min-width: 165px;
    gap: 3px;
}
.price-presets button {
    grid-template-columns: 13px minmax(48px, auto) 1fr;
    gap: 4px;
    padding: 3px 6px;
    border-radius: 6px;
}
.price-presets button span {
    font-size: .6rem;
}
.price-presets button strong {
    font-size: .62rem;
}
.manual-price-hint {
    padding: 3px 6px;
    font-size: .61rem;
}
.builder-table .icon-button {
    min-width: 29px;
    min-height: 29px;
}

@media (max-width: 1180px) {
    .builder-top-grid {
        grid-template-columns: 1fr;
    }
    .builder-top-grid .historical-price-copy {
        align-items: center;
        flex-direction: row;
    }
    .builder-top-grid .historical-price-select {
        width: min(290px, 100%);
        flex: 0 0 290px;
    }
}

@media (max-width: 820px) {
    .builder-top-grid .historical-price-copy {
        align-items: stretch;
        flex-direction: column;
    }
    .builder-top-grid .historical-price-select {
        width: 100%;
        flex: auto;
    }
}

/* Responsive layout corrections: 4K centering, bars and dense data tables ---- */
.builder-command-center {
    width: min(100%, 1320px);
    margin-left: auto;
    margin-right: auto;
}

/* HorizontalBars: label/value share the full row, the visual fill gets the
   entire width below it. This prevents the value column from being clipped
   when the component is rendered inside a narrow dashboard card. */
.horizontal-bars {
    min-width: 0;
}
.bar-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    min-width: 0;
}
.bar-row-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) max-content;
    align-items: start;
    gap: 12px;
    min-width: 0;
}
.bar-row-label {
    min-width: 0;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.3;
}
.bar-value {
    justify-self: end;
    min-width: max-content;
    max-width: 100%;
    text-align: right;
    white-space: nowrap;
}
.bar-track {
    width: 100%;
    min-width: 0;
}

/* The previous fixed minimum widths made a number of lists scroll even when
   there was enough usable desktop space. Keep tables fluid and spend width on
   descriptive text first; numeric/action columns retain their intrinsic size. */
table.data-table,
.search-results-table,
.estimates-table,
.price-observations-table,
.estimate-items-table,
.builder-table,
.analytics-table,
.recent-estimates-table,
.quality-estimates-table {
    width: 100%;
    min-width: 100% !important;
}

.data-table td,
.data-table .cell-subtitle,
.data-table .description-link {
    overflow-wrap: anywhere;
    word-break: normal;
}
.data-table .cell-subtitle,
.data-table .description-link {
    white-space: normal;
}

/* Investment / description columns are deliberately allowed to use multiple
   lines instead of forcing the whole table wider. */
.search-results-table th:nth-child(2),
.search-results-table td:nth-child(2) {
    width: 36%;
    min-width: 190px;
    white-space: normal;
}
.search-results-table th:last-child,
.search-results-table td:last-child {
    min-width: 150px;
}

.estimates-table th:nth-child(2),
.estimates-table td:nth-child(2) {
    width: 34%;
    min-width: 180px;
    white-space: normal;
}

.price-observations-table th:nth-child(2),
.price-observations-table td:nth-child(2) {
    width: 34%;
    min-width: 180px;
    white-space: normal;
}

.estimate-items-table th:nth-child(3),
.estimate-items-table td:nth-child(3) {
    width: 40%;
    min-width: 220px;
    white-space: normal;
}
.estimate-items-table th:nth-child(2),
.estimate-items-table td:nth-child(2) {
    min-width: 110px;
}

.builder-table .builder-description {
    width: 34%;
    min-width: 240px;
    white-space: normal;
    overflow-wrap: anywhere;
}

.analytics-table th:nth-child(2),
.analytics-table td:nth-child(2) {
    width: 34%;
    min-width: 180px;
    white-space: normal;
    overflow-wrap: anywhere;
}

.recent-estimates-table th:nth-child(2),
.recent-estimates-table td:nth-child(2),
.quality-estimates-table th:nth-child(2),
.quality-estimates-table td:nth-child(2) {
    width: 40%;
    min-width: 170px;
    white-space: normal;
    overflow-wrap: anywhere;
}

@media (max-width: 1100px) {
    /* On genuinely narrow viewports preserving readable numeric columns is more
       useful than squeezing every table into the viewport. */
    .search-results-table { min-width: 960px !important; }
    .estimates-table { min-width: 860px !important; }
    .price-observations-table { min-width: 820px !important; }
    .estimate-items-table { min-width: 940px !important; }
    .builder-table { min-width: 1020px !important; }
    .analytics-table { min-width: 900px !important; }
    .recent-estimates-table { min-width: 760px !important; }
    .quality-estimates-table { min-width: 760px !important; }
}

@media (max-width: 620px) {
    .bar-row-head {
        gap: 8px;
    }
    .bar-value {
        font-size: .7rem;
    }
}

/* Targeted desktop layout polish: Builder / Analytics / Estimates / Quality -- */

/* Builder: the generic heading rule used justify-content:space-between, which
   made the overhead copy look right-aligned next to its icon. Keep this block
   explicitly left-aligned. */
.builder-overheads-heading {
    justify-content: flex-start;
    text-align: left;
}
.builder-overheads-heading > div {
    flex: 1 1 auto;
    text-align: left;
}
.builder-overheads-heading strong,
.builder-overheads-heading small {
    text-align: left;
}

/* Builder import: reserve a real column for the upload action and pin it to the
   lower-right of the header instead of letting long copy squeeze/crop it. */
.builder-top-grid .takeoff-import-panel .panel-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) max-content;
    align-items: end;
    column-gap: 14px;
    row-gap: 10px;
}
.builder-top-grid .takeoff-import-panel .panel-header > .section-heading {
    min-width: 0;
}
.builder-top-grid .takeoff-import-panel .file-upload-button {
    align-self: end;
    justify-self: end;
    margin: 0;
}

/* Builder summary should use the same wide content canvas as the rest of the
   page on 4K. The main-content container already provides the safe max-width. */
.builder-command-center {
    width: 100%;
    max-width: none;
}

/* Analytics: keep percentage pills intact and reserve a touch more room for
   them by giving the description column slightly less width. */
.analytics-table th:nth-child(2),
.analytics-table td:nth-child(2) {
    width: 30%;
}
.analytics-table th:nth-child(7),
.analytics-table td:nth-child(7) {
    width: 92px;
    min-width: 92px;
}
.analytics-table .trend-pill {
    min-width: 74px;
    white-space: nowrap;
}

/* Estimates: the two row actions comfortably fit side by side on desktop. */
.estimates-table th:last-child,
.estimates-table td:last-child {
    width: 128px;
    min-width: 128px;
}
.estimates-table .table-actions {
    flex-wrap: nowrap;
    gap: 6px;
}
.estimates-table .table-actions > * {
    flex: 0 0 auto;
}

/* Data quality: give warning codes a little more breathing room without taking
   too much space away from the estimates table. */
.quality-page-grid {
    grid-template-columns: minmax(320px, .86fr) minmax(0, 2fr);
}

@media (max-width: 1180px) {
    /* Once Builder top cards stack, keep the import action on its own right-
       aligned line so long explanatory copy never competes for its width. */
    .builder-top-grid .takeoff-import-panel .panel-header {
        grid-template-columns: minmax(0, 1fr);
    }
    .builder-top-grid .takeoff-import-panel .file-upload-button {
        justify-self: end;
    }
}

@media (max-width: 1200px) and (min-width: 821px) {
    /* Preserve the intentionally wider warning-code card at notebook widths. */
    .quality-page-grid {
        grid-template-columns: minmax(300px, .9fr) minmax(0, 1.65fr);
    }
    .quality-page-grid .span-2 {
        grid-column: span 1;
    }
}

@media (max-width: 820px) {
    .quality-page-grid {
        grid-template-columns: 1fr;
    }
}
