/* ==========================================================================
   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: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 {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  min-width: 1360px;
  background: var(--base);
}
.app-main {
  display: grid;
  grid-template-columns: 300px minmax(560px, 1fr) 500px;
  min-height: 0;
  height: calc(100vh - 56px);
}
.app-main.sidebar-hidden { grid-template-columns: minmax(560px, 1fr) 500px; }
.app-main.compact { grid-template-columns: 60px minmax(560px, 1fr) 500px; }

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

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  height: 56px;
  white-space: nowrap;
}
.topbar > * { flex-shrink: 0; }
.topbar-doc { flex-shrink: 1; min-width: 0; }
.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; }

/* ==========================================================================
   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;
}

/* 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.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); font-style: italic; }

/* 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-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: 14px;
  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;
  overflow: hidden;
}

.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: 1;
  min-height: 0;
  overflow-y: auto;
  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);
}
.detail-back {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 18px;
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--paper);
  border-bottom: 1px solid var(--border-soft);
  color: var(--ink-soft);
  cursor: pointer;
  border-top: none; border-right: none; border-left: none;
  width: 100%; text-align: left;
}
.detail-back:hover { color: var(--ink); }

.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); }

.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-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-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 inline block (after paragraph in contract) */
.applied-suggestion {
  margin: 6px 0 14px;
  background: var(--paper-doc);
  border: 1px solid var(--match-edge);
  border-left: 4px solid var(--match);
  border-radius: var(--radius-2);
  padding: 12px 16px;
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  cursor: pointer;
  position: relative;
}
.applied-suggestion::before {
  content: "+";
  position: absolute;
  left: -14px;
  top: 11px;
  width: 20px; height: 20px;
  background: var(--match);
  color: #FBFAF6;
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 0 0 2px var(--paper-doc);
}
.applied-head {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--match);
  margin-bottom: 6px;
}
.applied-body {
  color: var(--ink);
  text-wrap: pretty;
  font-style: italic;
}

/* Mark.applied state: strong green highlight on original text */
.mark.applied {
  background: var(--match-bg);
  border-bottom: 1.5px solid var(--match);
}
.mark.applied.selected {
  background: var(--match-bg);
  box-shadow: 0 0 0 2px 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); }
