: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; }
}
