/* ==========================================================================
   PapersVal — Contract Review Workspace
   Design tokens + layout + components
   ========================================================================== */

:root {
  /* Neutrals — warm cream paper */
  --paper:        #FFFDF8;
  --paper-doc:   #FFFFFE;
  --base:        #F5F2EA;   /* app background */
  --base-2:      #EFEBE0;
  --panel:       #FBF8F1;
  --border:      #E0DBCC;
  --border-soft: #ECE7D8;
  --border-strong: #C9C2AE;

  /* Ink */
  --ink:         #1A1916;
  --ink-2:       #3A3833;
  --ink-soft:    #5D5A52;
  --ink-muted:   #8A867B;
  --ink-faint:   #B5B1A3;

  /* Accent — deep ink-navy. One accent only. */
  --accent:      #1F2A3A;
  --accent-2:    #2B3A4E;
  --accent-soft: #E6E9EF;

  /* Severity / Status (color + always paired with shape/label) */
  --high:        #A0381A;   /* terracotta */
  --high-bg:     #F5E2D9;
  --high-edge:   #D9A892;
  --med:         #8B6515;   /* mustard */
  --med-bg:      #F4E9CE;
  --med-edge:    #D9C28A;
  --low:         #5A5A55;
  --low-bg:      #ECE9DE;
  --match:       #2E5A37;
  --match-bg:    #DCE6D9;
  --match-edge:  #9CBA9F;
  --extra:       #2E5A8C;   /* light blue — new clauses outside playbook */
  --extra-bg:    #DEE5F0;
  --extra-edge:  #9BB0CC;
  --nf:          #B8651B;   /* warm amber — not found */
  --nf-bg:       #FAEEDA;
  --nf-edge:     #E8C99A;

  /* Evidence highlight colors */
  --hi-selected: #FFE8A8;   /* selected source range */
  --hi-related:  #FFF3CC;
  --hi-conflict: #F5D7C7;

  /* Shape */
  --radius:      4px;
  --radius-2:    8px;
  --radius-3:    12px;
  --shadow-1:    0 1px 0 rgba(20,18,14,0.04), 0 1px 2px rgba(20,18,14,0.04);
  --shadow-2:    0 2px 8px rgba(20,18,14,0.06), 0 1px 2px rgba(20,18,14,0.04);
  --shadow-pop:  0 12px 32px rgba(20,18,14,0.14), 0 2px 6px rgba(20,18,14,0.08);

  /* Fonts */
  --ui:   "Geist", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --serif:"Source Serif 4", Georgia, "Times New Roman", serif;
  --mono: "Geist Mono", ui-monospace, "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--ui);
  font-feature-settings: "ss01" on, "cv11" on;
  background: var(--base);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#root { height: 100vh; overflow-x: auto; overflow-y: hidden; }
body { overflow: hidden; }

/* ==========================================================================
   App shell
   ========================================================================== */
.app {
  /* Flex column (not a positional grid): optional in-flow strips — backend-error bar, one-time
     disclaimer bar — can sit between the topbar and the main shell without stealing the 1fr row
     or pushing the main shell below the fold. */
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 1360px;
  background: var(--base);
}
.app-main {
  display: grid;
  grid-template-columns: 300px minmax(520px, 1fr) 550px;
  min-height: 0;
  flex: 1 1 0;
  overflow: hidden;
}
.app-main.sidebar-hidden { grid-template-columns: minmax(520px, 1fr) 550px; }
.app-main.compact { grid-template-columns: 60px minmax(520px, 1fr) 550px; }

.app.no-sidebar { min-width: 1120px; }
.app.onboarding-mode {
  min-width: 1120px;
}

/* ==========================================================================
   Onboarding
   ========================================================================== */
.onboarding-shell {
  min-height: 0;
  flex: 1 1 0;
  overflow-y: auto;
  background:
    linear-gradient(180deg, var(--paper) 0%, var(--base) 100%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px 18px 20px;
}
.onboarding-modal {
  width: min(1080px, 100%);
  background: var(--paper-doc);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-2);
  padding: 18px;
}
.onboarding-modal.stage-type { width: min(820px, 100%); }
/* Step 2 runs full-screen — the centered modal card cramped the contract text
   (owner 2026-06-04). The shell stretches its child; the card fills it. */
.onboarding-shell.fullbleed {
  padding: 10px 12px 12px;
  align-items: stretch;
}
.onboarding-modal.stage-checklist {
  display: flex;
  flex-direction: column;
  width: 100%;
  flex: 1;
  height: auto;
  min-height: 0;
  padding: 14px;
}
.onboarding-modal-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.onboarding-modal-head h1 {
  margin: 4px 0 0;
  max-width: 720px;
  font-size: 23px;
  line-height: 1.16;
  letter-spacing: 0;
}
.onboarding-modal-head p {
  margin: 6px 0 0;
  max-width: 660px;
  color: var(--ink-soft);
  font-size: 13px;
}
.eyebrow,
.step-kicker {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}
.template-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-top: 18px;
}
.template-pick-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 16px;
  min-height: 112px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.template-pick-card:hover {
  border-color: var(--accent);
  background: var(--panel);
}
/* "Upload your own template" entry on the onboarding type screen — dashed to read as an add action. */
.template-pick-card.template-pick-upload {
  border-style: dashed;
  border-color: var(--accent);
  background: var(--panel);
}
.template-pick-card.template-pick-upload:hover {
  background: var(--paper);
}
/* Step-1 standard picker: clicking a contract-type card opens this small modal offering the type's
   ready standards or "upload your own" (owner-specified onboarding flow). */
.standard-picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(28, 25, 23, 0.32);
}
.standard-picker {
  width: min(560px, 100%);
  max-height: min(620px, 90vh);
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  background: var(--paper);
  box-shadow: 0 18px 48px rgba(28, 25, 23, 0.22);
}
.standard-picker-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.standard-picker-head h3 {
  margin: 4px 0 0;
  font-size: 17px;
  line-height: 1.2;
}
.standard-picker-head p {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 12.5px;
}
.standard-picker-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
}
.standard-option-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.standard-option-row:hover {
  border-color: var(--accent);
  background: var(--panel);
}
.standard-option-row.standard-option-upload {
  border-style: dashed;
  border-color: var(--accent);
  background: var(--panel);
}
.standard-option-row.standard-option-upload:hover { background: var(--paper); }
.standard-option-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.standard-option-body b { font-size: 13.5px; }
.standard-option-body small { color: var(--ink-muted); font-size: 12px; }
.standard-option-cta {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  white-space: nowrap;
}

/* Template-file dropzone inside the compile drawer (Word/PDF upload, or fall back to paste). */
.compile-drop {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius-2);
  background: var(--panel);
  color: var(--ink-muted);
  font-size: 13px;
  cursor: pointer;
}
.compile-drop:hover { background: var(--paper); }
.drawer.compile-modal.drag-active .compile-drop {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
}
.compile-drop svg { width: 16px; height: 16px; flex: none; }
.compile-drop .compile-drop-on { color: var(--ink); font-weight: 600; }
.compile-processing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 8px;
}
.compile-processing-title {
  font-size: 13px;
  color: var(--ink-muted);
}
.compile-progress {
  width: min(420px, 100%);
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--panel);
}
.compile-progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.35s ease;
}
.compile-progress-meta {
  width: min(420px, 100%);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--ink-soft);
}
.linklike {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}
.doc-icon {
  width: 38px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: grid;
  place-items: center;
  background: var(--paper-doc);
  color: var(--accent);
  box-shadow: var(--shadow-1);
}
.doc-icon.large {
  width: 46px;
  height: 58px;
  margin-bottom: 10px;
}
.template-pick-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.template-pick-name {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.template-pick-type,
.template-pick-meta {
  font-size: 12px;
  color: var(--ink-muted);
}
.template-choice-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.template-choice {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 62px;
  padding: 11px 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}
.template-choice:hover,
.template-choice.active {
  border-color: var(--accent);
  background: var(--paper-doc);
}
.template-choice-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.template-choice-name {
  font-size: 13px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.template-choice-type {
  font-size: 12px;
  color: var(--ink-muted);
}
.template-choice-count {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-soft);
}
.selected-template-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-top: 10px;
}
.selected-template-head h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}
.selected-template-head p {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  max-width: 560px;
}
.property-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0;
}
.property-summary div {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--panel);
}
.property-summary b {
  display: block;
  font-family: var(--mono);
  font-size: 18px;
  line-height: 1.1;
}
.property-summary span {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--ink-muted);
}
.property-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.property-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 10px;
  min-height: 58px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--paper);
}
.property-row span:nth-child(2) {
  font-weight: 600;
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.property-row small {
  grid-column: 2;
  color: var(--ink-muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.property-sev {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--med);
  grid-row: span 2;
}
.property-sev.high { background: var(--high); }
.property-sev.low { background: var(--low); }
.checklist-browser,
.onboarding-modal.stage-checklist .checklist-browser {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}
.standard-summary {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  border: 1px solid var(--border-soft);
  background: var(--paper);
  border-radius: var(--radius-2);
  padding: 12px 14px;
}
/* Merged step-2 header: step + standard + counters + Change type/Continue in ONE row. */
.standard-summary.merged {
  align-items: center;
  padding: 10px 14px;
}
.standard-summary.merged .standard-summary-id { flex: 1 1 auto; min-width: 0; }
.standard-summary.merged h2 { font-size: 17px; margin-top: 2px; }
.standard-summary.merged p {
  margin-top: 2px;
  font-size: 12.5px;
  max-width: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.standard-summary.merged .property-summary.compact { min-width: 0; flex: 0 0 auto; }
.standard-summary-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
  align-items: center;
}
.standard-summary h2 {
  margin: 4px 0 0;
  font-size: 19px;
  letter-spacing: 0;
}
.standard-summary p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  max-width: 560px;
}
.property-summary.compact {
  margin: 0;
  min-width: 330px;
}
.property-summary.compact div {
  padding: 8px 10px;
}
.chapter-review-grid {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 14px;
  margin-top: 12px;
  min-height: 0;
  flex: 1;
}
/* Step-2 doc-left review: the template's contract text left, chapter blocks + checks right.
   Clicking a chapter highlights its section in the text (owner feedback 2026-06-04). */
.doc-review-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(380px, 0.95fr);
  gap: 14px;
  margin-top: 12px;
  min-height: 0;
  flex: 1;
}
/* Full-screen step 2: template text | chapters | active chapter's checks — three
   full-height columns so clauses and chapters get real room (owner 2026-06-04). */
.doc-review-grid.three-col {
  grid-template-columns: minmax(0, 1.1fr) minmax(230px, 280px) minmax(340px, 0.9fr);
  gap: 12px;
}
.doc-review-grid.three-col .chapter-list,
.doc-review-grid.three-col .chapter-checks {
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}
.template-doc-pane {
  min-width: 0;
  overflow-y: auto;
  padding: 18px 22px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  background: var(--paper-doc, var(--paper));
}
.template-doc-pane .doc-section {
  padding: 8px 12px;
  margin: 0 -12px;
  border-left: 3px solid transparent;
  border-radius: var(--radius);
}
.template-doc-pane .doc-section.active {
  background: var(--accent-soft, rgba(193, 100, 28, 0.1));
  border-left-color: var(--accent);
}
.template-doc-pane h4 {
  margin: 10px 0 6px;
  font-size: 13.5px;
  letter-spacing: 0;
}
.template-doc-pane p {
  margin: 0 0 8px;
  white-space: pre-wrap;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-2, var(--ink));
}
.doc-review-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  min-width: 0;
}
.doc-review-side .chapter-list {
  flex: 0 0 auto;
  max-height: 38%;
  overflow-y: auto;
}
.doc-review-side .chapter-checks {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.chapter-list,
.chapter-checks {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  background: var(--paper);
  min-width: 0;
}
.chapter-list {
  padding: 8px;
  max-height: none;
  overflow-y: auto;
}
.chapter-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius);
  padding: 8px 9px;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}
.chapter-row:hover,
.chapter-row.active {
  border-color: var(--border);
  background: var(--paper-doc);
}
.chapter-row b {
  display: block;
  font-size: 13px;
}
.chapter-row small,
.chapter-risk {
  color: var(--ink-muted);
  font-size: 11.5px;
}
.chapter-risk {
  flex-shrink: 0;
  font-family: var(--mono);
}
.chapter-checks {
  padding: 14px 16px;
  max-height: none;
  overflow-y: auto;
}
.chapter-checks-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}
.chapter-checks-head h3 {
  margin: 4px 0 0;
  font-size: 18px;
  letter-spacing: 0;
}
.chapter-checks-head > span {
  font-family: var(--mono);
  color: var(--ink-muted);
  font-size: 11px;
}
.check-row-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}
.empty-checklist-state {
  margin-top: 12px;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink-soft);
}
.empty-checklist-state b {
  display: block;
  color: var(--ink);
  font-size: 13px;
}
.empty-checklist-state p {
  margin: 5px 0 0;
  font-size: 12.5px;
}
.checklist-check-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) minmax(112px, auto);
  gap: 12px;
  align-items: start;
  padding: 12px 14px 12px 10px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--paper-doc);
}
.checklist-check-row + .checklist-check-row {
  margin-top: 2px;
}
.checklist-check-copy {
  min-width: 0;
}
.checklist-check-main {
  margin: 0;
  color: var(--ink-2);
  font-size: 14.5px;
  line-height: 1.55;
}
.checklist-check-meta {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
}
.checklist-check-editor {
  width: 100%;
  min-height: 92px;
  font-size: 14px;
  line-height: 1.45;
}
.checklist-check-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.checklist-check-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.checklist-check-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.checklist-check-title b {
  display: block;
  font-size: 13px;
  min-width: 0;
}
.checklist-check-title span {
  color: var(--ink-muted);
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 10.5px;
}
.checklist-check-row p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.45;
}
.checklist-check-row p.checklist-check-main {
  margin: 0;
  color: var(--ink-2);
  font-size: 14.5px;
  line-height: 1.55;
}
.checklist-check-wording span {
  display: block;
  margin-bottom: 2px;
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
}
.checklist-check-severity {
  justify-self: end;
  min-width: 0;
  padding: 2px 8px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--panel);
  font-family: var(--mono);
  color: var(--ink-muted);
  font-size: 10.5px;
  line-height: 1.6;
  text-transform: uppercase;
}
.separate-workflow-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 13px;
}
.onboarding-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}
.onboarding-actions.full {
  grid-column: 1 / -1;
  margin-top: 0;
}
/* Step 3 "All done": readable at a glance — your template left, ONE action block right
   (Upload your draft + "or use a sample" beneath). Owner feedback 2026-06-04. */
.analyze-final-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(320px, 1.2fr);
  gap: 16px;
  padding-top: 16px;
}
.analyze-template-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  background: var(--paper);
}
.analyze-template-card h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.18;
  letter-spacing: 0;
}
.analyze-template-card .property-summary.compact {
  min-width: 0;
  width: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.analyze-action-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 24px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  background: var(--paper);
  text-align: center;
}
.analyze-action-card h3 {
  margin: 4px 0 0;
  font-size: 19px;
}
.analyze-action-card p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 12.5px;
}
.analyze-action-card .btn-lg {
  margin-top: 10px;
  height: 42px;
  padding: 0 22px;
  font-size: 14.5px;
  font-weight: 600;
}
.analyze-sample-link {
  margin-top: 2px;
  color: var(--ink-soft);
}
/* "Use a sample" — a real button in its own green tone next to the primary upload. */
.analyze-sample-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}
.analyze-sample-or {
  font-size: 12px;
  color: var(--ink-muted);
}
.btn.btn-sample {
  background: var(--match-bg);
  border-color: var(--match-edge);
  color: var(--match);
  font-weight: 600;
}
.btn.btn-sample:hover:not(:disabled) {
  background: color-mix(in srgb, var(--match-bg) 75%, var(--match-edge));
  border-color: var(--match);
}

/* ==========================================================================
   Lease Abstract
   ========================================================================== */
.app.lease-mode {
  min-width: 0;
}
.lease-abstract-workspace {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
  background: var(--base);
}
.lease-abstract-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  background: var(--paper-doc);
  box-shadow: var(--shadow-1);
}
.lease-abstract-head h1 {
  margin: 4px 0 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}
.lease-abstract-head p {
  margin: 6px 0 0;
  max-width: 760px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.45;
}
.lease-abstract-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.lease-abstract-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.lease-abstract-summary div {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--paper-doc);
  padding: 10px 12px;
}
.lease-abstract-summary b {
  display: block;
  font-family: var(--mono);
  font-size: 20px;
  line-height: 1.1;
}
.lease-abstract-summary span {
  display: block;
  margin-top: 4px;
  color: var(--ink-muted);
  font-size: 11.5px;
}
.lease-error {
  border: 1px solid var(--high-edge);
  border-left: 4px solid var(--high);
  border-radius: var(--radius);
  background: var(--high-bg);
  color: var(--high);
  padding: 10px 12px;
  font-size: 13px;
}
.lease-abstract-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(380px, 1fr) minmax(300px, 0.72fr);
  gap: 14px;
  min-height: 0;
}
.lease-source-panel,
.lease-fields-panel,
.lease-inspector-panel {
  min-height: 0;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  background: var(--paper-doc);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.lease-source-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.lease-fields-panel {
  overflow-y: auto;
  padding-bottom: 12px;
}
.lease-inspector-panel {
  overflow-y: auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.lease-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--paper);
}
.lease-panel-head h2 {
  margin: 4px 0 0;
  font-size: 18px;
  letter-spacing: 0;
}
.lease-panel-head > span {
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 11px;
}
.lease-source-document {
  overflow-y: auto;
  padding: 34px 48px;
  background: var(--paper-doc);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.72;
  color: var(--ink);
}
.lease-source-document p {
  margin: 0 0 16px;
}
.lease-source-highlight {
  background: var(--hi-selected);
  box-shadow: 0 0 0 2px var(--hi-selected);
}
.lease-paste-box {
  border-top: 1px solid var(--border-soft);
  padding: 12px 14px;
  background: var(--panel);
}
.lease-paste-box textarea {
  max-height: 160px;
  overflow-y: auto !important;
}
.lease-field-group {
  padding: 14px 16px 0;
}
.lease-loading-state {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 10px;
  align-items: center;
  margin: 16px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink-soft);
}
.lease-loading-state b {
  color: var(--ink);
  font-size: 13px;
}
.lease-loading-state p {
  grid-column: 2;
  margin: 0;
  font-size: 12.5px;
}
.lease-field-group-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
}
.lease-field-group-title h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}
.lease-field-group-title span {
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 11px;
}
.lease-field-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
  padding: 11px 12px;
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.lease-field-row:hover,
.lease-field-row.selected {
  border-color: var(--accent);
  border-left-color: var(--accent);
  background: var(--paper-doc);
  box-shadow: var(--shadow-1);
}
.lease-field-row.status-found,
.lease-field-row.status-computed {
  border-left-color: var(--match);
}
.lease-field-row.status-needs_review {
  border-left-color: var(--med);
}
.lease-field-row.status-not_found {
  border-left-color: var(--nf);
}
.lease-field-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.lease-field-title {
  font-size: 13px;
  font-weight: 650;
}
.lease-field-value {
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.35;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  white-space: normal;
}
.lease-field-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}
.lease-field-meta span {
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 2px 7px;
}
.lease-source-card {
  margin: 16px;
  padding: 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  background: var(--panel);
}
.lease-inspector-panel .lease-source-card {
  margin: 16px;
}
.lease-source-card h3 {
  margin: 4px 0 0;
  font-size: 15px;
  letter-spacing: 0;
}
.lease-source-card p {
  margin: 6px 0 10px;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.45;
}
.lease-quote-box {
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--med);
  border-radius: var(--radius);
  background: var(--paper-doc);
  padding: 10px 12px;
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 13.5px;
  line-height: 1.5;
}
.lease-source-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 11px;
}

@media (max-width: 1180px) {
  .lease-abstract-workspace {
    height: auto;
    min-height: calc(100vh - 56px);
    overflow: auto;
  }
  .lease-abstract-head {
    flex-direction: column;
  }
  .lease-abstract-grid {
    grid-template-columns: 1fr;
  }
  .lease-source-panel,
  .lease-fields-panel,
  .lease-inspector-panel {
    min-height: 420px;
  }
}

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  height: 56px;
  flex-shrink: 0; /* .app is a flex column; never let strips squeeze the topbar */
  white-space: nowrap;
}
.topbar > * { flex-shrink: 0; }
.topbar-doc { flex-shrink: 1; min-width: 0; }
.topbar-disclaimer {
  flex-shrink: 1;
  min-width: 0;
  max-width: 340px;
  margin: 0 auto; /* centered in the free middle of the bar (owner feedback 2026-06-04) */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-soft);
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: default;
}
/* "⋯" overflow menu — secondary workspaces (Commercial Lease Abstract). */
.topbar-more { position: relative; }
.topbar-more-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 130;
  min-width: 280px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  background: var(--paper);
  box-shadow: 0 10px 28px rgba(28, 25, 23, 0.18);
}
.topbar-more-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: var(--radius-1, 6px);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.topbar-more-item:hover { background: var(--panel); }
.topbar-more-item b { font-size: 12.5px; }
.topbar-more-item small { color: var(--ink-muted); font-size: 11.5px; white-space: normal; }
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 12px;
  border-right: 1px solid var(--border);
  height: 32px;
}
.brand-mark {
  width: 22px; height: 22px;
  background: var(--accent);
  color: var(--paper);
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.brand-name {
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 14px;
}
.topbar-doc {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}
.topbar-doc-title {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.005em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 380px;
}
.topbar-doc-meta {
  font-size: 12px;
  color: var(--ink-muted);
  font-family: var(--mono);
}
.topbar-doc-meta b { color: var(--ink-soft); font-weight: 500; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 4px;
}

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--paper-doc);
  border-radius: var(--radius);
  color: var(--ink-soft);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s;
}
.icon-btn:hover { border-color: var(--border-strong); background: var(--panel); }

.template-cluster {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--paper-doc);
  overflow: hidden;
  height: 32px;
}
.template-cluster .template-pill {
  border: none;
  background: transparent;
  padding: 0 6px 0 10px;
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
}
.template-cluster .template-pill:hover { background: var(--panel); }
.template-cluster .template-pill .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--match);
}
.template-cluster .template-pill .label {
  font-family: var(--mono); color: var(--ink-muted); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.template-cluster .template-pill .name { font-weight: 500; }
.template-cluster .template-pill .caret { color: var(--ink-faint); font-size: 10px; }

.template-reanalyze {
  width: 32px;
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
}
.template-reanalyze:hover { background: var(--panel); }

.btn-newcontract {
  padding: 0 12px;
  font-weight: 500;
}

.playbook-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 8px;
  border: 1px solid var(--border);
  background: var(--paper-doc);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color 0.15s;
}
.playbook-pill:hover { border-color: var(--border-strong); }
.playbook-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--match); }
.playbook-pill .label { font-family: var(--mono); color: var(--ink-muted); font-size: 11px; }
.playbook-pill .name { font-weight: 500; }
.playbook-pill .caret { color: var(--ink-faint); font-size: 10px; margin-left: 2px; }

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: var(--paper-doc);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-soft);
  font-family: var(--mono);
}
.status-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--match); }
.status-chip.high .dot { background: var(--high); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--paper-doc);
  color: var(--ink-2);
  font-weight: 500;
  height: 32px;
  transition: border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--border-strong); background: var(--panel); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #FBFAF6;
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}
.btn-ghost:hover { background: var(--panel); border-color: var(--border-soft); }
.btn-sm { height: 28px; font-size: 12px; padding: 4px 8px; }
.btn-icon { padding: 0 8px; }

/* Account control (Clerk login) — only rendered when login is configured */
.auth-signin, .auth-user { display: inline-flex; align-items: center; gap: 6px; }
.auth-user-label {
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px;
}
.auth-menu { position: relative; }
.auth-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  min-width: 200px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}
.auth-dropdown-email {
  padding: 6px 8px; font-size: 11px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-bottom: 1px solid var(--border-soft);
}
.auth-dropdown-item {
  display: block; width: 100%; text-align: left; margin-top: 4px; padding: 7px 8px;
  background: transparent; border: none; border-radius: 7px; cursor: pointer;
  font-size: 13px; color: var(--ink);
}
.auth-dropdown-item:hover { background: var(--bg-soft, rgba(0,0,0,0.04)); }

/* ==========================================================================
   Left sidebar
   ========================================================================== */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.sidebar-section { padding: 12px 12px; }
.sidebar-section + .sidebar-section { border-top: 1px solid var(--border-soft); }

.sidebar-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 8px 4px;
}

.playbook-card {
  background: var(--paper-doc);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.playbook-card-row {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}
.playbook-card-row .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--match); }
.playbook-card-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.005em;
  color: var(--ink);
}
.playbook-card-meta {
  font-size: 12px;
  color: var(--ink-soft);
}
.playbook-card-actions {
  display: flex; gap: 6px;
  margin-top: 6px;
}

.cta-new {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: var(--accent);
  color: var(--paper);
  border: none;
  border-radius: var(--radius-2);
  font-weight: 500;
  font-size: 13.5px;
  text-align: left;
}
.cta-new:hover { background: var(--accent-2); }
.cta-new .plus {
  width: 18px; height: 18px;
  border-radius: 4px;
  background: rgba(255,255,255,0.12);
  display: grid; place-items: center;
  font-weight: 600;
}

.history-search {
  position: relative;
  margin-bottom: 8px;
}
.history-search input {
  width: 100%;
  height: 30px;
  padding: 0 10px 0 28px;
  border: 1px solid var(--border);
  background: var(--paper-doc);
  border-radius: var(--radius);
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
}
.history-search input:focus { outline: none; border-color: var(--ink-muted); }
.history-search .glass {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  color: var(--ink-muted);
}

.history-section { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 16px; }
.history-day-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 12px 4px 6px;
}
.history-item {
  padding: 9px 10px;
  border-radius: var(--radius-2);
  cursor: pointer;
  border: 1px solid transparent;
}
.history-item:hover { background: var(--paper-doc); }
.history-item.active {
  background: var(--paper-doc);
  border-color: var(--border);
  box-shadow: var(--shadow-1);
}
.history-item-line1 {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
  color: var(--ink);
  min-width: 0;
}
.history-item-line1 .history-item-name {
  font-weight: 500;
  flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history-item-ratio {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.history-item-ratio.failed { color: var(--high); }
.history-item-line2 {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  margin-top: 2px;
  margin-left: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  letter-spacing: 0.02em;
}
.history-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-soft);
  flex-wrap: wrap;
}
.history-item-meta .when {
  margin-left: auto;
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 10.5px;
}
.history-item-meta-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.history-item-meta-line .when {
  margin-left: auto;
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 10.5px;
}
.history-item-meta-line .status-text { color: var(--ink-soft); }
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--match);
  flex-shrink: 0;
}
.status-dot.has-high { background: var(--high); }
.status-dot.has-missing { background: var(--paper-doc); border: 1.2px dashed var(--high); width: 8px; height: 8px; }
.status-dot.comparing { background: var(--med); }
.status-dot.failed { background: var(--high); }
.mini-stat {
  display: inline-flex; align-items: center; gap: 3px;
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 5px 1px 4px;
  border-radius: 3px;
  background: var(--base-2);
  color: var(--ink-soft);
  line-height: 1.4;
}
.mini-stat .glyph { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); }
.mini-stat.high .glyph { background: var(--high); }
.mini-stat.med .glyph { background: var(--med); }
.mini-stat.missing .glyph { background: var(--paper-doc); border: 1px dashed var(--high); }
.mini-stat.processing {
  font-family: var(--mono); color: var(--med); background: var(--med-bg);
}
.mini-stat.failed {
  color: var(--high); background: var(--high-bg);
}

/* ==========================================================================
   Main contract viewer
   ========================================================================== */
.viewer {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--base);
}
.viewer-toolbar {
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.viewer-search {
  position: relative;
  width: 260px;
}
.viewer-search input {
  width: 100%; height: 28px; padding: 0 10px 0 28px;
  border: 1px solid var(--border);
  background: var(--paper-doc);
  border-radius: var(--radius);
  font: inherit; font-size: 12.5px;
}
.viewer-search .glass {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  color: var(--ink-muted);
}
.viewer-toolbar-sep { width: 1px; height: 18px; background: var(--border); }
.viewer-toolbar .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.viewer-toolbar-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-muted);
}
.nav-arrow {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink-soft);
}
.nav-arrow:hover { background: var(--panel); }

/* View mode toggle in viewer toolbar */
.view-toggle {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px;
  margin-right: 4px;
}
.view-toggle button {
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 500;
  background: transparent;
  border: none;
  color: var(--ink-soft);
  border-radius: 3px;
  cursor: pointer;
  letter-spacing: 0.01em;
}
.view-toggle button:hover { color: var(--ink); }
.view-toggle button.on {
  background: var(--accent);
  color: #FBFAF6;
  box-shadow: var(--shadow-1);
}

/* Filter dim state */
.mark.dimmed {
  background: transparent;
  border-bottom-color: var(--border-soft);
  color: var(--ink-faint);
  opacity: 0.5;
}
.mark.dimmed:hover { opacity: 0.7; }

.missing-anchor.dimmed,
.inserted-clause.dimmed {
  opacity: 0.3;
  filter: saturate(0.5);
}
.missing-anchor.dimmed:hover,
.inserted-clause.dimmed:hover { opacity: 0.6; }

/* When filter active, contract text not in marks softens; highlighted marks pop more */
.viewer.filter-active .contract { color: var(--ink-soft); }
.viewer.filter-active .mark:not(.dimmed) {
  /* Active marks become more prominent against the softened body */
}
.viewer.filter-active .mark.conflict:not(.dimmed) {
  background: var(--hi-conflict);
  box-shadow: 0 0 0 2px var(--hi-conflict);
}
.viewer.filter-active .mark.extra:not(.dimmed) {
  background: var(--extra-bg);
  box-shadow: 0 0 0 2px var(--extra-bg);
}
.viewer.filter-active .mark:not(.conflict):not(.extra):not(.dimmed) {
  background: var(--hi-selected);
  box-shadow: 0 0 0 2px var(--hi-selected);
}
.viewer.filter-active .missing-anchor:not(.dimmed) {
  box-shadow: 0 0 0 3px var(--nf-bg);
}
/* Final view: inserted clauses look like normal sections */
.inserted-clause.final {
  margin: 20px 0;
  background: transparent;
  border: none;
  border-left: none;
  padding: 0;
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink);
}
.inserted-clause.final::before { display: none; }
.inserted-clause.final .ins-body { font-style: normal; }

.viewer-body {
  flex: 1;
  overflow-y: auto;
  padding: 32px 0 80px;
  scroll-behavior: smooth;
}
.contract {
  max-width: 720px;
  margin: 0 auto;
  background: var(--paper-doc);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  padding: 56px 64px 72px;
  box-shadow: var(--shadow-1);
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink);
}
.contract-header {
  text-align: center;
  margin-bottom: 36px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-soft);
}
.contract-header h1 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}
.contract-header .parties {
  font-size: 13.5px;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-style: italic;
}
.contract-header .meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 12px;
}
.section {
  margin-bottom: 24px;
  scroll-margin-top: 90px;
}
.section-title {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: 0;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.section-num {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 12px;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
  flex-shrink: 0;
  width: 28px;
}
.section p {
  margin: 0 0 10px;
  text-align: justify;
  hyphens: auto;
  text-wrap: pretty;
}

/* Word-style margin gutter: document text stays clean, findings live as numbered
   dots in the right margin (legal2 design). Every paragraph row reserves the same
   gutter width so the text measure never shifts. */
.doc-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.doc-row-body {
  flex: 1;
  min-width: 0;
}
.doc-gutter {
  width: 26px;
  flex: 0 0 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 2px;
}
.doc-dot {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 99px;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  line-height: 1;
  color: #FBFAF6;
  opacity: 0.92;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
}
.doc-dot:hover { transform: scale(1.25); opacity: 1; }
.doc-dot svg { width: 9px; height: 9px; }
.doc-dot.selected {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--paper-doc), 0 0 0 4px var(--accent);
}
.doc-dot.match-dot {
  width: 10px;
  height: 10px;
  margin-top: 2px;
  opacity: 0.75;
}
.doc-dot.match-dot.selected { opacity: 1; }
.doc-dot.dimmed { opacity: 0.25; }

/* Evidence marks */
.mark {
  background: var(--hi-related);
  border-bottom: 1.5px solid var(--med-edge);
  padding: 1px 0;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.mark:hover { background: var(--hi-selected); }
.mark.selected {
  background: var(--hi-selected);
  border-bottom-color: var(--med);
  box-shadow: 0 0 0 2px var(--hi-selected);
}
.mark.good { background: var(--match-bg); border-bottom-color: var(--match-edge); }
.mark.good:hover { background: var(--match-bg); }
.mark.good.selected {
  background: var(--match-bg);
  border-bottom-color: var(--match);
  box-shadow: 0 0 0 2px var(--match-bg);
}
.mark.conflict { background: var(--hi-conflict); border-bottom-color: var(--high-edge); }
.mark.conflict.selected {
  background: var(--hi-conflict);
  border-bottom-color: var(--high);
  box-shadow: 0 0 0 2px var(--hi-conflict);
}
.mark.extra {
  background: var(--extra-bg);
  border-bottom-color: var(--extra-edge);
}
.mark.extra.selected {
  border-bottom-color: var(--extra);
  box-shadow: 0 0 0 2px var(--extra-bg);
}
.mark.accepted {
  background: transparent;
  border-bottom: 1px dashed var(--match-edge);
  opacity: 0.7;
}
.mark.noted {
  background: var(--med-bg);
  border-bottom-color: var(--med-edge);
  opacity: 0.85;
}

/* Replace diff display */
.mark.replaced {
  background: transparent;
  border-bottom: none;
}
.mark.replaced .rm {
  text-decoration: line-through;
  text-decoration-color: var(--high);
  text-decoration-thickness: 1.5px;
  color: var(--ink-muted);
  background: var(--high-bg);
  padding: 0 1px;
}
.mark.replaced .ins {
  background: var(--match-bg);
  border-bottom: 1.5px solid var(--match);
  padding: 1px 2px;
  margin-left: 4px;
  color: var(--ink);
}

/* Inserted clause block (for missing clauses that were resolved by inserting) */
.inserted-clause {
  margin: 20px 0 20px 16px;
  background: var(--paper-doc);
  border: 1px solid var(--match-edge);
  border-left: 4px solid var(--match);
  border-radius: var(--radius-2);
  padding: 14px 18px;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  cursor: pointer;
  scroll-margin-top: 90px;
  position: relative;
}
.inserted-clause::before {
  content: "+";
  position: absolute;
  left: -14px;
  top: 13px;
  width: 22px; height: 22px;
  background: var(--match);
  color: #FBFAF6;
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 0 0 2px var(--paper-doc);
}
.inserted-clause.selected { box-shadow: 0 0 0 3px var(--match-bg); }
.inserted-clause .label {
  font-family: var(--ui);
  display: flex; align-items: center; gap: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--match);
  margin-bottom: 6px;
  font-weight: 600;
}
.inserted-clause .ins-body { color: var(--ink); }

/* Missing-anchor accepted state */
.missing-anchor.accepted {
  background: var(--match-bg);
  border-color: var(--match-edge);
}
.missing-anchor.accepted .icon {
  border: 1.5px solid var(--match);
  border-style: solid;
  color: var(--match);
}
.missing-anchor.accepted .label { color: var(--match); }

.evidence-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 0;
  padding: 3px 8px 3px 6px;
  background: var(--paper-doc);
  border: 1px solid var(--border);
  border-left: 3px solid var(--med);
  border-radius: 3px;
  font-family: var(--ui);
  font-size: 11.5px;
  color: var(--ink-soft);
  font-feature-settings: normal;
}
.evidence-label.high { border-left-color: var(--high); }
.evidence-label .sev {
  font-family: var(--mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--high); font-weight: 600;
}
.evidence-label .sev.med { color: var(--med); }
.evidence-label b { font-weight: 600; color: var(--ink); }

/* Missing clause sentinel placed where it would have been */
.missing-group {
  margin: 28px 0 8px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
}
.missing-group-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.missing-group-head h3 {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: 0;
}
.missing-group-head > span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-muted);
}
.missing-anchor {
  margin: 20px 0;
  border: 1px solid var(--nf-edge);
  background: linear-gradient(135deg, #FCF6E8 0%, #F9ECD0 100%);
  border-radius: var(--radius-2);
  padding: 14px 18px;
  font-family: var(--ui);
  font-size: 12.5px;
  color: var(--ink-2);
  display: flex; gap: 12px; align-items: flex-start;
  scroll-margin-top: 90px;
  cursor: pointer;
}
.missing-anchor.selected { box-shadow: 0 0 0 3px var(--nf-bg); }
.missing-anchor .icon {
  width: 22px; height: 22px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--paper-doc);
  border: 1.5px dashed var(--nf);
  display: grid; place-items: center;
  color: var(--nf);
  font-weight: 700;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1;
}
.missing-anchor .body { flex: 1; min-width: 0; }
.missing-anchor .label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--nf);
  margin-bottom: 2px;
  font-weight: 600;
}
.missing-anchor .title { font-weight: 600; color: var(--ink); }
.missing-anchor .desc { color: var(--ink-soft); margin-top: 2px; }

/* ==========================================================================
   Right review panel
   ========================================================================== */
.review {
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
}

.review-summary {
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--paper);
}
.review-summary-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.review-summary-eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.review-summary-verdict {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 4px;
}
.verdict-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--high); flex-shrink: 0; }
.review-summary-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 14px;
}
.review-summary-sub b { color: var(--ink); font-weight: 600; }

.risk-bar {
  display: flex;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--base-2);
  margin-bottom: 10px;
}
.risk-bar > div { transition: width 0.3s; }

.risk-counts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.risk-count {
  background: var(--paper-doc);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 8px 10px;
  display: flex; flex-direction: column; gap: 1px;
}
.risk-count .num {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-family: var(--ui);
}
.risk-count .lbl {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}
.risk-count.high .num { color: var(--high); }
.risk-count.med .num { color: var(--med); }
.risk-count.miss .num { color: var(--high); }
.risk-count.match .num { color: var(--match); }

/* Counter-as-filter buttons */
.filter-counters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 4px;
}
.fc {
  background: var(--paper-doc);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 9px 10px 8px;
  display: flex; flex-direction: column; gap: 2px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
  position: relative;
}
.fc:hover { border-color: var(--border-strong); }
.fc::before {
  content: '';
  position: absolute;
  left: 8px; top: 8px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
}
.fc-num {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-left: 14px;
  line-height: 1.1;
}
.fc-lbl {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}
.fc.high::before  { background: var(--high); }
.fc.med::before   { background: var(--med); }
.fc.miss::before  { background: var(--nf); border: 1.5px dashed var(--nf); background: transparent; width: 8px; height: 8px; left: 7px; top: 7px; }
.fc.extra::before { background: var(--extra); }
.fc.high .fc-num  { color: var(--high); }
.fc.med .fc-num   { color: var(--med); }
.fc.miss .fc-num  { color: var(--nf); }
.fc.extra .fc-num { color: var(--extra); }
.fc.on.high  { background: var(--high-bg);  border-color: var(--high-edge); }
.fc.on.med   { background: var(--med-bg);   border-color: var(--med-edge); }
.fc.on.miss  { background: var(--nf-bg);    border-color: var(--nf-edge); }
.fc.on.extra { background: var(--extra-bg); border-color: var(--extra-edge); }
.fc.on { box-shadow: var(--shadow-1); }
.fc.on .fc-lbl { color: var(--ink-2); }

.filter-meta {
  display: flex; align-items: baseline; justify-content: flex-start; gap: 8px;
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 10px;
}
.filter-meta b { color: var(--ink); font-weight: 500; }
.link-btn {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.link-btn:hover { text-decoration: underline; }

/* Resolution row */
.res-row {
  display: inline-flex;
  background: var(--base-2);
  border-radius: 6px;
  padding: 2px;
  gap: 0;
}
.res {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-radius: 4px;
  display: inline-flex; gap: 6px; align-items: center;
  cursor: pointer;
}
.res:hover { color: var(--ink); }
.res.on {
  background: var(--paper-doc);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}
.res-count {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-muted);
}
.res.on .res-count { color: var(--ink-soft); }
.res-dot {
  width: 7px; height: 7px; border-radius: 50%;
}
.res-dot.unresolved { background: var(--high); }
.res-dot.resolved { background: var(--match); }

/* Resolution badges on finding cards */
.resolution-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  margin-left: auto;
  padding: 2px 7px;
  border-radius: 3px;
}
.resolution-tag.accepted { background: var(--match-bg); color: var(--match); }
.resolution-tag.replaced { background: var(--accent-soft); color: var(--accent); }
.resolution-tag.noted    { background: var(--med-bg); color: var(--med); }

.finding-card.resolved { opacity: 0.78; }
.finding-card.resolved:hover { opacity: 1; }

.review-filters {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--panel);
}
.filter-segments {
  display: flex;
  background: var(--paper-doc);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 10px;
  position: relative;
}
.seg {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: flex-start; justify-content: center;
  gap: 1px;
  padding: 6px 10px 7px;
  border: none;
  background: transparent;
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.seg-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: -0.005em;
}
.seg-count {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.seg:hover .seg-label { color: var(--ink); }
.seg.active {
  background: var(--accent);
  box-shadow: var(--shadow-1);
}
.seg.active .seg-label { color: #FBFAF6; font-weight: 600; }
.seg.active .seg-count { color: rgba(255,255,255,0.7); }

.filter-note {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-muted);
  margin: -2px 4px 10px;
  padding-left: 8px;
  border-left: 2px solid var(--border);
}

/* old .tab-row removed */

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  font-size: 11.5px;
  border: 1px solid var(--border);
  background: var(--paper-doc);
  border-radius: 999px;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--ui);
}
.chip:hover { border-color: var(--border-strong); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #FBFAF6;
}
.chip .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-muted);
}
.chip.active .dot { background: #FBFAF6; }
.chip.high .dot { background: var(--high); }
.chip.med .dot { background: var(--med); }
.chip.miss .dot { background: var(--paper-doc); border: 1.5px dashed var(--high); width: 8px; height: 8px; }

.review-list {
  flex: none;
  min-height: 0;
  padding: 8px 12px 24px;
}

.finding-card {
  background: var(--paper-doc);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}
.finding-card:hover { border-color: var(--border-strong); }
.finding-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-1);
}
.finding-card.selected::before {
  content: '';
  position: absolute;
  left: -1px; top: 14px; bottom: 14px;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
}

.finding-meta {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
  text-transform: uppercase;
}
.finding-title {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--ink);
  margin: 0 0 4px;
}
.finding-summary {
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.45;
  margin: 0 0 8px;
}
.finding-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--ink-muted);
  font-family: var(--mono);
}
.finding-footer .ref { color: var(--ink-soft); font-weight: 500; }
.finding-footer .open-link {
  margin-left: auto;
  color: var(--ink-soft);
  text-decoration: none;
  font-family: var(--ui);
  font-size: 12px;
}
.finding-footer .open-link:hover { color: var(--accent); }

/* Severity / status pills */
.sev-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  line-height: 1.6;
}
.sev-pill.high { background: var(--high-bg); color: var(--high); }
.sev-pill.med  { background: var(--med-bg); color: var(--med); }
.sev-pill.low  { background: var(--low-bg); color: var(--low); }
.sev-pill.info { background: var(--extra-bg); color: var(--extra); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px 1px 6px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 500;
  line-height: 1.6;
  background: var(--paper);
  border: 1px solid var(--border);
  color: var(--ink-soft);
}
.status-pill .glyph {
  width: 8px; height: 8px;
  display: inline-block;
}
.status-pill.dnm .glyph { background: var(--high); border-radius: 50%; }
.status-pill.dnm { color: var(--high); }
.status-pill.partial .glyph {
  background: linear-gradient(to right, var(--med) 0 50%, transparent 50% 100%);
  border: 1.2px solid var(--med);
  border-radius: 50%;
}
.status-pill.partial { color: var(--med); }
.status-pill.not_found .glyph {
  border: 1.5px dashed var(--nf);
  background: transparent;
  border-radius: 50%;
}
.status-pill.not_found { color: var(--nf); }
.status-pill.match .glyph {
  background: var(--match); border-radius: 50%;
}
.status-pill.match { color: var(--match); }
.status-pill.extra .glyph {
  background: var(--extra); border-radius: 50%;
}
.status-pill.extra { color: var(--extra); }
.status-pill.needs_review .glyph {
  background: var(--med);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.status-pill.needs_review { color: var(--med); }

/* ==========================================================================
   Finding detail (overlays right panel as a slide-in)
   ========================================================================== */
.detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
}
/* Back to findings — tinted accent strip, the one obvious exit from case mode
   (owner 2026-06-05: "сейчас не очень понятно, как убрать этот режим"). */
.detail-back {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 18px;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  background: var(--accent-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--accent);
  cursor: pointer;
  border-top: none; border-right: none; border-left: none;
  width: 100%; text-align: left;
  transition: background 0.14s;
}
.detail-back:hover { background: color-mix(in srgb, var(--accent) 16%, var(--paper)); }

.detail-head {
  padding: 16px 20px 14px;
  background: var(--paper);
  border-bottom: 1px solid var(--border-soft);
}
.detail-pills {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-bottom: 8px;
}
.detail-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}
.detail-section-ref {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  display: flex; align-items: center; gap: 8px;
}
.detail-section-ref a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}
.detail-section-ref a:hover { text-decoration: underline; }

.detail-body {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 18px 22px 24px;
}
.detail-block + .detail-block { margin-top: 18px; }
.detail-block-label {
  font-family: var(--ui);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-soft);
  margin: 0 0 6px;
  font-weight: 600;
}
.detail-block p { margin: 0 0 0; font-size: 13.5px; line-height: 1.55; color: var(--ink-2); }

.quote {
  background: var(--paper-doc);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--med);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--serif);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-2);
  font-style: italic;
}
.quote.high { border-left-color: var(--high); }
/* Severity-framed quote: a thin border all the way around in the finding's color
   (owner: "не только слева — обвести вокруг, линии тоньше"). */
.quote.sev-high   { border: 1.5px solid var(--high-edge); }
.quote.sev-medium { border: 1.5px solid var(--med-edge); }
.quote.sev-low    { border: 1.5px solid var(--border-strong); }

/* "What's wrong here" — the problem statement opens the case (owner 2026-06-04:
   "почему здесь ошибка — первым делом"). Thin full severity border, soft tint. */
.problem-banner {
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
}
.problem-banner.sev-high   { border-color: var(--high-edge); background: color-mix(in srgb, var(--high-bg) 55%, var(--paper)); }
.problem-banner.sev-medium { border-color: var(--med-edge);  background: color-mix(in srgb, var(--med-bg) 55%, var(--paper)); }
.problem-banner ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); }
.problem-banner li { margin: 2px 0; }
.viewer-toolbar-meta .filter-note { color: var(--ink-muted); }
.detail-section-ref .section-issue-ref { color: var(--ink-muted); }
.detail-action-hint {
  padding: 0 18px 14px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-muted);
}
/* Floating "Next issue" stepper in the viewer's empty right margin. */
.float-next {
  position: sticky;
  top: calc(100% - 56px);
  float: right;
  margin-right: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 99px;
  background: var(--paper);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-2);
  z-index: 5;
  transition: background 0.14s, border-color 0.14s;
}
.float-next:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.float-next:disabled { opacity: 0.4; cursor: default; }
.float-next svg { width: 13px; height: 13px; }
.viewer-toolbar-meta .match-meta-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 99px;
  background: var(--match);
  margin-right: 6px;
  vertical-align: 1px;
}

.suggested-wrap {
  border: 1px solid var(--border);
  background: var(--paper-doc);
  border-radius: var(--radius-2);
  overflow: hidden;
}
.suggested-toolbar {
  display: flex; align-items: center;
  padding: 6px 6px 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--ui);
  font-size: 11.5px;
  color: var(--ink-muted);
  letter-spacing: 0;
  text-transform: none;
}
.suggested-toolbar .copy-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center; gap: 6px;
  padding: 4px 9px;
  font-family: var(--ui);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  background: var(--paper-doc);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--ink-2);
  cursor: pointer;
}
.suggested-toolbar .copy-btn:hover { border-color: var(--border-strong); background: var(--panel); }
.suggested-toolbar .copy-btn.copied { background: var(--match-bg); border-color: var(--match-edge); color: var(--match); }
.suggested-text {
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.55;
  padding: 12px 14px;
  color: var(--ink);
  text-wrap: pretty;
  background: var(--paper-doc);
  border: none;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--paper);
  border-top: 1px solid var(--border-soft);
}
.detail-actions .btn { height: 32px; }
.action-replace { flex: 1; justify-content: center; }
.action-replace .btn-primary { font-weight: 500; }

.resolution-banner {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: var(--radius);
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}
.resolution-banner.accepted { background: var(--match-bg); color: var(--match); }
.resolution-banner.replaced { background: var(--accent-soft); color: var(--accent); }
.resolution-banner.noted    { background: var(--med-bg); color: var(--med); }

.quote.extra { border-left-color: var(--extra); }

.candidates {
  margin-top: 10px;
  background: var(--paper-doc);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.candidates-row {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.candidate-chip {
  padding: 3px 8px;
  border-radius: 3px;
  background: var(--base-2);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-soft);
  cursor: pointer;
}
.candidate-chip:hover { background: var(--accent-soft); color: var(--accent); }

.boundary {
  margin-top: 22px;
  border-top: 1px solid var(--border-soft);
  padding-top: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.boundary-group {
  background: var(--paper-doc);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.boundary-group .lbl {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
  font-weight: 600;
}
.boundary-group.scope-contract .lbl { color: var(--accent); }
.boundary-group.scope-playbook .lbl { color: var(--high); }
.boundary-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.boundary-actions .btn { background: var(--panel); }

/* ==========================================================================
   Drawer (Upload / Playbook editor) — generic overlay
   ========================================================================== */
.scrim {
  position: fixed; inset: 0;
  background: rgba(20,18,14,0.4);
  backdrop-filter: blur(2px);
  z-index: 90;
  animation: fadein 0.18s ease-out;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 520px;
  background: var(--paper);
  z-index: 100;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-pop);
  animation: slidein 0.22s ease-out;
}
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.drawer.wide { width: 720px; }
.drawer.compile-modal {
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  width: min(720px, calc(100vw - 32px));
  max-height: min(820px, calc(100vh - 32px));
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  overflow: hidden;
  transform: translate(-50%, -50%);
  animation: popin 0.18s ease-out;
}
.drawer.compile-modal.drag-active {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
@keyframes popin { from { transform: translate(-50%, -48%); opacity: 0; } to { transform: translate(-50%, -50%); opacity: 1; } }
.drawer-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 10px;
}
.drawer-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.drawer-head .close {
  margin-left: auto;
  background: transparent; border: none;
  color: var(--ink-muted); cursor: pointer;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 4px;
}
.drawer-head .close:hover { background: var(--panel); color: var(--ink); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border-soft);
  display: flex; gap: 8px; justify-content: flex-end;
}

.form-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 6px;
  font-weight: 600;
}
.form-group + .form-group { margin-top: 18px; }

.dropzone {
  border: 1.5px dashed var(--border-strong);
  background: var(--panel);
  border-radius: var(--radius-2);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
}
.dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-size: 14px; font-weight: 500; color: var(--ink); }
.dropzone .small { font-size: 12px; color: var(--ink-muted); font-family: var(--mono); margin-top: 4px; }

.input {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--paper-doc);
  border-radius: var(--radius);
  font: inherit; font-size: 13px;
  color: var(--ink);
}
.input:focus { outline: none; border-color: var(--ink-muted); }
textarea.input { font-family: var(--serif); font-size: 13.5px; line-height: 1.5; min-height: 100px; resize: vertical; }

.format-row {
  display: flex; flex-wrap: wrap; gap: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  letter-spacing: 0.03em;
  margin-top: 10px;
}
.format-tag {
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--paper-doc);
  border: 1px solid var(--border-soft);
}
.format-tag.no { color: var(--high); border-color: var(--high-edge); background: var(--high-bg); text-decoration: line-through; opacity: 0.85; }

/* ==========================================================================
   Export drawer
   ========================================================================== */
.export-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.export-options { padding-right: 4px; }
.export-preview {
  border-left: 1px solid var(--border-soft);
  padding-left: 20px;
}
.export-preview-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 8px;
  font-weight: 600;
}
.export-page {
  background: var(--paper-doc);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 22px 24px;
  font-family: var(--serif);
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-2);
  min-height: 480px;
  box-shadow: var(--shadow-1);
  position: relative;
}
.ep-corner {
  position: absolute; top: 8px; right: 12px;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--ink-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.ep-title {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.005em;
}
.ep-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-muted);
}
.ep-rule { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.ep-section { margin-bottom: 14px; }
.ep-h {
  font-family: var(--ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  margin-bottom: 4px;
  text-transform: uppercase;
}
.ep-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px;
  color: var(--ink-2);
  margin-bottom: 2px;
}
.ep-bullet {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}
.ep-quote {
  font-size: 11px;
  line-height: 1.5;
  background: var(--panel);
  padding: 8px 10px;
  border-left: 2px solid var(--border-strong);
  border-radius: 2px;
  margin: 4px 0;
}
.ep-quote.ep-muted { color: var(--ink-muted); font-style: italic; }
.ep-small {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}
.ep-code {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--panel);
  padding: 8px;
  border-radius: 2px;
  white-space: pre-wrap;
  margin: 0;
}

.seg-toggle {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}
.seg-toggle button {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.seg-toggle button:hover { color: var(--ink); }
.seg-toggle button.on {
  background: var(--paper-doc);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

.form-hint {
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-top: 6px;
  line-height: 1.45;
}

.check-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
}
.check-row input { margin: 0; }
.check-row .muted { color: var(--ink-muted); font-family: var(--mono); font-size: 11px; margin-left: 4px; }

/* ==========================================================================
   Inline annotation (Word-style comment under paragraph)
   ========================================================================== */
.annotation {
  position: relative;
  margin: 4px 0 18px;
  border: 1px solid var(--border);
  background: var(--paper-doc);
  border-radius: var(--radius-2);
  padding: 12px 16px 14px;
  font-family: var(--ui);
  box-shadow: var(--shadow-1);
  scroll-margin-top: 90px;
}
.annotation.sev-high   { border-left: 4px solid var(--high); padding-left: 14px; }
.annotation.sev-medium { border-left: 4px solid var(--med);  padding-left: 14px; }
.annotation.sev-low    { border-left: 4px solid var(--low);  padding-left: 14px; }
.annotation.sev-info   { border-left: 4px solid var(--extra); padding-left: 14px; }
.annotation.applied { opacity: 0.85; }

.annotation-head {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 4px;
}
.annotation-close {
  margin-left: auto;
  background: transparent; border: none;
  color: var(--ink-muted);
  width: 22px; height: 22px;
  border-radius: 3px;
  display: grid; place-items: center;
  cursor: pointer;
}
.annotation-close:hover { background: var(--panel); color: var(--ink); }

.annotation-title {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--ink);
  margin: 2px 0 4px;
  text-wrap: pretty;
}
.annotation-summary {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
  margin-bottom: 10px;
}

.annotation-banner {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}
.annotation-banner.accepted { background: var(--match-bg); color: var(--match); }
.annotation-banner.noted    { background: var(--med-bg); color: var(--med); }
.annotation-banner.match-ok { background: var(--match-bg); color: var(--match); }

/* Right-panel banner for match findings: the green in-text highlight is the evidence,
   the panel only confirms there is nothing to act on. */
.match-ok-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--match-edge);
  border-radius: var(--radius);
  background: var(--match-bg);
  color: var(--match);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
}

.annotation-suggestion-label {
  font-family: var(--ui);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 6px 0 4px;
  display: flex; align-items: center; gap: 6px;
}
.copy-btn-tiny {
  margin-left: auto;
  width: 22px; height: 22px;
  border: 1px solid var(--border);
  background: var(--paper-doc);
  border-radius: 3px;
  display: grid; place-items: center;
  color: var(--ink-soft);
  cursor: pointer;
}
.copy-btn-tiny.copied { background: var(--match-bg); color: var(--match); border-color: var(--match-edge); }

.annotation-suggestion {
  width: 100%;
  font-family: var(--serif);
  font-size: 13.5px;
  line-height: 1.55;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  color: var(--ink);
  outline: none;
  box-sizing: border-box;
}
.annotation-suggestion:focus { border-color: var(--ink-muted); background: var(--paper-doc); }

.annotation-actions {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 10px;
}

/* Applied-suggestion — the added wording rendered as PART of the document flow:
   same serif, same measure, green-highlighted like a track-changes insertion.
   No card chrome — the lawyer reads an up-to-date draft, not a widget. */
.applied-suggestion {
  margin: 2px 0 16px;
  cursor: pointer;
}
.applied-head {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--match);
  margin-bottom: 3px;
}
.applied-head .link-btn { text-transform: none; letter-spacing: 0; font-family: var(--ui); }
.applied-body {
  margin: 0;
  color: var(--ink);
  text-wrap: pretty;
  /* inherits the contract's serif/size from .contract p context */
}

/* The inserted wording itself, highlighted green so "what was added" is unmistakable.
   Used for applied suggestions and inserted missing clauses. Overrides the browser's
   default yellow <mark> styling. */
.added-text {
  background: var(--match-bg);
  color: var(--ink);
  box-shadow: inset 0 -1.5px 0 var(--match);
  border-radius: 3px;
  padding: 1px 3px;
  font-style: normal;
}

/* Original clause a requested change is attached to — in Review mode it reads as
   track changes: the old wording struck through, the requested wording rendered as
   green inserted text right below (owner: "когда меняем текст — показать, что он
   был заменён"). Final view still renders the original untouched. */
.mark.applied {
  background: transparent;
  border-bottom: none;
  text-decoration: line-through;
  text-decoration-color: var(--high);
  text-decoration-thickness: 1.5px;
  color: var(--ink-muted);
}
.mark.applied.selected {
  background: var(--match-bg);
}
.tmpl-context {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  margin-bottom: 18px;
}
.tmpl-section-label {
  display: flex; align-items: baseline; gap: 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 4px 10px;
}
.tmpl-section-label > :first-child { color: var(--ink-soft); }
.tmpl-section-label > :last-child { margin-left: auto; }

.tmpl-list { display: flex; flex-direction: column; gap: 10px; }
.tmpl-card {
  background: var(--paper-doc);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  padding: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tmpl-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-1);
}
.tmpl-card-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.tmpl-radio {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  display: grid; place-items: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.tmpl-radio.on { border-color: var(--accent); }
.tmpl-radio .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.tmpl-card-name {
  font-weight: 600; font-size: 14.5px;
  letter-spacing: -0.005em;
  display: flex; align-items: center; gap: 8px;
}
.tmpl-active-tag {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px;
  background: var(--accent);
  color: #FBFAF6;
  border-radius: 3px;
  font-weight: 500;
}
.tmpl-card-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: 2px;
}
.tmpl-tags { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 10px 24px; }
.tmpl-tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 3px;
  text-transform: uppercase;
}

.tmpl-result {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-soft);
}
.tmpl-result-summary {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 8px;
}
.tmpl-result-summary.muted { color: var(--ink-muted); font-weight: 400; }
.result-dot { width: 8px; height: 8px; border-radius: 50%; }
.tmpl-result-stats {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 400;
  margin-left: 4px;
}
.tmpl-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tmpl-actions-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-soft);
}
.tmpl-currently {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.tmpl-running {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink-soft);
  padding: 6px 0;
}
.spin {
  width: 12px; height: 12px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 200;
  box-shadow: var(--shadow-pop);
  animation: toastup 0.2s ease-out;
}
@keyframes toastup { from { transform: translate(-50%, 10px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ==========================================================================
   Tweaks panel residue (kept in case)
   ========================================================================== */
.ext-meta { font-family: var(--mono); font-size: 11px; color: var(--ink-muted); }

/* ==========================================================================
   Template Compile Review (Stage-0 onboarding redesign — "Template Review")
   Warm paper + ink, one accent. Coverage model: covered / attention / missing.
   ========================================================================== */
.drawer.compile-modal.tcr-wide { width: min(1000px, calc(100vw - 32px)); }

.tcr-head-titles { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.tcr-head-sub { font-size: 12px; color: var(--ink-muted); }

.tcr { display: flex; flex-direction: column; gap: 14px; }

/* summary strip */
.tcr-summary { background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius-2); padding: 12px 14px; }
.tcr-summary-line { font-size: 13px; line-height: 1.5; color: var(--ink-soft); }
.tcr-summary-line strong { color: var(--ink); font-weight: 650; }
.tcr-summary-stats { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 9px; }
.tcr-stat { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.tcr-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); display: inline-block; flex: none; }
.tcr-stat.match .tcr-dot { background: var(--match); }
.tcr-stat.med .tcr-dot { background: var(--med); }
.tcr-stat.high .tcr-dot { background: var(--high); }

/* one control: coverage tabs */
.tcr-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tcr-tabs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tcr-tab { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px;
  font-family: var(--ui); font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  background: var(--paper); border: 1px solid var(--border); cursor: pointer;
  transition: background .14s, border-color .14s, color .14s; }
.tcr-tab:hover { border-color: var(--border-strong); }
.tcr-tab-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.tcr-tab.med .tcr-tab-dot { background: var(--med); }
.tcr-tab.high .tcr-tab-dot { background: var(--high); }
.tcr-tab.match .tcr-tab-dot { background: var(--match); }
.tcr-tab-count { font-family: var(--mono); font-size: 11px; opacity: .85; }
.tcr-tab.active { color: #fff; border-color: transparent; }
.tcr-tab.all.active { background: var(--accent); }
.tcr-tab.med.active { background: var(--med); }
.tcr-tab.high.active { background: var(--high); }
.tcr-tab.match.active { background: var(--match); }
.tcr-tab.active .tcr-tab-dot { background: rgba(255,255,255,.85); }
.tcr-tab.active .tcr-tab-count { opacity: .9; }
.tcr-acceptall { margin-left: auto; }

/* list + cards */
.tcr-list { display: flex; flex-direction: column; gap: 10px; }
.tcr-empty { text-align: center; color: var(--ink-muted); font-size: 13px; padding: 30px 0; }

.tcr-card { border: 1px solid var(--border-soft); border-left: 3px solid var(--border); border-radius: var(--radius-2);
  background: var(--paper); padding: 14px 16px; }
.tcr-card.covered { border-left-color: var(--match-edge); }
.tcr-card.attention { border-left-color: var(--med-edge); }
.tcr-card.missing { border-left-color: var(--high-edge); }
.tcr-card-head { display: flex; align-items: center; gap: 9px; }
.tcr-card-title { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: -0.005em; flex: 1; min-width: 0; }
.tcr-gap-glyph { width: 22px; height: 22px; flex: none; display: grid; place-items: center; border-radius: 50%;
  background: var(--high-bg); color: var(--high); }

.tcr-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.tcr-chip .tcr-dot { width: 6px; height: 6px; }
.tcr-chip.match { color: var(--match); background: var(--match-bg); }
.tcr-chip.match .tcr-dot { background: var(--match); }
.tcr-chip.med { color: var(--med); background: var(--med-bg); }
.tcr-chip.med .tcr-dot { background: var(--med); }
.tcr-chip.high { color: var(--high); background: var(--high-bg); }
.tcr-chip.high .tcr-dot { background: var(--high); }
.tcr-chip.low { color: var(--ink-soft); background: var(--low-bg); }
.tcr-chip.low .tcr-dot { background: var(--ink-muted); }

.tcr-card-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.tcr-readiness { font-size: 10.5px; font-weight: 650; padding: 2px 7px; border-radius: 999px; }
.tcr-area { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.03em; color: var(--ink-muted); text-transform: uppercase; }

.tcr-standard { margin: 10px 0 0; font-size: 12.5px; line-height: 1.55; color: var(--ink-muted); }
.tcr-standard span { font-weight: 600; color: var(--ink-soft); }
.tcr-gap-reason { color: var(--ink-soft); }

.tcr-reason { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; font-size: 12.5px; line-height: 1.5; color: var(--ink); }
.tcr-reason-glyph { flex: none; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center;
  background: var(--med-bg); color: var(--med); font-weight: 800; font-size: 11px; margin-top: 1px; }
.tcr-covered { display: flex; align-items: center; gap: 7px; margin-top: 10px; font-size: 12.5px; font-weight: 600; color: var(--match); }

.tcr-checks { margin-top: 11px; }
.tcr-checks-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-muted); margin-bottom: 5px; }
.tcr-checks ul { margin: 0; padding-left: 16px; display: flex; flex-direction: column; gap: 3px; }
.tcr-checks li { font-size: 12.5px; line-height: 1.45; color: var(--ink-soft); }
.tcr-crit { color: var(--high); font-weight: 650; }

.tcr-source { margin-top: 11px; }
.tcr-source-toggle { display: inline-flex; align-items: center; gap: 5px; background: none; border: none; padding: 0;
  color: var(--ink-muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.tcr-source-toggle:hover { color: var(--ink-soft); }
.tcr-caret { display: inline-flex; transition: transform .15s; }
.tcr-caret.open { transform: rotate(180deg); }
.tcr-source-body { margin-top: 7px; border: 1px solid var(--border-soft); background: var(--panel);
  border-radius: var(--radius); padding: 9px 11px; }
.tcr-source-meta { font-family: var(--mono); font-size: 10px; color: var(--ink-muted); margin-bottom: 4px; }
.tcr-source-body p { margin: 0; font-family: var(--serif); font-size: 13px; line-height: 1.6; color: var(--ink-2); }

.tcr-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 12px; padding-top: 11px;
  border-top: 1px solid var(--border-soft); flex-wrap: wrap; }
.tcr-actions .btn.is-active { box-shadow: 0 0 0 2px var(--accent-soft); }

.tcr-error-inline { border: 1px solid var(--high-edge); background: var(--high-bg); color: var(--high);
  border-radius: var(--radius); padding: 9px 11px; font-size: 12.5px; }

/* footer */
.tcr-foot-summary { flex: 1; min-width: 0; font-size: 12.5px; line-height: 1.45; }
.tcr-foot-spacer { flex: 1; }
.tcr-foot-actions { display: flex; gap: 8px; }
.tcr-foot-ok { display: inline-flex; align-items: center; gap: 6px; color: var(--match); font-weight: 600; }
.tcr-foot-wait { color: var(--ink-soft); }
.tcr-foot-wait strong { color: var(--ink); font-weight: 700; }

/* loading steps */
.tcr-steps { list-style: none; margin: 20px 0 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.tcr-step { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink); }
.tcr-step.todo { color: var(--ink-faint); }
.tcr-step-mark { width: 18px; height: 18px; flex: none; display: grid; place-items: center; border-radius: 50%; color: #fff; }
.tcr-step.done .tcr-step-mark { background: var(--match); }
.tcr-step.active .tcr-step-mark { border: 1.5px solid var(--accent); }
.tcr-step.todo .tcr-step-mark { border: 1.5px solid var(--border-strong); }
.tcr-step.active span:last-child { font-weight: 600; }
.tcr-step-pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: tcrpulse 1s ease-in-out infinite; }
@keyframes tcrpulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.55); opacity: .5; } }
.tcr-loading-note { font-size: 12.5px; color: var(--ink-muted); margin: 20px 0 0; text-align: center; }

/* error state */
.tcr-errorstate { padding: 14px 4px; }
.tcr-errorstate-row { display: flex; gap: 12px; }
.tcr-errorstate-glyph { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--high-bg); color: var(--high); font-weight: 800; font-size: 16px; }
.tcr-errorstate-msg { margin: 4px 0 0; font-size: 13.5px; line-height: 1.5; color: var(--ink); }
.tcr-techtoggle { margin-top: 12px; display: inline-flex; align-items: center; gap: 5px; background: none; border: none;
  padding: 0; color: var(--ink-muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.tcr-techtoggle:hover { color: var(--ink-soft); }
.tcr-techdetail { margin: 8px 0 0; padding: 9px 11px; background: var(--panel); border: 1px solid var(--border-soft);
  border-radius: var(--radius); font-family: var(--mono); font-size: 11.5px; color: var(--ink-soft);
  white-space: pre-wrap; word-break: break-word; }

/* responsive: cramped widths / mobile full-screen dialog */
@media (max-width: 720px) {
  .tcr-actions { justify-content: stretch; }
  .tcr-actions .btn { flex: 1; }
  .tcr-foot-summary { flex-basis: 100%; order: 2; margin-top: 6px; }
}

/* ─────────────────────────────────────────────────────────────────────────
   Lazy "suggested wording" block — shared by the criterion + gap cards (workspace right pane).
   ───────────────────────────────────────────────────────────────────────── */
.trw-suggest { margin-top: 11px; padding-top: 11px; border-top: 1px dashed var(--border-soft); }
.trw-suggest-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.trw-suggest-title { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); }
.trw-suggest-title svg { width: 13px; height: 13px; }
.trw-copy { display: inline-flex; align-items: center; gap: 4px; background: none; border: none; padding: 0; cursor: pointer;
  font-size: 11.5px; color: var(--accent); }
.trw-copy svg { width: 13px; height: 13px; }
.trw-suggest-cta { margin-top: 8px; }
.trw-suggest-loading { margin-top: 9px; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-soft); }
.trw-suggest-error { margin-top: 9px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12px;
  color: var(--high); }
.trw-suggest-body { margin-top: 9px; }
.trw-suggest-issue { display: flex; gap: 7px; align-items: flex-start; font-size: 12.5px; line-height: 1.5; color: var(--ink); }
.trw-suggest-glyph { flex: none; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center;
  background: var(--med-bg); color: var(--med); font-size: 11px; font-weight: 700; }
.trw-suggest-text { margin: 8px 0 0; padding: 11px 13px; border: 1px solid var(--border-soft); border-left: 3px solid var(--extra);
  background: var(--paper-doc); border-radius: var(--radius-2); font-family: var(--serif); font-size: 13.5px; line-height: 1.62;
  color: var(--ink-2); white-space: pre-wrap; }
.trw-suggest-note { margin: 7px 0 0; font-size: 11px; color: var(--ink-faint); }

/* ─────────────────────────────────────────────────────────────────────────
   Full-page Template Review workspace — document on the left, cases on the right.
   ───────────────────────────────────────────────────────────────────────── */
.trw-overlay { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
  background: var(--base, var(--paper)); }
.trw-top { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--border-soft); background: var(--paper); box-shadow: var(--shadow-1); }
.trw-top-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.trw-back { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border: 1px solid var(--border-soft);
  background: var(--panel); border-radius: var(--radius); font-size: 12.5px; color: var(--ink-soft); cursor: pointer; }
.trw-back:hover { background: var(--paper); color: var(--ink); }
.trw-back svg { width: 14px; height: 14px; }
.trw-top-titles { min-width: 0; }
.trw-top-titles h2 { margin: 0; font-size: 15px; font-weight: 650; color: var(--ink); }
.trw-top-sub { margin-top: 2px; font-size: 12px; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trw-top-stats { display: flex; align-items: center; gap: 14px; flex: none; }

.trw-fullmsg { flex: 1; display: grid; place-items: center; padding: 40px; }
.trw-fullmsg .tcr-errorstate { max-width: 520px; }

.trw-main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(380px, 0.95fr); }

/* LEFT — reconstructed template document with coverage highlights */
.trw-doc { min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--border-soft); background: var(--panel); }
.trw-doc-head { flex: none; padding: 11px 18px; border-bottom: 1px solid var(--border-soft); background: var(--paper); }
.trw-doc-title { font-family: var(--mono); font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-muted); }
.trw-doc-missing { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.trw-doc-missing-label { font-size: 11.5px; color: var(--ink-muted); }
.trw-missing-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--high-edge); background: var(--high-bg); color: var(--high); font-size: 11.5px; font-weight: 600; cursor: pointer; }
.trw-missing-chip svg { width: 11px; height: 11px; }
.trw-missing-chip.active { box-shadow: 0 0 0 2px var(--high-edge); }
.trw-doc-scroll { flex: 1; overflow-y: auto; padding: 22px clamp(18px, 4vw, 60px); }
.trw-doc-note { font-size: 12.5px; color: var(--ink-muted); padding: 10px 0; }
.trw-doc-note-err { color: var(--high); }
.trw-line { position: relative; margin: 0; padding: 2px 8px; font-family: var(--serif); font-size: 14px; line-height: 1.72;
  color: var(--ink-2); border-radius: var(--radius); transition: background .12s, opacity .12s; }
.trw-line.hit { cursor: pointer; }
.trw-line.hit.attention { background: var(--med-bg); box-shadow: inset 2px 0 0 var(--med); }
.trw-line.hit.covered { background: var(--match-bg); box-shadow: inset 2px 0 0 var(--match); }
.trw-line.hit:hover { filter: brightness(0.98); }
.trw-line.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.trw-line.dim { opacity: 0.34; }
.trw-line-marker { position: absolute; left: -2px; top: 0; bottom: 0; width: 3px; border-radius: 2px; }

/* RIGHT — coverage tabs + the case list (reused compile cards) */
.trw-side { min-width: 0; display: flex; flex-direction: column; background: var(--paper); }
.trw-side-controls { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 16px; border-bottom: 1px solid var(--border-soft); flex-wrap: wrap; }
.trw-side .tcr-error-inline { margin: 10px 16px 0; }
.trw-side-list { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.trw-card-wrap { border-radius: var(--radius-3); transition: box-shadow .12s; }
.trw-card-wrap.selected { box-shadow: 0 0 0 2px var(--accent); }
.trw-card-wrap.selected .tcr-card { border-color: transparent; }

.trw-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 11px 20px; border-top: 1px solid var(--border-soft); background: var(--paper); }
.trw-foot-status { flex: 1; min-width: 0; font-size: 12.5px; line-height: 1.45; }
.trw-foot-actions { display: flex; gap: 8px; flex: none; }

@media (max-width: 900px) {
  .trw-main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .trw-doc { border-right: none; border-bottom: 1px solid var(--border-soft); }
  .trw-top-stats { display: none; }
}
