/* --- Document ------------------------------------------------------------ */

/* A reading surface. Measure sits in the 45–75 character band, the scale is
   modular, and hierarchy comes from weight and colour as much as from size. */
.doc {
  --doc-measure: 68ch;
  max-width: var(--doc-measure);
  font-size: 18px;
  line-height: 1.7;
  color: var(--on-surface);
}

.doc-head { margin-bottom: var(--s8); padding-bottom: var(--s6); border-bottom: 1px solid var(--border); }
.doc-head h1 {
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1.15;
  letter-spacing: -0.025em;
  margin: 0 0 var(--s4);
  max-width: 22ch;
}
.doc-standfirst {
  font-size: 21px; line-height: 1.5; color: var(--on-surface-muted);
  margin: 0 0 var(--s4); max-width: 46ch;
}
.doc-meta {
  font-size: 13px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--on-surface-muted); margin: 0;
}

.doc-body > * { margin: 0 0 var(--s6); }
.doc-body > h2 {
  font-size: 27px; line-height: 1.25; letter-spacing: -0.015em;
  margin: var(--s12) 0 var(--s4);
}
.doc-body > h2:first-child { margin-top: 0; }
.doc-body > h3 { font-size: 20px; line-height: 1.3; margin: var(--s8) 0 var(--s3); }
.doc-body p { margin: 0 0 var(--s4); max-width: none; }
.doc-body ul, .doc-body ol { padding-left: var(--s6); margin: 0 0 var(--s4); }
.doc-body li { margin-bottom: var(--s2); }
.doc-body a { color: var(--primary); text-underline-offset: 3px; }

/* Reference markers: present but never competing with the sentence. */
.refs { font-size: .62em; font-weight: 700; letter-spacing: .04em; }
.refs a { color: var(--primary); text-decoration: none; padding: 0 1px; }
.refs a:hover { text-decoration: underline; }
.ref-sep { color: var(--on-surface-muted); }

.doc-toc {
  border-left: 2px solid var(--border); padding: 0 0 0 var(--s4);
  margin: 0 0 var(--s8);
}
.doc-toc h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--on-surface-muted); margin: 0 0 var(--s2);
}
.doc-toc ol { list-style: none; padding: 0; margin: 0; }
.doc-toc li { margin-bottom: var(--s1); }
.doc-toc a { color: var(--on-surface); text-decoration: none; font-size: 15px; }
.doc-toc a:hover { color: var(--primary); text-decoration: underline; }

/* The answer-first summary: the passage an answer engine lifts, so it looks
   like the most important thing on the page, because it is. */
.doc-key {
  background: var(--primary-quiet);
  border-radius: var(--radius);
  padding: var(--s6);
  margin-bottom: var(--s8);
}
.doc-key h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--primary); margin: 0 0 var(--s2);
}
.doc-key p { font-size: 19px; line-height: 1.55; margin: 0; font-weight: 500; }

.doc-figure {
  border-top: 2px solid var(--primary); border-bottom: 1px solid var(--border);
  padding: var(--s4) 0; margin: var(--s6) 0;
  display: grid; grid-template-columns: auto 1fr; gap: var(--s4); align-items: baseline;
}
.doc-figure-value {
  font-size: 40px; font-weight: 800; line-height: 1;
  letter-spacing: -0.03em; color: var(--primary); white-space: nowrap;
}
.doc-figure-label { font-size: 16px; line-height: 1.4; }
.doc-figure-source {
  grid-column: 2; font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--on-surface-muted);
}

.doc-quote { margin: var(--s8) 0; padding-left: var(--s6); border-left: 3px solid var(--primary); }
.doc-quote blockquote { margin: 0; }
.doc-quote p { font-size: 22px; line-height: 1.45; font-style: italic; margin: 0 0 var(--s2); }
.doc-quote figcaption { font-size: 14px; color: var(--on-surface-muted); }

.doc-table { margin: var(--s8) 0; }
.doc-table figcaption {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--on-surface-muted); margin-bottom: var(--s2);
}
.doc-table table { font-size: 15px; }
.doc-table th[scope="row"] { font-weight: 600; }
.doc-table tbody tr:hover { background: transparent; }

.doc-step { margin: var(--s6) 0; }
.doc-step h3 { display: flex; gap: var(--s3); align-items: baseline; margin-bottom: var(--s2); }
.doc-step-n {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}

.doc-faq { margin: var(--s6) 0; }
.doc-faq h3 { margin-bottom: var(--s2); }

.doc-def { margin: var(--s6) 0; padding: var(--s4); background: var(--surface-sunken); border-radius: var(--radius-sm); }
.doc-def dt { font-weight: 700; margin-bottom: var(--s1); }
.doc-def dd { margin: 0; }

.doc-callout {
  border-left: 3px solid var(--primary); background: var(--surface-sunken);
  padding: var(--s4); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.doc-callout.warning, .doc-callout.legal { border-left-color: var(--warning); }
.doc-callout p { margin: 0; }

.doc-cta {
  font-size: 19px; font-weight: 600;
  border-top: 1px solid var(--border); padding-top: var(--s6); margin-top: var(--s8);
}

.doc-media { margin: var(--s8) 0; }
.doc-media img { width: 100%; border-radius: var(--radius); display: block; }
.doc-media-placeholder {
  aspect-ratio: 16 / 10; border: 1px dashed var(--border-strong); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; padding: var(--s6);
  color: var(--on-surface-muted); text-align: center; font-size: 14px;
}
.doc-media figcaption { font-size: 13px; color: var(--on-surface-muted); margin-top: var(--s2); }

.doc-refs { margin-top: var(--s12); padding-top: var(--s6); border-top: 1px solid var(--border); }
.doc-refs h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--on-surface-muted); }
.doc-refs ol { padding-left: var(--s6); font-size: 15px; }
.doc-refs li { margin-bottom: var(--s2); }
.doc-refs li:target { background: var(--primary-quiet); border-radius: var(--radius-sm); padding: var(--s1) var(--s2); }
.doc-ref-meta { color: var(--on-surface-muted); font-size: 13px; }

.doc-footnote {
  margin-top: var(--s8); padding-top: var(--s4); border-top: 1px solid var(--border);
  font-size: 14px; color: var(--on-surface-muted);
}

/* Printing is how a document gets shared with someone who does not have a
   login, so the review chrome and the app shell come off. */
@media print {
  .sidebar, .tabs, .page-head button, .review-panel, .doc-toc, .skip-link, .banner { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  .doc { max-width: none; font-size: 11pt; color: #000; }
  .doc-key { background: none; border: 1pt solid #999; }
  .doc-figure-value, .refs a, .doc-body a { color: #000; }
  .doc-body a::after { content: " (" attr(href) ")"; font-size: 9pt; word-break: break-all; }
  h1, h2, h3 { break-after: avoid; }
  .doc-table, .doc-figure, .doc-quote { break-inside: avoid; }
}

/* --- Read / Review ------------------------------------------------------- */

.doc-toolbar {
  display: flex; gap: var(--s2); align-items: center;
  margin-bottom: var(--s6); padding-bottom: var(--s3);
  border-bottom: 1px solid var(--border);
}
button.seg {
  min-height: 36px; padding: var(--s1) var(--s4); border-radius: 99px;
  border-color: var(--border); background: transparent; font-weight: 600;
}
button.seg[aria-pressed="true"] {
  background: var(--primary); color: var(--on-primary); border-color: var(--primary);
}

/* In review mode the affordance sits in the margin, so the text keeps its
   measure and the page still reads as a document. */
/* Review mode widens the article by exactly the width of the tag rail, so the
   text column keeps its measure and a verdict never sits on top of a sentence. */
.doc[data-mode="review"] { max-width: calc(var(--doc-measure) + 130px); }
.doc[data-mode="review"] .part-wrap { padding-right: 130px; }
.part-tag { max-width: 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.part-wrap { position: relative; padding-left: var(--s4); margin-left: calc(var(--s4) * -1); border-left: 3px solid transparent; }
.part-wrap:hover { border-left-color: var(--border-strong); }
.part-wrap[aria-current="true"] { border-left-color: var(--primary); background: var(--primary-quiet); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.part-wrap[data-verdict="accepted"] { border-left-color: var(--success); }
.part-wrap[data-verdict="flagged"] { border-left-color: var(--error); }
.part-wrap[data-verdict="revised"] { border-left-color: var(--primary); }

.part-tag {
  position: absolute; top: 2px; right: 0; z-index: 2;
  min-height: 24px; padding: 2px var(--s2); border-radius: 99px;
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  border: 1px solid var(--border-strong); background: var(--surface-raised);
  color: var(--on-surface-muted); opacity: 0;
}
.part-wrap:hover .part-tag, .part-tag:focus-visible, .part-wrap[aria-current="true"] .part-tag { opacity: 1; }
/* A verdict is content, not chrome: it stays visible without a hover. */
.part-wrap[data-verdict] .part-tag { opacity: 1; }
.part-wrap[data-verdict="accepted"] .part-tag { color: var(--success); border-color: currentColor; }
.part-wrap[data-verdict="flagged"] .part-tag { color: var(--error); border-color: currentColor; }
.part-wrap[data-verdict="revised"] .part-tag { color: var(--primary); border-color: currentColor; }

.doc-stats { display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s4); margin: 0; font-size: 14px; }
.doc-stats dt { color: var(--on-surface-muted); }
.doc-stats dd { margin: 0; font-weight: 600; }

.cp-dialog {
  max-width: 900px; width: 94vw; max-height: 90vh; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-raised); color: var(--on-surface); padding: 24px;
}
.cp-stage { background: var(--surface); border-radius: var(--radius); padding: var(--s6); }
