/* =========================================================================
   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;
}

* { 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); }

/* ---- 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; }

/* ---- 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-messages { flex: 1; overflow-y: auto; padding: 20px clamp(12px, 2.5vw, 28px); }
.chat-msg { max-width: 880px; margin: 0 auto 24px; }
.chat-msg.user {
    position: sticky;
    top: 0;
    z-index: 5;
    isolation: isolate;
    margin-bottom: 18px;
    padding: 10px 0 8px;
}
.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: 11px; text-transform: uppercase; color: var(--text-faint); letter-spacing: 0.08em; margin-bottom: 6px; }
.chat-msg.user .role { color: var(--accent); }
.chat-msg .body {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    padding: 14px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
    white-space: pre-wrap;
}
.chat-msg.user .body { background: var(--accent-soft); border-color: var(--accent-soft-strong); }
.chat-msg .body code { background: var(--bg-elev-3); padding: 1px 6px; border-radius: 4px; font-family: var(--mono); font-size: 12.5px; }
.chat-msg .body pre { background: var(--bg-elev-3); padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; font-family: var(--mono); font-size: 12.5px; }

.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: 14px clamp(12px, 6vw, 80px) 22px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}
.chat-input-row {
    display: flex; gap: 10px; max-width: 760px; margin: 0 auto;
    align-items: flex-end;
}
.chat-input-row textarea {
    flex: 1; resize: none; min-height: 48px; max-height: 220px;
}
.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;
}
.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 {
    display: inline-flex; align-items: center;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--accent-soft-strong);
    padding: 0 6px; height: 18px;
    border-radius: 4px;
    font-size: 11.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); }

/* ---- 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-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; }
.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; }
.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; }

/* 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;
}
.qs-table thead th.col-toggle, .qs-table thead th.col-actions { padding-left: 8px; padding-right: 8px; }
.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-val, .qs-table .col-val2 { width: 64px; }
/* 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;
}
.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; }

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