/* Documents block (Build C, state/lanes/documents-design.md; components/documents-block.js). Same look as the lead
   panel's AI box: white card, the purple ✦ for AI marks, green primary. Own class prefix `docs-`. */
.lead-docs:empty, .deal-docs:empty { display: none; }
.deal-docs { max-width: 1152px; margin-top: var(--sp-7); }
.deal-docs .docs-block { margin-bottom: 0; }

.docs-block { background: var(--bg-surface); border-radius: var(--r-md); box-shadow: var(--shadow-raised);
  padding: var(--sp-4) var(--sp-5); margin: 0 0 var(--sp-5); font-size: var(--fs-md); color: var(--text); min-width: 0; }
.docs-block.is-quiet { box-shadow: none; border: 1px dashed var(--border); padding: var(--sp-3) var(--sp-4); }
.docs-head { display: flex; align-items: center; gap: var(--sp-3); min-height: 28px; cursor: pointer; }
.docs-block.is-quiet .docs-head { cursor: default; }
.docs-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text); flex: none; }
.docs-meta { font-size: var(--fs-sm); color: var(--text-2); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docs-spacer { flex: 1 1 auto; }
.docs-toggle { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: var(--r-sm); }
.docs-toggle .ic, .docs-toggle .ic svg { width: 16px; height: 16px; }
.docs-toggle .ic { transition: transform 120ms ease; transform: rotate(180deg); }
.docs-block.is-folded .docs-toggle .ic { transform: none; }

.docs-part { padding: var(--sp-4) 0; border-top: 1px solid var(--border); }
.docs-part:last-child { padding-bottom: 0; }
.docs-part-head { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-2); margin-bottom: var(--sp-3); }
.docs-sub { font-size: var(--fs-sm); color: var(--text-2); }

/* B. Fill empty fields */
.docs-fill { padding: var(--sp-4) 0; border-top: 1px solid var(--border); }
.docs-line { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.docs-line[hidden] { display: none; }
.docs-line-text { flex: 1 1 160px; min-width: 0; font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.docs-inline-text { flex: none; font-weight: var(--fw-semibold); }
.docs-why.input { box-sizing: border-box; height: var(--control-h); flex: 1 1 160px; min-width: 0; }
.docs-inline-row .docs-why.input { height: 28px; }
.docs-edit-panel { display: grid; gap: var(--sp-4); padding: var(--sp-4) 0 0 36px; min-width: 0; }
.docs-fill-row { display: grid; grid-template-columns: 160px minmax(0, 1fr) auto; gap: var(--sp-4); align-items: center; }
.docs-fill-label { display: flex; align-items: center; gap: var(--sp-3); color: var(--text); }
.docs-fill-row .input { height: var(--control-h); min-width: 0; }
.docs-src { font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; }
/* The Fill line opens into its fields (fix 2026-10-16): chevron + clickable text, then per row the value, its source
   and a short quote under it, and the row's own Dismiss / Approve. */
.docs-fill-toggle { width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: var(--r-sm); margin-left: calc(-1 * var(--sp-2)); }
.docs-fill-toggle .ic, .docs-fill-toggle .ic svg { width: 14px; height: 14px; }
.docs-fill-toggle .ic { transition: transform 120ms ease; transform: rotate(-90deg); }
.docs-fill.is-open .docs-fill-toggle .ic { transform: none; }
.docs-line-text.is-toggle { cursor: pointer; }
.docs-line-text.is-toggle:hover { text-decoration: underline; text-decoration-color: var(--border); }
.docs-fill-from { grid-column: 2 / -1; display: flex; align-items: baseline; gap: var(--sp-3); min-width: 0;
  margin-top: calc(-1 * var(--sp-3)); font-size: var(--fs-sm); color: var(--text-2); }
.docs-fill-quote { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); font-style: italic; }
.docs-fill-row .ai-acts { flex-wrap: nowrap; }
.docs-why-row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.docs-why-label { font-size: var(--fs-sm); color: var(--text-2); flex: none; min-width: 64px; }
.docs-why-label.is-inline { min-width: 0; }
.docs-edit-foot { display: flex; justify-content: flex-end; gap: var(--sp-3); flex-wrap: wrap; }

/* C. Waiting for */
.docs-wait + .docs-wait { margin-top: var(--sp-3); }
.docs-wait-line { display: flex; align-items: center; gap: var(--sp-3); min-height: 28px; flex-wrap: wrap; }
.docs-wait-line[hidden] { display: none; }
.docs-wait-ic, .docs-wait-ic svg { width: 14px; height: 14px; color: var(--text-muted); flex: none; }
.docs-wait-type { color: var(--text); }
/* A 'Not needed' item stays as one quiet line, with 'Still need it' to put it back. */
.docs-notneeded { margin-top: var(--sp-3); padding-left: 22px; font-size: var(--fs-sm); color: var(--text-muted); }
.docs-still-need.link-btn { font-size: var(--fs-sm); }
/* '+ Add' in the head: quiet, but a real link (the team asked by phone or in their own email). */
.docs-wait-head { display: flex; align-items: center; gap: var(--sp-3); }
.docs-wait-add.link-btn { align-self: center; margin-top: 0; font-size: var(--fs-sm); flex: none; }
.docs-pop-title { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-2); padding: 0 var(--sp-3); }
.docs-none { margin-top: var(--sp-3); font-size: var(--fs-sm); color: var(--text-2); }

/* D. Received */
.docs-doc + .docs-doc { margin-top: var(--sp-5); }
.docs-doc-head { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; min-height: 28px; }
.docs-doc-ic { width: 28px; height: 28px; border-radius: 50%; background: var(--bg-hover); color: var(--text-2);
  display: grid; place-items: center; flex: none; }
.docs-doc-ic .ic, .docs-doc-ic svg { width: 14px; height: 14px; }
.docs-type-chip { display: inline-flex; align-items: center; gap: var(--sp-2); padding: 0; border: 0; background: none;
  font: inherit; font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text); cursor: pointer; }
.docs-type-chip:hover:not(:disabled) { text-decoration: underline; text-underline-offset: 2px; }
.docs-type-chip:disabled { cursor: default; color: var(--text-2); }
.docs-chip-caret, .docs-chip-caret svg { width: 12px; height: 12px; }
.docs-doc-name { min-width: 0; overflow-wrap: anywhere; }
.docs-file { color: var(--link); text-decoration: none; }
.docs-file:hover { text-decoration: underline; }
.docs-facts { padding-left: 36px; margin-top: var(--sp-2); }
.docs-facts[hidden] { display: none; }
.docs-fact { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: var(--sp-5); min-height: 28px;
  align-items: start; padding: var(--sp-2) 0; border-radius: var(--r-sm); }
.docs-fact:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.docs-fact-label { color: var(--text-2); }
.docs-fact-value { color: var(--text); overflow-wrap: anywhere; }
.docs-fact.is-edited .docs-fact-value::after { content: ' ✎'; color: var(--text-muted); font-size: var(--fs-sm); }
.docs-fact.is-clause { grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); }
.docs-clause { background: var(--bg-app); border-radius: var(--r-md); padding: var(--sp-4) var(--sp-5); white-space: pre-wrap;
  overflow-wrap: anywhere; font-size: var(--fs-md); color: var(--text); }
.docs-clause:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.docs-conflict { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-1); font-size: var(--fs-sm);
  color: var(--yellow-text); width: fit-content; }
.docs-warn-ic, .docs-warn-ic svg { width: 14px; height: 14px; color: var(--yellow-icon); flex: none; }
.docs-fact.is-editing { align-items: center; }
/* Edit: every input the same width; Remove / Keep / Restore sit in one fixed-width slot on the right, centred on the
   input; "Use the document's value" goes under the input. */
.docs-fact.is-editing .docs-fact-main { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.docs-fact.is-editing .docs-edit-main { display: grid; grid-template-columns: minmax(0, 1fr) 88px; column-gap: var(--sp-3);
  row-gap: var(--sp-1); align-items: center; }
.docs-fact.is-editing .input { flex: 1 1 auto; min-width: 0; height: var(--control-h); }
/* The label lines up with its input, also when "Use the document's value" sits under it. */
.docs-fact.is-editing:not(.is-clause) > .docs-fact-label { align-self: start; line-height: var(--control-h); }
.docs-fact.is-editing.is-gone > .docs-fact-label { align-self: center; line-height: inherit; }
.docs-edit-main .link-btn { align-self: center; justify-self: start; margin-top: 0; }
.docs-edit-main .docs-use-doc.link-btn { grid-column: 1; grid-row: 2; }
.docs-fact.is-clause.is-editing .docs-edit-main .docs-remove { align-self: start; margin-top: var(--sp-2); }
.docs-fact.is-editing textarea.input { height: auto; min-height: 96px; resize: vertical; }
.docs-fact.is-clause.is-editing .docs-fact-main { align-items: flex-start; }
.docs-fact.is-removed .input { text-decoration: line-through; color: var(--text-muted); }
.docs-remove.link-btn { flex: none; font-size: var(--fs-sm); }
.docs-use-doc.link-btn, .docs-restore.link-btn { flex: none; font-size: var(--fs-sm); white-space: nowrap; }
/* Removed facts in Edit: faint until 'Restore' is picked (it comes back on Save). */
.docs-gone-head { margin-top: var(--sp-4); font-size: var(--fs-sm); color: var(--text-2); }
.docs-fact.is-gone .docs-fact-label, .docs-fact.is-gone .docs-gone-value { color: var(--text-muted); }
.docs-fact.is-gone .docs-gone-value { text-decoration: line-through; }
.docs-gone-value { min-width: 0; }
.docs-type-pop { padding: var(--sp-3); display: grid; gap: var(--sp-4); width: 280px; max-width: calc(100vw - 32px); }
.docs-type-list { display: grid; }
.docs-type-option { display: flex; align-items: center; gap: var(--sp-3); height: 32px; padding: 0 var(--sp-3); border: 0;
  background: none; border-radius: var(--r-sm); font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.docs-type-option:hover, .docs-type-option.is-on { background: var(--bg-hover); }
.docs-type-tick { width: 16px; height: 16px; display: inline-grid; place-items: center; color: var(--green, #2e8748); }
.docs-type-tick .ic, .docs-type-tick svg { width: 14px; height: 14px; }

/* E. Firm value, not found, could not read */
.docs-fv-head { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.docs-fv-head .docs-part-head { margin-bottom: 0; }
.docs-fv-team { font-size: var(--fs-xs); background: var(--bg-hover); border-radius: var(--r-pill); padding: 0 var(--sp-3);
  color: var(--text-2); }
.docs-fv-result { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.docs-fv-missing { font-size: var(--fs-sm); font-weight: normal; color: var(--text-2); }
.docs-fv-tier { display: inline-block; padding: 0 var(--sp-3); border-radius: var(--r-pill); color: #fff; font-size: var(--fs-sm); }
.docs-fv-tier.is-low { background: var(--quality-low); }
.docs-fv-tier.is-medium { background: var(--quality-medium); }
.docs-fv-tier.is-hot { background: var(--quality-hot); }
.docs-fv-inputs { display: flex; flex-wrap: wrap; gap: var(--sp-5); align-items: center; }
.docs-fv-field { display: inline-flex; align-items: center; gap: var(--sp-3); }
.docs-fv-label { font-size: var(--fs-sm); color: var(--text-2); }
.docs-fv-input.input { width: 96px; height: var(--control-h); box-sizing: border-box; }
.docs-fv-note { margin-top: var(--sp-3); font-size: var(--fs-sm); color: var(--text-2); }
.docs-fv-default[hidden] { display: none; }
.docs-fv-foot { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; margin-top: var(--sp-4); }
.docs-fv-state { font-size: var(--fs-sm); color: var(--text-2); }
.docs-note-line { color: var(--text-2); padding: var(--sp-1) 0 var(--sp-1) 36px; }
.docs-problem { color: var(--text-2); padding: var(--sp-1) 0; }
.docs-problem + .docs-problem { margin-top: var(--sp-2); }
.docs-state-line { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; color: var(--text-2); }
.docs-state-line .btn { margin-left: auto; }

/* G. The edited AI draft is older than a document (ai-triage.js, in the Email tab above the body). */
.ai-email-stale { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; margin: var(--sp-3) 0;
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-sm); background: var(--bg-note); color: var(--yellow-text);
  font-size: var(--fs-sm); }
.ai-email-stale .docs-warn-ic { color: var(--yellow-icon); }
.ai-email-stale-text { flex: 1 1 200px; min-width: 0; }

/* Narrow panel: the fact grid and the fill rows stack; nothing scrolls sideways. */
@media (max-width: 720px) {
  .docs-fact, .docs-fill-row { grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); }
  .docs-fill-from { grid-column: auto; margin-top: 0; flex-wrap: wrap; }
  .docs-facts, .docs-edit-panel, .docs-note-line { padding-left: 0; }
}

/* 'Use as deal value' (2026-10-16): one calm row under the firm value's foot. */
.docs-fv-use-row { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; margin-top: var(--sp-4);
  padding-top: var(--sp-3); border-top: 1px dashed var(--border); font-size: var(--fs-sm); }
.docs-fv-deal { color: var(--text); }
.docs-fv-same { color: var(--text-2); }
.docs-fv-same .ic, .docs-fv-same .ic svg, .docs-fv-changed .ic, .docs-fv-changed .ic svg { width: 12px; height: 12px; }
.docs-fv-changed { display: inline-flex; align-items: center; gap: var(--sp-2); color: var(--yellow-text); }

/* Mark as reviewed (2026-10-16): a calm row under each read document; noticeable, never tiny. */
.docs-review-row { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; margin-top: var(--sp-3);
  padding-left: 36px; font-size: var(--fs-sm); }
.docs-review-btn.btn { display: inline-flex; align-items: center; gap: var(--sp-2); }
.docs-review-btn .ic, .docs-review-btn .ic svg, .docs-reviewed .ic, .docs-reviewed .ic svg { width: 14px; height: 14px; }
.docs-reviewed { display: inline-flex; align-items: center; gap: var(--sp-2); color: var(--green); }
.docs-review-row .link-btn { font-size: var(--fs-sm); }
.docs-review-changed { display: inline-flex; align-items: center; gap: var(--sp-2); color: var(--yellow-text); }
.docs-review-changed .ic, .docs-review-changed .ic svg { width: 12px; height: 12px; }
.docs-received-head { display: flex; align-items: center; gap: var(--sp-3); }
@media (max-width: 720px) { .docs-review-row { padding-left: 0; } }
/* A read document the AI flagged ('not signed'): one amber line on the document, by its facts. */
.docs-flag { margin: var(--sp-3) 0 0; padding-left: 36px; }
.docs-flag-head { font-weight: var(--fw-semibold); flex: none; }
@media (max-width: 720px) { .docs-flag { padding-left: 0; } }
/* BUG-163 (7877 run 3): the fill row's sources when they disagree, newest first; the one in the box is marked. */
.docs-fill-opts { grid-column: 2 / -1; display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-1, 4px) var(--sp-2);
  margin-top: calc(-1 * var(--sp-2)); font-size: var(--fs-sm); color: var(--text-2); min-width: 0; }
.docs-fill-opts-label { color: var(--text-muted); }
.docs-fill-opt { background: none; border: 1px solid transparent; border-radius: var(--r-sm, 6px); padding: 1px var(--sp-2);
  color: var(--text-2); font: inherit; cursor: pointer; text-align: left; }
.docs-fill-opt:hover { background: var(--bg-hover); color: var(--text); }
.docs-fill-opt[aria-pressed="true"] { border-color: #ddd5ff; background: #f6f4ff; color: var(--text); }
.docs-fill-opt-value { font-weight: var(--fw-semibold); }
.docs-fill-opt-sep { color: var(--text-muted); }
@media (max-width: 720px) { .docs-fill-opts { grid-column: auto; margin-top: 0; } }
