:root {
    --bg: #0f172a;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --card-stripe: #e2e8f0;
    --border: #cbd5e1;
    --text: #1e293b;
    --text-muted: #64748b;
    --input-bg: #ffffff;
    --input-missing-bg: #fffbeb;
    --chip-bg: #f8fafc;
    --canvas-bg: #e8edf3;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --yellow-bg: #fef9c3;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
    --radius: 12px;
    --sidebar-w: 260px;
}

* { box-sizing: border-box; }

html {
    height: 100%;
}

body {
    margin: 0;
    min-height: 100%;
    min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--surface-alt);
    line-height: 1.5;
}

/* Auth pages: fill viewport and match dark canvas (no light strip under zoom/DPI). */
body:has(.auth) {
    background: #0f172a;
}

/* ---------- Brand ---------- */
.brand-mark { font-weight: 800; color: var(--primary); letter-spacing: .5px; }
.brand-ai { font-weight: 800; color: var(--text); }

/* ---------- App layout ---------- */
.layout {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(0);
    transition: transform .2s ease;
    z-index: 40;
}
.sidebar__brand { padding: 8px 12px 24px; }
.sidebar__brand-name {
    font-size: 1.18rem;
    line-height: 1.2;
}
.sidebar__brand .brand-mark { color: var(--primary); }
.sidebar__brand .brand-ai { color: #fff; }
.sidebar__tagline {
    display: block;
    margin-top: 8px;
    color: #ffffff;
    font-size: .72rem;
    font-weight: 500;
    letter-spacing: 0;
    line-height: 1.45;
    max-width: 170px;
}
.sidebar__nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-link {
    color: #cbd5e1;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-link.is-active {
    background: #2563eb;
    color: #fff;
    font-weight: 700;
    box-shadow: inset 3px 0 0 #ffffff;
}
.nav-link.is-active:hover { background: #1d4ed8; color: #fff; }
.nav-badge {
    display: inline-block;
    min-width: 18px;
    padding: 0 6px;
    margin-left: 4px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    line-height: 18px;
}
.sidebar__footer { border-top: 1px solid rgba(255, 255, 255, .1); padding-top: 16px; }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 0; overflow: hidden; }
.user-chip__avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: grid; place-items: center; font-weight: 700;
    flex-shrink: 0;
}
.user-chip__meta { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.user-chip__name { color: #fff; font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip__role { font-size: .75rem; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 28px;
    min-height: 64px;
    box-sizing: border-box;
    display: flex; align-items: center; gap: 16px;
    position: sticky; top: 0; z-index: 30;
}
.topbar__menu { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text); }
.topbar__title {
    font-size: 1.25rem;
    margin: 0;
    min-width: 0;
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    flex: 1;
    line-height: 1.2;
}
.topbar__count {
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-muted);
}
.topbar__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
    min-height: 36px;
}
.topbar__actions .btn {
    min-height: 36px;
    padding: 8px 14px;
    box-sizing: border-box;
}
.topbar__actions .badge {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    box-sizing: border-box;
}

.content { padding: 28px; flex: 1; width: 100%; box-sizing: border-box; min-width: 0; }

/* BOQ detail pages use the full main area next to the sidebar. */
.boq-view {
    width: 100%;
    max-width: none;
}
.boq-view > .panel {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
}

/* ---------- Auth ---------- */
.auth {
    position: fixed;
    inset: 0;
    min-height: 100%;
    width: 100%;
    display: grid;
    place-items: center;
    padding: 24px;
    overflow: auto;
    background: linear-gradient(135deg, #1e293b, #0f172a);
}
.auth__card { background: var(--surface); border-radius: 16px; box-shadow: 0 20px 40px rgba(0,0,0,.25); padding: 40px; width: 100%; max-width: 400px; }
.auth__brand { display: flex; flex-direction: column; align-items: center; font-size: 1.55rem; text-align: center; margin-bottom: 12px; }
.auth__brand-name { width: 100%; }
.auth__brand-tagline {
    margin: 2px 0 0;
    color: var(--text-muted);
    font-size: .84rem;
    font-weight: 400;
    line-height: 1.25;
    text-align: center;
    width: 100%;
}
.auth__title { margin: 0 0 4px; font-size: 1.5rem; }
.auth__subtitle { margin: 0 0 24px; color: var(--text-muted); font-size: .92rem; }
.auth__link { display: block; text-align: center; margin-top: 18px; color: var(--primary); text-decoration: none; font-size: .9rem; }
.auth__link:hover { text-decoration: underline; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 16px; }
.field__label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.field__required { color: var(--red); margin-left: 3px; font-weight: 800; }
.field__error { display: block; color: var(--red); font-size: .8rem; margin-top: 4px; }
.field__help { display: block; color: var(--text-muted); font-size: .8rem; margin-top: 4px; }
.form-control, .form-select {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 8px;
    font-size: .95rem; background: #fff; color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.form-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 8px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 10px 16px; border-radius: 8px; border: 1px solid transparent;
    font-size: .9rem; font-weight: 600; cursor: pointer; text-decoration: none;
    transition: background .15s, border-color .15s, color .15s;
}
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--surface-alt); }
.btn--danger { background: #b91c1c; color: #fff; }
.btn--danger:hover { background: #991b1b; }
.btn--classy-red { background: #ab0b1c; color: #fff; }
.btn--classy-red:hover { background: #870613; }
.btn--block { width: 100%; }
.btn--small { padding: 6px 10px; font-size: .8rem; }
.icon-button {
    width: 30px; height: 30px; border-radius: 8px;
    border: 1px solid transparent; background: transparent;
    color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; text-decoration: none; vertical-align: middle;
    padding: 0; transition: background .15s, border-color .15s, color .15s;
}
.icon-button:hover { background: var(--surface-alt); border-color: var(--border); }
.icon-button--edit:hover { color: var(--primary); border-color: #bfdbfe; }
.icon-button--danger:hover { background: var(--red-bg); color: var(--red); border-color: #fecaca; }
.icon { width: 1em; height: 1em; fill: currentColor; }

/* ---------- Cards / panels ---------- */
.welcome { margin-bottom: 24px; }
.welcome__title { margin: 0 0 4px; }
.welcome__tagline {
    color: var(--primary);
    font-size: .9rem;
    font-weight: 700;
    margin: 0 0 6px;
}
.welcome__text { color: var(--text-muted); margin: 0; }

/* ---------- Dashboard ---------- */
.dash {
    display: flex;
    flex-direction: column;
    gap: 22px;
    max-width: 1180px;
}

.dash-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    padding: 22px 24px;
    border-radius: 16px;
    background:
        linear-gradient(135deg, rgba(37, 99, 235, 0.10), rgba(15, 23, 42, 0.03) 55%, transparent),
        var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.dash-hero__title {
    margin: 0 0 6px;
    font-size: 1.55rem;
    font-weight: 750;
    letter-spacing: -0.02em;
    color: var(--text);
}

.dash-hero__text {
    margin: 0;
    max-width: 40rem;
    color: var(--text-muted);
    font-size: 0.94rem;
    line-height: 1.45;
}

.dash-hero__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.dash-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.dash-metric {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px 18px 16px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
    position: relative;
    overflow: hidden;
}

.dash-metric::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
}

.dash-metric--blue::before { background: #2563eb; }
.dash-metric--amber::before { background: #d97706; }
.dash-metric--green::before { background: #16a34a; }
.dash-metric--slate::before { background: #64748b; }

.dash-metric__icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 0.85rem;
    font-weight: 800;
}

.dash-metric--blue .dash-metric__icon {
    background: rgba(37, 99, 235, 0.12);
    color: #2563eb;
}
.dash-metric--amber .dash-metric__icon {
    background: rgba(217, 119, 6, 0.14);
    color: #b45309;
}
.dash-metric--green .dash-metric__icon {
    background: rgba(22, 163, 74, 0.12);
    color: #15803d;
}
.dash-metric--slate .dash-metric__icon {
    background: rgba(100, 116, 139, 0.14);
    color: #475569;
}

.dash-metric__value {
    font-size: 1.9rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.03em;
    color: var(--text);
}

.dash-metric__label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-muted);
}

.dash-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(260px, 0.85fr);
    gap: 16px;
    align-items: start;
}

.dash-section {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
    padding: 18px 20px 16px;
}

.dash-section__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.dash-section__title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}

.dash-table th,
.dash-table td {
    text-align: left;
    padding-left: 4px;
    padding-right: 12px;
    background: transparent !important;
}

.dash-table tbody tr:last-child td {
    border-bottom: 0;
}

.dash-table__name {
    font-weight: 650;
    color: var(--text);
}

.dash-steps {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.dash-step {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    position: relative;
    padding-bottom: 18px;
}

.dash-step:last-child { padding-bottom: 0; }

.dash-step:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 16px;
    top: 34px;
    bottom: 0;
    width: 2px;
    background: rgba(37, 99, 235, 0.18);
}

.dash-step__num {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    font-weight: 800;
    color: #fff;
    background: #2563eb;
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.28);
    position: relative;
    z-index: 1;
}

.dash-step__title {
    display: block;
    margin-top: 4px;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
}

.dash-step__text {
    margin: 4px 0 0;
    font-size: 0.84rem;
    line-height: 1.45;
    color: var(--text-muted);
}

@media (max-width: 980px) {
    .dash-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dash-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .dash-metrics { grid-template-columns: 1fr; }
}

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.metric-card__value { font-size: 2rem; font-weight: 800; color: var(--primary); }
.metric-card__label { color: var(--text-muted); font-size: .9rem; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.panel--narrow { max-width: 560px; }
.panel__title { margin: 0 0 8px; font-size: 1.1rem; }
.panel__text { color: var(--text-muted); margin: 0; }
.profile-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: stretch;
    max-width: 560px;
}
.profile-grid .panel {
    max-width: none;
    width: 100%;
}
.profile-grid .panel__text { margin-bottom: 18px; }

/* List pages: Search : [textbox] on one horizontal row above the table card */
.list-search {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 10px;
    margin: 0 0 14px;
    padding: 0;
    background: none;
    border: 0;
    box-shadow: none;
}
.list-search__label {
    display: inline-block;
    font-size: .875rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    flex: 0 0 auto;
    margin: 0;
}
.list-search__input,
.list-search .extraction-input {
    display: inline-block !important;
    width: 280px !important;
    max-width: min(360px, calc(100% - 90px)) !important;
    min-width: 160px !important;
    flex: 0 0 auto !important;
    margin: 0;
}
.list-search__hint {
    font-size: .8rem;
    margin-left: auto;
}

/* Shared list-table sort headers — default theme text; active sort uses primary blue */
.table-sort,
.table-sort:link,
.table-sort:visited,
.table-sort:hover,
.table-sort:active,
.table-sort:focus {
    color: inherit !important;
    text-decoration: none !important;
    border-bottom: 0 !important;
    box-shadow: none !important;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
}
.table-sort:hover {
    color: var(--text) !important;
    text-decoration: none !important;
}
.table-sort.is-active,
.table-sort.is-active:link,
.table-sort.is-active:visited,
.table-sort.is-active:hover {
    color: var(--primary) !important;
    text-decoration: none !important;
}
.table-sort__arrows {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 0.7;
    gap: 1px;
    font-size: 0.55rem;
    color: #94a3b8 !important;
    vertical-align: middle;
    text-decoration: none !important;
}
.table-sort:hover .table-sort__arrows {
    color: #64748b !important;
}
.table-sort.is-active.is-asc .table-sort__up,
.table-sort.is-active.is-desc .table-sort__down {
    color: var(--primary) !important;
}
.table-sort.is-active.is-asc .table-sort__down,
.table-sort.is-active.is-desc .table-sort__up {
    color: #cbd5e1 !important;
}
.list-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-start;
}
.list-actions .btn--ghost {
    background: #ffffff !important;
    border: 1px solid #d0d7e2 !important;
    color: #334155 !important;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    padding: 6px 8px;
    min-height: 32px;
}
.list-actions .btn--ghost:hover {
    background: #f8fafc !important;
    color: #0f172a !important;
}
.list-actions .btn--ghost.btn--danger {
    color: var(--red) !important;
}
.list-actions .btn--ghost.btn--danger:hover {
    background: var(--red-bg) !important;
    border-color: #fecaca !important;
    color: var(--red) !important;
}
.topbar-view,
.topbar-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    padding: 0;
    border: none;
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, box-shadow .15s, transform .15s;
}
.topbar-view svg,
.topbar-delete svg { display: block; }
.topbar-view {
    background: #2563eb;
    box-shadow: 0 1px 2px rgba(37, 99, 235, .35);
}
.topbar-view:hover {
    background: #1d4ed8;
    box-shadow: 0 4px 10px rgba(37, 99, 235, .4);
    transform: translateY(-1px);
    color: #fff;
}
.topbar-delete {
    background: #dc2626;
    box-shadow: 0 1px 2px rgba(220, 38, 38, .35);
}
.topbar-delete:hover {
    background: #b91c1c;
    box-shadow: 0 4px 10px rgba(220, 38, 38, .4);
    transform: translateY(-1px);
    color: #fff;
}
.dark-mode .list-actions .btn--ghost {
    background: var(--surface) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
    box-shadow: none;
}
.dark-mode .list-actions .btn--ghost:hover {
    background: var(--surface-alt) !important;
}
.dark-mode .topbar-view,
.dark-mode .topbar-delete {
    color: #fff;
}
.dark-mode .topbar-view {
    background: #2563eb;
}
.dark-mode .topbar-view:hover {
    background: #1d4ed8;
    color: #fff;
}
.dark-mode .topbar-delete {
    background: #dc2626;
}
.dark-mode .topbar-delete:hover {
    background: #b91c1c;
    color: #fff;
}
.list-row.is-filtered-out,
.boq-list-row.is-filtered-out,
.db-list-row.is-filtered-out,
.audit-list-row.is-filtered-out,
.notif-list-row.is-filtered-out,
.users-list-row.is-filtered-out {
    display: none;
}


/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.toolbar__info { color: var(--text-muted); margin: 0; font-weight: 600; }

.link-action {
    color: #7c3aed;
    font-weight: 600;
    text-decoration: none;
}
.link-action:hover { color: #6d28d9; text-decoration: underline; }

.detail-list { margin: 0; }
.detail-list__row {
    display: grid;
    grid-template-columns: minmax(120px, 180px) 1fr;
    gap: 8px 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.detail-list__row:last-child { border-bottom: none; }
.detail-list__row dt {
    margin: 0;
    color: var(--text-muted);
    font-size: .85rem;
    font-weight: 600;
}
.detail-list__row dd { margin: 0; font-weight: 500; }

.topbar__heading-row {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    text-decoration: none;
}
.topbar__heading-text {
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: none;
    color: var(--text);
}
.topbar__back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 10px;
    border: 1px solid transparent;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(37, 99, 235, .35);
    transition: background .15s, box-shadow .15s, transform .15s;
}
.topbar__back:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 10px rgba(37, 99, 235, .4);
    transform: translateX(-2px);
}
.topbar__back svg { display: block; }

.tab-bar {
    display: inline-flex;
    gap: 6px;
    padding: 4px;
    margin-bottom: 20px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.tab-bar--lg {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    max-width: 640px;
    padding: 8px;
    margin-bottom: 28px;
    border-radius: 16px;
    box-shadow: inset 0 1px 3px rgba(15, 23, 42, .05);
}
.tab-bar__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: .88rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .18s, color .18s, box-shadow .18s, transform .12s;
}
.tab-bar--lg .tab-bar__btn {
    min-height: 52px;
    padding: 16px 24px;
    font-size: 1.05rem;
    font-weight: 700;
    border-radius: 12px;
    letter-spacing: .01em;
}
.tab-bar__btn:hover { color: var(--primary); background: rgba(37, 99, 235, .08); }
.tab-bar__btn.is-active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, .32);
}
.tab-bar--lg .tab-bar__btn.is-active:hover { color: #fff; }

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}
.sheet-header .panel__title { margin: 0; }
.sheet-header__file { font-size: .85rem; }

.boq-detail-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
    flex-wrap: wrap;
}

        .boq-detail-toolbar {
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto;
            align-items: center;
            gap: 12px;
            width: 100%;
            margin-bottom: 8px;
        }

        .boq-detail-toolbar__status {
            justify-self: start;
        }

        .boq-detail-toolbar__actions {
            justify-self: end;
            display: flex;
            align-items: center;
            justify-content: flex-end;
            gap: 8px;
            flex-wrap: wrap;
        }

.boq-detail-toolbar__actions form {
    display: inline-flex;
    margin: 0;
}

.boq-detail-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 4px;
    width: 100%;
    position: sticky;
    top: 63px;
    z-index: 10;
    background: var(--surface-alt);
    padding-top: 0;
}

.boq-detail-header .boq-tabs {
    margin-bottom: 0;
}

.boq-tab-context {
    display: flex;
    align-items: center;
    gap: 8px 12px;
    width: 100%;
    min-height: 0;
    padding: 2px 0 4px;
}

.boq-tab-context__status {
    flex-shrink: 0;
}

.boq-tab-context__summary {
    flex: 1 1 auto;
    min-width: 0;
    font-size: .8rem;
    line-height: 1.35;
    color: var(--text-muted);
}

.boq-tab-context__summary strong {
    color: var(--text);
    font-weight: 600;
}

.boq-tab-context__actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.btn--analysis-loading,
.btn--analysis-loading:disabled {
    background: #f59e0b !important;
    border-color: #f59e0b !important;
    color: #111827 !important;
    cursor: wait;
    box-shadow: 0 2px 8px rgba(245, 158, 11, .28);
}

.btn--matching-loading,
.btn--matching-loading:disabled {
    background: #ef4444 !important;
    border-color: #ef4444 !important;
    color: #fff !important;
    cursor: wait;
    box-shadow: 0 2px 8px rgba(239, 68, 68, .28);
}

.analysis-loading-panel__dot--red {
    background: #ef4444;
}

.boq-view .panel {
    margin-top: 0;
}

.boq-view {
    width: 100%;
}

.boq-view .panel__text--muted {
    margin: 0 0 10px;
    font-size: .85rem;
}

.analysis-review-form {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0;
}

.analysis-review-form select {
    min-width: 180px;
    max-width: 260px;
    padding: 4px 8px;
    font-size: .8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
}

.analysis-loading-panel {
    border: 1px solid rgba(245, 158, 11, .45);
    border-radius: 12px;
    background: rgba(245, 158, 11, .08);
    padding: 14px;
}

.analysis-tab-canvas {
    position: relative;
    min-height: 420px;
}

.analysis-loading-center--active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    min-height: 420px;
    width: 100%;
    padding: 64px 20px;
    text-align: center;
    box-sizing: border-box;
}

.analysis-loading-center__spinner {
    display: block;
    flex-shrink: 0;
    box-sizing: border-box;
    width: 56px;
    height: 56px;
    margin: 0 auto;
    border-radius: 50%;
    border: 5px solid #bfdbfe;
    border-top-color: #2563eb;
    animation: analysisSpinnerSpin 0.7s linear infinite;
}

.analysis-loading-center__percent {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.analysis-loading-center__title {
    margin: 0;
    max-width: 24rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.35;
}

.analysis-loading-panel__body {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
}

.analysis-loading-panel__body--centered {
    flex-direction: column;
    justify-content: center;
    text-align: center;
    gap: 12px;
    padding: 18px 12px 8px;
}

.analysis-loading-panel__copy {
    min-width: 0;
}

.analysis-loading-panel__percent {
    display: block;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text);
    line-height: 1.2;
}

.analysis-loading-panel__title {
    margin: 6px 0 0;
    color: var(--text);
    font-size: .95rem;
    font-weight: 600;
}

.analysis-loading-panel__detail {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: .82rem;
}

.analysis-loading-panel__copy strong {
    display: block;
    font-size: 1rem;
}

.analysis-loading-panel__copy p {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: .86rem;
}

/* Small rotating spinner (CSS only — not an SVG fill). */
.analysis-loading-spinner {
    position: relative;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.analysis-loading-spinner__arc {
    display: block;
    box-sizing: border-box;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid rgba(245, 158, 11, 0.22);
    border-top-color: #f59e0b;
    animation: analysisSpinnerSpin 0.75s linear infinite;
}

@keyframes analysisSpinnerSpin {
    to {
        transform: rotate(360deg);
    }
}

.analysis-loading-progress__bar--determinate {
    width: 4%;
    animation: none;
    transition: width 0.35s ease;
}

.analysis-loading-panel--match .analysis-loading-spinner__arc {
    border-color: rgba(239, 68, 68, 0.22);
    border-top-color: #ef4444;
}

.analysis-loading-panel__dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: #f59e0b;
    box-shadow: 0 0 0 0 rgba(245, 158, 11, .5);
    animation: analysisPulse 1.25s infinite;
}

.analysis-loading-rows {
    display: grid;
    gap: 7px;
}

.analysis-loading-progress {
    margin-top: 2px;
}

.analysis-loading-progress__track {
    height: 10px;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.18);
    overflow: hidden;
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.analysis-loading-progress__bar {
    display: block;
    height: 100%;
    width: 42%;
    border-radius: 999px;
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
    animation: analysisProgressSlide 1.35s ease-in-out infinite;
}

.analysis-loading-panel--match .analysis-loading-progress__track {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.25);
}

.analysis-loading-panel--match .analysis-loading-progress__bar {
    background: linear-gradient(90deg, #ef4444, #f87171);
}

@keyframes analysisProgressSlide {
    0% {
        transform: translateX(-120%);
    }
    100% {
        transform: translateX(320%);
    }
}

.analysis-loading-row {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) 80px;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
}

.analysis-loading-row span {
    font-weight: 700;
    color: var(--primary);
}

.analysis-loading-row div {
    min-width: 0;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.analysis-loading-row em {
    justify-self: end;
    color: #b45309;
    font-style: normal;
    font-size: .78rem;
    font-weight: 700;
}

@keyframes analysisPulse {
    0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, .55); }
    70% { box-shadow: 0 0 0 9px rgba(245, 158, 11, 0); }
    100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

.analysis-table td { vertical-align: middle; }
.analysis-row--pending td { background: rgba(234, 179, 8, .06); }
.analysis-row--matched td { background: rgba(34, 197, 94, .04); }
.analysis-row--reviewed td { background: rgba(37, 99, 235, .05); }

.boq-sheet-wrap { overflow-x: auto; width: 100%; }
.boq-sheet-wrap--fit {
    overflow-x: hidden;
    max-width: 100%;
    width: 100%;
}
.table.boq-sheet { width: 100%; min-width: 100%; table-layout: auto; }
.table.boq-sheet > thead > tr > th,
.table.boq-sheet > tbody > tr > td {
    text-align: left !important;
    vertical-align: top;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
    color: var(--text);
}
.boq-sheet th {
    font-weight: 700;
    text-transform: none !important;
    font-size: .8rem !important;
    letter-spacing: normal !important;
    color: var(--text) !important;
    line-height: 1.25;
    white-space: nowrap;
    hyphens: none;
}
.boq-sheet td { font-weight: 500; }
/* Keep sheet depth backgrounds; do not apply list zebra striping */
.table.boq-sheet tbody tr:nth-child(odd) td,
.table.boq-sheet tbody tr:nth-child(even) td,
.dark-mode .table.boq-sheet tbody tr:nth-child(odd) td,
.dark-mode .table.boq-sheet tbody tr:nth-child(even) td {
    background-color: transparent;
}
/* Indent hierarchy on Description only (BOQ tab). Cap deep nesting so serial
   and description stay aligned — unlimited depth*14px looked like random gaps. */
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__cell.boq-sheet__col-desc {
    padding-left: 12px !important;
}
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__row--depth-1 .boq-sheet__col-desc {
    padding-left: 20px !important;
}
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__row--depth-2 .boq-sheet__col-desc,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__row--depth-3 .boq-sheet__col-desc,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__row--depth-4 .boq-sheet__col-desc,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__row--depth-5 .boq-sheet__col-desc,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__row--depth-6 .boq-sheet__col-desc,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__row--depth-7 .boq-sheet__col-desc,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__row--depth-8 .boq-sheet__col-desc {
    padding-left: 28px !important;
}
.table.boq-sheet.boq-sheet--make-list .boq-sheet__cell.boq-sheet__col-desc {
    padding-left: 12px !important;
}
.boq-sheet__row--depth-0 td { background: transparent !important; }
.boq-sheet__row--depth-1 td { background: rgba(37, 99, 235, .03) !important; }
.boq-sheet__row--depth-2 td,
.boq-sheet__row--depth-3 td,
.boq-sheet__row--depth-4 td,
.boq-sheet__row--depth-5 td,
.boq-sheet__row--depth-6 td,
.boq-sheet__row--depth-7 td,
.boq-sheet__row--depth-8 td { background: rgba(37, 99, 235, .06) !important; }
.dark-mode .boq-sheet__row--depth-1 td { background: rgba(37, 99, 235, .08) !important; }
.dark-mode .boq-sheet__row--depth-2 td,
.dark-mode .boq-sheet__row--depth-3 td,
.dark-mode .boq-sheet__row--depth-4 td,
.dark-mode .boq-sheet__row--depth-5 td,
.dark-mode .boq-sheet__row--depth-6 td,
.dark-mode .boq-sheet__row--depth-7 td,
.dark-mode .boq-sheet__row--depth-8 td { background: rgba(37, 99, 235, .12) !important; }

/* BOQ sheet: min-widths so extra floor/qty columns (GF, 1ST, …) do not crush
   Unit/Qty/Rate. Horizontal scroll via .boq-sheet-wrap when needed. */
.table.boq-sheet:not(.boq-sheet--make-list) col.boq-sheet__col-sno,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__col-sno {
    min-width: 4.5rem;
    width: 4.5rem;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: keep-all !important;
}
.table.boq-sheet:not(.boq-sheet--make-list) col.boq-sheet__col-desc,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__col-desc {
    min-width: 16rem;
    width: auto;
    white-space: normal !important;
}
.table.boq-sheet:not(.boq-sheet--make-list) col.boq-sheet__col-unit,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__col-unit {
    min-width: 3.5rem;
    width: 4rem;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
}
.table.boq-sheet:not(.boq-sheet--make-list) col.boq-sheet__col-qty,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__col-qty {
    min-width: 4rem;
    width: 4.5rem;
}
.table.boq-sheet:not(.boq-sheet--make-list) col.boq-sheet__col-rate,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__col-rate {
    min-width: 5rem;
    width: 6rem;
}
.table.boq-sheet:not(.boq-sheet--make-list) col.boq-sheet__col-amount,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__col-amount {
    min-width: 5rem;
    width: 6rem;
}
.table.boq-sheet:not(.boq-sheet--make-list) col.boq-sheet__col-other,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__col-other {
    min-width: max-content;
    width: max-content;
    max-width: none;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: keep-all !important;
    hyphens: none !important;
}
.table.boq-sheet:not(.boq-sheet--make-list) col.boq-sheet__col-floor,
.table.boq-sheet:not(.boq-sheet--make-list) .boq-sheet__col-floor {
    min-width: max-content;
    width: max-content;
    max-width: none;
    text-align: center !important;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: keep-all !important;
    hyphens: none !important;
    font-size: .78rem;
}
.table.boq-sheet:not(.boq-sheet--make-list) th.boq-sheet__col-floor {
    font-size: .72rem !important;
    line-height: 1.25;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: keep-all !important;
    hyphens: none !important;
}

.analysis-table--compact {
    table-layout: fixed;
    width: 100%;
}
.analysis-table--compact th,
.analysis-table--compact td {
    padding: 6px 8px;
    font-size: .78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.analysis-table--compact .analysis-col-desc {
    white-space: nowrap;
    width: 22%;
}
.analysis-table--compact .analysis-col-sno { width: 4.5%; }
.analysis-table--compact .analysis-col-qty { width: 4%; }
.analysis-table--compact .analysis-col-status { width: 6%; }
.analysis-table--compact .analysis-col-conf { width: 4.5%; }
.analysis-table--compact .analysis-col-num { width: 6.5%; text-align: right; }
.analysis-table--compact .analysis-col-tech { width: 8%; }
.analysis-table--compact .analysis-col-actions {
    width: 9%;
    text-align: center;
    white-space: nowrap;
    overflow: visible;
}
.analysis-action-icons {
    display: inline-flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 2px;
}
.analysis-table--compact .analysis-review-form {
    display: inline-flex;
    margin: 0;
}

/* Review Output format: many numeric columns — keep dense + scroll horizontally. */
.analysis-table--review-output {
    min-width: 1600px;
}
.analysis-table--review-output th,
.analysis-table--review-output td {
    white-space: nowrap;
    font-size: .72rem;
}
.analysis-table--review-output .analysis-col-desc {
    white-space: normal;
    min-width: 140px;
    max-width: 220px;
}
.boq-export-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.analysis-action-btn.btn {
    padding: 2px 7px !important;
    font-size: .62rem !important;
    line-height: 1.2 !important;
    min-height: 0 !important;
    height: 22px !important;
    border-radius: 4px !important;
    font-weight: 600 !important;
    white-space: nowrap !important;
    border-width: 1px !important;
    border-style: solid !important;
}
.analysis-action-btn--confirm.btn {
    background: #2563eb !important;
    border-color: #1d4ed8 !important;
    color: #fff !important;
}
.analysis-action-btn--confirm.btn:hover {
    background: #1d4ed8 !important;
    color: #fff !important;
}
.analysis-action-btn--rematch.btn {
    background: #b91c1c !important;
    border-color: #991b1b !important;
    color: #fff !important;
}
.analysis-action-btn--rematch.btn:hover {
    background: #991b1b !important;
    color: #fff !important;
}
.analysis-action-btn--ghost.btn {
    background: var(--surface) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}
.analysis-action-btn--ghost.btn:hover {
    background: var(--surface-alt) !important;
}
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}
.btn-icon svg { display: block; width: 12px; height: 12px; }
.btn-icon--primary {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}
.btn-icon--primary:hover { background: #1d4ed8; }
.btn-icon--match {
    background: #b91c1c;
    border-color: #991b1b;
    color: #fff;
}
.btn-icon--match:hover { background: #991b1b; }
.btn-icon--ghost:hover { background: var(--surface-alt); }


/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: .9rem; }
.table th {
    color: var(--text) !important;
    font-weight: 700 !important;
    text-transform: uppercase;
    font-size: .72rem !important;
    letter-spacing: .04em;
}
.table th a,
.table th a:link,
.table th a:visited,
.table th a:hover,
.table th a:active,
.table th a:focus {
    color: inherit !important;
    text-decoration: none !important;
    border-bottom: 0 !important;
}
.table th a.table-sort.is-active,
.table th a.table-sort.is-active:link,
.table th a.table-sort.is-active:visited,
.table th a.table-sort.is-active:hover {
    color: var(--primary) !important;
}
.dark-mode .table th,
.dark-mode .table th a,
.dark-mode .table th a:link,
.dark-mode .table th a:visited,
.dark-mode .table-sort,
.dark-mode .table-sort:link,
.dark-mode .table-sort:visited,
.dark-mode .table-sort:hover {
    color: var(--text) !important;
    text-decoration: none !important;
}
.dark-mode .table-sort.is-active,
.dark-mode .table-sort.is-active:link,
.dark-mode .table-sort.is-active:visited,
.dark-mode .table-sort.is-active:hover,
.dark-mode .table th a.table-sort.is-active {
    color: #60a5fa !important;
    text-decoration: none !important;
}
.dark-mode .table-sort__arrows {
    color: #94a3b8 !important;
}
.dark-mode .table-sort.is-active.is-asc .table-sort__up,
.dark-mode .table-sort.is-active.is-desc .table-sort__down {
    color: #60a5fa !important;
}
.dark-mode .table-sort.is-active.is-asc .table-sort__down,
.dark-mode .table-sort.is-active.is-desc .table-sort__up {
    color: #475569 !important;
}
.table th.table__actions, .table td.table__actions, .table__empty {
    text-align: left;
}
.table tbody tr:nth-child(odd) td { background-color: #ffffff; }
.table tbody tr:nth-child(even) td { background-color: #e2e8f0; }
.table.table--plain tbody tr td,
.table.table--plain tbody tr:nth-child(odd) td,
.table.table--plain tbody tr:nth-child(even) td {
    background-color: transparent !important;
}
.table__actions { text-align: left; white-space: nowrap; }
.table__actions > * { margin-left: 0; }
.table tbody .table__actions .btn--ghost {
    background: #ffffff !important;
    border: 1px solid #d0d7e2 !important;
    color: #334155 !important;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.table tbody .table__actions .btn--ghost:hover {
    background: #f8fafc !important;
    color: #0f172a !important;
}
.dark-mode .table tbody .table__actions .btn--ghost {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
    color: #1e293b !important;
}
.btn--table-action {
    background: #ffffff !important;
    border: 1px solid #d0d7e2 !important;
    color: #334155 !important;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    text-decoration: none;
}
.btn--table-action:hover {
    background: #f8fafc !important;
    color: #0f172a !important;
}
.btn--table-action svg {
    display: block;
    flex-shrink: 0;
}
.dark-mode .btn--table-action {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
    color: #1e293b !important;
}
.table__empty { text-align: center; color: var(--text-muted); padding: 32px; }
.inline-form { display: inline; }

/* Make List tab: fluid CSS grid — scales on resize; scroll only when needed.
   Stretch cells + row-level border so wrapped descriptions never get mid-row
   lines from shorter/empty neighbouring cells. */
.make-list-sheet {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.make-list-sheet__head,
.make-list-sheet__row {
    display: grid;
    width: 100%;
    min-width: min(100%, 36rem);
    box-sizing: border-box;
    /* S.No | Description | Category | Subcategory | Approved Makes */
    grid-template-columns:
        minmax(2.75rem, 3.5rem)
        minmax(7rem, 1.35fr)
        minmax(4.5rem, 0.55fr)
        minmax(5rem, 0.65fr)
        minmax(7rem, 1.25fr);
    column-gap: clamp(0.5rem, 2vw, 2rem);
    align-items: stretch;
    border-bottom: 1px solid var(--border);
}
.make-list-sheet__cell {
    padding: 12px 8px;
    font-size: .9rem;
    color: var(--text);
    overflow-wrap: break-word;
    word-break: normal;
    min-width: 0;
    text-align: left;
}
.make-list-sheet__cell.boq-sheet__col-mapped-cat,
.make-list-sheet__cell.boq-sheet__col-mapped-sub,
.make-list-sheet__cell.boq-sheet__col-makes {
    width: 100%;
    max-width: none;
    justify-self: stretch;
}
.make-list-sheet__cell--head {
    font-weight: 700;
    font-size: .85rem;
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface);
}
.make-list-sheet__cell.boq-sheet__col-sno {
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: keep-all;
}
.make-list-sheet__row--section .make-list-sheet__cell.boq-sheet__col-desc {
    font-weight: 700;
    color: var(--text);
}
.make-list-sheet__row--section {
    background: color-mix(in srgb, var(--surface-alt) 70%, transparent);
}

/* ---------- Status toggle ---------- */
.status-toggle {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 4px 8px 4px 5px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text-muted); font: inherit; font-size: .8rem; font-weight: 700;
    cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
.status-toggle__track {
    width: 32px; height: 18px; border-radius: 999px;
    display: inline-flex; align-items: center; padding: 2px;
    background: #cbd5e1; transition: background .15s;
}
.status-toggle__knob {
    width: 14px; height: 14px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, .24);
    transition: transform .15s;
}
.status-toggle--active { color: var(--green); border-color: #bbf7d0; background: var(--green-bg); }
.status-toggle--active .status-toggle__track { background: var(--green); }
.status-toggle--active .status-toggle__knob { transform: translateX(14px); }
.status-toggle--inactive { color: var(--red); border-color: #fecaca; background: var(--red-bg); }
.status-toggle--inactive .status-toggle__track { background: var(--red); }
.status-toggle--disabled { cursor: default; opacity: .75; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-alt); border: 1px solid var(--border); }
.badge--green { background: var(--green-bg); color: var(--green); border-color: transparent; }
.badge--red { background: var(--red-bg); color: var(--red); border-color: transparent; }
.badge--yellow { background: var(--yellow-bg); color: #854d0e; border-color: transparent; }
.badge--orange { background: #f3e0c8; color: #7c2d12; border-color: transparent; }
.badge--blank { background: var(--surface-alt); color: var(--text-muted); }
.badge--warn { background: #ffedd5; color: #9a3412; border-color: transparent; }
.badge--purple { background: #f3e8ff; color: #7e22ce; border-color: transparent; }
.badge--blue { background: #dbeafe; color: #1d4ed8; border-color: transparent; }
.badge--gray { background: #f1f5f9; color: #475569; border-color: transparent; }
.badge--dark { background: #334155; color: #f8fafc; border-color: transparent; }

.extraction-list {
    margin: 0;
    padding-left: 1.1rem;
    font-size: .85rem;
}

.extraction-list li + li {
    margin-top: 4px;
}

.extraction-db-candidates__sep {
    color: #334155;
    font-weight: 600;
}

.extraction-db-candidates__tech {
    color: #1e293b;
}

/* ---------- Review ---------- */
.select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: .85rem; }
.select--small { font-size: .8rem; max-width: 220px; }
.muted { color: var(--text-muted); font-size: .8rem; }
.review-row__desc { max-width: 320px; }
.review-row--green { border-left: 3px solid var(--green); }
.review-row--yellow { border-left: 3px solid #ca8a04; }
.review-row--orange { border-left: 3px solid #c2410c; }
.review-row--red { border-left: 3px solid var(--red); }
.review-row--blank { border-left: 3px solid var(--border); }
.review-row--nested td { background: var(--surface-alt); }
.review-row--nested .review-row__desc { padding-left: 12px; }
.review-detail { padding: 8px 0 12px; }
.review-detail__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.review-detail__title {
    margin: 0 0 8px;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}
.review-detail__list {
    margin: 0;
    padding-left: 18px;
}
.review-detail__list li { margin-bottom: 6px; }
.review-detail__matches { margin-top: 12px; }
.review-detail__section { margin-bottom: 16px; }
.review-detail__subtitle {
    margin: 10px 0 6px;
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
}
.review-detail__list--rich li { margin-bottom: 10px; }
.review-detail__specs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    margin-top: 4px;
    font-size: .78rem;
    color: var(--text-muted);
}
.review-detail__specs span::before { content: "· "; }
.review-detail__specs span:first-child::before { content: ""; }
.review-row__meta { font-size: .78rem; line-height: 1.35; }
.review-rate-picker { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.table--review { min-width: 1100px; }
.table--review th,
.table--review td { font-size: .82rem; vertical-align: top; }
.review-breakdown-table { width: 100%; margin-top: 4px; }
.review-breakdown-table th,
.review-breakdown-table td { font-size: .78rem; }
.review-breakdown-table__total-label { text-align: right; font-weight: 600; }
.review-meta-list {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    font-size: .82rem;
}
.review-meta-list dt { color: var(--text-muted); font-weight: 500; }
.review-meta-list dd { margin: 0; }

/* Make & Vendor / Labour / Review line cards — same white/grey as Analysis. */
.make-vendor-line {
    margin: 0;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.make-vendor-lines > .make-vendor-line:nth-of-type(even),
.make-vendor-line--alt {
    background: var(--card-stripe, #e2e8f0) !important;
}

/* ---------- Alerts / messages ---------- */
.messages { display: flex; flex-direction: column; gap: 10px; padding: 16px 28px 0; }
.messages--floating { position: fixed; top: 16px; right: 16px; z-index: 100; padding: 0; max-width: 360px; }
.alert { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-radius: 8px; font-size: .9rem; background: var(--surface-alt); border: 1px solid var(--border); }
.alert--success { background: var(--green-bg); color: var(--green); border-color: transparent; }
.alert--error { background: var(--red-bg); color: var(--red); border-color: transparent; }
.alert--info { background: #dbeafe; color: var(--primary-dark); border-color: transparent; }
.alert--warning { background: var(--yellow-bg); color: #854d0e; border-color: transparent; }
.alert__close { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: inherit; }

/* ---------- Confirmation modal ---------- */
.confirm-modal {
    position: fixed; inset: 0; z-index: 200;
    display: grid; place-items: center; padding: 24px;
}
.confirm-modal[hidden] { display: none; }
.confirm-modal__backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, .58);
}
.confirm-modal__dialog {
    position: relative; width: min(420px, 100%);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: 0 24px 64px rgba(15, 23, 42, .28);
    padding: 22px;
}
.confirm-modal__title { margin: 0 0 8px; color: var(--text); font-size: 1.1rem; }
.confirm-modal__message { margin: 0; color: var(--text-muted); white-space: pre-line; }
.confirm-modal__field {
    display: grid;
    gap: 6px;
    margin-top: 14px;
}
.confirm-modal__field[hidden] { display: none !important; }
.confirm-modal__field-label {
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-muted);
}
.confirm-modal__input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    background: var(--surface);
    color: var(--text);
}
.confirm-modal__error {
    margin: 10px 0 0;
    color: var(--red);
    font-size: .88rem;
}
.confirm-modal__error[hidden] { display: none !important; }
.confirm-modal__actions {
    display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px;
}

/* ---------- Processing / progress ---------- */
.proc { display: flex; flex-direction: column; gap: 8px; }
.proc__head { display: flex; align-items: center; gap: 12px; }
.proc__msg { color: var(--text-muted); font-size: .9rem; }
.proc__pct { color: var(--text-muted); font-size: .8rem; align-self: flex-end; }
.progress { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 999px; height: 10px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .4s ease; }
.progress__bar--error { background: var(--red); }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.pagination__info { color: var(--text-muted); font-size: .85rem; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .sidebar {
        width: min(280px, 86vw);
        max-width: calc(100vw - 48px);
        transform: translateX(-100%);
    }
    .sidebar.is-open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.4); }
    .main { margin-left: 0; min-width: 0; width: 100%; }
    .topbar {
        padding: 12px 14px;
        gap: 10px;
    }
    .topbar__menu { display: block; }
    .topbar__title {
        font-size: 1.05rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .content {
        padding: 14px;
    }
    .panel {
        padding: 16px;
    }
    .toolbar {
        flex-wrap: wrap;
        gap: 10px;
        align-items: flex-start;
    }
    .form-actions {
        flex-wrap: wrap;
    }
    .profile-grid {
        grid-template-columns: 1fr;
        flex-direction: column;
    }
    .detail-list__row {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .auth__card {
        padding: 28px 20px;
    }
    .messages--floating {
        left: 12px;
        right: 12px;
        max-width: none;
    }
    .panel:has(.table),
    .d-panel:has(.table),
    .boq-sheet-wrap,
    .boq-sheet-wrap--fit {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .d-panel > div:has(.table) {
        overflow-x: auto !important;
        overflow-y: hidden;
    }
    .table {
        table-layout: auto;
        width: max-content;
        min-width: 100%;
    }
    .table th,
    .table td {
        white-space: nowrap;
    }
    .table.boq-sheet {
        width: 100% !important;
        min-width: 100% !important;
        max-width: none !important;
        table-layout: auto !important;
    }
    .make-list-sheet__head,
    .make-list-sheet__row {
        grid-template-columns:
            minmax(2.5rem, 3rem)
            minmax(6rem, 1.2fr)
            minmax(4rem, 0.5fr)
            minmax(4.5rem, 0.55fr)
            minmax(6rem, 1.1fr) !important;
        column-gap: clamp(0.35rem, 1.5vw, 1.25rem) !important;
        min-width: 0 !important;
    }
    .table.boq-sheet th,
    .table.boq-sheet td {
        text-align: left !important;
        white-space: nowrap !important;
        hyphens: none !important;
    }
    .table.boq-sheet .boq-sheet__col-desc,
    .table.boq-sheet td.boq-sheet__col-desc {
        white-space: normal !important;
    }
    .table.boq-sheet .boq-sheet__col-sno,
    .table.boq-sheet .boq-sheet__col-unit,
    .table.boq-sheet .boq-sheet__col-floor,
    .table.boq-sheet .boq-sheet__col-other {
        white-space: nowrap !important;
        overflow-wrap: normal !important;
        word-break: keep-all !important;
        hyphens: none !important;
        max-width: none !important;
    }
    .analysis-table--compact {
        table-layout: auto;
        min-width: 960px;
    }
    .analysis-table--compact th,
    .analysis-table--compact td {
        white-space: nowrap;
    }
}

@media (max-width: 560px) {
    .content {
        padding: 12px;
    }
    .topbar {
        padding: 10px 12px;
    }
    .btn {
        min-height: 42px;
    }
    .btn--small {
        min-height: 36px;
        padding: 8px 12px;
    }
    .form-actions {
        flex-direction: column-reverse;
        align-items: stretch;
    }
    .form-actions .btn {
        width: 100%;
    }
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar .btn {
        width: 100%;
        justify-content: center;
    }
    .pagination {
        flex-wrap: wrap;
    }
    .auth {
        padding: 16px;
    }
}

/* Labour tab */
.labour-panel {
    display: grid;
    gap: 14px;
    width: 100%;
    box-sizing: border-box;
}
.labour-toolbar,
.labour-toolbar--bar {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    width: 100% !important;
    max-width: 100%;
    box-sizing: border-box;
    margin-bottom: 4px;
}
.labour-mode-toggle {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    flex: 0 0 auto;
}
.labour-toolbar__spacer {
    flex: 1 1 auto;
    min-width: 16px;
}
.labour-toolbar__actions {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex: 0 0 auto;
    margin-left: 0;
}
.labour-manual-card {
    margin: 0;
    padding: 12px 14px;
}
/* Flex wrap: compact for 2 inputs, wraps cleanly for 10–15. */
.labour-category-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 12px;
    align-items: end;
}
.labour-category-field {
    flex: 0 1 170px;
    width: 170px;
    max-width: 100%;
    min-width: 140px;
    margin: 0;
}
.extraction-field--mismatched .extraction-input,
.extraction-input--mismatched {
    background-color: #ffeaea !important;
    border-color: #ffbaba !important;
}

.labour-category-field .extraction-field__label {
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.labour-category-field .extraction-input {
    width: 100%;
    box-sizing: border-box;
}
.labour-missing { color: #b91c1c; }
.labour-table-wrap { margin-top: 4px; }
.labour-lines { margin-top: 4px; }

@media (max-width: 560px) {
    .labour-category-field {
        flex: 1 1 100%;
        width: 100%;
    }
}
