/* Leakage workspace (views/leakage.js). Kit tokens only. */

/* Amounts: leakage reads destructive, overbilling reads warning */
.lk-amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.lk-amt.leakage { color: var(--destructive); }
.lk-amt.overbilling { color: var(--warning); }
.lk-amt.flag { color: var(--muted-foreground); }

/* Header export menu */
.lk-export { position: relative; }
.lk-export > summary { list-style: none; }
.lk-export > summary::-webkit-details-marker { display: none; }
.lk-export > summary svg.lucide:last-child { width: 14px; height: 14px; color: var(--muted-foreground); }
.lk-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 40; width: 240px; padding: 4px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--popover); box-shadow: var(--shadow-filter-popover); }

/* Empty state before the first run */
.lk-start { border: 1px dashed var(--border); border-radius: var(--radius-xl); background: var(--card); }

/* Close run: streaming log left, exceptions feed right */
.lk-run { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-bottom: 24px; }
.lk-run-feed { border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--background); padding: 12px 16px 16px; min-height: 100%; }
.lk-feed-head { display: flex; align-items: center; gap: 8px; height: 32px; }
.lk-feed-n { font-size: 12px; font-weight: 600; color: var(--primary); padding: 0 8px; line-height: 20px; border-radius: var(--radius-full); background: var(--muted-brand); }
.lk-feed-total { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 12px; }
.lk-feed-total .lk-amt { font-size: 22px; line-height: 30px; margin-right: 12px; }
.lk-feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 360px; overflow-y: auto; }
.lk-feed-row { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: var(--radius-lg); background: var(--muted); animation: lk-in var(--motion-standard) var(--ease-enter); }
.lk-feed-ic { width: 24px; height: 24px; display: grid; place-items: center; border-radius: var(--radius-md); background: var(--destructive-foreground); color: var(--destructive); flex: none; }
.lk-feed-row.overbilling .lk-feed-ic { background: var(--warning-foreground); color: var(--warning); }
.lk-feed-ic svg.lucide { width: 14px; height: 14px; }
.lk-feed-main { display: block; font-size: 14px; line-height: 20px; }
.lk-feed-sub { display: block; font-size: 12px; line-height: 16px; color: var(--muted-foreground); }
.lk-feed-wait { display: flex; align-items: center; gap: 8px; padding: 16px 0; color: var(--muted-foreground); font-size: 13px; }
@keyframes lk-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.lk-run-done { display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin-bottom: 24px; border: 1px solid var(--border-brand); border-radius: var(--radius-xl); background: var(--background-brand); }
.lk-run-done-ic { color: var(--success); display: grid; place-items: center; }

/* Summary strip with readiness card */
.lk-summary { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: stretch; margin-bottom: 24px; }
.lk-summary .rx-kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.lk-summary .rx-kpi-value { font-size: 24px; line-height: 32px; }
.lk-ready { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); min-width: 0; }
.lk-ready-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.lk-ready-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.lk-ready-list li { display: flex; align-items: center; gap: 8px; height: 28px; font-size: 13px; min-width: 0; }
.lk-ready-list svg.lucide { width: 16px; height: 16px; flex: none; }
.lk-ready-list li.ok svg.lucide { color: var(--success); }
.lk-ready-list li.open svg.lucide { color: var(--warning); }

/* View switch and toolbar */
.lk-switch { margin-bottom: 16px; }
.lk-toolbar .rx-search { flex: 1 1 200px; min-width: 180px; }
.lk-toolbar .select { min-width: 0; width: auto; max-width: 180px; }
.lk-results-meta { display: flex; align-items: center; gap: 12px; min-height: 32px; margin-bottom: 8px; }

/* Register */
.lk-cust { max-width: 160px; display: block; }
.lk-clause { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.lk-clause .cite-chip, .lk-clause .cite { max-width: 140px; }
.lk-action { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border-radius: var(--radius-md); border: 1px solid var(--border-brand); background: var(--background-brand); color: var(--primary); font-size: 12px; font-weight: 500; white-space: nowrap; cursor: help; }
.lk-action svg.lucide { width: 12px; height: 12px; }
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }
.lk-group { margin-bottom: 16px; }
.lk-group-head { display: flex; align-items: center; gap: 8px; margin: 16px 0 8px; }
.lk-group-head .count { font-size: 12px; color: var(--muted-foreground); }

/* By contract */
.lk-type { max-width: 180px; white-space: normal; }
.lk-chev { width: 16px; height: 16px; color: var(--muted-foreground); }
.lk-totals { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; padding: 12px 16px; margin-top: 8px; font-size: 13px; color: var(--muted-foreground); }
.lk-totals b { color: var(--foreground); font-variant-numeric: tabular-nums; }

/* Compare sources */
.lk-cmp-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.lk-cmp-head { display: grid; grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr); gap: 8px; align-items: stretch; margin-bottom: 16px; }
.lk-cmp-vs { display: grid; place-items: center; color: var(--muted-foreground); }
.lk-cmp-sum { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--muted); min-width: 0; }
.lk-cmp-sum-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.lk-cmp-logo { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius-lg); background: var(--background); box-shadow: var(--shadow-2xs); color: var(--primary); flex: none; }
.lk-cmp-rows { margin: 0; display: flex; flex-direction: column; }
.lk-cmp-rows > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 13px; border-bottom: 1px solid var(--border); }
.lk-cmp-rows dt { color: var(--muted-foreground); }
.lk-cmp-rows dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 500; }
.lk-cmp-rows .lk-cmp-total { border-bottom: 0; font-weight: 600; }
.lk-cmp-rows .lk-cmp-total dt { color: var(--foreground); }
.lk-cmp-cols, .lk-cmp-row { display: grid; grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr) 300px; gap: 8px; align-items: center; }
.lk-cmp-cols { padding: 0 4px 6px; font-size: 12px; font-weight: 500; color: var(--muted-foreground); }
.lk-cmp-list { display: flex; flex-direction: column; gap: 6px; }
.lk-cmp-row { padding: 4px; border-radius: var(--radius-lg); }
.lk-cmp-row:hover { background: var(--muted); }
.lk-cmp-cell { min-width: 0; }
.lk-cmp-rec { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); min-width: 0; }
.lk-cmp-rec .cell-main, .lk-cmp-rec .cell-sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lk-cmp-amt { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.lk-cmp-none { display: flex; align-items: center; min-height: 48px; padding: 6px 12px; border: 1px dashed var(--border); border-radius: var(--radius-lg); color: var(--muted-foreground); font-size: 13px; }
.lk-cmp-mid { display: grid; place-items: center; }
.lk-cmp-ind { width: 24px; height: 24px; display: grid; place-items: center; border-radius: var(--radius-full); }
.lk-cmp-ind svg.lucide { width: 14px; height: 14px; }
.lk-cmp-ind.success { background: var(--success-foreground); color: var(--success); }
.lk-cmp-ind.destructive { background: var(--destructive-foreground); color: var(--destructive); }
.lk-cmp-ind.warning { background: var(--warning-foreground); color: var(--warning); }
.lk-cmp-act { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }

/* Detail panel: traced stepper */
.lk-detail { display: flex; flex-direction: column; gap: 20px; }
.lk-detail-top { display: flex; align-items: flex-start; gap: 12px; }
.lk-detail-amt { font-size: 28px; line-height: 36px; }
.lk-trace { list-style: none; margin: 0; padding: 0; position: relative; }
.lk-step { position: relative; display: flex; gap: 12px; padding-bottom: 16px; }
.lk-step:not(:last-child)::before { content: ""; position: absolute; left: 13px; top: 30px; bottom: 2px; width: 2px; background: var(--border); }
.lk-step-ic { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: var(--radius-full); background: var(--muted); border: 1px solid var(--border); color: var(--muted-foreground); }
.lk-step-ic svg.lucide { width: 14px; height: 14px; }
.lk-step.leakage .lk-step-ic { background: var(--destructive-foreground); color: var(--destructive); border-color: transparent; }
.lk-step.overbilling .lk-step-ic { background: var(--warning-foreground); color: var(--warning); border-color: transparent; }
.lk-step.fina .lk-step-ic { background: var(--muted-brand); color: var(--primary); border-color: transparent; }
.lk-step-body { flex: 1; min-width: 0; padding-top: 3px; display: flex; flex-direction: column; gap: 6px; }
.lk-step-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.lk-step-label { font-size: 13px; font-weight: 600; }
.lk-step-amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.lk-quote { margin: 0; padding: 10px 12px; border-left: 3px solid var(--primary); border-radius: var(--radius-md); background: var(--background-brand); font-family: var(--font-serif); font-size: 14px; line-height: 22px; }
.lk-calc { font-size: 13px; line-height: 20px; color: var(--foreground); font-variant-numeric: tabular-nums; }
.lk-src { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted-foreground); }
.lk-src svg.lucide { width: 12px; height: 12px; }
.lk-step-meta { gap: 8px; align-items: center; }
.lk-fina-text { margin: 0; font-family: var(--font-serif); font-size: 14px; line-height: 22px; }

.lk-rec { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); }
.lk-rec-head { display: flex; align-items: center; gap: 8px; }
.lk-rec-head svg.lucide { color: var(--primary); width: 16px; height: 16px; }
.lk-rec-why { margin: 0; font-size: 13px; line-height: 20px; color: var(--muted-foreground); }
.lk-btns { gap: 8px; }

/* Drafted document preview */
.lk-doc { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--background); box-shadow: var(--shadow-sm); overflow: hidden; }
.lk-doc-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--muted); border-bottom: 1px solid var(--border); }
.lk-doc-head svg.lucide { width: 16px; height: 16px; color: var(--muted-foreground); }
.lk-doc-title { display: block; font-size: 13px; font-weight: 600; }
.lk-doc-lines { width: 100%; border-collapse: collapse; font-size: 12px; }
.lk-doc-lines th, .lk-doc-lines td { padding: 6px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.lk-doc-lines th { color: var(--muted-foreground); font-weight: 500; }
.lk-doc-lines .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lk-doc-lines tfoot td { font-weight: 600; border-bottom: 0; }
.lk-doc-text { margin: 0; padding: 10px 12px; font-size: 13px; line-height: 20px; }

.lk-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0; padding: 16px; border-radius: var(--radius-xl); background: var(--muted); }
.lk-meta dt { font-size: 12px; color: var(--muted-foreground); }
.lk-meta dd { margin: 2px 0 0; display: flex; align-items: center; gap: 6px; font-size: 14px; }
.lk-link { display: inline-flex; align-items: center; gap: 4px; color: var(--primary); font-weight: 500; }
.lk-link svg.lucide { width: 14px; height: 14px; }
.lk-h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.lk-h3 .count { font-size: 12px; color: var(--muted-foreground); font-weight: 500; }
.lk-activity { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lk-activity li { display: flex; align-items: baseline; gap: 10px; font-size: 13px; line-height: 20px; }
.lk-act-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border); flex: none; transform: translateY(-2px); }

@media (max-width: 1100px) {
  .lk-summary { grid-template-columns: minmax(0, 1fr); }
  .lk-run { grid-template-columns: minmax(0, 1fr); }
  .lk-cmp-cols, .lk-cmp-row { grid-template-columns: minmax(0, 1fr) 32px minmax(0, 1fr); }
  .lk-cmp-act { grid-column: 1 / -1; }
}

/* Additions for the RA3 shapes */
.lk-ready-list li.pending svg.lucide { color: var(--muted-foreground); }
.lk-title-line { margin: -8px 0 0; font-size: 14px; line-height: 20px; }
.lk-cmp-st { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; margin-right: auto; }
.lk-basis { white-space: normal; max-width: 220px; }
.lk-pre-reason { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 300px; font-family: var(--font-serif); font-size: 13px; line-height: 18px; margin-bottom: 4px; }
.lk-quote mark.rx-hl { padding: 0 2px; border-radius: var(--radius-xs); }
/* Integration pass: re-run prompt after a contract is added, KPI cards at natural height (I). */
.lk-rerun { display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin-bottom: 16px; border-radius: var(--radius-xl); background: var(--background-brand); border: 1px solid color-mix(in srgb, var(--primary) 22%, transparent); }
.lk-rerun-ic { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-md); background: var(--background); color: var(--primary); flex: none; }
.lk-rerun-ic svg.lucide { width: 16px; height: 16px; }
.lk-summary { align-items: start; }

/* Close run, design 4B: full-screen overlay with source tiles, phase stepper and results summary */
.lk-close-scrim { position: fixed; inset: 0; z-index: 90; display: flex; justify-content: center; align-items: flex-start; overflow-y: auto; padding: 32px 16px; background: color-mix(in srgb, var(--foreground) 45%, transparent); animation: lk-in var(--motion-standard) var(--ease-enter); }
.lk-close-scrim[hidden] { display: none; }
body.lk-close-lock { overflow: hidden; }
.lk-close { position: relative; width: min(1120px, 100%); display: flex; flex-direction: column; align-items: center; gap: 24px; padding: 32px 40px 32px; border-radius: var(--radius-xl); background: var(--background); box-shadow: var(--shadow-lg); }
.lk-close-x { position: absolute; top: 16px; right: 16px; }
.lk-close-head { text-align: center; }
.lk-close-head .rx-head-sub { display: inline-flex; align-items: center; gap: 8px; margin-top: 4px; }
.lk-close-steps { display: flex; align-items: center; gap: 12px; margin: 0; padding: 0; list-style: none; width: 100%; max-width: 940px; }
.lk-close-steps li { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; color: var(--muted-foreground); white-space: nowrap; }
.lk-close-steps li + li::before { content: ''; flex: 0 0 16px; height: 2px; background: var(--border); }
.lk-close-steps li.done + li::before, .lk-close-steps li.done::before { background: var(--primary); }
.lk-close-steps li.on { color: var(--foreground); font-weight: 500; }
.lk-close-steps li.done { color: var(--foreground); }
.lk-close-n { display: grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: var(--radius-full); background: var(--muted); font-size: 12px; font-weight: 600; }
.lk-close-steps li.done .lk-close-n { background: var(--primary); color: var(--primary-foreground); }
.lk-close-steps li.on .lk-close-n { background: var(--muted-brand); }
.lk-close-n svg.lucide { width: 13px; height: 13px; }
.lk-close-n .rx-spin { width: 14px; height: 14px; }
.lk-close-tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; width: 100%; }
.lk-close-tile { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); opacity: .55; transition: opacity var(--motion-standard), border-color var(--motion-standard), box-shadow var(--motion-standard), background var(--motion-standard); }
.lk-close-tile.active { opacity: 1; border-color: var(--border-brand); box-shadow: 0 0 0 4px var(--muted-brand); }
.lk-close-tile.done { opacity: 1; border-color: var(--border-brand); background: var(--background-brand); }
.lk-close-tile .row { min-height: 36px; }
.lk-close-tn { font-weight: 600; font-size: 14px; line-height: 20px; }
.lk-close-ok { color: var(--success); }
.lk-close-now { width: 100%; max-width: 720px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; min-height: 120px; }
.lk-close-bar { width: 100%; border-radius: var(--radius-full); overflow: hidden; margin-top: 8px; }
.lk-close-run { display: flex; align-items: baseline; gap: 8px; margin-top: 8px; font-size: 13px; }
.lk-close-run .lk-amt { font-size: 18px; font-weight: 600; }
.lk-close-res { width: 100%; display: flex; flex-direction: column; gap: 16px; padding: 20px 24px; border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-md); animation: lk-in var(--motion-standard) var(--ease-enter); }
.lk-close-top { display: flex; flex-direction: column; }
.lk-close-row { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 8px; border: 0; border-bottom: 1px solid var(--border); background: transparent; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.lk-close-row:last-child { border-bottom: 0; }
.lk-close-row:hover { background: var(--accent); }
.lk-close-btns { gap: 8px; }
@media (max-width: 1100px) { .lk-close-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } .lk-close-steps li { white-space: normal; } }

/* Compare sources actions (A3) */
.lk-mt, .lk-nx { display: flex; flex-direction: column; gap: 12px; }
.lk-mt-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius-lg); background: var(--muted); }
.lk-mt-list { display: flex; flex-direction: column; gap: 8px; }
.lk-mt-cand { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); cursor: pointer; }
.lk-mt-cand:hover { background: var(--accent); }
.lk-mt-cand.on { border-color: var(--border-brand); background: var(--background-brand); }
.lk-mt-cand input { margin-top: 3px; accent-color: var(--primary); }
.lk-mt-why { margin-top: 4px; font-size: 13px; line-height: 18px; }
.lk-nx-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.lk-nx-reason { height: auto; min-height: 72px; padding-top: 8px; resize: vertical; }
#nx-err { color: var(--destructive); min-height: 16px; }
.lk-cmp-act .btn.icon { flex: none; }

/* QA fixes (V4): KPI cards in one row, Close readiness as a compact horizontal row under them (no empty gap beside the cards). */
.lk-summary { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.lk-summary .rx-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.lk-ready { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; padding: 8px 16px; min-height: 48px; }
.lk-ready-head { flex: none; margin: 0; gap: 8px; }
.lk-ready-head .t-title { flex: none; }
.lk-ready-list { flex: 1 1 480px; flex-direction: row; flex-wrap: wrap; gap: 4px 20px; }
.lk-ready-list li { height: 24px; }
.lk-ready-list li .grow { flex: none; overflow: visible; text-overflow: clip; }
@media (max-width: 1100px) { .lk-summary .rx-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.lk-ready-list li.rerun svg.lucide { color: var(--primary); }
