/* ============================================================
   OTI Deal Jacket — modern theme (revamped 2026-07, design
   language modeled on OTI.Web.Reports). Brand identity (navy +
   gold) retained; layered surfaces, soft shadows, rounded cards,
   focus rings and hover motion adopted from the reports app.
   All existing class names preserved — no markup changes.
   ============================================================ */
:root {
    /* ---- accent (indigo) — modeled on OTI.Web.Reports ---- */
    --brand:        #6366F1;   /* indigo (primary accent) */
    --brand-d:      #4F46E5;   /* darker — hovers/gradients */
    --brand-l:      #818CF8;
    --brand-ink:    #ffffff;
    --accent:       #6366F1;
    --accent-d:     #4F46E5;
    --accent-l:     #818CF8;
    --accent-soft:  rgba(99,102,241,.10);
    --accent-soft-2:rgba(99,102,241,.16);

    /* ---- surfaces (light, layered) ----
       The page sits a shade deeper than the panels rather than nearly matching them, and the
       lines are strong enough to actually read as edges. Panels stay white: the contrast between
       the ground and the cards is what gives the layout structure, and without it a long page of
       white panels on a near-white page reads as one washed-out sheet. */
    --bg:           #e9ebf0;
    --surface:      #ffffff;
    --panel:        #ffffff;
    --surface-2:    #f2f3f6;
    --sidebar-bg:   #f4f5f8;
    --border:       #dbdee5;
    --line:         #dbdee5;
    --line-2:       #e7e9ee;
    --ink:          #1d1d1f;
    --muted:        #6e6e73;
    --muted-2:      #86868b;

    /* ---- status ---- */
    --ok:           #15803D;  --ok-bg:      #E7F6EC;
    --warn:         #B45309;  --warn-bg:    #FBF3E2;
    --alert:        #DC2626;  --alert-bg:   #FBEAEA;
    --neutral:      #475569;  --neutral-bg: #eef1f6;

    /* ---- misc ---- */
    --radius:       14px;
    --radius-sm:    9px;
    --ring:         rgba(99,102,241,.35);
    --ease:         cubic-bezier(.4,0,.2,1);
    --sh-1:         0 1px 2px rgba(17,24,39,.04), 0 1px 3px rgba(17,24,39,.05);
    --sh-2:         0 2px 8px rgba(17,24,39,.05), 0 8px 24px rgba(17,24,39,.05);
    --sh-3:         0 6px 16px rgba(17,24,39,.08), 0 16px 40px rgba(17,24,39,.10);
    --shadow:       var(--sh-1);
    --font:         system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }

.loading-shell {
    display: flex; align-items: center; justify-content: center;
    height: 100vh; color: var(--muted);
}

/* ---------------- Shell + sidebar ---------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 236px; flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--ink);
    display: flex; flex-direction: column;
    padding: 18px 12px;
    position: sticky; top: 0; height: 100vh;
    border-right: 1px solid var(--line);
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; padding: 4px 6px 18px; border-bottom: 1px solid var(--line); }
.brand-mark {
    width: 40px; height: 40px; border-radius: 11px;
    background: linear-gradient(135deg, var(--accent), var(--accent-d)); color: #fff;
    display: grid; place-items: center; font-weight: 800; font-size: 15px;
    box-shadow: 0 4px 12px var(--ring);
}
.brand-name { font-weight: 700; letter-spacing: -.01em; color: var(--ink); }
.brand-sub { font-size: 11px; color: var(--muted-2); margin-top: 1px; }

.nav-items { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; border-radius: var(--radius-sm);
    color: var(--ink); font-weight: 500;
    transition: background .14s var(--ease), color .14s var(--ease), transform .1s var(--ease), box-shadow .14s var(--ease);
}
.nav-item:hover { background: var(--accent-soft-2); color: var(--accent-d); }
.nav-item:active { transform: translateY(.5px); }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 2px 8px var(--ring); }
.nav-item.active:hover { background: var(--accent-d); color: #fff; }
.nav-ico { width: 18px; text-align: center; opacity: .9; }
.nav-badge {
    margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
    border-radius: 10px; font-size: 11px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent-soft); color: var(--accent-d);
}
.nav-item.active .nav-badge { background: rgba(255,255,255,.22); color: #fff; }

.sidebar-foot { padding: 6px; }
.env-pill {
    font-size: 11px; padding: 5px 11px; border-radius: 20px;
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
    display: inline-block; font-weight: 500;
}

.content { flex: 1; overflow-x: auto; min-width: 0; }
.content-inner { max-width: 1200px; margin: 0 auto; padding: 28px 32px 64px; }

/* ---------------- Top bar (dealership filter) ---------------- */
.topbar { display: flex; justify-content: flex-end; align-items: center; gap: 10px;
    padding: 11px 32px; border-bottom: 1px solid var(--line); z-index: 5;
    background: rgba(255,255,255,.8); backdrop-filter: saturate(1.8) blur(20px);
    -webkit-backdrop-filter: saturate(1.8) blur(20px);
    position: sticky; top: 0; box-shadow: var(--sh-1); }
.rooftop-filter { display: flex; align-items: center; gap: 8px; }
.rooftop-label { font-size: 11px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .05em; }
.rooftop-select, .auth-select { font: inherit; font-size: 13.5px; color: var(--ink); min-width: 200px; cursor: pointer;
    appearance: none; -webkit-appearance: none;
    border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 7px 32px 7px 12px; box-shadow: var(--sh-1);
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
    background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%2394a2b5' stroke-width='1.5'><path d='M3 4.5 6 7.5 9 4.5'/></svg>") no-repeat right 11px center; }
.rooftop-select:hover, .auth-select:hover { border-color: #c7cdd8; }
.rooftop-select:focus-visible, .auth-select:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }

/* ---------------- DMS validation ---------------- */
.dms-lookup { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dms-label { font-size: 11px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .05em; }
.dms-input { font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 7px 11px; width: 160px; box-shadow: var(--sh-1);
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease); }
.dms-input:hover { border-color: #c7cdd8; }
/* Roles table: wide enough for the longest option, which is a role that is no longer assignable
   and carries a "(not assignable)" suffix. */
.role-select { min-width: 210px; }

/* ---------------- Alert preferences + outbox ---------------- */
.pref-list { display: flex; flex-direction: column; gap: 8px; }
.pref-row { display: flex; align-items: center; gap: 10px; font-size: 13.5px; cursor: pointer; }
.pref-row input { cursor: pointer; }
.outbox-body { margin: 6px 0 0; padding: 12px; background: var(--surface-2);
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.dms-input:focus, .dms-input:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.dms-facts { display: grid; gap: 4px; font-size: 14px; }
.dms-facts .dms-k { display: inline-block; min-width: 74px; color: var(--muted);
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

/* ---------------- Headings ---------------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
h1 { font-size: 25px; margin: 4px 0 2px; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }
.back { color: var(--muted); font-size: 13px; transition: color .15s var(--ease); }
.back:hover { color: var(--brand); }
.pad { padding: 16px 18px; }

/* One row, wrapping only when it runs out of width. Stacked, the actions and status badges read
   as a list of unrelated things; in a row they read as one toolbar for the deal. */
.head-right { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.deliver-gate { font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 8px; }
.deliver-gate.ok { background: var(--ok-bg); color: var(--ok); }
.deliver-gate.blocked { background: var(--alert-bg); color: var(--alert); }

/* ---------------- KPI cards ---------------- */
.kpi-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 14px; margin-bottom: 24px;
}
.kpi {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--sh-2);
    padding: 16px 18px; position: relative; overflow: hidden;
    transition: transform .18s var(--ease), box-shadow .18s var(--ease);
}
.kpi::before { content:''; position:absolute; left:0; top:0; bottom:0; width:4px; background: var(--stripe, var(--neutral)); }
.kpi:hover { transform: translateY(-2px); box-shadow: var(--sh-3); }
.kpi-val { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi-label { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi-ok    { --stripe: var(--ok); }
.kpi-warn  { --stripe: var(--warn); }
.kpi-alert { --stripe: var(--alert); }

/* ---------------- Panels ---------------- */
.panel {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--sh-2);
    margin-bottom: 18px; overflow: hidden;
}
/* A faint tint on the header separates it from the panel's body, so each card reads as a titled
   section rather than text floating on white. Brand themes override this (see fredbeans.css). */
.panel-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px 18px; border-bottom: 1px solid var(--line); gap: 12px;
    background: var(--surface-2);
}
.panel-head.clickable { transition: background .15s var(--ease); }
.panel-head.clickable:hover { background: var(--surface-2); }

/* ---------------- Jacket layout ---------------- */
.jacket-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.jacket-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 860px) { .jacket-grid { grid-template-columns: 1fr; } }

/* ---------------- Tables ---------------- */
.grid { width: 100%; border-collapse: collapse; }
.grid th {
    text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); font-weight: 600; padding: 11px 18px; border-bottom: 1px solid var(--line);
}
.grid td { padding: 13px 18px; border-bottom: 1px solid var(--line-2); }
.grid.tight td, .grid.tight th { padding: 9px 18px; }
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr { transition: background .12s var(--ease); }
.clickable { cursor: pointer; }
.grid tbody tr.clickable:hover { background: var(--surface-2); }
.chev { color: var(--muted-2); text-align: right; font-size: 18px; }

.bar { display: inline-block; width: 80px; height: 6px; background: var(--neutral-bg); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-d)); }
.bar-label { font-size: 12px; color: var(--muted); margin-left: 8px; }

/* ---------------- Toolbar ---------------- */
.toolbar { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.search {
    flex: 1; min-width: 220px; padding: 9px 14px;
    border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 14px; background: var(--surface);
    box-shadow: var(--sh-1); transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.search:hover { border-color: #c7cdd8; }
.search:focus, .search:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter {
    border: 1px solid var(--line); background: var(--surface);
    padding: 7px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; font-weight: 500;
    box-shadow: var(--sh-1); transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), transform .1s var(--ease);
}
.filter:hover { border-color: #c7cdd8; background: #fafbfc; }
.filter:active { transform: translateY(.5px); }
.filter.on { border-color: var(--brand); background: var(--brand); color: #fff; box-shadow: var(--sh-2); }
.filter.on .badge { background: rgba(255,255,255,.18); color: #fff; }

/* ---------------- Badges ---------------- */
.badge {
    display: inline-block; font-size: 11px; font-weight: 600;
    padding: 3px 10px; border-radius: 20px; white-space: nowrap;
}
.badge.ok      { background: var(--ok-bg);      color: var(--ok); }
.badge.warn    { background: var(--warn-bg);    color: var(--warn); }
.badge.alert   { background: var(--alert-bg);   color: var(--alert); }
.badge.neutral { background: var(--neutral-bg); color: var(--neutral); }

/* ---------------- Checklist ---------------- */
.checklist, .compliance { list-style: none; margin: 0; padding: 8px 0; }
.checklist li {
    display: flex; align-items: center; justify-content: space-between;
    padding: 9px 18px;
}
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.check .done { color: var(--muted); text-decoration: line-through; }
.gate-tag { font-size: 11px; color: var(--alert); background: var(--alert-bg); padding: 2px 8px; border-radius: 12px; }

/* ---------------- Compliance list ---------------- */
.compliance li { display: flex; gap: 12px; align-items: flex-start; padding: 11px 18px; }

/* ---------------- Documents ---------------- */
.doc-group { padding: 0; }

/* The folder header is a filled band, so it reads as a divider between folders rather than as
   another row in the list. Its rows are then indented under it and share a left rail, which is
   what actually answers "which documents are in this folder?". */
.doc-group-head {
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--ink); font-weight: 700;
    padding: 9px 18px;
    background: var(--surface-2);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}
.doc-group-toggle {
    display: flex; align-items: center; gap: 9px; width: 100%;
    border: 0; font-family: inherit; cursor: pointer; text-align: left;
    transition: background .12s var(--ease), color .12s var(--ease);
}
.doc-group-toggle:hover { background: var(--accent-soft); color: var(--accent-d); }
.doc-group-toggle:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--ring); }
.doc-group-count { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted); }

/* CSS triangle rather than a glyph — the arrow characters render as a hairline dash at this
   size in some fonts. Shared by the folder and submission-package toggles. */
.doc-group-caret {
    width: 0; height: 0; flex: 0 0 auto;
    border-left: 5px solid currentColor;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    opacity: .55;
    transition: transform .15s var(--ease);
}
[aria-expanded="true"] > .doc-group-caret { transform: rotate(90deg); }

/* Documents sit inside their folder: indented, with a rail running down the group. */
.doc-group .doc-row {
    padding-left: 36px;
    border-left: 3px solid var(--line-2);
}

/* A slot with nothing filed is marked on the name itself. Deliberately not a filled row: a new
   deal has twenty empty slots, and tinting every one of them turns the normal starting state of
   the page into a wall of red. */
.doc-row.doc-missing .doc-name > span:first-child { color: var(--alert); }

/* ---------------- Submission packages ---------------- */
/* Same documents as the deal file, grouped by where they get sent. */
.pkg-head {
    display: flex; align-items: center; gap: 10px; width: 100%;
    background: none; border: 0; font-family: inherit; font-size: 13px; cursor: pointer;
    text-align: left; color: var(--ink); padding: 11px 18px;
    transition: background .12s var(--ease);
}
.pkg-head:hover { background: var(--surface-2); }
.pkg-head:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); border-radius: var(--radius-sm); }
.pkg-name { font-weight: 600; }
.pkg-dest { font-size: 11px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .05em; }
.pkg-count { margin-left: auto; color: var(--muted); }
/* Package rows share the deal file's .doc-group wrapper, so they pick up the same indent, rail
   and missing-document highlight without a second set of rules. */
.req-tag { font-size: 11px; color: var(--muted); background: var(--surface-2); padding: 2px 8px; border-radius: 12px; }

/* ---------------- Accounting queue ---------------- */
/* A deal that has waited too long is flagged with a rail rather than a filled row — the same
   reasoning as the deal file: a busy queue shouldn't render as a solid block of red. */
.row-alert > td:first-child { box-shadow: inset 3px 0 0 var(--alert); font-weight: 600; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.return-box { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 4px 0; }
.return-box .search { flex: 1 1 260px; }
.turnover-bar {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); font-size: 13px;
}
.turnover-note { color: var(--muted); margin-right: auto; }

/* Push-to-archive (CDK) bar at the top of the deal file. */
.archive-bar {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 12px 18px; border-bottom: 1px solid var(--line);
    background: var(--surface-2); font-size: 13px;
}
.archive-note { color: var(--muted); margin-right: auto; }
.archive-msg { color: var(--ink); font-weight: 500; }

/* Pre-flight alert: what is outstanding before anything is billed to CDK. */
.archive-alert {
    padding: 12px 18px; border-bottom: 1px solid var(--line);
    background: var(--warn-bg); font-size: 13px;
}
.archive-alert.blocking { background: var(--alert-bg); }
.archive-alert-head { margin: 0 0 8px; font-weight: 600; color: var(--ink); }
.archive-alert-list { margin: 0 0 10px; padding-left: 20px; color: var(--ink); }
.archive-alert-list li { margin: 2px 0; }
.archive-alert-actions { display: flex; gap: 8px; }
.doc-row {
    display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
    padding: 10px 18px; border-top: 1px solid var(--line-2);
    transition: background .12s var(--ease);
}
.doc-row:hover { background: var(--surface-2); }
.doc-name { display: flex; flex-direction: column; gap: 4px; }
.doc-name > span:first-child { display: flex; align-items: center; gap: 10px; }
.sig-tag { font-size: 11px; color: var(--warn); background: var(--warn-bg); padding: 2px 8px; border-radius: 12px; }
.stored-meta { font-size: 12px; color: var(--muted); }
.doc-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.upload-btn { cursor: pointer; }
.upload-btn input[type=file] { display: none; }

/* ---------------- Buttons ---------------- */
.btn-sm {
    border: 1px solid var(--line); background: var(--surface);
    padding: 7px 13px; border-radius: var(--radius-sm); font-size: 12.5px; cursor: pointer; white-space: nowrap;
    font-weight: 500; color: var(--ink); box-shadow: var(--sh-1);
    transition: background .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease), transform .1s var(--ease);
}
.btn-sm:hover { background: #fafbfc; border-color: #c7cdd8; box-shadow: var(--sh-2); }
.btn-sm:active { transform: translateY(.5px); box-shadow: var(--sh-1); }
.btn-sm:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.btn-sm:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm.primary { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }
.btn-sm.primary:hover { background: var(--brand-d); border-color: var(--brand-d); }
.btn-sm.danger { color: var(--alert); border-color: var(--alert); background: var(--surface); }
.btn-sm.danger:hover { background: var(--alert); color: #fff; }

/* ---------------- Records retention & legal hold ---------------- */
.records-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 18px; border-top: 1px solid var(--line-2); }
.records-actions .search { min-width: 280px; flex: 1; }

/* ---------------- Product cancellation / refunds ---------------- */
.strike { text-decoration: line-through; }
.refund-amt { width: 90px; padding: 5px 8px; font-size: 12.5px; }

/* ---------------- Trade-in / title blocks ---------------- */
.title-block { padding: 15px 18px; border-top: 1px solid var(--line-2); }
.title-block:first-of-type { border-top: none; }
.title-block-head {
    display: flex; justify-content: space-between; align-items: center;
    font-weight: 600; margin-bottom: 10px;
}
.kv-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px 24px; margin-bottom: 10px;
}
.kv-grid > div { display: flex; flex-direction: column; }
.kv-k { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kv-v { font-size: 13.5px; }
.kv-v.neg { color: var(--alert); font-weight: 600; }
.trade-status { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; border-top: 1px dashed var(--line); }
.trade-status-row { display: flex; align-items: center; gap: 10px; }
.trade-status-row .kv-k { min-width: 130px; }
.title-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- Batch scan import ---------------- */
.batch-bar { display: flex; align-items: center; gap: 12px; padding: 14px 18px; flex-wrap: wrap; }
.batch-review { border-top: 1px solid var(--line); }
.batch-assign { min-width: 240px; padding: 7px 11px; font-size: 13px;
    border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--sh-1);
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease); }
.batch-assign:hover { border-color: #c7cdd8; }
.batch-assign:focus, .batch-assign:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.batch-actions { display: flex; gap: 8px; padding: 14px 18px; }

/* ---------------- Forms (create / edit deal) ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.form-input {
    padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
    font-size: 14px; background: var(--surface); width: 100%; box-shadow: var(--sh-1);
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.form-input:hover { border-color: #c7cdd8; }
.form-input:focus, .form-input:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.form-input:disabled { background: var(--surface-2); color: var(--muted); }
.check-field { justify-content: flex-end; }
.trade-edit { padding: 15px 18px; border-top: 1px solid var(--line-2); }
.trade-edit .btn-sm { margin-top: 10px; }
.form-actions { display: flex; gap: 10px; margin: 18px 0 40px; }
.form-error {
    background: var(--alert-bg); color: var(--alert); border: 1px solid var(--alert);
    padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13px;
}

/* ---------------- Auth / login ---------------- */
.auth-shell { min-height: 100vh; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--brand), var(--brand-d)); padding: 20px; }
.auth-card {
    width: 100%; max-width: 380px; background: var(--surface);
    border-radius: 16px; box-shadow: var(--sh-3); padding: 30px;
}
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.auth-title { font-size: 20px; margin: 0 0 18px; font-weight: 700; letter-spacing: -.01em; }
.auth-card .field { margin-bottom: 14px; }
.auth-submit { width: 100%; justify-content: center; padding: 11px; margin-top: 4px; }
.auth-hint { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.auth-hint ul { margin: 8px 0 0; padding-left: 16px; }
.auth-hint li { margin: 2px 0; }

/* ---------------- Sidebar user ---------------- */
.user-box { padding: 10px 6px; border-top: 1px solid var(--line); margin-top: 4px; }
/* Organisation block above the user's name. These carried no styling at all, which ran the org
   name and its level together as one word ("Farmington FordDealership"). */
.user-org { margin-bottom: 8px; }
.org-name { font-size: 12.5px; font-weight: 600; color: var(--ink); line-height: 1.35;
    overflow-wrap: anywhere; }
.org-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px;
    font-size: 11px; color: var(--muted); line-height: 1.4; }
.org-level { text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.org-sep { opacity: .55; }
.user-name { font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.35;
    overflow-wrap: anywhere; }
.user-role { font-size: 11px; color: var(--muted); }
.signout {
    width: 100%; text-align: left; background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); padding: 9px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px;
    box-shadow: var(--sh-1); transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.signout:hover { background: var(--accent-soft); color: var(--accent-d); border-color: transparent; }

/* ---------------- Activity / audit ---------------- */
.activity { list-style: none; margin: 0; padding: 6px 0; }
.activity li { padding: 11px 18px; border-top: 1px solid var(--line-2); }
.activity li:first-child { border-top: none; }
.activity-action { font-weight: 600; }

/* ---------------- Document viewer modal ---------------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,.55);
    backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 24px;
    animation: modal-in .14s var(--ease) both;
}
@keyframes modal-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
    background: #fff; width: 88%; height: 90%; max-width: 1100px;
    border-radius: 14px; box-shadow: var(--sh-3);
    display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 12px;
}
.modal-title { font-weight: 600; font-size: 14px; }
.modal-actions { display: flex; gap: 8px; }
/* The scroll box stays put; the frame inside it is scaled by the zoom control. */
.modal-frame-scroll { flex: 1; overflow: auto; background: var(--surface-2); }
.modal-frame { width: 100%; height: 100%; border: none; background: var(--surface-2); transform-origin: 0 0; }

/* ---------------- Misc ---------------- */
.not-found { text-align: center; padding: 80px 20px; }

#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--alert-bg); color: var(--alert); border-top: 1px solid var(--alert);
    padding: 10px 16px; box-shadow: 0 -1px 3px rgba(0,0,0,.1); z-index: 1000;
}
#blazor-error-ui .reload { text-decoration: underline; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

/* ---------------- Scrollbars ---------------- */
.content, .grid { scrollbar-width: thin; scrollbar-color: var(--muted-2) transparent; }

/* ---------------- Mobile / responsive ---------------- */
@media (max-width: 640px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: auto; height: auto; position: static; flex-direction: row; align-items: center; gap: 8px; padding: 8px 10px; overflow-x: auto; }
    .brand { margin-bottom: 0; flex-shrink: 0; padding: 0 6px; border-bottom: none; }
    .brand-sub { display: none; }
    .nav-items { flex-direction: row; flex: 0 1 auto; gap: 2px; }
    .nav-item { padding: 8px 10px; white-space: nowrap; }
    .nav-item.active { box-shadow: inset 0 -3px 0 var(--accent); }
    .sidebar-foot { margin-left: auto; flex-shrink: 0; padding: 0; }
    .user-box { display: none; }

    .content-inner { padding: 16px 14px 48px; }
    .topbar { padding: 10px 14px; }
    .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
    .head-right { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
    .grid { display: block; overflow-x: auto; white-space: nowrap; }
    .modal { width: 96vw; height: 92vh; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
    .kpi:hover { transform: none; }
}

.rollup-total td { font-weight: 700; border-top: 2px solid var(--line); }

/* ---------------- Scan-import progress (non-blocking, estimated) ---------------- */
.scan-loader {
    position: fixed; right: 22px; bottom: 22px; z-index: 900; width: 306px;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--sh-3); padding: 14px 16px; animation: modal-in .15s var(--ease) both;
}
.scan-loader-top { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; color: var(--ink); }
.scan-loader-top strong { font-variant-numeric: tabular-nums; color: var(--accent-d); }
.scan-loader-top .sp { width: 16px; height: 16px; flex: 0 0 auto; border: 2.5px solid var(--line);
    border-top-color: var(--accent); border-radius: 50%; animation: oti-spin .7s linear infinite; }
.scan-loader-track { margin-top: 11px; height: 7px; background: var(--surface-2); border-radius: 7px; overflow: hidden; }
.scan-loader-fill { height: 100%; border-radius: 7px; background: linear-gradient(90deg, var(--accent), var(--accent-l));
    transition: width .2s var(--ease); }
.scan-loader-note { margin-top: 9px; font-size: 11px; color: var(--muted); line-height: 1.4; }
@keyframes oti-spin { to { transform: rotate(360deg); } }

/* ---------------- Outstanding-work digest ---------------- */
.digest { padding: 14px 18px; display: flex; flex-direction: column; gap: 8px; }
.digest p { margin: 0; color: var(--muted); }
.digest strong { color: var(--ink); }
.digest a { color: var(--brand-d); text-decoration: underline; }
.digest table { margin-top: 6px; }

/* ---------------- Deal thread ---------------- */
.thread { list-style: none; margin: 0; padding: 0; }
.thread-msg { padding: 11px 18px; border-top: 1px solid var(--line-2); }
.thread-meta { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.thread-author { font-weight: 600; }
.thread-role { font-size: 11px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .05em; }
.thread-time { font-size: 12px; color: var(--muted); margin-left: auto; }
.thread-body { margin-top: 4px; white-space: pre-wrap; }
.thread-compose { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }
.thread-compose .search { flex: 1; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------------- Accounting review ---------------- */
.stage-bar {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.stage-label {
    font-size: 11px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .05em; margin-right: 4px;
}
.stage-pill {
    font: inherit; font-size: 12.5px; font-weight: 500;
    padding: 6px 13px; border-radius: 20px; cursor: pointer;
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    transition: background .14s var(--ease), border-color .14s var(--ease), color .14s var(--ease);
}
.stage-pill:hover:not(:disabled) { border-color: var(--accent-l); color: var(--accent-d); }
.stage-pill:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.stage-pill:disabled { opacity: .55; cursor: not-allowed; }
.stage-pill.current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* Accounting marks their compliance sheet with an E, not a tick — the checkbox drives the state,
   the E is what they read. */
.e-checklist .check input { position: absolute; opacity: 0; width: 16px; height: 16px; cursor: pointer; }
.e-mark {
    display: inline-grid; place-items: center;
    width: 22px; height: 22px; flex: 0 0 auto;
    border: 1.5px solid var(--line); border-radius: 5px;
    font-size: 12px; font-weight: 800; color: var(--ok); background: var(--surface);
}
.e-checklist .check:hover .e-mark { border-color: var(--accent-l); }

/* ---------------- Add a document slot ---------------- */
.add-doc-bar {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.add-doc-bar .search { flex: 1 1 240px; }
.add-doc-bar .rooftop-select { min-width: 150px; }

/* ---------------- Accounting handoff strip ---------------- */
.handoff-strip {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    margin: -8px 0 18px; padding: 11px 18px;
    background: var(--accent-soft); border: 1px solid var(--accent-l);
    border-radius: var(--radius-sm); font-size: 13px; color: var(--ink);
}
.handoff-strip > span:first-child { margin-right: auto; }

/* ---------------- Accounting's accept / send-back decision ---------------- */
.decision-bar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 13px 18px; border-top: 1px solid var(--line); background: var(--surface-2);
}
.return-box.pad { padding: 12px 18px; border-top: 1px solid var(--line-2); }

/* ---------------- Messages widget (docked bottom-right, every screen) ---------------- */
.msg-widget {
    position: fixed; right: 20px; bottom: 20px; z-index: 40;
    display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
.msg-launcher {
    display: flex; align-items: center; gap: 8px;
    font: inherit; font-size: 13px; font-weight: 600;
    padding: 10px 16px; border-radius: 24px; cursor: pointer;
    color: #fff; background: var(--accent); border: 1px solid var(--accent-d);
    box-shadow: var(--sh-3);
    transition: background .14s var(--ease), transform .1s var(--ease);
}
.msg-launcher:hover { background: var(--accent-d); }
.msg-launcher:active { transform: translateY(1px); }
.msg-launcher:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring), var(--sh-3); }
.msg-count {
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    background: rgba(255,255,255,.24); color: #fff;
}

.msg-panel {
    width: 370px; max-width: calc(100vw - 40px);
    height: 460px; max-height: calc(100vh - 120px);
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--sh-3);
}
.msg-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.msg-title { font-weight: 600; font-size: 13.5px; }
.msg-icon-btn {
    font: inherit; font-size: 13px; line-height: 1; cursor: pointer;
    border: 0; background: none; color: var(--muted); padding: 4px 6px; border-radius: 6px;
}
.msg-icon-btn:hover { color: var(--ink); background: var(--surface); }
.msg-icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

.msg-body { flex: 1; overflow-y: auto; }
.msg-empty, .msg-foot { margin: 0; padding: 16px 14px; color: var(--muted); font-size: 13px; }
.msg-foot { border-top: 1px solid var(--line); background: var(--surface-2); }
.msg-error { margin: 0; padding: 10px 14px; font-size: 12.5px; color: var(--alert); background: var(--alert-bg); }

.msg-list { list-style: none; margin: 0; padding: 0; }
.msg-item { padding: 10px 14px; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.msg-author { font-weight: 600; }
.msg-role { font-size: 10.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .05em; }
.msg-time { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.msg-text { margin-top: 3px; white-space: pre-wrap; }

.msg-compose { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--surface-2); }
.msg-compose input {
    flex: 1; min-width: 0; font: inherit; font-size: 13px; color: var(--ink);
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm); padding: 8px 11px;
}
.msg-compose input:focus, .msg-compose input:focus-visible {
    outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring);
}

@media (max-width: 860px) {
    .msg-widget { right: 12px; bottom: 12px; }
    .msg-panel { height: 60vh; }
}

/* Conversation list — one row per deal, the way a phone lists people. */
.msg-convo {
    display: flex; gap: 11px; align-items: flex-start;
    padding: 11px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer;
}
.msg-convo:hover { background: var(--surface-2); }
.msg-convo:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--ring); }
.msg-avatar {
    flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%;
    display: grid; place-items: center;
    font-size: 12.5px; font-weight: 700; letter-spacing: .02em;
    color: #fff; background: linear-gradient(135deg, var(--accent-l), var(--accent-d));
}
.msg-convo-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.msg-convo-top { display: flex; align-items: baseline; gap: 8px; }
.msg-convo-name { font-weight: 600; font-size: 13.5px; }
.msg-convo-top .msg-time { margin-left: auto; flex: 0 0 auto; }
.msg-convo-deal {
    display: flex; align-items: center; gap: 6px;
    font-size: 11.5px; color: var(--accent-d); font-weight: 600;
}
.msg-convo-count {
    min-width: 16px; height: 16px; padding: 0 5px; border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 700; color: var(--accent-d); background: var(--accent-soft);
}
.msg-convo-preview {
    font-size: 12.5px; color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.digest-caption { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
