/* ── Library Page ── */
.library-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  align-items: center;
}

.filter-bar .form-input { flex: 1; }

.contracts-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.contracts-table-header {
  display: grid;
  grid-template-columns: 30px 2.5fr 1fr 1fr 1.2fr 1fr 70px 80px;
  padding: 10px 16px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
}

.contracts-table-row {
  display: grid;
  grid-template-columns: 30px 2.5fr 1fr 1fr 1.2fr 1fr 70px 80px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  cursor: pointer;
  transition: background 0.1s;
}

.contracts-table-row:last-child { border-bottom: none; }
.contracts-table-row:hover { background: var(--bg4); }
.cc-select-cell { display: flex; align-items: center; }
.cc-select { width: 16px; height: 16px; cursor: pointer; }

#page-contract-compare h1 { font-size: 20px; margin: 0 0 18px; }
.cc-toolbar { display: flex; gap: 8px; margin-bottom: 20px; }
.cc-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); padding: 18px; margin-bottom: 16px; }
.cc-section h2 { font-size: 16px; margin: 0 0 12px; }
.cc-section p { margin: 0 0 12px; }
.cc-table-wrap { overflow-x: auto; }
.cc-table { width: 100%; }
.cc-match { color: var(--green); background: var(--green-bg); }
.cc-diverge { color: var(--amber); background: var(--amber-bg); }
.cc-checklist { display: grid; gap: 8px; }
.cc-checklist label { display: flex; align-items: start; gap: 8px; cursor: pointer; }
.cc-checklist input { flex: none; margin-top: 2px; }
@media print {
  body:has(#page-contract-compare.active) .sidebar,
  body:has(#page-contract-compare.active) .topbar,
  body:has(#page-contract-compare.active) nav { display: none !important; }
  #page-contract-compare.active { display: block !important; }
  body:has(#page-contract-compare.active) .main { display: block; overflow: visible; }
  #page-contract-compare .page-scroll { overflow: visible !important; height: auto !important; padding: 0 !important; }
  #page-contract-compare .bpv-diff-list { max-height: none; overflow: visible; }
  #page-contract-compare .cc-toolbar { display: none; }
  #page-contract-compare .cc-section { break-inside: avoid; }
}
@keyframes row-flash-anim {
  0%   { background: var(--green-bg); box-shadow: inset 0 0 0 1px var(--green-border); }
  70%  { background: var(--green-bg); box-shadow: inset 0 0 0 1px var(--green-border); }
  100% { background: transparent;    box-shadow: none; }
}
.contracts-table-row.row-flash { animation: row-flash-anim 2s ease-out forwards; }

.contract-name-cell { }
.contract-name { font-size: 13px; font-weight: 500; margin-bottom: 2px; }
.contract-sub  { font-size: 10px; color: var(--text2); font-family: var(--mono); }

.cell-date {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text2);
  line-height: 1.8;
}

.cell-lines {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text2);
}

/* ── Wizard Page ── */
.wizard-container { max-width: 780px; margin: 0 auto; }

.wizard-progress {
  display: flex;
  align-items: center;
  margin-bottom: 32px;
}

.wizard-step { display: flex; align-items: center; gap: 8px; flex: 1; }

.step-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  border: 1.5px solid var(--border2);
  color: var(--text3);
  transition: all 0.3s;
  flex-shrink: 0;
  font-family: var(--mono);
}

.step-circle.active { border-color: var(--blue);  color: var(--blue);  background: var(--blue-bg); }
.step-circle.done   { border-color: var(--green); color: var(--green); background: var(--green-bg); }

.step-label { font-size: 11px; color: var(--text3); white-space: nowrap; }
.step-label.active { color: var(--text); }
.step-label.done   { color: var(--text2); }

.step-connector {
  flex: 1;
  height: 1px;
  background: var(--border);
  margin: 0 10px;
  transition: background 0.4s;
}
.step-connector.done { background: var(--green-border); }

/* Drop Zone */
.drop-zone {
  border: 1.5px dashed var(--border2);
  border-radius: var(--radius-lg);
  padding: 52px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.drop-zone:hover, .drop-zone.over {
  border-color: var(--blue);
  background: var(--blue-bg);
}

.drop-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  background: var(--bg5);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-title { font-size: 15px; font-weight: 500; margin-bottom: 6px; }
.drop-sub   { font-size: 12px; color: var(--text3); }
.drop-types { display: flex; gap: 6px; justify-content: center; margin-top: 14px; }

.file-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-top: 14px;
}

/* ── Step 1 upload progress bar ── */
.s1-upload-bar {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
}
.s1-upload-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 8px;
}
.s1-progress-track {
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}
.s1-progress-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 2px;
  transition: width 0.15s ease;
}
.s1-upload-error {
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--red);
}

.file-type-badge {
  width: 38px;
  height: 38px;
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--red);
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

.file-info-name { font-size: 13px; font-weight: 500; }
.file-info-meta { font-size: 11px; color: var(--text3); margin-top: 1px; }

.file-remove {
  background: none;
  border: 0;
  font: inherit;
  text-align: left;
  margin-left: auto;
  cursor: pointer;
  color: var(--text3);
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
}
.file-remove:hover { color: var(--red); }

/* Step 1 upload progress bar */
.s1-upload-bar { margin-top: 16px; }
.s1-upload-label { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text2); margin-bottom: 6px; }
.s1-progress-track { height: 6px; background: var(--bg3); border-radius: var(--radius-sm); overflow: hidden; }
.s1-progress-fill { height: 100%; background: var(--blue); border-radius: var(--radius-sm); transition: width 0.15s ease; }
.s1-upload-error { margin-top: 12px; padding: 10px 14px; background: var(--red-bg); border: 1px solid var(--red-border); color: var(--red); border-radius: var(--radius-md); font-size: 0.85rem; }

/* Step 3 auto-approve notice (replaces action buttons when status === AutoApproved) */
.autoapproved-notice { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--green-bg); border: 1px solid var(--green-border); border-radius: var(--radius-md); font-size: 13px; color: var(--green); }

/* Agent Cards */
.pass-label {
  font-size: 10px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text3);
  margin: 16px 0 8px;
}

.agents-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.agent-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  transition: all 0.3s;
}

.agent-card.running { border-color: var(--blue-border);  background: var(--blue-bg); }
.agent-card.done    { border-color: var(--green-border); }
.agent-card.error   { border-color: var(--red-border); }

.agent-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }

.agent-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text3);
  transition: all 0.3s;
  flex-shrink: 0;
}

.agent-dot.running { background: var(--blue);  animation: pulse 1s infinite; }
.agent-dot.done    { background: var(--green); }
.agent-dot.error   { background: var(--red); }

.agent-name { font-size: 12px; font-weight: 500; }
.agent-role { font-size: 10px; color: var(--text3); }

.agent-log {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text3);
  margin-top: 4px;
  line-height: 1.9;
  max-height: 64px;
  overflow: hidden;
}

.agent-log .log-line { display: block; }

.agent-full-width { grid-column: 1 / -1; }

/* Pipeline progress */
.pipeline-progress {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 12px;
}

.progress-bar-wrap {
  background: var(--bg5);
  border-radius: 4px;
  height: 5px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--purple));
  border-radius: 4px;
  width: 0%;
  transition: width 0.4s ease;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text3);
  margin-top: 4px;
}

/* Step strip (js/stepstrip.js): Prepare · Pass 1 · Pass 2 · Finish, then the Now line */
.step-strip {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr 1fr;
  gap: 8px;
  margin: 12px 0 10px;
}
.ss-stage {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  min-width: 0;
  transition: border-color .3s, background .3s;
}
.ss-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text3);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.ss-stage.ss-running { border-color: var(--blue-border);  background: var(--blue-bg); }
.ss-stage.ss-running .ss-head { color: var(--blue); }
.ss-stage.ss-done    { border-color: var(--green-border); }
.ss-stage.ss-done .ss-head { color: var(--green); }
.ss-stage.ss-slow    { border-color: var(--amber-border); background: var(--amber-bg); }
.ss-stage.ss-slow .ss-head { color: var(--amber); }
.ss-stage.ss-failed  { border-color: var(--red-border);   background: var(--red-bg); }
.ss-stage.ss-failed .ss-head { color: var(--red); }

.ss-steps { list-style: none; }
.ss-step {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 0;
  font-size: 12.5px;
  color: var(--text3);
}
.ss-ico {
  width: 14px; height: 14px; flex: none;
  border-radius: 50%;
  border: 1.5px solid var(--text3);
  display: grid; place-items: center;
  font-size: 9px; font-weight: 700; line-height: 1;
  color: var(--on-accent);
}
.ss-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ss-time { font-family: var(--mono); font-size: 10px; color: var(--text3); font-variant-numeric: tabular-nums; }
.ss-step.ss-running { color: var(--text); }
.ss-step.ss-running .ss-ico { border-color: var(--blue); border-top-color: transparent; animation: spin .9s linear infinite; }
.ss-step.ss-done    { color: var(--text2); }
.ss-step.ss-done .ss-ico   { background: var(--green); border-color: var(--green); }
.ss-step.ss-slow    { color: var(--text); }
.ss-step.ss-slow .ss-ico   { background: var(--amber); border-color: var(--amber); }
.ss-step.ss-failed  { color: var(--text); }
.ss-step.ss-failed .ss-ico { background: var(--red); border-color: var(--red); }
@media (prefers-reduced-motion: reduce) { .ss-step.ss-running .ss-ico { animation: none; border-top-color: var(--blue); } }
.ss-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.step-now {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border-left: 3px solid var(--blue);
  font-size: 13px;
  color: var(--text);
}
.step-now-label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--blue);
  flex: none;
}
.step-now-msg  { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.step-now-time { font-family: var(--mono); font-size: 11px; color: var(--text3); font-variant-numeric: tabular-nums; }
.step-now-done   { border-left-color: var(--green); } .step-now-done .step-now-label   { color: var(--green); }
.step-now-slow   { border-left-color: var(--amber); } .step-now-slow .step-now-label   { color: var(--amber); }
.step-now-failed { border-left-color: var(--red); }   .step-now-failed .step-now-label { color: var(--red); }
.progress-info { align-items: center; margin-top: 8px; }
.progress-total { color: var(--text3); }

/* Agent cards folded under the strip */
.agent-details { margin-top: 12px; }
.agent-details > summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text2);
  padding: 4px 0;
  width: fit-content;
}
.agent-details > summary:hover { color: var(--text); }
.agent-details > summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
.agent-details[open] > summary { margin-bottom: 4px; }

/* Pre-screener */
.prescreener-result {
  background: var(--bg3);
  border: 1px solid var(--green-border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ps-icon {
  width: 30px;
  height: 30px;
  background: var(--green-bg);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--green);
  flex-shrink: 0;
}

/* Routing banner */
.routing-banner {
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.routing-banner.auto-approve  { background: var(--green-bg);  border: 1px solid var(--green-border); }
.routing-banner.standard      { background: var(--blue-bg);   border: 1px solid var(--blue-border); }
.routing-banner.needs-review  { background: var(--amber-bg);  border: 1px solid var(--amber-border); }
.routing-banner.escalate      { background: var(--red-bg);    border: 1px solid var(--red-border); }

.routing-label { font-size: 17px; font-weight: 600; }
.routing-sub   { font-size: 11px; color: var(--text2); margin-top: 2px; }

.routing-conf       { margin-left: auto; text-align: right; }
.routing-conf-num   { font-size: 22px; font-weight: 600; font-family: var(--mono); }
.routing-conf-label { font-size: 10px; color: var(--text3); font-family: var(--mono); }

/* Result stats strip */
.result-stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.rstat {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  text-align: center;
}

.rstat-val   { font-size: 18px; font-weight: 600; font-family: var(--mono); line-height: 1.2; }
.rstat-label { font-size: 10px; color: var(--text3); margin-top: 3px; text-transform: uppercase; letter-spacing: 0.05em; }

.rstat-link { cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.rstat-link:hover { border-color: var(--amber-border); background: var(--amber-bg); }

/* Section confidence bars */
.section-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.section-row:last-child { margin-bottom: 0; }
.section-row-name { font-size: 12px; flex: 1; }

.section-bar-track {
  width: 72px;
  height: 4px;
  background: var(--bg5);
  border-radius: 2px;
  flex-shrink: 0;
}

.section-bar-fill { height: 4px; border-radius: 2px; }
.section-conf-label { font-size: 10px; font-family: var(--mono); width: 30px; text-align: right; }

/* ── Detail Page ── */
.detail-title {
  font-size: 20px;
  font-weight: 400;
  letter-spacing: -0.02em;
  font-family: var(--serif);
  font-style: italic;
  line-height: 1.3;
  margin-bottom: 10px;
}

/* Newest ContractManager delivery package of the contract (js/detail.js _renderDelivery). */
.detail-delivery { margin: -12px 0 16px; }
.detail-delivery .badge { white-space: normal; text-align: left; line-height: 1.4; }

.detail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.back-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  text-align: left;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text3);
  font-size: 12px;
  cursor: pointer;
  margin-bottom: 12px;
  transition: color 0.15s;
  user-select: none;
}

.back-link:hover { color: var(--text2); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.detail-kv-table { width: 100%; border-collapse: collapse; }
.detail-kv-table td { padding: 5px 0; vertical-align: top; }
.detail-kv-table td:first-child { color: var(--text3); font-size: 11px; width: 42%; }
.detail-kv-table td:last-child  { font-size: 12px; }

.rate-table-detail { width: 100%; border-collapse: collapse; }
.rate-table-detail th { font-size: 10px; color: var(--text3); text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); font-family: var(--mono); font-weight: 500; }
.rate-table-detail td { font-size: 11px; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.rate-table-detail tr:last-child td { border-bottom: none; }

.chart-wrap { position: relative; }

/* ── Audit Logs v2: 7-column grid with Timestamp ── */
.al-grid-v2 {
  display: grid;
  grid-template-columns: 2.2fr 1.1fr 0.9fr 80px 110px 90px 150px;
  gap: 0 12px;
  align-items: center;
  padding: 11px 16px;
}
.contracts-table-header.al-grid-v2 { padding: 10px 16px; }

/* ── Review Page: Tab Badge (unresolved flag count) ── */
.rv-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  font-size: 9px;
  font-family: var(--mono);
  font-weight: 600;
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid var(--amber-border);
  margin-left: 4px;
  vertical-align: middle;
  line-height: 1;
}
.rv-tab-badge:empty { display: none; }

/* ── Trace Timeline ── */
.trace-timeline { display: flex; flex-direction: column; padding: 4px 0; }

.trace-step-item { display: flex; gap: 12px; }

.trace-step-spine {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 28px;
}

.trace-step-node {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--on-accent);
  flex-shrink: 0;
  font-family: var(--mono);
  letter-spacing: 0;
}

.trace-step-line {
  width: 1px;
  flex: 1;
  min-height: 12px;
  background: var(--border2);
  margin: 3px 0;
}

.trace-step-body { flex: 1; padding-bottom: 16px; min-width: 0; }

.trace-step-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 6px;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--mono);
}

.trace-step-content {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

/* ── Trace Tab: Two-Section Audit Timeline ── */

.trace-origin-card {
  background: var(--purple-bg);
  border: 1px solid var(--purple-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 20px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.trace-section-heading {
  font-size: 10px;
  font-weight: 600;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text3);
  padding: 8px 0;
  margin-top: 4px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.trace-section-heading::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.trace-change-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 8px;
}
.trace-change-card.error   { border-left-color: var(--red); }
.trace-change-card.warning { border-left-color: var(--amber); }
.trace-change-card.info    { border-left-color: var(--blue); }

.trace-change-card-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.trace-diff-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.trace-diff-cell {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-width: 0;
}
.trace-diff-cell.before {
  border-color: var(--red-border);
  background: var(--red-bg);
}
.trace-diff-cell.after {
  border-color: var(--green-border);
  background: var(--green-bg);
}

.trace-diff-label {
  font-size: 9px;
  font-weight: 600;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 5px;
}
.trace-diff-cell.before .trace-diff-label { color: var(--red); }
.trace-diff-cell.after  .trace-diff-label { color: var(--green); }

.trace-diff-value {
  font-size: 11px;
  font-family: var(--mono);
  line-height: 1.6;
  word-break: break-all;
}
.trace-diff-cell.before .trace-diff-value { color: var(--red); opacity: 0.85; }
.trace-diff-cell.after  .trace-diff-value { color: var(--green); }

.trace-pending-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  min-width: 0;
}
.trace-pending-msg {
  font-size: 11px;
  color: var(--text3);
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}
.trace-pending-resolve {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--blue);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
  transition: color 0.15s;
}
.trace-pending-resolve:hover { color: var(--blue-light); }

.trace-status-card {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.trace-status-row {
  font-size: 12px;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.trace-status-row.error   { color: var(--red); }
.trace-status-row.warning { color: var(--amber); }
.trace-status-row.ok      { color: var(--green); }

/* ── Blueprint Version Timeline ─────────────────────────────────── */
.bpv-timeline {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 14px;
}
.bpv-heading {
  font-size: 10px;
  font-weight: 600;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
  margin-bottom: 10px;
}
.bpv-entry {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  opacity: 0.7;
}
.bpv-entry:last-child { border-bottom: none; }
.bpv-entry.current    { opacity: 1; }
.bpv-marker {
  min-width: 28px;
  height: 22px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.bpv-marker.current {
  background: var(--blue-bg);
  border-color: var(--blue-border);
  color: var(--blue);
}
.bpv-body { flex: 1; min-width: 0; }
.bpv-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.bpv-by {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text2);
  font-weight: 500;
}
.bpv-ts {
  font-size: 10px;
  color: var(--text3);
  font-family: var(--mono);
}
.bpv-diff {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.bpv-diff-field {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text3);
  word-break: break-all;
  flex-basis: 100%;
}
.bpv-diff-before {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--red);
  background: var(--red-bg);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  text-decoration: line-through;
  opacity: 0.8;
}
.bpv-diff-arrow {
  font-size: 10px;
  color: var(--text3);
}
.bpv-diff-after {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--green);
  background: var(--green-bg);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

/* ── Blueprint Version Browser ──────────────────────────────────── */
.bp-layout {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg);
}

/* Label above the tab row */
.bp-versions-label {
  padding: 8px 14px 0;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text3);
  background: var(--bg3);
}

/* Scrollable row of version buttons */
.bp-sidebar {
  display: flex;
  flex-direction: row;
  gap: 8px;
  padding: 10px 14px 12px;
  background: var(--bg3);
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.bp-sidebar::-webkit-scrollbar { height: 4px; }
.bp-sidebar::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* Each version is a real <button> */
.bpv-tab-btn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 14px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  min-width: 160px;
  max-width: 220px;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
  flex-shrink: 0;
}
.bpv-tab-btn:hover {
  border-color: var(--blue-border);
  background: var(--blue-bg);
}
.bpv-tab-btn.active {
  border-color: var(--blue);
  background: var(--blue-bg);
  box-shadow: 0 0 0 1px var(--blue);
}

.bpv-tab-badge {
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.bpv-tab-btn.active .bpv-tab-badge { color: var(--blue); }

.bpv-tab-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bpv-tab-sub {
  font-size: 10px;
  color: var(--text3);
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bpv-tab-latest {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--blue);
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}

/* Viewer pane */
.bp-viewer {
  display: flex;
  flex-direction: column;
  min-height: 440px;
  overflow: hidden;
}

.bpv-viewer-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.bpv-viewer-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

/* Inline change pill inside viewer header */
.bpv-change-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px 8px;
  font-size: 10px;
  font-family: var(--mono);
}
.bpv-change-field  { color: var(--text3); }
.bpv-change-from   { color: var(--red);   background: var(--red-bg);   padding: 0 4px; border-radius: 3px; }
.bpv-change-arrow  { color: var(--text3); }
.bpv-change-to     { color: var(--green); background: var(--green-bg); padding: 0 4px; border-radius: 3px; }

.bpv-viewer-pre {
  flex: 1;
  margin: 0;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  overflow: auto;
  line-height: 1.75;
  background: var(--bg);
}

.bpv-diff-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 16px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}
.bpv-diff-toggle, .bpv-compare-select {
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  padding: 5px 8px;
}
.bpv-diff-toggle { cursor: pointer; }
.bpv-diff-toggle.active { color: var(--blue); border-color: var(--blue); background: var(--blue-bg); }
.bpv-diff-toggle:disabled, .bpv-compare-select:disabled { opacity: .55; cursor: default; }
.bpv-diff-counts { color: var(--text2); flex: 1; min-width: 180px; }
.bpv-compare-label { color: var(--text3); }
.bpv-diff-list { max-height: 360px; overflow: auto; background: var(--bg); border-bottom: 1px solid var(--border); }
.bpv-diff-list[hidden] { display: none; }
.bpv-diff-entry { padding: 9px 16px; border-bottom: 1px solid var(--border); border-left: 3px solid var(--amber); }
.bpv-diff-entry.added { border-left-color: var(--green); background: var(--green-bg); }
.bpv-diff-entry.removed { border-left-color: var(--red); background: var(--red-bg); }
.bpv-diff-entry.changed { background: var(--amber-bg); }
.bpv-diff-path { color: var(--text); font: 11px var(--mono); overflow-wrap: anywhere; }
.bpv-diff-values { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 5px; font: 10px var(--mono); overflow-wrap: anywhere; }
.bpv-diff-before { color: var(--red); }
.bpv-diff-after { color: var(--green); }
.bpv-diff-arrow { color: var(--text3); }
.bpv-diff-empty { padding: 14px 16px; color: var(--text3); }

/* ── Flags tab — resolution summary bar ─────────────────────────── */
.rv-flags-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text2);
}
.rv-flags-summary-count {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.rv-flags-summary-all-done {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--green);
}

/* Resolved flags section divider within the Flags list */
.rv-flags-resolved-heading {
  font-size: 10px;
  font-weight: 600;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--green);
  padding: 8px 0;
  margin-top: 4px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.rv-flags-resolved-heading::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--green-border);
}

/* ── Audit Logs: Confidence Bar (Overview tab) ── */
.al-conf-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.al-conf-bar-track {
  width: 80px;
  height: 5px;
  background: var(--bg5);
  border-radius: 3px;
  flex-shrink: 0;
  overflow: hidden;
}

.al-conf-bar-fill {
  height: 5px;
  border-radius: 3px;
  transition: width 0.4s ease-out;
}

/* ── Review Page: Confidence Meter (routing banner) ── */
.conf-meter {
  width: 80px;
  height: 4px;
  background: var(--bg5);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 5px;
}

.conf-meter-fill {
  height: 4px;
  border-radius: 2px;
  background: var(--blue);
  transition: width 0.4s ease-out;
}

/* ── Review Page: Inspection Checklist ── */
.cl-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 6px;
  overflow: hidden;
}

.cl-section.cl-ok    { border-left: 3px solid var(--green); }
.cl-section.cl-warn  { border-left: 3px solid var(--amber); }
.cl-section.cl-error { border-left: 3px solid var(--red); }

.cl-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: var(--bg3);
  border: none;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  transition: background 0.15s;
}

.cl-header:hover { background: var(--bg4); }

.cl-header-static {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg3);
  font-size: 13px;
  opacity: 0.6;
}

.cl-icon { font-size: 12px; flex-shrink: 0; width: 16px; text-align: center; }
.cl-icon-ok    { color: var(--green); }
.cl-icon-warn  { color: var(--amber); }
.cl-icon-error { color: var(--red); }

.cl-title  { font-size: 12px; font-weight: 500; flex: 1; }
.cl-counts { font-size: 10px; color: var(--text3); font-family: var(--mono); white-space: nowrap; }
.cl-chevron {
  font-size: 9px;
  color: var(--text3);
  flex-shrink: 0;
  transition: transform 0.15s;
}

.cl-body {
  padding: 8px 12px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.cl-body .insp-flag-card { margin-bottom: 8px; }
.cl-body .insp-flag-card:last-child { margin-bottom: 0; }

/* Market definition form (Settings → Markets, Review "save as market definition"; js/marketDefinitions.js).
   minmax(0, 1fr) lets the field column shrink: a plain 1fr can't go below its widest row (two 150 px dates). */
.md-form {
  display: grid;
  grid-template-columns: var(--md-label-w, 150px) minmax(0, 1fr);
  gap: 8px 12px;
  align-items: start;
  font-size: 12px;
}
.md-form .form-input { max-width: 100%; min-width: 0; box-sizing: border-box; }
/* Examples, not values: lighter and italic so an empty field never looks filled in */
.md-form .form-input::placeholder { color: var(--text3); font-style: italic; opacity: 1; }

/* ── Markdown view (Settings → Pattern Library; js/markdown.js) ── */
.mdv-switch { display: inline-flex; border: 1px solid var(--border2); border-radius: var(--radius-sm); overflow: hidden; flex-shrink: 0; }
.mdv-switch-btn { background: none; border: 0; padding: 4px 10px; font-size: 11px; color: var(--text2); cursor: pointer; font-family: inherit; }
.mdv-switch-btn + .mdv-switch-btn { border-left: 1px solid var(--border2); }
.mdv-switch-btn.active { background: var(--bg3); color: var(--text); font-weight: 600; }
.mdv-switch-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.mdv {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 16px 20px; max-height: 620px; overflow: auto; color: var(--text2);
  font-size: 13px; line-height: 1.6; overflow-wrap: anywhere;
}
.mdv > * { max-width: 80ch; }
.mdv h1, .mdv h2, .mdv h3, .mdv h4 { color: var(--text); line-height: 1.3; margin: 1.2em 0 .5em; }
.mdv > :first-child { margin-top: 0; }
.mdv h1 { font-size: 18px; }
.mdv h2 { font-size: 15px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.mdv h3, .mdv h4 { font-size: 13px; }
.mdv p { margin: 0 0 .8em; }
.mdv ul, .mdv ol { margin: 0 0 .8em; padding-left: 22px; }
.mdv li { margin: 3px 0; }
.mdv li > ul, .mdv li > ol { margin: 3px 0 0; }
.mdv strong { color: var(--text); }
.mdv code { font-family: var(--mono); font-size: .9em; background: var(--bg3); border-radius: 3px; padding: 1px 4px; color: var(--text); }
.mdv-pre { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; overflow-x: auto; margin: 0 0 .8em; }
.mdv-pre code { background: none; padding: 0; font-size: 11.5px; white-space: pre; }
.mdv hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.mdv-table { overflow-x: auto; margin: 0 0 .8em; max-width: 100%; }
.mdv table { border-collapse: collapse; font-size: 12px; }
.mdv th, .mdv td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; vertical-align: top; }
.mdv th { background: var(--bg3); color: var(--text); font-weight: 600; }

/* Result of Save Draft on the contract page: stays until dismissed (detail.js _showSaveStatus). */
.save-status { position: sticky; top: 0; z-index: 5; display: flex; align-items: flex-start; gap: 10px; margin: 0 0 14px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg2); color: var(--text); font-size: 13px; line-height: 1.45; }
.save-status.ok  { background: var(--green-bg); border-color: var(--green-border); }
.save-status.err { background: var(--red-bg);   border-color: var(--red-border); }
.save-status-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.save-status-close { flex-shrink: 0; border: 0; background: none; color: var(--text2); cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 4px; }
.save-status-close:hover { color: var(--text); }
.save-status-close:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ── Reports page (admin) ── */
.nav-item[hidden] { display: none; }
.rp-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.rp-intro { font-size: 13px; color: var(--text2); margin-bottom: 16px; max-width: 760px; }
.rp-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.rp-field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--text3); min-width: 130px; }
.rp-field-wide { min-width: 220px; flex: 1 1 220px; max-width: 360px; }
.rp-field-narrow { min-width: 70px; width: 80px; }
.rp-actions { display: flex; gap: 8px; }
.rp-window { font-size: 12px; color: var(--text2); margin-bottom: 10px; }
.rp-clear { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 14px; padding: 0 2px; }
.rp-clear:hover, .rp-clear:focus-visible { color: var(--text); }
.rp-stats { margin-bottom: 14px; }
.rp-card { margin-bottom: 14px; padding: 16px; min-width: 0; }
.rp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.rp-grid .rp-card { margin-bottom: 14px; }
.rp-chart { position: relative; height: 220px; }
.rp-chart-tall { height: 280px; }
.rp-table-wrap { overflow-x: auto; }
.rp-table { width: 100%; font-size: 12px; }
.rp-table .rp-num { text-align: right; white-space: nowrap; }
.rp-table tbody tr.rp-static { cursor: default; }
.rp-table tbody tr[data-filter]:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.rp-facts { display: grid; grid-template-columns: auto auto; gap: 6px 16px; font-size: 12px; margin: 0; }
.rp-facts dt { color: var(--text3); }
.rp-facts dd { margin: 0; color: var(--text); text-align: right; white-space: nowrap; }
.rp-empty { padding: 28px 16px; text-align: center; color: var(--text3); font-size: 13px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 14px; }
.rp-empty-small { padding: 12px; border: none; background: none; margin: 0; }
.rp-note { font-size: 11px; color: var(--text3); line-height: 1.5; margin: 4px 0 24px; max-width: 900px; }
.rp-warn { color: var(--amber); }
#rp-body[aria-busy="true"] { opacity: 0.6; transition: opacity 0.15s; }
