/* =========================================================================
   THEME TOKENS — single source of truth.
   The entire app is themed from the variables in this :root block. To
   re-skin the app (colours, gradients, borders, shadows, radii), change
   values here only; nothing below hard-codes a colour.
   Current theme: light "shiny green / silver".
   ========================================================================= */
:root {
    /* ---- Surfaces (light silver, faint green tint; elevation -> whiter) ---- */
    --bg: #e7eeea;
    --bg-elev: #f3f7f4;
    --bg-elev-2: #ffffff;
    --bg-elev-3: #dde8e1;

    /* ---- Borders (green — used on buttons, tables, inputs, chips, cards) ---- */
    --border: #5cba8b;
    --border-strong: #2f9d66;

    /* ---- Text (dark green-slate) ---- */
    --text: #16271d;
    --text-dim: #46584d;
    --text-faint: #7b8a81;

    /* ---- Accent (shiny emerald) ---- */
    --accent: #0e9f6e;
    --accent-hover: #0b8358;
    --accent-soft: rgba(14, 159, 110, 0.12);
    --accent-soft-strong: rgba(14, 159, 110, 0.20);
    --accent-ink: #ffffff;              /* text/icons on top of accent fills */
    --accent-grad-from: #34d399;
    --accent-grad-to: #0e9f6e;
    --accent-grad-hover-from: #4ade9f;
    --accent-grad-hover-to: #13b27c;
    --metric-total: #2563eb;            /* "Total" special option in metric category picker */

    /* ---- Silver (shiny neutral fills, e.g. avatars / metallic chrome) ---- */
    --silver-grad-from: #fdfefe;
    --silver-grad-to: #c6d2cb;

    /* ---- Status ---- */
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success-soft: rgba(22, 163, 74, 0.14);
    --warning-soft: rgba(217, 119, 6, 0.16);
    --danger-soft: rgba(220, 38, 38, 0.12);
    --success-text: #15803d;
    --warning-text: #b45309;
    --danger-text: #b91c1c;

    /* ---- Translucent chrome / overlays ---- */
    --overlay: rgba(18, 38, 28, 0.38);
    --topbar-bg: rgba(243, 247, 244, 0.85);
    --sticky-bg: rgba(243, 247, 244, 0.92);
    --row-hover: rgba(14, 159, 110, 0.07);
    --row-tint: rgba(14, 159, 110, 0.04);
    --hairline: rgba(22, 39, 29, 0.06);

    /* ---- Auth backdrop glows ---- */
    --glow-1: rgba(14, 159, 110, 0.16);
    --glow-2: rgba(52, 211, 153, 0.14);

    /* ---- Badges (special categories) ---- */
    --badge-internal-bg: rgba(202, 138, 4, 0.16);
    --badge-internal-fg: #a16207;
    --badge-internal-bd: rgba(202, 138, 4, 0.45);
    --badge-labour-bg: rgba(14, 159, 110, 0.16);
    --badge-labour-fg: #0b8358;
    --badge-labour-bd: rgba(14, 159, 110, 0.45);
    --badge-uli-bg: rgba(220, 38, 38, 0.12);
    --badge-uli-fg: #b91c1c;
    --badge-uli-bd: rgba(220, 38, 38, 0.40);

    /* ---- PDF / viewer stage ---- */
    --stage-bg: #c8d2cc;

    /* ---- Radii ---- */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;

    /* ---- Shadows (soft, green-tinted) ---- */
    --shadow-sm: 0 1px 2px rgba(20, 45, 32, 0.10);
    --shadow: 0 6px 18px rgba(20, 45, 32, 0.12);
    --shadow-lg: 0 14px 44px rgba(20, 45, 32, 0.18);
    --shadow-glow: 0 2px 10px rgba(14, 159, 110, 0.32);
    /* metallic top-edge highlight for a "shiny" finish on filled controls */
    --sheen: inset 0 1px 0 rgba(255, 255, 255, 0.45);

    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
}

/* Theme the shared Mason app shell (mason_common/app_shell.css — Dashboard +
 * Projects) with the Quotes palette so those shared screens render in green,
 * identical to the rest of the app. Only these tokens differ between apps. */
body {
    --mc-bg: var(--bg);
    --mc-surface: var(--bg-elev);
    --mc-surface-2: var(--bg-elev-2);
    --mc-border: var(--border);
    --mc-border-strong: var(--border-strong);
    --mc-text: var(--text);
    --mc-text-dim: var(--text-dim);
    --mc-text-faint: var(--text-faint);
    --mc-accent: var(--accent);
    --mc-accent-ink: var(--accent-ink);
    --mc-accent-soft: var(--accent-soft);
    --mc-accent-grad-from: var(--accent-grad-from);
    --mc-accent-grad-to: var(--accent-grad-to);
    --mc-accent-grad-hover-from: var(--accent-grad-hover-from);
    --mc-accent-grad-hover-to: var(--accent-grad-hover-to);
    --mc-radius: var(--radius);
    --mc-radius-sm: var(--radius-sm);
    --mc-radius-lg: var(--radius-lg);
    --mc-shadow: var(--shadow);
    --mc-shadow-lg: var(--shadow-lg);
    --mc-shadow-glow: var(--shadow-glow);
    --mc-sheen: var(--sheen);
    --mc-overlay: var(--overlay);
    --mc-mono: var(--mono);
}

/* Theme the shared Mason table (mason_common/table.css) with the Quotes
 * palette + the BOM "Rates & Quantities" density. The rates table carries the
 * .mtbl classes; these vars make it render exactly as before. App-specific cell
 * internals (inputs, tree lines, join pill, badges, readouts) stay below. */
.mtbl {
    --mtbl-surface: var(--bg-elev-2);
    --mtbl-head-bg: var(--bg-elev-2);
    --mtbl-foot-bg: var(--bg-elev-2);
    --mtbl-group-bg: var(--bg-elev-3);
    --mtbl-border: var(--border);
    --mtbl-hairline: var(--hairline);
    --mtbl-text: var(--text);
    --mtbl-text-dim: var(--text-dim);
    --mtbl-row-hover: var(--row-tint);
    --mtbl-accent: var(--accent);
    --mtbl-font: 12.5px;
    --mtbl-head-font: 11px;
    --mtbl-cell-pad: 0 8px;
    --mtbl-head-pad: 10px 14px;
    --mtbl-group-pad: 3px 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
::placeholder { color: var(--text-faint); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- Layout ---- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.main { flex: 1; padding: 32px clamp(20px, 4vw, 48px); max-width: 1400px; width: 100%; margin: 0 auto; }
.main--wide { max-width: 1700px; }
.main--full { max-width: none; padding: 0; }

/* ---- Top nav ---- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--topbar-bg);
    backdrop-filter: saturate(150%) blur(12px);
    -webkit-backdrop-filter: saturate(150%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 60px;
    padding: 0 clamp(20px, 4vw, 48px);
    max-width: 1700px;
    margin: 0 auto;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--text);
    margin-right: 24px;
    letter-spacing: -0.01em;
}
.brand-mark {
    width: 28px; height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent-grad-from), var(--accent-grad-to));
    display: grid; place-items: center;
    color: var(--accent-ink); font-weight: 800;
    box-shadow: var(--shadow-glow);
}
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-link {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg-elev-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }

.user-chip {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 12px 4px 4px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elev);
    color: var(--text);
}
.project-chip {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 4px 4px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elev);
    color: var(--text);
    margin-right: 8px;
    max-width: 360px;
}
.project-chip-icon {
    font-size: 12px;
    color: var(--text-faint);
}
.project-chip-name {
    color: var(--text);
    font-weight: 500;
    font-size: 13px;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}
.project-chip-name:hover { color: var(--text); }
.project-chip-ai {
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.project-chip-ai:hover { background: var(--accent-soft-strong); color: var(--accent-hover); }
.project-chip-ai.active {
    background: linear-gradient(180deg, var(--accent-grad-from), var(--accent-grad-to));
    color: var(--accent-ink);
}
.avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, var(--silver-grad-from), var(--silver-grad-to));
    color: var(--text);
    display: grid; place-items: center;
    font-weight: 600; font-size: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--sheen);
}
.user-chip form { margin: 0; }
.btn-link {
    background: none; border: 0; color: var(--text-dim); cursor: pointer;
    font-size: 12px; padding: 4px 8px; border-radius: 6px;
}
.btn-link:hover { background: var(--bg-elev-2); color: var(--text); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--text);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.05s;
    text-decoration: none;
}
.btn:hover { background: var(--bg-elev-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: linear-gradient(180deg, var(--accent-grad-from), var(--accent-grad-to));
    color: var(--accent-ink);
    border-color: transparent;
    font-weight: 600;
    box-shadow: var(--shadow-glow), var(--sheen);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--accent-grad-hover-from), var(--accent-grad-hover-to)); color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-elev-2); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 6px; }

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.input, textarea.input, select.input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.input:focus, textarea.input:focus, select.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: var(--bg-elev-2);
}
.input--lg { padding: 12px 14px; font-size: 15px; }
.input--otp { font-family: var(--mono); letter-spacing: 0.4em; text-align: center; font-size: 22px; }

/* ---- Cards ---- */
.card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.card h3 { margin: 0 0 12px; font-weight: 600; }

/* ---- Page header ---- */
.page-header {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 24px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.page-header h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.page-header p { margin: 4px 0 0; color: var(--text-dim); }

/* ---- Messages ---- */
.flash {
    margin: 0 auto 16px; padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elev);
    font-size: 13px;
    max-width: 1400px;
}
.flash.error { border-color: var(--danger); background: var(--danger-soft); color: var(--danger-text); }
.flash.warning { border-color: var(--warning); background: var(--warning-soft); color: var(--warning-text); }
.flash.success { border-color: var(--success); background: var(--success-soft); color: var(--success-text); }

/* ---- Auth ---- */
.auth-shell {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 24px;
    background:
        radial-gradient(1200px 600px at 80% -10%, var(--glow-1), transparent 70%),
        radial-gradient(800px 400px at -10% 110%, var(--glow-2), transparent 70%),
        var(--bg);
}
.auth-card {
    width: 100%; max-width: 420px;
    padding: 36px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card p.lede { color: var(--text-dim); margin: 0 0 24px; }
.auth-brand {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 24px; font-weight: 600;
}

/* ---- Dashboard ---- */
.stat-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 28px; }
.stat-card { padding: 18px 20px; }
.stat-card .label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card .value { font-size: 28px; font-weight: 600; margin-top: 6px; letter-spacing: -0.02em; }

.dash-grid { display: grid; gap: 20px; grid-template-columns: 1.4fr 1fr; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

.activity-list { display: flex; flex-direction: column; gap: 4px; }
.activity-item {
    display: grid; grid-template-columns: 32px 1fr auto; gap: 12px; align-items: center;
    padding: 10px 12px; border-radius: var(--radius-sm);
}
.activity-item:hover { background: var(--bg-elev-2); }
.activity-icon {
    width: 32px; height: 32px; border-radius: 8px;
    background: var(--accent-soft); color: var(--accent);
    display: grid; place-items: center; font-size: 14px;
}
.activity-summary { font-size: 13.5px; }
.activity-user { font-weight: 700; color: var(--accent); }
.activity-meta { font-size: 12px; color: var(--text-faint); }
.activity-time { color: var(--text-faint); font-size: 12px; white-space: nowrap; }

.empty-state { text-align: center; padding: 32px 16px; color: var(--text-dim); }
.empty-state h3 { color: var(--text); }

/* ---- Project list ---- */
.project-grid {
    display: grid; gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.project-card {
    padding: 18px;
    transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
    cursor: pointer;
    display: flex; flex-direction: column; gap: 10px;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    border-radius: var(--radius);
    color: var(--text);
}
.project-card:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow); }
.project-card .name { font-weight: 600; font-size: 15px; }
.project-card .meta { color: var(--text-dim); font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; }
.project-card .desc { color: var(--text-dim); font-size: 13px; min-height: 36px; }
.project-card .email { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }
.project-card-wrap { position: relative; display: flex; }
.project-card-wrap > .project-card { flex: 1; min-width: 0; }
.project-card-archive { position: absolute; top: 10px; right: 10px; z-index: 2; margin: 0; }
.project-archive-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; padding: 0;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg-elev); color: var(--text-dim); cursor: pointer;
    opacity: 0; transition: opacity .12s, color .12s, border-color .12s;
}
.project-card-wrap:hover .project-archive-btn,
.project-archive-btn:focus-visible { opacity: 1; }
.project-archive-btn:hover { color: var(--text); border-color: var(--border-strong); }
.project-archive-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.project-card-wrap.archived > .project-card { opacity: .68; }
.project-card-wrap.archived:hover > .project-card { opacity: .85; }
.archived-section { margin-top: 28px; }
.archived-section > summary { cursor: pointer; font-weight: 600; color: var(--text-dim); padding: 6px 0; user-select: none; }
.archived-section > summary:hover { color: var(--text); }
.archived-section .project-grid { margin-top: 14px; }
.project-restore-btn { padding: 3px 10px; font-size: 12px; }

/* ---- Modal ---- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: var(--overlay);
    display: none; align-items: center; justify-content: center;
    z-index: 100; padding: 20px;
    backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; }
.modal {
    width: 100%; max-width: 520px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .lede { color: var(--text-dim); font-size: 13px; margin: 0 0 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---- File drop ---- */
.dropzone {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 22px;
    text-align: center;
    color: var(--text-dim);
    background: var(--bg-elev-2);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone strong { color: var(--text); }
.dropzone .hint { font-size: 12px; margin-top: 6px; }
.dropzone input[type=file] { display: none; }
.dropzone-compact {
    padding: 9px 12px;
    text-align: center;
    font-size: 13px;
    border-style: dashed;
    border-width: 1px;
    border-radius: var(--radius-sm);
}
.dropzone-compact strong { font-weight: 500; }
.upload-actions {
    display: flex; justify-content: center; gap: 8px; margin-top: 12px;
}
.upload-summary { margin-top: 10px; }
.upload-summary-head {
    font-size: 12px; color: var(--text-dim);
    margin-bottom: 6px;
}
.rail-upload-buttons {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px;
}
.rail-upload-buttons .btn { padding: 7px 8px; font-size: 12.5px; }
.file-pills {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-top: 10px; max-height: 120px; overflow: auto;
}
.file-pill {
    background: var(--bg-elev-3); padding: 4px 10px;
    border-radius: 999px; font-size: 12px; color: var(--text-dim);
    border: 1px solid var(--border);
}

/* ---- Project detail layout ---- */
.workspace {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    height: calc(100vh - 60px);
    overflow: hidden;
}
@media (max-width: 1200px) {
    .workspace { grid-template-columns: 240px 1fr; }
    .workspace .right-rail { display: none; }
}
@media (max-width: 800px) {
    .workspace { grid-template-columns: 1fr; }
    .workspace .left-rail { display: none; }
}
.left-rail, .right-rail {
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.right-rail { border-right: 0; border-left: 1px solid var(--border); }
/* Folders & files browser: just a folder rail + a wide viewer. */
.workspace--browser { grid-template-columns: 300px 1fr; }
@media (max-width: 800px) { .workspace--browser { grid-template-columns: 1fr; } }
.viewer-pane { background: var(--bg); display: flex; flex-direction: column; min-width: 0; }
/* Project dashboard center column (recent activity); scrolls, not centered. */
.project-dash { flex: 1; overflow-y: auto; padding: 24px; }
.project-dash .card { max-width: 820px; }

.rail-section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.rail-section h4 {
    margin: 0 0 8px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-faint);
    letter-spacing: 0.08em;
    display: flex; justify-content: space-between; align-items: center;
}
.rail-section h4 .add-btn {
    background: none; border: 0; color: var(--text-dim);
    cursor: pointer; padding: 2px 6px; border-radius: 4px; font-size: 14px;
}
.rail-section h4 .add-btn:hover { background: var(--bg-elev-2); color: var(--text); }

.tree-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}
.tree-item:hover { background: var(--bg-elev-2); }
.tree-item.folder { font-weight: 500; }
.tree-item.system { color: var(--text-dim); }
.tree-item .icon { width: 16px; text-align: center; flex-shrink: 0; }
.tree-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .meta { color: var(--text-faint); font-size: 11px; }
.tree-children { padding-left: 16px; border-left: 1px dashed var(--border); margin-left: 8px; }
.tree-item.file.active { background: var(--accent-soft); color: var(--accent); }
.tree-item form { display: inline-flex; }

/* Collapsible folder caret */
.tree-caret {
    width: 14px; height: 14px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: none; border: 0; cursor: pointer; padding: 0;
    color: var(--text-faint); font-size: 10px; line-height: 1;
    transition: transform 0.12s ease;
}
.tree-folder.open > .tree-item > .tree-caret { transform: rotate(90deg); }
.tree-caret-spacer { width: 14px; flex-shrink: 0; display: inline-block; }
.filter-hidden { display: none !important; }

.rail-section h4 .rail-head-actions { display: inline-flex; gap: 2px; }
.tree-search { margin-bottom: 8px; }
.tree-search .input-sm {
    width: 100%; padding: 6px 9px; font-size: 12.5px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg-elev-3); color: var(--text);
}
.tree-search .input-sm:focus { outline: none; border-color: var(--accent); }

/* Upload progress bar */
.upload-progress { margin-top: 10px; }
.upload-progress-head { font-size: 11.5px; color: var(--text-dim); margin-bottom: 5px; }
.upload-progress-track {
    height: 7px; border-radius: 999px; overflow: hidden;
    background: var(--bg-elev-3); border: 1px solid var(--border);
}
.upload-progress-bar {
    height: 100%; width: 0;
    background: var(--accent, #0e9f6e);
    transition: width 0.15s ease;
}

/* ---- Viewer ---- */
.viewer-toolbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elev);
}
.viewer-toolbar .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-toolbar .title .name { font-weight: 500; }
.viewer-toolbar .title .meta { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.viewer-body { flex: 1; overflow: auto; padding: 20px; display: flex; align-items: center; justify-content: center; }
.viewer-body iframe, .viewer-body video, .viewer-body audio, .viewer-body img {
    max-width: 100%; max-height: 100%;
}
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: white; border-radius: var(--radius-sm); }
.viewer-body img { object-fit: contain; }
.viewer-text {
    width: 100%; height: 100%;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 18px;
    font-family: var(--mono);
    font-size: 12.5px;
    white-space: pre-wrap;
    overflow: auto;
    color: var(--text);
}
.viewer-empty {
    text-align: center; color: var(--text-dim); padding: 60px 20px;
}
.viewer-empty .big-icon { font-size: 36px; margin-bottom: 12px; }
.viewer-cad {
    text-align: center; color: var(--text-dim); padding: 40px 20px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 540px;
}
.viewer-cad h3 { color: var(--text); margin-bottom: 8px; }

/* ---- Spreadsheet viewer ---- */
.viewer-spreadsheet {
    width: 100%; height: 100%;
    display: flex; flex-direction: column;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.xlsx-tabs {
    display: flex; gap: 2px; flex-shrink: 0;
    padding: 6px 6px 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    background: var(--bg-elev-2);
}
.xlsx-tab {
    background: transparent;
    border: 1px solid transparent;
    border-bottom: 0;
    color: var(--text-dim);
    padding: 6px 14px;
    font-size: 12.5px;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    white-space: nowrap;
}
.xlsx-tab:hover { background: var(--bg-elev-3); color: var(--text); }
.xlsx-tab.active {
    background: var(--bg-elev);
    border-color: var(--border);
    color: var(--text);
    margin-bottom: -1px;
    border-bottom: 1px solid var(--bg-elev);
}
.xlsx-canvas { flex: 1; overflow: auto; padding: 0; min-height: 0; }
.xlsx-table-wrap { padding: 0; }
.xlsx-table-wrap table {
    border-collapse: collapse;
    font-size: 12.5px;
    color: var(--text);
    background: var(--bg-elev);
    width: max-content;
    min-width: 100%;
}
.xlsx-table-wrap th,
.xlsx-table-wrap td {
    border: 1px solid var(--border);
    padding: 5px 9px;
    text-align: left;
    white-space: nowrap;
    max-width: 360px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.xlsx-table-wrap tr:first-child td,
.xlsx-table-wrap th {
    background: var(--bg-elev-2);
    font-weight: 600;
    color: var(--text);
    position: sticky;
    top: 0;
    z-index: 1;
}
.xlsx-table-wrap tr:hover td { background: var(--bg-elev-2); }
.xlsx-table-wrap td[data-t="n"],
.xlsx-table-wrap td:has(> div[align="right"]) { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Right rail ---- */
.email-card {
    background: var(--accent-soft);
    border: 1px solid var(--accent-soft-strong);
    border-radius: var(--radius-sm);
    padding: 12px;
}
.email-card .label {
    font-size: 11px; color: var(--accent); text-transform: uppercase;
    letter-spacing: 0.08em; font-weight: 600; margin-bottom: 6px;
}
.email-address {
    font-family: var(--mono); font-size: 13px; color: var(--text);
    word-break: break-all; display: flex; gap: 6px; align-items: center;
}
.email-address button { font-size: 11px; }
.placeholder-card {
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 14px;
    color: var(--text-dim);
    font-size: 13px;
}
.placeholder-card strong { color: var(--text); display: block; margin-bottom: 4px; }

/* ---- AI Chat ---- */
.ai-shell {
    display: grid;
    --sidebar-w: 240px;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr) minmax(0, 1.1fr);
    height: calc(100vh - 60px);
    overflow: hidden;
    transition: grid-template-columns 0.25s ease;
}
.ai-shell.sidebar-collapsed { --sidebar-w: 52px; }
.ai-shell.sidebar-collapsed .chat-sidebar { padding: 14px 6px; }
.ai-shell .chat-sidebar { transition: padding 0.25s ease; }
.ai-shell.sidebar-collapsed .chat-sidebar .text-xs { display: none; }
.ai-shell.sidebar-collapsed .chat-sidebar .chat-new {
    width: 40px; height: 40px; padding: 0; margin: 0 auto 12px;
    font-size: 0; display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.ai-shell.sidebar-collapsed .chat-sidebar .chat-new::before {
    content: "+"; font-size: 22px; line-height: 1; color: inherit;
}
.ai-shell.sidebar-collapsed .chat-sidebar .chat-list-item {
    font-size: 0; color: transparent; padding: 0;
    width: 8px; height: 8px;
    margin: 10px auto;
    border-radius: 50%;
    background: var(--border-strong);
    transition: background 0.15s, transform 0.15s;
    overflow: hidden;
    border: 0;
}
.ai-shell.sidebar-collapsed .chat-sidebar .chat-list-item:hover {
    background: var(--accent); transform: scale(1.4);
}
.ai-shell.sidebar-collapsed .chat-sidebar .chat-list-item.active {
    background: var(--accent);
}
@media (max-width: 1100px) {
    .ai-shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
    .ai-shell .viewer-rail { position: fixed; top: 60px; right: 0; bottom: 0; width: min(560px, 90vw); z-index: 60; transform: translateX(100%); transition: transform 0.2s ease; box-shadow: var(--shadow-lg); }
    .ai-shell .viewer-rail.open { transform: translateX(0); }
}
@media (max-width: 800px) { .ai-shell { grid-template-columns: 1fr; } .ai-shell .chat-sidebar { display: none; } }
.chat-shell {
    display: grid; grid-template-columns: 280px 1fr; height: calc(100vh - 60px);
}
@media (max-width: 800px) { .chat-shell { grid-template-columns: 1fr; } .chat-shell .chat-sidebar { display: none; } }
.chat-sidebar { background: var(--bg-elev); border-right: 1px solid var(--border); overflow-y: auto; padding: 14px; min-height: 0; }
.chat-sidebar .chat-new {
    width: 100%; padding: 10px; margin-bottom: 14px;
}
.chat-list-item {
    display: block; padding: 8px 10px; border-radius: 6px;
    color: var(--text); font-size: 13px; margin-bottom: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-list-item:hover { background: var(--bg-elev-2); }
.chat-list-item.active { background: var(--accent-soft); color: var(--accent); }
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
/*
 * Chat message bubbles.
 *
 * Density was tuned to match a modern IDE chat panel (Cursor / VS Code
 * Copilot) — 13px body copy, 1.5 line-height, tight vertical rhythm so
 * a screenshot captures ~2 exchanges instead of ~1. If you're going to
 * bump the font size here, also revisit `.chat-table` in the tables
 * section further down; both should read as a single scale.
 */
.chat-messages { flex: 1; overflow-y: auto; padding: 12px clamp(10px, 2vw, 22px); }
.chat-msg {
    max-width: 900px;
    margin: 0 auto 12px;
    font-size: 13px;
}
.chat-msg.user {
    position: sticky;
    top: 0;
    z-index: 5;
    isolation: isolate;
    margin-bottom: 10px;
    padding: 6px 0 5px;
}
.chat-msg.user::before {
    content: '';
    position: absolute;
    top: 0; bottom: 0;
    left: -100vw; right: -100vw;
    background: var(--sticky-bg);
    backdrop-filter: saturate(150%) blur(10px);
    -webkit-backdrop-filter: saturate(150%) blur(10px);
    border-bottom: 1px solid var(--border);
    z-index: -1;
}
.chat-msg .role { font-size: 10px; text-transform: uppercase; color: var(--text-faint); letter-spacing: 0.07em; margin-bottom: 3px; }
.chat-msg.user .role { color: var(--accent); }
.chat-msg .body {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    line-height: 1.5;
    white-space: pre-wrap;
    font-size: 13px;
}
.chat-msg.user .body {
    background: var(--accent-soft);
    border-color: var(--accent-soft-strong);
    padding: 6px 12px;
}
.chat-msg .body code { background: var(--bg-elev-3); padding: 1px 5px; border-radius: 3px; font-family: var(--mono); font-size: 12px; }
.chat-msg .body pre { background: var(--bg-elev-3); padding: 10px 12px; border-radius: var(--radius-sm); overflow-x: auto; font-family: var(--mono); font-size: 12px; line-height: 1.45; margin: 6px 0; }
/*
 * Markdown-ish spacing INSIDE a bubble: keep paragraph gaps small so a
 * multi-paragraph reply doesn't visually blow up like a full doc.
 * The renderer emits `<br>` between wrapped lines plus a blank string
 * between paragraphs (rendered as a bare "\n" which becomes empty
 * whitespace inside `white-space: pre-wrap`) — the pre-wrap plus this
 * rule together get us tight paragraph breaks without sacrificing
 * readability.
 */
.chat-msg .body p { margin: 0 0 6px; }
.chat-msg .body p:last-child { margin-bottom: 0; }

.chat-sources {
    margin-top: 10px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}
.chat-sources-head {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    margin-bottom: 8px;
}
.chat-sources-list { display: flex; flex-direction: column; gap: 6px; }
.chat-source {
    display: block;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    font-size: 12.5px;
    transition: border-color 0.15s, background 0.15s;
    text-align: left;
    width: 100%;
    cursor: pointer;
    font-family: inherit;
}
.chat-source:hover { border-color: var(--border-strong); background: var(--bg-elev-3); color: var(--text); }
.chat-source-num { color: var(--accent); font-weight: 600; margin-right: 6px; }
.chat-source-name { font-weight: 500; }
.chat-source-loc { color: var(--text-faint); }
.chat-source-snip { color: var(--text-dim); margin-top: 4px; font-size: 12px; line-height: 1.45; }

/* file tree status dot */
.tree-item .status {
    width: 8px; height: 8px; border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-faint);
}
.tree-item .status.indexed   { background: var(--success); box-shadow: 0 0 6px var(--success-soft); }
.tree-item .status.running   { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.tree-item .status.pending   { background: var(--text-faint); }
.tree-item .status.skipped   { background: transparent; border: 1px solid var(--border-strong); }
.tree-item .status.failed    { background: var(--danger); }
.chat-input-bar {
    padding: 8px clamp(10px, 4vw, 48px) 12px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}
.chat-input-row {
    display: flex; gap: 8px; max-width: 900px; margin: 0 auto;
    align-items: flex-end;
}
.chat-input-row textarea {
    flex: 1; resize: none; min-height: 36px; max-height: 220px;
    font-size: 13px; line-height: 1.45; padding: 8px 10px;
}
.chat-input-row .btn { padding: 7px 14px; font-size: 13px; }
.chat-empty {
    height: 100%; display: grid; place-items: center; color: var(--text-dim);
}
.chat-empty .big {
    font-size: 22px; color: var(--text); margin-bottom: 8px; font-weight: 600;
}
.chat-empty .suggestions {
    display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    max-width: 720px; margin-top: 24px;
}
.chat-empty .suggest {
    text-align: left;
    padding: 12px 14px;
}
/* DA Tracker hero row: single centred button that visually leads the
   suggestion list. Sits above the standard 2x2 grid, filled-green so users
   spot it instantly. Auto-submits (via data-send) rather than pre-filling. */
.chat-empty .suggestions--hero {
    display: flex; justify-content: center; margin-top: 22px; max-width: 720px;
}
/*
 * DA Tracker hero button. The class was `.suggest--find-contacts` before
 * the "Project Info & Contacts" rename; both selectors are kept here so
 * any cached page-render referring to the old class still styles up
 * correctly.
 */
.chat-empty .suggest--info-contacts,
.chat-empty .suggest--find-contacts {
    display: inline-flex; align-items: center; gap: 10px;
    padding: 14px 26px; font-size: 15px; font-weight: 700;
    background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
    color: #fff; border: 1px solid #16a34a; border-radius: 999px;
    box-shadow: 0 6px 18px rgba(22, 163, 74, .28);
    cursor: pointer; transition: transform .12s, box-shadow .12s, filter .12s;
}
.chat-empty .suggest--info-contacts:hover,
.chat-empty .suggest--find-contacts:hover {
    filter: brightness(1.05); transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(22, 163, 74, .32);
}
.chat-empty .suggest--info-contacts:active,
.chat-empty .suggest--find-contacts:active { transform: translateY(0); }
.chat-empty .suggest__icon { font-size: 16px; line-height: 1; }
.chat-empty .suggest__label { letter-spacing: .01em; }

/*
 * Markdown pipe-tables inside an AI reply (the DA-Tracker contacts table
 * is the main one). We shrink the font a notch versus the surrounding
 * chat body — six columns (Name / Number / Email / Company / Role /
 * Source) at 13.5px was pushing phone numbers onto three physical lines
 * when the viewer rail was open. `tabular-nums` keeps digits from
 * shifting between rows, and the tel:/mailto: anchors are pinned
 * `nowrap` so a "0400 111 222" or "hydraulic.engineer@example.com" is
 * always one visual line — if the table overflows horizontally the
 * wrapping `.chat-table-wrap` already scrolls.
 */
.chat-table-wrap { overflow-x: auto; margin: 8px 0; border: 1px solid var(--border); border-radius: 8px; }
.chat-table {
    width: 100%; border-collapse: collapse;
    font-size: 12px; line-height: 1.35;
    font-variant-numeric: tabular-nums;
}
.chat-table thead th {
    text-align: left; background: var(--panel);
    color: var(--text-dim); font-weight: 600;
    padding: 6px 9px; font-size: 11.5px;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
    white-space: nowrap;
}
.chat-table td {
    padding: 6px 9px; border-bottom: 1px solid var(--border);
    vertical-align: top; color: var(--text);
    word-break: break-word;
}
.chat-table tbody tr:last-child td { border-bottom: none; }
.chat-table tbody tr:hover td { background: color-mix(in srgb, var(--accent, #2563eb) 4%, transparent); }
.chat-table a { color: var(--accent, #2563eb); text-decoration: none; }
.chat-table a:hover { text-decoration: underline; }
/* Prevent phone numbers + email addresses from breaking mid-value. */
.chat-table td a[href^="tel:"],
.chat-table td a[href^="mailto:"] { white-space: nowrap; }
/* Citation buttons stay compact in the Source column. */
.chat-table td .cite { margin-right: 2px; }
.spinner-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-faint);
    animation: pulse 1.2s ease-in-out infinite;
    display: inline-block; margin-right: 4px;
}
.spinner-dot:nth-child(2) { animation-delay: 0.15s; }
.spinner-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

/* ---- Inline citations ----
 *
 * `.cite`         — live citation: N matched a Source returned for this
 *                    message. Clicking opens the source in the iviewer.
 * `.cite--orphan` — the AI wrote `[N]` but no Source #N came back in
 *                    the RAG response for this message (either RAG was
 *                    off, returned nothing, or the model hallucinated a
 *                    higher index). We still render a pill so the
 *                    inline text visually reads the same, but muted so
 *                    the user isn't misled into thinking it opens
 *                    something.
 */
.cite {
    display: inline-flex; align-items: center;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--accent-soft-strong);
    padding: 0 5px; height: 16px;
    border-radius: 3px;
    font-size: 10.5px; font-weight: 600;
    cursor: pointer;
    margin: 0 1px;
    vertical-align: baseline;
    line-height: 1;
    transition: background 0.15s, color 0.15s, transform 0.05s;
}
.cite:hover { background: var(--accent); color: var(--accent-ink); }
.cite:active { transform: translateY(1px); }
.cite--orphan {
    background: transparent;
    color: var(--text-faint);
    border-color: var(--border);
    cursor: default;
}
.cite--orphan:hover { background: transparent; color: var(--text-faint); }
.cite--orphan:active { transform: none; }

/* ---- Viewer rail (right pane on AI page) ---- */
.viewer-rail {
    background: var(--bg-elev);
    border-left: 1px solid var(--border);
    display: flex; flex-direction: column;
    min-width: 0; min-height: 0;
    overflow: hidden;
}
.viewer-rail-head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elev-2);
    position: relative;
}
.viewer-rail-title {
    font-weight: 600; font-size: 14px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.viewer-rail-meta {
    color: var(--text-dim); font-size: 12px; margin-top: 4px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-icon {
    position: absolute; top: 10px; right: 10px;
    width: 28px; height: 28px;
    background: transparent; border: 1px solid var(--border);
    color: var(--text-dim); border-radius: 6px;
    cursor: pointer; font-size: 16px; line-height: 1;
}
.btn-icon:hover { background: var(--bg-elev-3); color: var(--text); }
.viewer-rail-body { flex: 1; overflow: hidden; display: flex; min-height: 0; }
.viewer-rail-body iframe { flex: 1; width: 100%; height: 100%; border: 0; background: var(--bg); }
.viewer-rail-empty {
    margin: auto; text-align: center;
    color: var(--text-dim); padding: 40px 30px; max-width: 360px;
}
.viewer-rail-empty .big-icon { font-size: 36px; margin-bottom: 12px; opacity: 0.6; }
.viewer-rail-empty h3 { color: var(--text); margin: 0 0 6px; font-size: 15px; }
.viewer-rail-empty p { margin: 0; font-size: 13px; line-height: 1.5; }

/* ---- QS Rates / BOM editor ---- */
.qs-shell { display: grid; height: calc(100vh - 60px); overflow: hidden; gap: 0; }
.qs-shell--rates { grid-template-columns: minmax(187px, 27%) minmax(0, 1fr); }
.qs-shell--bom   { grid-template-columns: minmax(230px, 25%) minmax(0, 1fr); }
.qs-shell--settings { grid-template-columns: minmax(230px, 25%) minmax(0, 1fr); }
.qs-leftrail {
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    min-height: 0;
    padding: 12px 14px 16px;
}
.qs-leftrail h2 { font-size: 16px; margin: 0 0 6px; }
.qs-leftrail h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin: 10px 0 5px; }
.qs-leftrail .hint { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; margin-bottom: 8px; }
.qs-leftrail-section { padding-top: 7px; border-top: 1px dashed var(--border); margin-top: 8px; }
.qs-leftrail-section:first-of-type, .qs-leftrail-head { border-top: 0; padding-top: 0; margin-top: 0; }
.qs-inline-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.qs-inline-form .input { flex: 1; min-width: 0; padding: 6px 10px; font-size: 12.5px; }
.qs-inline-form .input.input-num { flex: 0 0 90px; }
.qs-inline-form button { white-space: nowrap; }
.qs-checkbox { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--text-dim); cursor: pointer; }
.qs-checkbox input { margin: 0; }
.qs-globalxero { display: flex; flex-direction: column; gap: 6px; }
.qs-globalxero .qs-checkbox { font-size: 12.5px; color: var(--text); font-weight: 500; }
.qs-globalxero-input { border: 1px solid var(--border); background: var(--bg-elev-3); padding: 5px 8px; font-size: 12.5px; }
.qs-globalxero-input[hidden] { display: none; }

.qs-unit-list { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 1px; }
.qs-unit-row { display: flex; gap: 6px; align-items: center; padding: 0; }
.qs-unit-row .drag { color: var(--text-faint); cursor: grab; user-select: none; font-size: 14px; }
.qs-unit-row .input-bare { flex: 1; min-width: 0; padding: 1px 8px; height: 22px; line-height: 1.3; font-size: 12.5px; }
.qs-unit-row .btn-icon-sm { width: 22px; height: 22px; }
.qs-unit-row .input-num { flex: 0 0 90px; text-align: right; font-variant-numeric: tabular-nums; }

/* Named rates list (left rail) — mirrors the quantities list. */
.qs-rate-list { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 1px; }
.qs-rate-row { display: flex; gap: 6px; align-items: center; padding: 0; }
.qs-rate-row .drag { color: var(--text-faint); cursor: grab; user-select: none; font-size: 14px; }
.qs-rate-row .input-bare { flex: 1; min-width: 0; padding: 1px 8px; height: 22px; line-height: 1.3; font-size: 12.5px; }
.qs-rate-row .btn-icon-sm { width: 22px; height: 22px; }
.qs-rate-row .input-num { flex: 0 0 84px; text-align: right; font-variant-numeric: tabular-nums; }

/* Calculated quantity create form + list */
.qs-calc-form .qs-calc-term { display: flex; gap: 3px; align-items: center; width: 100%; }
.qs-calc-form .qs-calc-paren { flex: 0 0 auto; color: var(--text-dim); font-size: 15px; font-weight: 600; line-height: 1; }
.qs-calc-form .qs-calc-ops { display: flex; gap: 4px; align-items: center; flex: 1 1 auto; min-width: 0; }
.qs-calc-form .qs-calc-operand { display: flex; align-items: center; gap: 1px; min-width: 0; }
.qs-calc-form .qs-calc-operand[data-role="num"] { flex: 0 0 auto; }
.qs-calc-form .qs-calc-operand[data-role="qty"] { flex: 1 1 auto; min-width: 0; }
.qs-calc-form .qs-calc-grip { cursor: grab; color: var(--text-faint); font-size: 10px; line-height: 1; user-select: none; padding: 0 1px; }
.qs-calc-form .qs-calc-grip:active { cursor: grabbing; }
.qs-calc-form .input-num { flex: 0 0 46px; min-width: 0; padding: 4px 6px; text-align: right; }
.qs-calc-form .qs-calc-op { flex: 0 0 44px; padding: 4px 4px; }
.qs-calc-form .qs-calc-qsel { flex: 1 1 auto; min-width: 0; padding: 4px 6px; }
.qs-calc-form .qs-calc-join { width: 100%; padding: 4px 6px; font-size: 12px; }
.qs-calc-form .sortable-ghost { opacity: 0.4; }
.qs-calc-row { align-items: flex-start; }
.qs-calc-rowbody { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0; }
.qs-calc-rowbody .qs-calc-name { width: 100%; flex: none; }
.qs-calc-formula { font-size: 11px; padding: 0 8px 2px; line-height: 1.25; }
.qs-calc-formula strong { color: var(--text); font-variant-numeric: tabular-nums; }
.btn-icon-sm {
    background: transparent; border: 1px solid var(--border);
    color: var(--text-dim);
    width: 24px; height: 24px;
    border-radius: 4px;
    cursor: pointer; font-size: 13px; line-height: 1; padding: 0;
    flex-shrink: 0;
}
.btn-icon-sm:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

.qs-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.qs-main-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--border); background: var(--bg-elev); flex-shrink: 0; }
.qs-main-head h1 { font-size: 16px; margin: 0; }
.qs-main-head .hint { color: var(--text-dim); font-size: 12px; }
.qs-main { overflow-y: auto; }

.qs-empty { padding: 60px 22px; color: var(--text-dim); text-align: center; }

/* View tabs — segmented control (Rates & Quantities | Metrics) */
.qs-viewtabs { display: inline-flex; gap: 2px; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.qs-viewtab { appearance: none; border: 0; background: transparent; color: var(--text-dim); font-size: 13px; font-weight: 600; padding: 5px 14px; border-radius: 6px; cursor: pointer; line-height: 1.4; }
.qs-viewtab:hover { color: var(--text); }
.qs-viewtab.active { background: linear-gradient(180deg, var(--accent-grad-from), var(--accent-grad-to)); color: var(--accent-ink); box-shadow: 0 1px 3px var(--accent-soft-strong); }

/* Metrics editor */
.qs-view { min-width: 0; }
/* Global Rates page: gutter between the Rates & Quantities table and the
   screen edges. (The project BOM's panel — .qs-view--rates — pads via
   .qs-bom-tablewrap instead, so it's excluded here.) */
.qs-view[data-view-panel="rates"]:not(.qs-view--rates) { padding: 12px 22px 16px; }
.qs-view[data-view-panel="metrics"] { padding: 18px 22px 12px; }
.qs-metrics-table {
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-elev);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    /* No overflow:hidden — it would clip the category/unit dropdown menus. */
}
.qs-metrics-table .col-metric-name { width: 32%; }
.qs-metrics-table .col-metric-display { width: 100px; }
.qs-metrics-table .col-metric-value { width: 96px; text-align: right; }
.qs-metrics-table .col-actions { width: 60px; padding: 3px 20px 3px 6px; text-align: center; }
.qs-metrics-table thead th { position: static; background: var(--bg-elev-2); padding: 8px 14px; }
.qs-metrics-table thead th:first-child { border-top-left-radius: 10px; }
.qs-metrics-table thead th:last-child { border-top-right-radius: 10px; }
/* Metric rows mirror the category-header rows from the Rates table:
   compact 3px/8px padding, the elevated band background and a bold name. */
.qs-metrics-table td { padding: 3px 8px; background: var(--bg-elev-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
.qs-metric-row .col-metric-name .qs-metric-namecell { display: flex; align-items: center; }
.qs-metric-row .col-metric-name .input-bare { font-weight: 700; flex: 1 1 auto; min-width: 0; }
.qs-metrics-table tbody tr:last-child td { border-bottom: none; }
.qs-metrics-table tbody tr:last-child td:first-child { border-bottom-left-radius: 10px; }
.qs-metrics-table tbody tr:last-child td:last-child { border-bottom-right-radius: 10px; }
.qs-calc { display: flex; align-items: center; gap: 6px; }
.qs-calc .qs-calc-cat { flex: 1 1 45%; min-width: 0; }
.qs-calc .qs-calc-op { flex: 0 0 60px; text-align: center; text-align-last: center; }
.qs-calc .qs-calc-unit { flex: 1 1 45%; min-width: 0; }

/* Category multiselect (checkbox = combine, text click = pick one, Total = all) */
.qs-msel { position: relative; min-width: 0; }
.qs-msel-btn { display: flex; align-items: center; justify-content: space-between; gap: 4px; width: 100%; cursor: pointer; text-align: left; }
.qs-msel-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qs-msel-btn.is-placeholder .qs-msel-label { color: var(--text-dim); }
.qs-msel-caret { color: var(--text-dim); font-size: 9px; flex: 0 0 auto; }
.qs-msel-btn.is-total .qs-msel-label { color: var(--metric-total); font-weight: 600; }
.qs-msel-menu {
    position: absolute; z-index: 30; top: calc(100% + 3px); left: 0;
    min-width: 100%; max-width: 320px; max-height: 260px; overflow-y: auto;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16); padding: 4px;
}
.qs-msel-opt { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.qs-msel-opt:hover { background: var(--accent-soft); }
.qs-msel-opt .qs-msel-cb { flex: 0 0 auto; cursor: pointer; margin: 0; accent-color: var(--accent); }
.qs-msel-opt .qs-msel-text { flex: 1 1 auto; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qs-msel-total { border-top: 1px solid var(--border); margin-top: 4px; }
.qs-msel-total .qs-msel-text { color: var(--metric-total); font-weight: 600; }
.qs-msel-total .qs-msel-cb { accent-color: var(--metric-total); }
/* Section headings (Categories / Units) inside the second-operand picker */
.qs-msel-group { padding: 6px 8px 3px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); pointer-events: none; }
.qs-msel-group ~ .qs-msel-group { border-top: 1px solid var(--border); margin-top: 4px; }
/* Unit rows: no checkbox, single-pick — indent text to align with checkbox rows */
.qs-msel-pick .qs-msel-text { margin-left: 22px; }
.qs-msel-pick.selected { background: var(--accent-soft-strong); font-weight: 600; }
.qs-add-metric { margin: 14px 0 4px; }
.qs-metrics-note { margin: 8px 2px 6px; }

/* Quotes tab: same LHS rail | RHS iviewer split as Units. Mounted from
   _quotes_panel.html; the .qs-quotes wrapper takes over the full-width
   `units-view` shell row when this tab is active. */
.qs-view--quotes:not([hidden]) { display: grid; grid-template-rows: minmax(0, 1fr); min-height: 0; flex: 1 1 auto; }
.qs-quotes { display: grid; grid-template-columns: minmax(280px, 36%) 1fr; min-width: 0; min-height: 0; height: 100%; }
.qs-quotes-rail { border-right: 1px solid var(--border); overflow-y: auto; min-width: 0; padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; background: var(--bg); }
.qs-quotes-head { display: flex; align-items: center; gap: 8px; }
.qs-quotes-listwrap { display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.qs-quotes-listhead { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 700; padding: 0 2px; }
.qs-quotes-list { list-style: none; margin: 0; padding: 0; max-height: 26vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elev); }
.qs-quotes-itm { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.qs-quotes-itm:last-child { border-bottom: 0; }
.qs-quotes-itm:hover { background: var(--accent-soft); }
.qs-quotes-itm.is-active { background: var(--accent-soft-strong); }
.qs-quotes-itm-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.qs-quotes-itm-amt { color: var(--text-dim); font-variant-numeric: tabular-nums; flex-shrink: 0; font-size: 11.5px; }
.qs-quotes-empty { padding: 14px; text-align: center; }

.qs-quotes-form { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; border-top: 1px dashed var(--border); }
.qs-quotes-form-head { display: flex; align-items: center; gap: 6px; }
.qs-quotes-form-title { font-weight: 700; font-size: 13px; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qs-quotes-totals { display: grid; grid-template-columns: 1fr 90px 90px; gap: 6px; }
.qs-quotes-fld { display: flex; flex-direction: column; gap: 2px; }
.qs-quotes-fld-lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 700; padding: 0 2px; }
.qs-quotes-fld input { font-size: 12.5px; }
.qs-quotes-alloc-wrap { display: flex; flex-direction: column; gap: 4px; }
.qs-quotes-alloc-head { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 700; padding: 0 2px; }
.qs-quotes-alloc { width: 100%; font-size: 12px; }
.qs-quotes-alloc th, .qs-quotes-alloc td { padding: 4px 6px; vertical-align: middle; }
.qs-quotes-alloc thead th { position: static; font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); }
.qs-quotes-alloc .qs-qa-rate, .qs-quotes-alloc .qs-qa-qty,
.qs-quotes-alloc .qs-qa-net, .qs-quotes-alloc .qs-qa-gst { width: 76px; text-align: right; }
.qs-quotes-alloc .qs-qa-act { width: 28px; text-align: right; }
.qs-quotes-alloc .qs-qa-net { font-variant-numeric: tabular-nums; color: var(--text-dim); }
.qs-quotes-alloc .qs-qa-item-sel { width: 100%; }
.qs-quotes-alloc .input-num { text-align: right; }
.qs-quotes-add-row td { padding-top: 6px !important; padding-bottom: 6px !important; border-bottom: 1px dashed var(--border); }
.qs-quotes-stillrow { font-weight: 700; background: var(--bg-elev-2); }
.qs-quotes-stillrow td { border-top: 1px solid var(--border); padding: 6px 6px !important; font-variant-numeric: tabular-nums; }
.qs-qa-still-lbl { text-align: right; color: var(--text-dim); font-weight: 700; }
.still-zero { color: #16a34a; }
.still-neg { color: #dc2626; }
.still-pos { color: #2563eb; }

.qs-quotes-savebar { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding-top: 6px; border-top: 1px dashed var(--border); }
.qs-quotes-msg { flex: 1 1 auto; }
.qs-quotes-msg--err { color: #dc2626; }
.qs-quotes-msg--ok { color: #16a34a; }

.qs-quotes-viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.qs-quotes-viewer .qs-ref-frame { width: 100%; height: 100%; border: 0; display: block; }
.qs-quotes-viewer .qs-ref-viewer-empty { padding: 40px 22px; text-align: center; }

/* Committed + Uncommitted superheadings (only present when the BOM page
   shows the Committed roll-up). Sub-columns are slim — these are read-only
   readouts and the row is height-driven by the inputs underneath them. */
.qs-table--committed thead th.col-uncommitted-super,
.qs-table--committed thead th.col-committed-super {
    text-align: center; background: var(--bg-elev-2);
    border-bottom: 1px solid var(--border);
    border-left: 1px solid var(--border);
}
.qs-table--committed thead th.col-committed-super { background: color-mix(in srgb, var(--accent) 10%, var(--bg-elev-2)); }
.col-committed { text-align: right; font-variant-numeric: tabular-nums; }
.col-committed-qty, .col-committed-rate { width: 78px; }
.col-committed-amt { width: 72px; }
/* Uncommitted's own Amount ($): last column of the Uncommitted group; its
   category/footer subtotals reuse the qs-cat-total / qs-grand-total look. */
.col-uncommitted-amt { text-align: right; font-variant-numeric: tabular-nums; width: 90px; }
.qs-table--committed td.col-committed-qty,
.qs-table--committed th.col-committed-qty { border-left: 1px solid var(--border); }
.qs-multi { color: var(--text-faint); font-style: italic; font-size: 11px; }

/* Units tab: Unit | Reference table (left) + reference viewer (right) */
.qs-view--units:not([hidden]) { display: grid; grid-template-columns: minmax(240px, 30%) 1fr; min-height: 0; flex: 1 1 auto; }
.qs-units-rail { border-right: 1px solid var(--border); overflow-y: auto; min-width: 0; }
.qs-units-table { width: 100%; }
.qs-units-table thead th { position: static; }
.qs-units-table .col-uref-name { width: 34%; }
.qs-units-table .col-uref-value { width: 84px; }
.qs-units-table .col-uref-value .input-num { text-align: right; }
.qs-units-table .col-uref-notes { width: 56px; text-align: center; }
.qs-note-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 6px; cursor: pointer; padding: 0;
    border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-dim);
}
.qs-note-btn:hover { color: var(--metric-total); border-color: var(--metric-total); }
.qs-note-btn.has-note { background: var(--metric-total); border-color: var(--metric-total); color: #fff; }
.qs-note-pop {
    position: fixed; z-index: 60; width: 280px; padding: 8px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}
.qs-note-input { width: 100%; resize: vertical; min-height: 66px; font-size: 13px; }

/* General project notes — full-page editor (from chip) + BOM slide-in drawer */
.qs-main-head-actions { display: flex; align-items: center; gap: 10px; }

.notes-page { max-width: 1000px; margin: 0 auto; width: 100%; padding: 26px clamp(20px, 4vw, 48px); display: flex; flex-direction: column; gap: 12px; height: calc(100vh - 60px); }
.notes-page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.notes-page-head h1 { margin: 0 0 2px; font-size: 20px; }
.notes-page-area { flex: 1 1 auto; resize: none; font-size: 14px; line-height: 1.6; padding: 16px; }
.notes-save-state { font-size: 12px; }

.app-shell { transition: padding-right 0.25s ease; }
.notes-drawer-open .app-shell { padding-right: 33vw; }
.notes-drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: 33vw; min-width: 320px; z-index: 80;
    background: var(--bg-elev); border-left: 1px solid var(--border);
    box-shadow: -12px 0 32px rgba(0, 0, 0, 0.16);
    display: flex; flex-direction: column;
    transform: translateX(100%); transition: transform 0.25s ease;
}
.notes-drawer-open .notes-drawer { transform: none; }
.notes-drawer-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.notes-drawer-title { font-weight: 600; font-size: 14px; }
.notes-drawer-head .notes-save-state { margin-left: auto; }
.notes-drawer-area { flex: 1 1 auto; resize: none; border: 0; border-radius: 0; padding: 16px; font-size: 14px; line-height: 1.6; background: var(--bg-elev); }
.notes-drawer-area:focus { outline: none; box-shadow: none; }
.qs-units-table td { padding: 6px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.qs-ref-cell { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.qs-ref-view, .qs-ref-add {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
    border: 1px solid var(--border); background: var(--bg-elev); padding: 0;
}
.qs-ref-add { color: var(--accent); border-style: dashed; font-size: 16px; line-height: 1; }
.qs-ref-add:hover { background: var(--accent-soft); }
.qs-ref-view { color: var(--text-dim); }
.qs-ref-view:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.qs-ref-view.active { color: var(--accent-ink); background: linear-gradient(180deg, var(--accent-grad-from), var(--accent-grad-to)); border-color: transparent; }
.qs-ref-ic { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.qs-ref-viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.qs-ref-viewer-empty { padding: 40px 22px; text-align: center; }
.qs-ref-viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--bg-elev); flex-shrink: 0; }
.qs-ref-viewer-title { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qs-ref-viewer-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
.qs-ref-frame { width: 100%; height: 100%; border: 0; display: block; }
.qs-ref-transcript { padding: 14px 18px; }
.qs-tr-msg { margin-bottom: 14px; }
.qs-tr-role { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); margin-bottom: 3px; }
.qs-tr-text { white-space: pre-wrap; font-size: 13px; line-height: 1.5; }
.qs-tr-user .qs-tr-text { color: var(--text); font-weight: 500; }
.qs-tr-sources { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.qs-tr-src { font-size: 11px; background: var(--accent-soft); color: var(--accent-hover); padding: 2px 7px; border-radius: 99px; }

/* Add-reference popover (file upload + embedded AI chat) */
.qs-ref-pop { position: fixed; z-index: 60; width: 340px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22); overflow: hidden; }
.qs-ref-pop-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.qs-ref-pop-title { font-weight: 600; font-size: 13px; }
.qs-ref-pop-tabs { display: flex; gap: 2px; padding: 8px 10px 0; }
.qs-ref-pop-tab { flex: 1; appearance: none; border: 0; background: var(--bg-elev-2); color: var(--text-dim); font-weight: 600; font-size: 12px; padding: 6px 0; border-radius: 7px 7px 0 0; cursor: pointer; }
.qs-ref-pop-tab.active { background: var(--accent-soft); color: var(--accent-hover); }
.qs-ref-pop-body { padding: 12px; }
.qs-ref-pop-panel { display: flex; flex-direction: column; gap: 8px; }
.qs-ref-file-input { font-size: 12px; }
.qs-ref-chat { max-height: 220px; min-height: 60px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--bg); }
.qs-ref-msg { margin-bottom: 8px; font-size: 12.5px; line-height: 1.45; }
.qs-ref-msg-text { white-space: pre-wrap; }
.qs-ref-msg--user .qs-ref-msg-text { font-weight: 600; }
.qs-ref-msg--assistant .qs-ref-msg-text { color: var(--text-dim); }
.qs-ref-chat-form { display: flex; gap: 6px; }
.qs-ref-chat-form .input { flex: 1; }

/* Units tab collapses the project-setup rail to free up width for the viewer.
   Use a single column (not 0 1fr) so the remaining .qs-main item — once the
   hidden rail is out of grid flow — auto-places into the full-width track. */
.qs-shell--bom.units-view,
.qs-shell--bom.rail-collapsed { grid-template-columns: minmax(0, 1fr); }
.qs-shell--bom.units-view .qs-leftrail,
.qs-shell--bom.rail-collapsed .qs-leftrail { display: none; }

/* LHS rail show/hide toggle (BOM header). */
.qs-main-head-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.qs-rail-toggle {
    display: inline-flex; align-items: center; gap: 1px;
    height: 30px; padding: 0 7px;
    background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text-dim); cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.qs-rail-toggle:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.qs-rail-toggle .qs-rail-chev { font-size: 14px; line-height: 1; font-weight: 700; }
/* Hide the toggle on the Units tab, where the rail is force-collapsed. */
.qs-shell--bom.units-view .qs-rail-toggle { display: none; }

/* AI assistant inside the reference viewer: chat (left) + source viewer (right) */
.qs-airef { flex: 1 1 auto; display: grid; grid-template-columns: minmax(300px, 42%) 1fr; min-height: 0; }
.qs-airef-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border); }
.qs-airef-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--bg-elev); flex-shrink: 0; }
.qs-airef-title { font-weight: 600; font-size: 13px; }
.qs-airef-actions { display: flex; align-items: center; gap: 6px; }
.qs-airef-messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.qs-airef-msg { font-size: 13px; line-height: 1.5; }
.qs-airef-role { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); margin-bottom: 3px; }
.qs-airef-body { white-space: pre-wrap; }
.qs-airef-msg.user .qs-airef-body { font-weight: 500; }
.qs-airef-msg.assistant .qs-airef-body { color: var(--text); }
.qs-airef-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); flex-shrink: 0; align-items: flex-end; }
.qs-airef-input { flex: 1; resize: none; max-height: 160px; }
.qs-airef-viewer { position: relative; min-width: 0; min-height: 0; overflow: hidden; display: flex; }
.qs-airef-viewer-empty { margin: auto; text-align: center; padding: 24px; max-width: 280px; }
.qs-airef-frame { width: 100%; height: 100%; border: 0; }

.qs-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.qs-table thead th {
    position: sticky; top: 0; z-index: 5;
    background: var(--bg-elev-2);
    border-bottom: 1px solid var(--border);
    text-align: left;
    color: var(--text-dim);
    font-weight: 500; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.05em;
    /* 14px horizontal matches the text inset of the inputs/selects below
       (cell 8px + input 6px), so every header lines up with its column data. */
    padding: 10px 14px;
}
/* Edge gutters: the first (toggle) and last (actions) columns carry the
   table's inside margins so content isn't flush against the table edges. */
.qs-table thead th.col-toggle { padding-left: 16px; padding-right: 8px; }
.qs-table thead th.col-actions { padding-left: 8px; padding-right: 16px; }
.qs-table td.col-toggle { padding-left: 16px; }
.qs-table td.col-actions { padding-right: 16px; }
.qs-table .col-toggle { width: 28px; text-align: center; }
.qs-table .col-name   { width: 21.6%; }
.qs-table .col-xero   { width: 70px; }
.qs-table .col-rate, .qs-table .col-qty, .qs-table .col-total { width: 90px; }
.qs-table .col-note { width: 48px; text-align: center; }
.qs-table td.col-note { text-align: center; }
.qs-table .col-val, .qs-table .col-val2 { width: 76px; }
/* Numeric columns: right-align both header and data so short headers (Qty,
   Val, Total) line up with their right-aligned values. */
.qs-table th.col-rate, .qs-table th.col-val, .qs-table th.col-val2, .qs-table th.col-qty, .qs-table th.col-total,
.qs-table td.col-rate, .qs-table td.col-val, .qs-table td.col-val2, .qs-table td.col-qty, .qs-table td.col-total { text-align: right; font-variant-numeric: tabular-nums; }
/* Readout/total cells have no input, so add the input's 6px text inset (8+6=14)
   to keep their values aligned under the right-aligned headers + input columns. */
.qs-item-row td.col-qty, .qs-item-row td.col-total,
.qs-cat-row td.qs-cat-total, .qs-total-row td.qs-grand-total { padding-right: 14px; }
.qs-table .col-unit, .qs-table .col-unit2 { width: 220px; }
.qs-table .col-op, .qs-table .col-op2, .qs-table .col-join { width: 60px; }
.qs-table .col-actions{ width: 36px; }
/* Join control. Until a second term exists (row is not .op2-on) it's a plain
   '+' affordance — no native dropdown arrow. Once active it looks exactly like
   an Op select (native arrow, default colour). */
/* '+' affordance styled as a real button (pill, filled, hover) so it reads as
   clickable and distinct from the flat arrow-selects used for operators. */
.qs-item-row:not(.op2-on) .col-join .qs-join {
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
    background-image: none;
    display: block; margin: 0 auto;
    width: 22px; height: 22px; padding: 0;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent); font-weight: 700; font-size: 14px;
    text-align: center; text-align-last: center;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}
.qs-item-row:not(.op2-on) .col-join .qs-join:hover {
    background: var(--accent); color: #fff;
    box-shadow: 0 1px 3px rgba(14, 159, 110, 0.35);
}

/* Grouping brackets: rate × ( term A  join  term B ). Shown only when a row
   has a second term (.op2-on). The parens live in the cell gutters so they
   don't crowd the inputs. */
.qs-item-row.op2-on .col-unit,
.qs-item-row.op2-on .col-val2 { position: relative; }
.qs-item-row.op2-on .col-unit::before,
.qs-item-row.op2-on .col-val2::after {
    position: absolute; top: 50%; transform: translateY(-50%);
    color: var(--text-dim); font-weight: 700; font-size: 15px; pointer-events: none;
}
.qs-item-row.op2-on .col-unit::before { content: '('; left: 1px; }
.qs-item-row.op2-on .col-val2::after  { content: ')'; right: 1px; }
.qs-item-row.op2-on .col-unit .input-bare  { padding-left: 12px; }
.qs-item-row.op2-on .col-val2 .input-bare  { padding-right: 12px; }
/* Strip increment/decrement spinners from number inputs in the table. */
.qs-table input[type=number]::-webkit-outer-spin-button,
.qs-table input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qs-table input[type=number] { -moz-appearance: textfield; appearance: textfield; }

.qs-cat-row td { background: var(--bg-elev-3); border-top: 1px solid var(--border); padding: 3px 8px; }
.qs-cat-row .col-name { font-weight: 700; }
.qs-cat-row .qs-cat-name { width: 100%; max-width: 360px; font-weight: 700; }
.qs-toggle {
    background: transparent; border: 0; color: var(--text-dim);
    cursor: pointer; font-size: 12px; padding: 2px;
}
.qs-cat.collapsed .qs-item-row,
.qs-cat.collapsed .qs-empty-row { display: none; }
.drag-handle { color: var(--text-faint); cursor: grab; user-select: none; margin-right: 6px; font-size: 13px; }
.qs-badge { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; font-size: 10px; font-weight: 600; letter-spacing: 0.05em; }
.qs-badge--internal { background: var(--badge-internal-bg); color: var(--badge-internal-fg); border: 1px solid var(--badge-internal-bd); }
.qs-badge--labour { background: var(--badge-labour-bg); color: var(--badge-labour-fg); border: 1px solid var(--badge-labour-bd); }
.qs-badge--unexpected_line_items { background: var(--badge-uli-bg); color: var(--badge-uli-fg); border: 1px solid var(--badge-uli-bd); }

.qs-item-row td { padding: 0 8px; border-bottom: 1px solid var(--hairline); }
.qs-item-row:hover td { background: var(--row-tint); }
.qs-empty-row td { padding: 4px 14px 4px 34px; color: var(--text-faint); font-size: 12px; }
.qs-item-row .qs-item-name { font-weight: 400; }

/* Tree connectors: a vertical line descends from the category and an elbow
   ticks into each costing, clearly nesting items under their category. */
.qs-item-row .col-name { position: relative; padding-left: 30px; }
.qs-item-row .col-name::before {
    content: ""; position: absolute;
    left: 12px; top: 0; bottom: 0;
    width: 1px; background: var(--border-strong);
}
.qs-item-row .col-name::after {
    content: ""; position: absolute;
    left: 12px; top: 50%;
    width: 12px; height: 1px;
    background: var(--border-strong);
}
/* Last costing: stop the vertical line at the elbow so it doesn't dangle. */
.qs-item-row:last-child .col-name::before { bottom: auto; height: 50%; }
.input-bare {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    padding: 2px 6px;
    border-radius: 4px;
    width: 100%;
    font-size: 12.5px;
    line-height: 1.4;
    transition: border-color 0.12s, background 0.12s;
}
.input-bare:hover { border-color: var(--border); }
.input-bare:focus { outline: 0; border-color: var(--accent); background: var(--bg-elev-3); }
.input-bare:disabled { color: var(--text-dim); cursor: not-allowed; }
.input-bare.input-num { text-align: right; font-variant-numeric: tabular-nums; }
/* Compact table controls. Needed because `select.input` (specificity 0,1,1)
   would otherwise beat `.input-bare` and keep the tall 10px/12px padding,
   making item rows jumbo. The two-class selector here wins for all controls. */
.qs-table .input-bare {
    height: 24px;
    padding: 1px 6px;
    line-height: 1.3;
    font-size: 12.5px;
}
/* Item rows specifically: shrink the inputs/readouts another touch. Category
   rows keep their existing heft so they stand out as section headers.
   Notes:
     - `box-sizing: border-box` is essential. Without it, `height: 20px`
       grows to ~24px once the 1px transparent border + 1px padding are
       added on every side, and the row never gets shorter than that.
     - Native <select> on macOS has a baked-in min-height; we strip the
       chrome with appearance:none and draw a tiny chevron with a
       background SVG so a 20px select renders at exactly 20px. */
.qs-table .qs-item-row .input-bare {
    box-sizing: border-box;
    height: 20px;
    min-height: 0;
    padding: 0 5px;
    font-size: 11.5px;
    line-height: 1.1;
}
.qs-table .qs-item-row select.input-bare {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 14px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 4px center;
    background-size: 8px 5px;
}
.qs-item-row td { padding: 0 7px; line-height: 1.1; }
.qs-item-row td.col-name { padding-left: 28px; }
.qs-item-row .qs-readout,
.qs-item-row .qs-multi { font-size: 11.5px; line-height: 1.1; }

/* Selectable rates: a "Rate ($)" cell linked to a named Rate shows a blue,
   read-only chip (border + font blue) instead of the manual money input. */
.qs-rate-linked {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: #2563eb;
    font-weight: 600;
    border: 1px solid #2563eb;
    border-radius: var(--radius-sm);
    padding: 0 5px;
    height: 20px;
    line-height: 18px;
    font-size: 11.5px;
    cursor: context-menu;
}
.qs-table .col-rate.rate-linked { color: #2563eb; }

/* Right-click menu to pick a rate (or revert to manual "User Input"). */
.qs-rate-menu {
    position: fixed;
    z-index: 1000;
    min-width: 180px;
    max-width: 280px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-elev, #fff);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    padding: 4px;
}
.qs-rate-menu[hidden] { display: none; }
.qs-rate-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 12.5px;
    text-align: left;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
}
.qs-rate-menu-item:hover { background: var(--accent-soft); }
.qs-rate-menu-item:first-child { color: var(--text-dim); font-weight: 600; }
.qs-rate-menu-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qs-rate-menu-val { color: #2563eb; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.qs-rate-menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.qs-rate-menu-empty { padding: 6px 8px; font-size: 12px; color: var(--text-faint); }
.qs-item-row .qs-note-btn { width: 20px; height: 20px; }
.qs-item-row .qs-ref-ic { width: 12px; height: 12px; }
.qs-item-row .drag-handle { font-size: 11px; line-height: 1; }
/* The "+" join pill: shrink to match the inputs alongside it so it's not
   the cell driving row height. The full select form (when .op2-on) is
   already covered by the .input-bare override above. */
.qs-item-row:not(.op2-on) .col-join .qs-join {
    width: 20px; height: 20px; font-size: 12px;
}
.qs-table td, .qs-table th { vertical-align: middle; }
.qs-readout { color: var(--text); }
.qs-readout:empty::before { content: '—'; color: var(--text-faint); }
/* Collapsed/expanded category subtotal shown in the Total column of the
   category header row. */
.qs-cat-row td.qs-cat-total { font-weight: 600; color: var(--text); }
/* Grand total row: sticks to the bottom of the scroll viewport, but never
   below where the table's natural bottom row would sit. */
.qs-foot .qs-total-row td {
    position: sticky; bottom: 0; z-index: 6;
    background: var(--bg-elev-2);
    border-top: 2px solid var(--border);
    padding: 10px 8px;
    font-weight: 700;
}
.qs-foot .col-total-label {
    color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 0.05em; font-size: 12px;
}
.qs-foot .qs-grand-total { font-size: 14px; }
.qs-foot .qs-grand-total:empty::before { content: '0.00'; color: var(--text-dim); }
.input-bare.save-ok { border-color: var(--success); background: var(--success-soft); }
.input-bare.save-err { border-color: var(--danger); background: var(--danger-soft); }
@keyframes qs-pop { from { transform: scale(1.04); } to { transform: scale(1); } }
.input-bare.save-ok, .input-bare.save-err { animation: qs-pop 0.4s ease-out; }

/* ===== BOM: shared mason_table (reusable-table) skin ====================
   The BOM page loads mason_table/table.css — the Contract Budget table
   chrome extracted from project-management — AFTER this file, so it wins
   equal-specificity ties and owns the table's look (container, header,
   row heights, category bands, green committed cells, details dropdown,
   slide-out doc viewer). The rules below are the qs-side bridge: panel
   layout for the viewer host, plus higher-specificity overrides that keep
   qs-specific UX (bare inputs, tree connectors, icon-column gutters)
   inside that chrome. Scoped to .qs-shell--bom so the global Rates page —
   which shares these partials but not the shared stylesheet — is
   unaffected. */

/* Rates panel = doc-viewer host: bordered container with the scroll INSIDE
   it (sticky head/foot keep working, rounded corners stay put); the shared
   viewer slides out on the right of this flex row. */
.qs-view--rates:not([hidden]) { display: flex; flex: 1 1 auto; min-height: 0; }
.qs-bom-tablewrap { display: flex; flex-direction: column; padding: 10px 22px 12px; }
.qs-bom-tablebox { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.qs-bom-tablescroll { overflow-y: auto; flex: 1 1 auto; min-height: 0; }

/* Show a visible input box (matching the global Rates "Rates & Quantities"
   table) plus compact control sizing inside the shared chrome. The border
   was always 1px here (previously transparent), so making it visible causes
   no layout shift. */
.qs-shell--bom .qs-table.reusable-table .input-bare {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: none;
    height: 24px; min-height: 0;
    padding: 1px 6px;
    font-size: 12.5px; line-height: 1.3;
}
.qs-shell--bom .qs-table.reusable-table .input-bare:hover { border-color: var(--border-strong, var(--border)); }
.qs-shell--bom .qs-table.reusable-table .input-bare:focus { border-color: var(--accent); background: var(--bg-elev-3); box-shadow: none; outline: 0; }
.qs-shell--bom .qs-table.reusable-table .qs-item-row .input-bare {
    box-sizing: border-box; height: 20px; padding: 0 5px; font-size: 11px; line-height: 1.2;
}
/* Category headings read as plain bold text (no input box) — matching the
   global Rates table. A subtle border still reveals on hover/focus so they
   stay discoverable as editable. */
.qs-shell--bom .qs-table.reusable-table .qs-cat-name {
    background: transparent;
    border-color: transparent;
}
/* The "+" join control is a round pill (matches the Rates table), not a
   square box, when no second term is in play. */
.qs-shell--bom .qs-table.reusable-table .qs-item-row:not(.op2-on) .col-join .qs-join {
    border-radius: 999px;
}
.qs-shell--bom .qs-table.reusable-table .qs-item-row .qs-readout,
.qs-shell--bom .qs-table.reusable-table .qs-item-row .qs-multi { font-size: 11px; }
/* Narrower name column (the tree gutter eats little real width) frees room
   for the formula/committed columns so their controls don't truncate. */
.qs-shell--bom .qs-table .col-name { width: 14%; }
/* Density: pack item rows tight. The package default (6px vertical cell
   padding + 28px row height) wastes vertical space at BOM scale; drop the
   vertical padding and let the 20px controls set a 22px row. Category rows
   keep the package heft so they still read as section bands. */
.qs-shell--bom .qs-table.reusable-table .qs-item-row td {
    height: 22px;
    padding-top: 0;
    padding-bottom: 0;
}
.qs-shell--bom .qs-table.reusable-table .qs-item-row .qs-note-btn { width: 18px; height: 18px; }
/* Rows aren't click targets in the BOM (cells/inputs are); category rows
   stay clickable for collapse/expand. */
.qs-shell--bom .qs-table.reusable-table tbody tr { cursor: default; }
.qs-shell--bom .qs-table.reusable-table tbody tr.qs-cat-row { cursor: pointer; }
/* Narrow icon columns can't afford the package's 12px cell gutters on the
   inner side; the outer side keeps the table-edge breathing room. */
.qs-shell--bom .qs-table.reusable-table td.col-toggle,
.qs-shell--bom .qs-table.reusable-table th.col-toggle { padding-left: 16px; padding-right: 6px; }
.qs-shell--bom .qs-table.reusable-table td.col-actions,
.qs-shell--bom .qs-table.reusable-table th.col-actions { padding-left: 6px; padding-right: 16px; }
/* Tree connectors need their indent back over the package's 12px padding. */
.qs-shell--bom .qs-table.reusable-table .qs-item-row td.col-name { padding-left: 28px; }
/* Keep readout values aligned under the right-aligned headers + inputs
   (cell 12px + input text inset 5px). */
.qs-shell--bom .qs-table.reusable-table .qs-item-row td.col-qty,
.qs-shell--bom .qs-table.reusable-table .qs-item-row td.col-total,
.qs-shell--bom .qs-table.reusable-table .qs-cat-row td.qs-cat-total,
.qs-shell--bom .qs-table.reusable-table .qs-total-row td.qs-grand-total { padding-right: 17px; }
/* Two-row header (Uncommitted/Committed superheadings): the second row
   sticks below the first instead of sliding over it. */
.qs-shell--bom .qs-table.reusable-table thead tr:nth-child(2) th { top: var(--rt-row-height, 28px); }

/* ===== Tender (scopes + coverage matrix + invites) ======================
   LHS rail reuses the qs-leftrail look; RHS is another instantiation of
   the shared mason_table chrome (same package as the BOM table). */
.qs-shell--tender { grid-template-columns: minmax(320px, 30%) minmax(0, 1fr); }
.qs-tender-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; padding: 10px 14px 12px; }
.qs-tender-tablebox { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.qs-tender-scroll { overflow-y: auto; flex: 1 1 auto; min-height: 0; }

/* Coverage matrix */
.qs-tender-table th.col-scope { width: 110px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.qs-tender-table th.col-scope,
.qs-tender-table td.col-scope { text-align: center; }
.qs-tender-table .qs-tender-chk { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; margin: 0; vertical-align: middle; }
.qs-shell--tender .qs-table.reusable-table .qs-item-row td.col-name { padding-left: 28px; }
/* Item covered by ≥1 scope / category fully covered → green name */
.qs-tender-name.is-covered { color: var(--success, #16a34a); font-weight: 600; }

/* Scope cards on the rail */
.qs-scope-card {
    display: flex; flex-direction: column; gap: 6px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg-elev-2); padding: 8px; margin-bottom: 8px;
}
.qs-scope-card--new { border-style: dashed; background: transparent; }
.qs-scope-card-head { display: flex; gap: 6px; align-items: center; }
.qs-scope-card-head .qs-scope-name { flex: 1 1 auto; min-width: 0; font-weight: 600; font-size: 12.5px; padding: 4px 8px; }
.qs-scope-card .qs-scope-text {
    width: 100%; resize: vertical; min-height: 64px;
    font-size: 12.5px; line-height: 1.5; padding: 6px 8px;
    font-family: var(--mono); white-space: pre;
}

/* Settings: Project Manager edit form */
.settings-pm-form { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.settings-pm-form .input { padding: 6px 10px; font-size: 12.5px; }
.settings-pm-form button { align-self: flex-end; }

/* Plan-type attachment picker inside scope cards */
.qs-scope-plans { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; padding: 2px 0 0; border-top: 1px dashed var(--border); margin-top: 2px; padding-top: 6px; }

/* Send-tender form + sent list */
.qs-tender-sendform { display: flex; flex-direction: column; gap: 7px; }
.qs-tender-sendform .input { padding: 6px 10px; font-size: 12.5px; }
.qs-tender-scopepick { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 2px 0; }
.qs-tender-picklbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); font-weight: 700; }
.qs-tender-planshold { border: 1px dashed var(--border); border-radius: 6px; padding: 8px 10px; margin: 0; }
.qs-tender-invite { border-top: 1px dashed var(--border); padding: 8px 0; }
.qs-tender-invite:first-of-type { border-top: 0; }
.qs-tender-invite-top { display: flex; align-items: center; gap: 8px; }
.qs-tender-invite-top strong { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.qs-tender-invite-top form { margin: 0; }
.qs-tender-invite-meta { font-size: 11.5px; color: var(--text-dim); line-height: 1.5; }
.qs-tender-unsent { color: var(--danger); }
.qs-tender-chip {
    flex-shrink: 0; display: inline-block; padding: 1px 8px; border-radius: 999px;
    font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em;
}
.qs-tender-chip--opened { background: var(--success-soft, #dcfce7); color: var(--success, #16a34a); border: 1px solid var(--success, #16a34a); }
.qs-tender-chip--waiting { background: var(--bg-elev-3); color: var(--text-dim); border: 1px solid var(--border); }

.flex { display: flex; }
.gap-sm { gap: 8px; }
.gap { gap: 12px; }
.gap-lg { gap: 20px; }
.mt-sm { margin-top: 8px; }
.mt { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-0 { margin-bottom: 0 !important; }
.text-dim { color: var(--text-dim); }
.text-faint { color: var(--text-faint); }
.text-mono { font-family: var(--mono); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }
.right { margin-left: auto; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Project Settings ------------------------------------------------- */
.settings-navbtn {
    width: 100%; text-align: left;
    padding: 9px 12px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--bg-elev);
    color: var(--text); font-weight: 600; font-size: 13px; cursor: pointer;
}
.settings-navbtn.active { border-color: var(--brand, #0e9f6e); color: var(--brand, #0e9f6e); background: var(--bg); }
.settings-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-toggle-label { font-weight: 600; font-size: 13px; }
.pill-toggle {
    position: relative; width: 46px; height: 26px; flex: none;
    border-radius: 999px; border: 1px solid var(--border);
    background: var(--border); cursor: pointer; padding: 0;
    transition: background .15s, border-color .15s;
}
.pill-toggle .pill-toggle-knob {
    position: absolute; top: 2px; left: 2px;
    width: 20px; height: 20px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25);
    transition: transform .15s;
}
.pill-toggle.on { background: var(--brand, #0e9f6e); border-color: var(--brand, #0e9f6e); }
.pill-toggle.on .pill-toggle-knob { transform: translateX(20px); }
.settings-table { width: 100%; }
.settings-table th { font-weight: 600; text-align: left; }
.settings-table th.col-total, .settings-table td.col-total { text-align: right; font-variant-numeric: tabular-nums; }
.settings-table .col-mapped { width: 320px; }
.settings-table .col-total { width: 160px; }
.settings-spread-opt { color: #2563eb; }
.costs-hidden .settings-total-col { display: none; }

/* Give the Category & Total ($) columns room to breathe at the page edges. */
.qs-view[data-view-panel="client-summary"] { padding: 18px 28px 18px; }
.settings-table th.col-name, .settings-table td.col-name { padding-left: 20px; }
.settings-table th.col-total, .settings-table td.col-total { padding-right: 20px; }

/* Collapsible LHS settings rail (mirrors the BOM rail toggle). */
.qs-shell--settings.rail-collapsed { grid-template-columns: minmax(0, 1fr); }
.qs-shell--settings.rail-collapsed .qs-leftrail { display: none; }
.qs-main-head-title { min-width: 0; }
.qs-main-head-title .hint { white-space: normal; }

/* Item-allocation: indented item sub-rows under a special category. */
.settings-cat-name { font-weight: 600; }
.settings-itemalloc { display: inline-flex; align-items: center; gap: 5px; margin-top: 5px; font-size: 11.5px; color: var(--text-dim); cursor: pointer; user-select: none; }
.settings-itemalloc input { margin: 0; cursor: pointer; }
.settings-cat-row.item-alloc-on .settings-map { opacity: 0.5; }
.settings-item-row { background: var(--bg); }
.settings-item-row td.settings-item-name { padding-left: 40px; color: var(--text-dim); font-style: italic; }
.settings-item-row .settings-item-map { font-size: 12px; }

/* ---- Contracts -------------------------------------------------------- */
.qs-main-title { font-size: 18px; font-weight: 700; margin: 0 0 2px; }
.input-sm { padding: 4px 8px; font-size: 12.5px; height: auto; }
.contract-card {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #d9e2dc);
    border-radius: 12px;
    padding: 16px 18px;
    margin: 0 18px 18px;
    box-shadow: 0 1px 2px rgba(16, 40, 28, .04);
}
.contract-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.contract-card-head h2 { font-size: 15px; font-weight: 700; margin: 0; }
.contract-card-actions { display: flex; align-items: center; gap: 10px; }
.contract-gen-form { display: flex; align-items: center; gap: 6px; }
.contract-table { width: 100%; }
.contract-table th { font-weight: 600; text-align: left; }
.contract-table .contract-col-flag { width: 64px; text-align: center; }
.contract-table td.contract-col-flag { text-align: center; }
.contract-key code {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--brand, #0e9f6e);
    white-space: nowrap;
}
.contract-target { min-width: 200px; }
.contract-target > * { width: 100%; }
.contract-save-row { margin-top: 12px; display: flex; justify-content: flex-end; }

/* ---------------------------------------------------------------------------
 * Submit — client quote submissions (LHS setup rail + RHS PDF viewer).
 * The rail slides away (animated grid column) when reading an old submission
 * so the PDF / BOM snapshot / plan register get the full width.
 * ------------------------------------------------------------------------- */
.qs-shell--submit {
    grid-template-columns: minmax(260px, 27%) minmax(0, 1fr);
    transition: grid-template-columns 0.28s ease;
}
.qs-shell--submit.rail-collapsed { grid-template-columns: 0px minmax(0, 1fr); }
.qs-shell--submit .qs-leftrail { min-width: 0; }
.qs-shell--submit.rail-collapsed .qs-leftrail {
    padding: 0; border-right: 0; overflow: hidden; visibility: hidden;
}

/* Slim toolbar: just the rail toggle (+ history tabs) — no title text. */
.qs-submit-toolbar { display: flex; align-items: center; gap: 12px; padding: 10px 18px 0; flex-shrink: 0; }

.qs-submit-body { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px 18px 16px; }
.qs-submit-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.qs-submit-pane[hidden] { display: none; }
.qs-submit-pane .mf-viewer { flex: 1; min-height: 0; --mc-accent: var(--accent); }
.qs-submit-pane--scroll { display: block; overflow-y: auto; }

/* Send card */
.qs-sendform { display: flex; flex-direction: column; gap: 5px; }
.qs-sendform-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 4px; }
.qs-sendform-price {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-top: 8px; padding: 8px 10px; border-radius: 8px;
    background: var(--accent-soft); font-size: 12.5px;
}
.qs-sendform-price strong { font-size: 15px; color: var(--accent); font-variant-numeric: tabular-nums; }
.qs-sendform-btn { margin-top: 6px; }

/* Included-categories table (checkbox + "map to" dropdown + $) */
.qs-catmap { width: 100%; border-collapse: collapse; margin: 2px 0 4px; }
.qs-catmap th {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-faint); text-align: left; padding: 2px 4px 4px;
    border-bottom: 1px solid var(--border);
}
.qs-catmap th.num, .qs-catmap td.num { text-align: right; }
.qs-catmap td { padding: 2px 4px; border-bottom: 1px dashed var(--border); vertical-align: middle; }
.qs-catmap tr:last-child td { border-bottom: 0; }
.qs-catmap form { margin: 0; }
.qs-catmap-sel { width: 100%; max-width: 150px; padding: 2px 4px; font-size: 11.5px; }
.qs-cattoggle-row {
    display: flex; align-items: center; gap: 7px;
    padding: 2px 0; font-size: 12.5px; cursor: pointer; border-radius: 5px;
}
.qs-cattoggle-row input { margin: 0; accent-color: var(--accent); }
.qs-cattoggle-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qs-cattoggle-amt { font-variant-numeric: tabular-nums; color: var(--text-dim); font-size: 12px; }
.qs-catmap tr.is-excluded .qs-cattoggle-name,
.qs-catmap tr.is-excluded .qs-cattoggle-amt { color: var(--text-faint); text-decoration: line-through; }
.qs-catmap tr.is-excluded .qs-catmap-sel { opacity: 0.5; }

/* Special (display-only) categories: chips + create form */
.qs-special-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.qs-special-chip {
    display: inline-flex; align-items: center; gap: 5px; margin: 0;
    padding: 2px 4px 2px 9px; border: 1px solid var(--border); border-radius: 999px;
    font-size: 11.5px; background: var(--bg-elev-3);
}
.qs-special-x {
    background: transparent; border: 0; cursor: pointer; color: var(--text-faint);
    font-size: 13px; line-height: 1; padding: 1px 4px; border-radius: 999px;
}
.qs-special-x:hover { color: #b91c1c; background: #fef2f2; }
.qs-special-create { margin-top: 8px; }
.qs-special-create summary {
    cursor: pointer; font-size: 12px; font-weight: 600; color: var(--accent);
    list-style: none; user-select: none;
}
.qs-special-create summary::-webkit-details-marker { display: none; }
.qs-special-create summary:hover { text-decoration: underline; }
.qs-cattoggle-total {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-top: 6px; padding: 6px 2px 0; border-top: 1px solid var(--border);
    font-size: 12.5px;
}
.qs-cattoggle-total strong { color: var(--accent); font-variant-numeric: tabular-nums; }

/* Submission template editor (shared with the global Rates rail) */
.qs-subsetup-upload { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.qs-subsetup-upload input[type="file"] { flex: 1; min-width: 0; font-size: 11.5px; padding: 4px; }
.qs-subsetup-file { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qs-subsetup-ph { font-family: var(--mono); font-size: 10.5px; word-break: break-all; color: var(--accent); }
.qs-subfield { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.qs-subfield-head { display: flex; gap: 6px; align-items: center; }
.qs-subfield-title { flex: 1; min-width: 0; font-weight: 600; }
.qs-subfield-body { font-family: var(--mono); font-size: 11.5px; line-height: 1.45; resize: vertical; }
.qs-subfield-grip {
    cursor: grab; user-select: none; color: var(--text-faint);
    font-size: 13px; padding: 0 2px; flex-shrink: 0;
}
.qs-subfield-grip:active { cursor: grabbing; }
.qs-subfield.is-dragging { opacity: 0.45; outline: 1px dashed var(--accent); border-radius: 6px; }
.qs-subfield-bodywrap { position: relative; display: flex; flex-direction: column; }
.qs-subfield-actions { display: flex; justify-content: flex-end; gap: 6px; }
.qs-addqty { color: var(--accent); }
.qs-qtymenu {
    position: absolute; z-index: 40; min-width: 180px; max-width: 260px;
    max-height: 220px; overflow-y: auto; padding: 4px;
    background: var(--bg-elev-2, #fff); border: 1px solid var(--border);
    border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.qs-qtymenu-item {
    display: flex; justify-content: space-between; gap: 12px; width: 100%;
    padding: 5px 8px; border: 0; background: none; border-radius: 6px;
    font-size: 12px; text-align: left; cursor: pointer; color: var(--text);
}
.qs-qtymenu-item:hover { background: var(--accent-soft, rgba(0, 0, 0, 0.06)); }
.qs-qtymenu-val { color: var(--text-faint); font-family: var(--mono); font-size: 11px; }
.qs-qtymenu-empty { padding: 8px 10px; font-size: 12px; color: var(--text-faint); }

/* Past submissions list */
.qs-subhist {
    display: flex; flex-direction: column; gap: 1px;
    padding: 6px 8px; margin-bottom: 4px; border: 1px solid var(--border);
    border-radius: 7px; text-decoration: none; color: var(--text);
    font-size: 12px; transition: border-color 0.15s, background 0.15s;
}
.qs-subhist:hover { border-color: var(--accent); background: var(--accent-soft); }
.qs-subhist.is-active { border-color: var(--accent); background: var(--accent-soft); }
.qs-subhist-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.qs-subhist-num { font-weight: 700; }
.qs-subhist-open {
    font-size: 10.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
    border: 1px solid var(--border); color: var(--text-faint); background: var(--bg-elev-3);
    white-space: nowrap;
}
.qs-subhist-open.is-opened { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.qs-subhist-meta { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.qs-subhist-to { color: var(--text-faint); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qs-subhist--current { flex-direction: row; justify-content: center; font-weight: 600; color: var(--accent); }

/* Frozen BOM snapshot table + plan register (history tabs) */
.qs-snapbom { width: 100%; }
.qs-snapbom th.num, .qs-snapbom td.num { text-align: right; font-variant-numeric: tabular-nums; }
.qs-snapbom-cat td { background: var(--bg-elev-3); font-weight: 700; }
.qs-snapbom-item { padding-left: 18px; }
.qs-snapbom-notes { color: var(--text-dim); font-size: 11.5px; max-width: 220px; }
.qs-snapbadge {
    display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 999px;
    font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
    background: var(--bg-elev); color: var(--text-faint); border: 1px solid var(--border);
}
.qs-snapbadge--excl { color: #b91c1c; border-color: #fca5a5; background: #fef2f2; }
.qs-snapplans { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.qs-snapplans li { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* =====================================================================
   Sub-categories (option groups inside a Rates/BOM category)
   ===================================================================== */
.qs-subcat-row td { background: var(--bg-elev); border-top: 1px solid var(--border); padding: 2px 8px; }
.qs-subcat-row .col-name { position: relative; padding-left: 30px; font-weight: 600; }
.qs-subcat-arrow { color: var(--text-faint); margin-right: 2px; }
.qs-subcat-name { width: 100%; max-width: 320px; font-weight: 600; }
.qs-badge--subcat { background: rgba(147, 51, 234, 0.12); color: #7c3aed; border: 1px solid rgba(147, 51, 234, 0.35); }
/* Items inside a sub-category indent one step further than direct items. */
.qs-item-row--sub .col-name { padding-left: 48px; }
.qs-item-row--sub .col-name::before { left: 30px; }
.qs-cat.collapsed .qs-subcat-row { display: none; }
/* The "Add sub category" form stacks vertically — its candidate multi-select
   needs the full rail width. */
form[data-action="create-subcategory"] { flex-direction: column; align-items: stretch; }
form[data-action="create-subcategory"] .input { flex: 0 0 auto; width: 100%; }
form[data-action="create-subcategory"] button { align-self: flex-end; }
.qs-subcat-items { min-height: 84px; font-size: 12.5px; }

/* =====================================================================
   Scope page — panel types, per-panel quantities & item selection
   ===================================================================== */
.qs-panel-list { display: flex; flex-direction: column; gap: 2px; }
.qs-panel-row { display: flex; align-items: center; gap: 6px; padding: 2px 6px; border-radius: 8px; }
.qs-panel-row .qs-panel-link { flex: 1; text-decoration: none; color: var(--text); font-size: 13px; padding: 3px 4px; border-radius: 6px; }
.qs-panel-row:hover { background: var(--row-tint); }
.qs-panel-row.active { background: var(--accent-soft, rgba(14, 159, 110, 0.12)); }
.qs-panel-row.active .qs-panel-link { font-weight: 600; color: var(--accent); }
.qs-panelqty-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.qs-panelqty-name { flex: 1; font-size: 12.5px; color: var(--text-dim); }
.qs-panelqty-row .input-num { width: 90px; text-align: right; }
.qs-panelqty-row .qs-readout { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--text-dim); }
.qs-panelcalc-list { margin-top: 6px; border-top: 1px dashed var(--border); padding-top: 6px; }
.qs-scope-catname { font-weight: 700; }
.qs-scope-subname { font-weight: 600; padding-left: 18px; white-space: nowrap; }
.qs-scope-table .col-itemname { min-width: 160px; }
.qs-scope-table .col-itemname .input-bare,
.qs-scope-table .col-itemname .qs-scope-select { width: 100%; }
.qs-scope-item td { padding: 0 8px; border-bottom: 1px solid var(--hairline); }
.qs-scope-item:hover td { background: var(--row-tint); }
/* Purple until an item has been selected for the sub-category on this panel. */
.qs-scope-pending td { background: rgba(147, 51, 234, 0.14) !important; }
.qs-scope-pending:hover td { background: rgba(147, 51, 234, 0.2) !important; }
.qs-scope-pending .qs-scope-select { border-color: #9333ea; color: #7c3aed; font-weight: 600; }
.qs-scope-purple-hint { color: #7c3aed; font-weight: 600; }
