/* Shared stylesheet with neutral and ThetaParse themes.
 *
 * Everything below paints from these tokens, so a brand is a token swap rather
 * than a fork of the CSS. The default set is a neutral dark theme; the
 * [data-brand="twotheta"] block further down overrides it with TwoTheta's light
 * palette. The brand script in index.html stamps data-brand on <html> from the
 * hostname before first paint.
 *
 * The "tone" tokens are the semantic chip colours (info / good / warn / bad /
 * estate / bank), each a text + border + fill triplet. They exist because those
 * combinations appear a dozen times across badges, confidence chips, review
 * flags and notices, and every one of them needs different values on a light
 * background than on a dark one. */
:root {
  --bg: #070b16;
  --bg-raised: #0d1425;
  --bg-panel: #101a30;
  --bg-header: rgba(7, 11, 22, 0.85);
  --border: #1e2a44;
  --text: #f4f7fc;
  --text-muted: #93a1bd;
  --accent: #3b82f6;
  --accent-hover: #2f6fe0;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --accent-contrast: #fff;
  --hero-glow: rgba(59, 130, 246, 0.16);
  --row-stripe: rgba(255, 255, 255, 0.02);
  --danger: #f87171;

  /* The header and footer bands. Separate from the page tokens so a brand can
   * paint them a solid colour — a knockout logo on a coloured band — without
   * the content area having to follow. Default: the same surface as the page. */
  --header-bg: var(--bg-header);
  --header-text: var(--text);
  --header-muted: var(--text-muted);
  --header-border: var(--border);
  --header-rule: transparent;
  --footer-bg: transparent;
  --footer-text: var(--text-muted);
  --footer-border: var(--border);

  --font-body: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font-body);
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-chip: 999px;

  /* Spacing and type scales.
   *
   * Derived from what this file was already doing, not invented: before these
   * existed it carried 35 distinct spacing values and 25 distinct font sizes,
   * FOURTEEN of them between 0.68 and 1.05rem — a range too narrow for any of
   * them to read as different from each other. The hierarchy those 25 sizes were
   * meant to encode could not actually be seen.
   *
   * Every NEW rule uses these. Existing rules are deliberately left alone: this
   * change ships before a demo and there is no visual regression coverage to
   * catch what a full migration would move. Migrating the rest is TODO-9. */
  --space-1: 0.25rem;
  --space-2: 0.4rem;
  --space-3: 0.6rem;
  --space-4: 0.8rem;
  --space-5: 1.2rem;
  --space-6: 1.6rem;
  --space-7: 2.4rem;

  /* Brand-aware shell tokens.
   *
   * The dashboard was built entirely from --text and --border, which is correct
   * for safety and wrong for identity: on twotheta that is near-black on warm
   * off-white, a grid that could belong to anyone. These give the shell a way
   * to carry a brand WITHOUT reaching for --accent, which on twotheta is the
   * same hex as --danger.
   *
   * --brand-emphasis: headline text — figures, card titles, the current nav
   *   item. --brand-ink is a real brand colour that is not the error colour.
   * --brand-rule: a hairline that marks something as ours. Brand red appears as
   *   a RULE or an OUTLINE, never a fill — the vocabulary .about-lede and
   *   .demo-badge already established on this theme.
   *
   * Both fall back to what the shell used before, so themes only change where
   * they define the token. */
  --brand-emphasis: var(--brand-ink, var(--text));
  --brand-rule: var(--brand-accent, var(--accent));

  /* The light theme overrides these to separate white cards from the page. */
  --card-border: var(--border);
  --card-shadow: none;

  --text-1: 0.72rem;
  --text-2: 0.8rem;
  --text-3: 0.9rem;
  --text-4: 1rem;
  --text-5: 1.15rem;
  --text-6: 1.4rem;
  --text-7: 1.8rem;

  /* Semantic tones: foreground / border / fill */
  --tone-info-fg: #bfdbfe;
  --tone-info-bd: rgba(59, 130, 246, 0.4);
  --tone-info-bg: rgba(59, 130, 246, 0.12);
  --tone-good-fg: #a7f3d0;
  --tone-good-bd: rgba(52, 211, 153, 0.4);
  --tone-good-bg: rgba(52, 211, 153, 0.12);
  --tone-warn-fg: #fde68a;
  --tone-warn-bd: rgba(251, 191, 36, 0.4);
  --tone-warn-bg: rgba(251, 191, 36, 0.1);
  --tone-bad-fg: #fca5a5;
  --tone-bad-bd: rgba(248, 113, 113, 0.4);
  --tone-bad-bg: rgba(248, 113, 113, 0.1);
  --tone-estate-fg: #ddd6fe;
  --tone-estate-bd: rgba(167, 139, 250, 0.45);
  --tone-estate-bg: rgba(167, 139, 250, 0.13);
  --tone-bank-fg: #99f6e4;
  --tone-bank-bd: rgba(45, 212, 191, 0.45);
  --tone-bank-bg: rgba(45, 212, 191, 0.12);

  /* Confidence tiers — paired with an icon + word (never colour alone). */
  --conf-high: #34d399;
  --conf-med: #fbbf24;
  --conf-low: #f87171;

  /* The highlighter over a quoted span. Its own token because the semantic
     tints are all too pale to find at a glance inside a paragraph. */
  --cite-mark: rgba(250, 204, 21, 0.32);
  font-size: 16px;
}

/* TwoTheta: light, warm, red accent — matching twotheta.com. */
:root[data-brand="twotheta"] {
  /* Sampled from the logo PNG itself, so the wordmark matches it exactly. */
  --brand-ink: #102347;
  --brand-accent: #b91c1c;
  --bg: #fafaf8;
  --bg-raised: #ffffff;
  --bg-panel: #f0efe9;
  --bg-header: rgba(250, 250, 248, 0.88);
  --border: #e5e3dc;
  --text: #111110;
  --text-muted: #6b7280;
  --accent: #b91c1c;
  --accent-hover: #991b1b;
  --accent-soft: rgba(185, 28, 28, 0.08);
  --accent-contrast: #ffffff;
  --hero-glow: rgba(185, 28, 28, 0.07);
  --row-stripe: rgba(17, 17, 16, 0.02);
  --danger: #b91c1c;

  --font-body: "DM Sans", system-ui, sans-serif;
  --font-display: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Courier New", monospace;
  --radius: 8px;
  --radius-sm: 6px;

  /* Darkened foregrounds so every chip clears contrast on the warm off-white. */
  --tone-info-fg: #1e40af;
  --tone-info-bd: rgba(30, 64, 175, 0.28);
  --tone-info-bg: rgba(30, 64, 175, 0.07);
  --tone-good-fg: #047857;
  --tone-good-bd: rgba(4, 120, 87, 0.28);
  --tone-good-bg: rgba(4, 120, 87, 0.07);
  --tone-warn-fg: #92400e;
  --tone-warn-bd: rgba(146, 64, 14, 0.28);
  --tone-warn-bg: rgba(146, 64, 14, 0.07);
  --tone-bad-fg: #b91c1c;
  --tone-bad-bd: rgba(185, 28, 28, 0.28);
  --tone-bad-bg: rgba(185, 28, 28, 0.07);
  --tone-estate-fg: #5b21b6;
  --tone-estate-bd: rgba(91, 33, 182, 0.28);
  --tone-estate-bg: rgba(91, 33, 182, 0.07);
  --tone-bank-fg: #0f766e;
  --tone-bank-bd: rgba(15, 118, 110, 0.28);
  --tone-bank-bg: rgba(15, 118, 110, 0.07);

  --conf-high: #047857;
  --conf-med: #92400e;
  --conf-low: #b91c1c;
  --cite-mark: rgba(250, 204, 21, 0.6);

  /* White cards on a warm off-white page need an edge the background step does
     not give them. Warm-tinted to match the paper rather than a grey hairline. */
  --card-border: #dedbd1;
  --card-shadow: 0 1px 2px rgba(16, 35, 71, 0.04), 0 1px 8px rgba(16, 35, 71, 0.03);
}

/* The three rules that used to live here pinned column widths on .ci-field,
 * because every evidence row was its own grid and that was the only way to make
 * a reviewer scanning downward find the chips at the same x on every line.
 * Evidence rows are a real table now and share their column tracks, so the
 * alignment those rules bought is a property of the markup and they are gone.
 * See .field-table. */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1,
h2,
h3,
.brand-name {
  font-family: var(--font-display);
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 2rem;
  border-bottom: 1px solid var(--header-border);
  background: var(--header-bg);
  color: var(--header-text);
  position: sticky;
  top: 0;
  backdrop-filter: blur(8px);
  /* Above .doc-viewer (90). The drawer is fixed to the right edge and would
     otherwise cover the header's Upload button whenever a citation is open —
     which is exactly when the demo is being watched. */
  z-index: 95;
}

/* A brand's accent rule across the top of the band. Transparent by default, so
 * it costs the other themes nothing. */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--header-rule);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-logo {
  height: 30px;
  width: auto;
  display: block;
}

/* Company logo | product lockup */
.brand-divider {
  width: 1px;
  align-self: stretch;
  margin: 0.15rem 0.2rem;
  background: var(--border);
}

.product-lockup {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  flex-wrap: wrap;
}

/* The wordmark: same typeface and weight as the logo, "Parse" in the logo's
   red. Both hexes are sampled from the logo file, so the lockup stays true to
   it even if the surrounding theme tokens change. */
.product-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.18rem;
  letter-spacing: -0.02em;
  color: var(--brand-ink, var(--text));
  white-space: nowrap;
}

.product-accent {
  color: var(--brand-accent, var(--accent));
}

.product-descriptor {
  color: var(--text-muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Sits against the wordmark so the label travels with the product name — the
   point is that nobody reads this as a shipping product. */
.demo-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand-accent, var(--accent));
  border: 1px solid var(--brand-accent, var(--accent));
  border-radius: var(--radius-chip);
  padding: 0.1rem 0.5rem;
  white-space: nowrap;
  align-self: center;
}

/* About panel */
.about {
  max-width: 68ch;
  line-height: 1.7;
}

.about h2 {
  font-size: 1.05rem;
  margin: 1.8rem 0 0.6rem;
}

.about p { margin-bottom: 0.9rem; }

.about-lede {
  font-size: 1.05rem;
  border-left: 3px solid var(--brand-accent, var(--accent));
  padding-left: 1rem;
  margin-bottom: 1.4rem;
}

.about-list {
  padding-left: 1.1rem;
  margin-bottom: 0.9rem;
}

.about-list li { margin-bottom: 0.4rem; }

.about-note {
  color: var(--text-muted);
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  padding: 0.8rem 1rem;
  margin-top: 1.6rem;
}

/* Constrain the wrapper, not the table — the wrapper carries the border and
   background, so capping only the table leaves an empty ledge beside it. */
.about .table-wrap { max-width: 40rem; }
.block-table { width: 100%; }

.block-name {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--brand-ink, var(--text));
  white-space: nowrap;
}

.block-current { background: var(--accent-soft); }

.block-badge {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-left: 0.5rem;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .product-descriptor {
    display: none;
  }
}

.header-tag {
  color: var(--header-muted);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Layout */
main {
  flex: 1;
  min-width: 0;
  max-width: 1180px;
  padding: var(--space-7) var(--space-7) 4rem;
}

/* Document-type selector */
.doc-type-row {
  display: grid;
  grid-template-columns: auto minmax(0, 22rem);
  align-items: center;
  gap: 0.5rem 0.9rem;
  margin-bottom: 1rem;
}

.doc-type-label {
  font-size: 0.9rem;
  font-weight: 600;
}

.doc-type-select {
  font: inherit;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  width: 100%;
}

.doc-type-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.doc-type-hint {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 0.83rem;
  line-height: 1.5;
}

@media (max-width: 640px) {
  .doc-type-row {
    grid-template-columns: 1fr;
  }
}

/* Upload card */
.upload-card {
  background: var(--bg-raised);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.6rem 2rem;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.upload-card.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-idle svg {
  color: var(--accent);
  margin-bottom: 0.8rem;
}

.upload-idle p {
  line-height: 1.7;
}

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.upload-busy .spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 1rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.upload-error {
  color: var(--danger);
  margin-top: 1rem;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* Results */
.results {
  margin-top: 2.5rem;
}

.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
}

.results-title {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.results-header h2 {
  font-size: 1.3rem;
  font-weight: 600;
}

.badge {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--tone-info-bd);
  background: var(--accent-soft);
  color: var(--tone-info-fg);
  white-space: nowrap;
}

.badge-sow { border-color: var(--tone-info-bd); color: var(--tone-info-fg); background: var(--tone-info-bg); }
.badge-msa,
.badge-contract { border-color: var(--tone-good-bd); color: var(--tone-good-fg); background: var(--tone-good-bg); }
.badge-invoice { border-color: var(--tone-warn-bd); color: var(--tone-warn-fg); background: var(--tone-warn-bg); }
.badge-other { border-color: var(--border); color: var(--text-muted); background: transparent; }

/* Real estate */
.badge-lease,
.badge-lease_amendment,
.badge-psa,
.badge-property_management,
.badge-vendor_service { border-color: var(--tone-estate-bd); color: var(--tone-estate-fg); background: var(--tone-estate-bg); }

/* Banking & lending */
.badge-appraisal,
.badge-credit_memo,
.badge-loan_agreement,
.badge-security_instrument,
.badge-guaranty { border-color: var(--tone-bank-bd); color: var(--tone-bank-fg); background: var(--tone-bank-bg); }

.file-facts {
  color: var(--text-muted);
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  min-width: 0;
}
.results-header.drive-facts-wrapped .file-facts { flex: 1 1 100%; }
.results-header > .library-actions, .results-header > #drive-source-versions { flex: 0 0 100%; }
.drive-provenance { margin-left: auto; }

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}

@media (max-width: 800px) {
  .results-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  min-width: 0;
}

.panel h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 1.1rem;
}

/* Section headings.
   They were muted grey, which put them BELOW the field labels they are meant
   to group — so a document with five sections read as one long list. Full
   contrast, bolder, and a rule running to the edge, so the eye can find where
   one group ends and the next begins while scrolling.
   Deliberately not --accent: on ThetaParse that token is the same hex as
   --danger, and a red section heading reads as an error. */
.panel h4 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text);
  margin: 1.9rem 0 0.6rem;
}
.panel h4::after {
  content: "";
  flex: 1;
  height: 1px;
  background: currentColor;
  opacity: 0.22;
}
.panel h4:first-child { margin-top: 0.4rem; }

.panel dl {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: 0.6rem 1rem;
  font-size: 0.95rem;
}

.panel dt {
  color: var(--text-muted);
}

.panel dd {
  overflow-wrap: anywhere;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  background: var(--accent-soft);
  color: var(--tone-info-fg);
  border: 1px solid var(--tone-info-bd);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.82rem;
}

.chip.entity-people { border-color: var(--tone-good-bd); color: var(--tone-good-fg); background: var(--tone-good-bg); }
.chip.entity-locations { border-color: var(--tone-warn-bd); color: var(--tone-warn-fg); background: var(--tone-warn-bg); }

#text-preview,
#json-output {
  font-family: var(--font-mono);
}

#text-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem;
  max-height: 300px;
  overflow: auto;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-wrap;
  color: var(--text-muted);
}

/* Deep, type-specific extraction panel */
.panel-wide {
  margin-bottom: 1.2rem;
}

#deep-content dl {
  display: grid;
  grid-template-columns: minmax(130px, auto) 1fr;
  gap: 0.6rem 1rem;
  font-size: 0.95rem;
  margin-bottom: 0.4rem;
}

#deep-content dt {
  color: var(--text-muted);
}

#deep-content dd {
  overflow-wrap: anywhere;
}

.deep-note {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.table-wrap {
  overflow-x: auto;
  margin: 0.3rem 0 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  background: var(--bg-raised);
}

/* Zebra striping so rows read as distinct, not clubbed together. */
.data-table tbody tr:nth-child(even) td {
  background: var(--row-stripe);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table td {
  color: var(--text);
  overflow-wrap: anywhere;
  white-space: normal;
}

/* Upload progress queue */
.upload-queue {
  list-style: none;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
}

.q-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.q-status {
  font-size: 0.82rem;
  white-space: nowrap;
  color: var(--text-muted);
}

.q-status--extracting { color: var(--accent); }
.q-status--done { color: var(--conf-high); }
.q-status--error { color: var(--danger); }

/* "Not saved to history" notice */
.persisted-notice {
  background: var(--tone-warn-bg);
  border: 1px solid var(--tone-warn-bd);
  color: var(--tone-warn-fg);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1.2rem;
  font-size: 0.9rem;
}

/* Forced type disagreed with what Claude read */
.mismatch-notice {
  background: var(--tone-info-bg);
  border: 1px solid var(--tone-info-bd);
  color: var(--tone-info-fg);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1.2rem;
  font-size: 0.9rem;
}

/* Reviewer bar: who is reviewing, what state the document is in, and the
   actions that move it forward. */
.review-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.8rem 1rem;
  margin-bottom: 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
}

.review-bar-left,
.review-bar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.reviewer-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.reviewer-input,
.field-input {
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.6rem;
}

.reviewer-input:focus-visible,
.field-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-input {
  min-width: min(28rem, 60vw);
}

.review-state {
  font-size: 0.85rem;
  font-weight: 600;
}

.review-state.is-approved { color: var(--conf-high); }
.review-state.is-pending { color: var(--text-muted); }

.primary-button {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-contrast);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.9rem;
  cursor: pointer;
}

.primary-button:hover:not(:disabled) { background: var(--accent-hover); }
.primary-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.ghost-button {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  cursor: pointer;
}

.ghost-button:hover { border-color: var(--accent); color: var(--accent); }

/* Collapsed-by-default panels: the exception worklist and the document
   history. Both are there when a reviewer wants them and out of the way of the
   fields and the source document until then. */
.disclosure {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  margin-bottom: 1.2rem;
}

.disclosure-summary {
  padding: 0.85rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.disclosure-summary::-webkit-details-marker { display: none; }

/* Own marker, so the affordance survives the list-style reset above. */
.disclosure-summary::before {
  content: "\25B8";
  color: var(--text-muted);
  font-size: 0.8em;
  transition: transform 0.15s ease;
}

.disclosure[open] > .disclosure-summary::before { transform: rotate(90deg); }
.disclosure-summary:hover { color: var(--accent); }
.disclosure-summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.disclosure > *:not(.disclosure-summary) { padding: 0 1.2rem 1.1rem; }

.exception-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.exception {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  padding: 0.6rem 0.8rem;
}

.exception.sev-error { border-left-color: var(--tone-bad-fg); }
.exception.sev-warning { border-left-color: var(--tone-warn-fg); }
.exception.sev-info { border-left-color: var(--tone-info-fg); }

.exception-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.exception-message { font-weight: 600; font-size: 0.92rem; }

.exception-detail {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-top: 0.3rem;
  white-space: pre-wrap;
}

.exception-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.4rem;
}

.exception-field {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
}

.severity-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: var(--radius-chip);
  padding: 0.05rem 0.5rem;
  white-space: nowrap;
}

.severity-chip.sev-error {
  color: var(--tone-bad-fg);
  background: var(--tone-bad-bg);
  border: 1px solid var(--tone-bad-bd);
}
.severity-chip.sev-warning {
  color: var(--tone-warn-fg);
  background: var(--tone-warn-bg);
  border: 1px solid var(--tone-warn-bd);
}
.severity-chip.sev-info {
  color: var(--tone-info-fg);
  background: var(--tone-info-bg);
  border: 1px solid var(--tone-info-bd);
}

.field-editor {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}

.field-error {
  color: var(--danger);
  font-size: 0.82rem;
}


/* Reviewer queue filters */
.queue-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.queue-filter {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  padding: 0.3rem 0.85rem;
  cursor: pointer;
}

.queue-filter:hover { color: var(--text); }

.queue-filter.is-active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-chip.is-approved { color: var(--conf-high); }
.status-chip.is-pending { color: var(--text-muted); }

/* Aggregate "N fields need review" banner above the results */
.review-notice {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
  background: var(--tone-warn-bg);
  border: 1px solid var(--tone-warn-bd);
  color: var(--tone-warn-fg);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1.2rem;
  font-size: 0.9rem;
}

/* History: expiry countdown + review count */
.expiry-chip,
.review-flag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  margin-left: 0.4rem;
  white-space: nowrap;
}

.expiry-soon {
  color: var(--tone-warn-fg);
  border: 1px solid var(--tone-warn-bd);
  background: var(--tone-warn-bg);
}

.expiry-past {
  color: var(--tone-bad-fg);
  border: 1px solid var(--tone-bad-bd);
  background: var(--tone-bad-bg);
}

.review-clear {
  color: var(--text-muted);
}

/* Structured JSON output */
.json-panel {
  margin-top: 1.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  padding: 1rem 1.2rem;
}

.json-panel > summary {
  cursor: pointer;
  font-weight: 600;
}

.json-panel > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.json-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin: 0.9rem 0 0.6rem;
}

.json-note {
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 46ch;
  line-height: 1.5;
}

.json-actions {
  display: flex;
  gap: 0.4rem;
}

#json-output {
  max-height: 26rem;
  overflow: auto;
}

/* Fields the model wasn't confident about. Icon + word + colour, never colour
   alone — same rule the confidence chips follow. */
/* Layout comes from the shared .expiry-chip/.review-flag rule above. */
.review-flag {
  color: var(--tone-warn-fg);
  border: 1px solid var(--tone-warn-bd);
  background: var(--tone-warn-bg);
}

.review-icon {
  font-size: 0.85em;
}

/* A flagged row gets an edge, not a wash.
   The wash was fine on one or two rows and wrong on a lease, where eight of
   fifteen fields come back low-confidence and the whole table reads as an
   error state. An edge marks exactly the same rows and leaves the table
   looking like a table.
   It also lets the two signals differ: amber is the extractor doubting itself,
   red is two models disagreeing. Those are not the same fact and should not
   have looked the same. */
.field-table tr.needs-review > td:first-child {
  box-shadow: inset 3px 0 0 var(--conf-med);
}
.field-table tr.conflict > td:first-child {
  box-shadow: inset 3px 0 0 var(--danger);
}

/* Contract intelligence: value, confidence, cross-check, source.
   Previously a flex list of independent grids — one grid per row — so the
   columns only lined up where a brand had pinned their widths. Rows in a table
   share their tracks, which is the entire fix; nothing below sets a width
   except the caret column, which holds one glyph. */
/* Fixed, so the declared column widths hold and every field table on the page
   shares them. Auto layout would size each table to its own contents and the
   sections would step in and out down the page. */
.field-table { table-layout: fixed; }
.field-table td { vertical-align: top; }
.field-table th { white-space: nowrap; }
/* Same row, different jobs: the label is wayfinding, the value is the thing
   someone opened the document to check. They should not carry equal weight. */
.field-table .ci-label { color: var(--text-muted); font-size: 0.85rem; }
.field-table .ci-value { color: var(--text); font-weight: 500; overflow-wrap: anywhere; }
.field-table .col-source { width: 1%; white-space: nowrap; text-align: right; }

/* Section headings, now rows inside the one table rather than <h4>s between
   several. Same job as before — tell the reader where one group of fields ends
   and the next begins — but they no longer drag a repeated column header along
   with them.
   Deliberately not --accent: on ThetaParse that token is the same hex as
   --danger, and a red section heading reads as an error. */
.field-table tr.section-row > th {
  padding: 1.5rem 0.6rem 0.4rem;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.field-table tr.section-row:first-child > th { padding-top: 0.35rem; }

/* A row that belongs to the one above it: no rule between them, so the citation
   and the field it explains read as one thing. */
.field-table tr.citation-row > td,
.field-table tr.editor-row > td {
  padding-top: 0;
  border-top: none;
}
/* The panel belongs to the row above, so it carries the same edge rather than
   the tint it used to inherit. */
.field-table tr.needs-review + tr.citation-row > td:first-child,
.field-table tr.needs-review + tr.editor-row > td:first-child {
  box-shadow: inset 3px 0 0 var(--conf-med);
}
.field-table tr.conflict + tr.citation-row > td:first-child,
.field-table tr.conflict + tr.editor-row > td:first-child {
  box-shadow: inset 3px 0 0 var(--danger);
}

/* The cross-check cell: a verdict, and under it the other model's reading. */
.cross-cell {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem;
}

/* What a second model made of the value. Icon + word, never colour alone. */
.cross-check {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.3rem;
  font-size: 0.82rem;
}
.cross-icon { font-size: 0.9em; }
.cross-agrees { color: var(--tone-good-fg); }
.cross-absent { color: var(--tone-warn-fg); }
.cross-none { color: var(--text-muted); }

/* Deliberately the loudest thing in the table. It is the only signal here
   backed by two independent readings of the document; a model's low opinion of
   itself is not, and must not shout as loud. */
.cross-differs {
  color: var(--tone-bad-fg);
  font-weight: 600;
  background: var(--tone-bad-bg);
  border: 1px solid var(--tone-bad-bd);
  border-radius: var(--radius-chip);
  padding: 0.05rem 0.5rem;
}

/* The other model's reading, on its own line under the verdict. A conflict a
   reviewer has to expand to see is a conflict most of them will not see. */
.cross-value {
  display: block;
  width: 100%;
  color: var(--text);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

/* The verifier's reason, under the verdict on a flagged row. Muted and smaller
   than the reading above it: it explains the evidence, it is not the evidence. */
.cross-reason {
  display: block;
  width: 100%;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

/* Plain text, not a pill.
   It was a bordered pill, which was right when it was the only signal in the
   row. Beside a Differs pill it is a second thing shouting, and the one that
   is merely a model's opinion of itself wins on visual weight — exactly
   backwards. Icon and word remain, so this is still never colour alone. */
.conf-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.conf-icon { font-size: 0.7rem; line-height: 1; }
/* Colour only. The tints and borders went with the pill — left behind they
   made a tinted blob with no edge, which is worse than either shape. */
.conf-high { color: var(--conf-high); }
.conf-med { color: var(--conf-med); }
.conf-low { color: var(--conf-low); }

.source-tag {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* The same reference, made operable where there is a citation behind it. Only
   fields the model could quote get this — nothing grows an affordance that
   would lead nowhere. */
/* Now that the trigger is a bare caret with no words in it, a borderless glyph
   floating at the right edge of the row does not read as a control at all. It
   gets a resting box — and a 32px minimum, since it is also the smallest touch
   target in the table. */
.source-tag-button {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  font: inherit;
  font-size: 0.76rem;
  color: var(--text);
  cursor: pointer;
  min-width: 32px;
  min-height: 32px;
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-sm);
  text-align: center;
}

/* On the dark theme --border against --bg-panel is barely a line, so the box
   this rule exists to draw disappears in exactly one brand. Lift it there
   rather than thickening it everywhere. */
:root:not([data-brand]) .source-tag-button {
  background: #16203a;
  border-color: #2b3a5c;
}

.source-tag-button:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.source-tag-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.cite-caret {
  margin-left: 0.25rem;
  font-size: 0.7em;
}

/* Inside the citation trigger the caret is not an ornament next to a label —
   it IS the control, and at 0.7em of a 0.76rem button it rendered about eight
   pixels tall and read as a speck. It gets the button's full size and no
   leading margin, since there is no longer any text for it to sit beside. */
.source-tag-button .cite-caret {
  margin-left: 0;
  font-size: 1rem;
  line-height: 1;
}

.source-tag-button[aria-expanded="true"] .cite-caret {
  /* Points at the panel it opened. */
  display: inline-block;
  transform: rotate(180deg);
}

/* The citation itself: it sits in a row of its own that spans every column,
   which is the table's own way of saying "this belongs to the row above". */
.citation {
  margin: 0 0 0.7rem;
  padding: 0.7rem 0.85rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--bg-raised);
  box-shadow: inset 0 0 0 1px var(--border);
}

.cite-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid;
  white-space: nowrap;
}

.cite-icon { font-size: 0.85em; line-height: 1; }

.cite-verified {
  color: var(--tone-good-fg);
  border-color: var(--tone-good-bd);
  background: var(--tone-good-bg);
}

.cite-partial {
  color: var(--tone-info-fg);
  border-color: var(--tone-info-bd);
  background: var(--tone-info-bg);
}

.cite-missing {
  color: var(--tone-warn-fg);
  border-color: var(--tone-warn-bd);
  background: var(--tone-warn-bg);
}

/* Chat only. The stream ended before the server said anything about this quote,
   which is a different claim from "not found in the document text" — that one
   asserts a check that never ran. Deliberately the muted, least-alarming tone:
   nothing is wrong with the document, we just did not get to look. */
.cite-pending {
  color: var(--text-muted);
  border-color: var(--border);
  background: var(--row-stripe);
}

/* Visible to screen readers, not to the eye. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* The document's own words. Serif sets them apart from the interface around
   them — this is quoted material, not our text. */
.cite-text {
  margin-top: 0.5rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text);
}

.cite-text mark {
  background: var(--cite-mark);
  color: inherit;
  font-weight: 600;
  padding: 0.05em 0.15em;
  border-radius: 3px;
}

/* No surrounding context to show, so the quote stands alone. */
.cite-quote-only {
  font-style: italic;
  color: var(--text-muted);
}

/* Citation headline above the extracted fields. */
.citation-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: -0.3rem 0 1rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--border);
}

/* The outcome of the last cross-model check. Tone plus words, never tone
   alone — the same rule the confidence and cross-check chips follow. */
.verify-note { font-size: 0.82rem; color: var(--text-muted); }
.verify-note--good { color: var(--conf-high); }
.verify-note--warn { color: var(--conf-med); }
.verify-note--bad { color: var(--danger); }

.citation-summary {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Counterparty flag on a party row */
.cp-badge {
  display: inline-block;
  margin-left: 0.5rem;
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tone-warn-fg);
  border: 1px solid var(--tone-warn-bd);
  background: var(--tone-warn-bg);
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  vertical-align: middle;
}

/* History */
.history-state {
  color: var(--text-muted);
  text-align: center;
  padding: 2.5rem 1rem;
  line-height: 1.7;
}

.history-state--error { color: var(--danger); }
.history-state .link-button { margin-left: 0.3rem; }

.history-row { cursor: pointer; }
.history-row:hover td { background: var(--accent-soft); }
.history-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.history-table td { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }

/* History table collapses to cards on narrow screens (D5) */
@media (max-width: 640px) {
  /* The field table collapses to labelled cards, the same shape History uses
     right below. Four columns of evidence do not fit 375px, and a horizontally
     scrolling table is a table nobody reads the right-hand half of. */
  .field-table thead { display: none; }
  .field-table tr { display: block; border: 1px solid var(--border); border-radius: 10px;
                    margin-bottom: 0.6rem; padding: 0.3rem 0.2rem; }
  .field-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    width: 100%;
    border: none;
    padding: 0.4rem 0.8rem;
    text-align: right;
  }
  .field-table td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex: 0 0 auto;
    white-space: nowrap;
    align-self: flex-start;
    padding-top: 0.15rem;
  }
  .field-table .col-source { width: 100%; text-align: right; }
  /* The citation panel is prose; it gets the card's full width and no label. */
  /* The edge markers move to the card itself. Specificity matters here: a bare
     `tr.conflict` loses to `.field-table tr` above, and the marker would vanish
     on the layout where people skim fastest. */
  .field-table tbody tr.needs-review > td:first-child,
  .field-table tbody tr.conflict > td:first-child { box-shadow: none; }
  .field-table tbody tr.needs-review { border-left: 3px solid var(--conf-med); }
  .field-table tbody tr.conflict { border-left: 3px solid var(--danger); }

  .field-table tbody tr.section-row { display: block; border: none; margin: 1rem 0 0.4rem; }
  .field-table tbody tr.section-row > th {
    display: block; width: 100%; padding: 0 0 0.35rem; text-align: left;
  }

  .field-table tr.citation-row, .field-table tr.editor-row { border: none; padding: 0; }
  .field-table tr.citation-row td::before,
  .field-table tr.editor-row td::before { content: none; }
  .field-table tr.citation-row td,
  .field-table tr.editor-row td { display: block; text-align: left; }

  #history-list .table-wrap { border: none; overflow: visible; }
  .history-table thead { display: none; }
  .history-table,
  .history-table tbody,
  .history-table tr,
  .history-table td { display: block; width: 100%; }
  .history-table tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 0.6rem;
    padding: 0.3rem 0.2rem;
  }
  .history-table td {
    border: none;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    white-space: normal;
    max-width: none;
    padding: 0.5rem 0.8rem;
    overflow: visible;
    text-overflow: clip;
  }
  .history-table td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    /* Without this the flex row squeezes the label to one letter per line
       whenever the value is long — "V A L U E" down the left edge. */
    flex: 0 0 auto;
    white-space: nowrap;
    align-self: flex-start;
    padding-top: 0.15rem;
  }
  .history-table td {
    align-items: flex-start;
    text-align: right;
  }
  .history-table td[data-label="File"] { font-weight: 600; }
}

/* Login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
}

.login-card {
  width: min(380px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  text-align: center;
}

.login-card h1 { font-size: 1.4rem; font-weight: 700; }
.login-card p { color: var(--text-muted); font-size: 0.92rem; }

.login-card input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  color: var(--text);
  font: inherit;
}

.login-card input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.login-button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.login-button:hover { background: var(--accent-hover); }
.login-error { color: var(--danger); font-size: 0.88rem; }

/* Header right side + logout */
.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logout-button {
  background: none;
  border: 1px solid currentColor;
  color: var(--header-muted);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  min-height: 32px;
}

.logout-button:hover { color: var(--header-text); border-color: currentColor; }

/* History toolbar + clear */
.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.history-count { color: var(--text-muted); font-size: 0.9rem; }

.history-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.danger-button {
  background: var(--tone-bad-bg);
  color: var(--danger);
  border: 1px solid var(--tone-bad-bd);
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  min-height: 40px;
}

.danger-button:hover { background: var(--tone-bad-bg); filter: brightness(0.96); }

.clear-confirm {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.confirm-msg { color: var(--text); font-size: 0.88rem; }

/* Footer */
.site-footer {
  border-top: 1px solid var(--footer-border);
  background: var(--footer-bg);
  padding: 1.2rem 2rem;
  color: var(--footer-text);
  font-size: 0.85rem;
  text-align: center;
}

/* ---------------------------------------------------------------------------
   Source document viewer

   A drawer beside the fields on a wide screen, a full sheet below 800px.
   z-index sits under .login-overlay (100) on purpose: an expired session must
   still be able to cover everything, viewer included.
   --------------------------------------------------------------------------- */
.doc-viewer {
  position: fixed;
  /* Starts BELOW the site header, not at the top of the viewport.
   *
   * The header is sticky at z-index 95 so the drawer cannot cover the Upload
   * button; the drawer is 90. With `top: 0` that ordering put the viewer's own
   * control bar — close, page prev/next, zoom — underneath the header, where
   * elementFromPoint returns .site-header and none of them can be clicked.
   *
   * Offsetting is the fix rather than another z-index shuffle: whichever of the
   * two wins that fight, the loser's controls become unreachable. --header-h is
   * measured and published by shell.js, because the header's height is
   * content-driven and differs per brand (the two logos are not the same size).
   * The 0px fallback keeps this sane if the script has not run yet. */
  top: var(--header-h, 0px);
  right: 0;
  bottom: 0;
  width: min(46rem, 50vw);
  z-index: 90;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  box-shadow: -18px 0 48px rgba(0, 0, 0, 0.28);
}

.doc-viewer-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}

.doc-viewer-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-viewer-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: none;
}

.doc-ctl {
  min-width: 1.9rem;
  height: 1.9rem;
  padding: 0 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.doc-ctl:hover { border-color: var(--accent); color: var(--accent); }
.doc-ctl:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.doc-ctl-close { font-size: 1.25rem; }

.doc-ctl-sep {
  width: 1px;
  height: 1.2rem;
  background: var(--border);
  margin: 0 0.2rem;
}

.doc-page-count,
.doc-zoom-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 3rem;
  text-align: center;
}

.doc-viewer-note {
  margin: 0;
  padding: 0.6rem 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
}

.doc-pages {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  background: var(--bg);
}

/* One page. Positioned so the highlight overlay can sit on top of the canvas
   in page coordinates. */
.pdf-page {
  position: relative;
  flex: none;
  background: #fff;
  box-shadow: 0 1px 10px rgba(0, 0, 0, 0.22);
}

.pdf-canvas { display: block; }

/* The marker over the quoted words. Same token as the inline citation panel's
   <mark>, so the two read as one object seen twice. Never painted into the
   canvas: canvas marks are lost on every zoom re-render. */
.pdf-hl {
  position: absolute;
  background: var(--cite-mark);
  border-radius: 2px;
  pointer-events: none;
  mix-blend-mode: multiply;
}

.pdf-page-target { animation: cite-pulse 1.2s ease-out 1; }

@keyframes cite-pulse {
  0%   { box-shadow: 0 0 0 3px var(--accent), 0 1px 10px rgba(0, 0, 0, 0.22); }
  100% { box-shadow: 0 0 0 0 transparent, 0 1px 10px rgba(0, 0, 0, 0.22); }
}

/* Fallback reader: DOCX, scans stored without a text layer, and anything
   uploaded before documents were kept. */
.doc-pages-text { align-items: stretch; }

.doc-text-page {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
}

.doc-text-label {
  margin: 0 0 0.6rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.doc-text-body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.9rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.doc-text-body mark {
  background: var(--cite-mark);
  color: inherit;
  font-weight: 600;
  padding: 0.05em 0.15em;
  border-radius: 3px;
}

/* The control that opens all this, inside a citation panel. */
.cite-open {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.5rem;
  padding: 0.28rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.cite-open:hover { border-color: var(--accent); background: var(--accent-soft); }
.cite-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 800px) {
  .doc-viewer {
    width: 100%;
    left: 0;
    border-left: none;
  }
}

/* Correcting a field in place. The pencil sits inside the value cell rather
   than claiming a column of its own — an edit affordance is part of the value,
   not a separate fact about the field. */
.value-edit {
  margin-left: 0.4rem;
  padding: 0 0.25rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85em;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease;
}

/* Revealed on hover for the mouse, and always for the keyboard — an
   opacity-0 control that never takes focus is unreachable without a pointer. */
.field-table tr:hover .value-edit,
.field-table tr:focus-within .value-edit,
.value-edit:focus-visible { opacity: 1; }
.value-edit:hover { color: var(--accent); background: var(--accent-soft); }
.value-edit:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.value-edited {
  margin-left: 0.45rem;
  padding: 0.05rem 0.4rem;
  border-radius: var(--radius-chip);
  background: var(--tone-good-bg);
  border: 1px solid var(--tone-good-bd);
  color: var(--tone-good-fg);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.field-editor-host { padding: 0.25rem 0 0.5rem; }

/* Document history: what happened to this document, in order. The correction
   entries matter most — they are the only place the model's original answer
   survives once a reviewer has overwritten it. */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

/* The spine. Inset to sit under the centre of the dots. */
.timeline::before {
  content: "";
  position: absolute;
  left: 0.32rem;
  top: 0.6rem;
  bottom: 0.6rem;
  width: 1px;
  background: var(--border);
}

.timeline-event {
  position: relative;
  display: flex;
  gap: 0.85rem;
  padding: 0.55rem 0;
}

.timeline-dot {
  flex: none;
  width: 0.7rem;
  height: 0.7rem;
  margin-top: 0.3rem;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  z-index: 1;
}

.timeline-edit .timeline-dot { border-color: var(--conf-med); }
.timeline-approve .timeline-dot { border-color: var(--conf-high); }
.timeline-upload .timeline-dot { border-color: var(--accent); }

.timeline-body { min-width: 0; }

.timeline-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.6rem;
}

.timeline-title { font-weight: 600; font-size: 0.9rem; }

.timeline-when {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.timeline-detail {
  margin: 0.15rem 0 0;
  font-size: 0.83rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* The Send button, and why it does nothing. */
.ghost-button.is-inert {
  opacity: 0.55;
  cursor: not-allowed;
  border-style: dashed;
}

.ghost-button.is-inert:hover { border-color: var(--border); color: var(--text); }

.send-note {
  margin: -0.6rem 0 1.2rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------- Chat panel

   Painted entirely from tokens. One trap worth naming, because it is invisible
   in the default theme: --accent-soft is NOT usable as
   a neutral container fill here. In [data-brand=twotheta] --accent and --danger
   are the same hex (#b91c1c), so a question bubble tinted with it renders in the
   product's error colour, inches from a real error. Use --bg-raised plus a
   hairline border to distinguish conversation roles without colour alone. */

.chat-panel {
  /* A reading measure, and — not by accident — narrow enough that the document
     viewer (position: fixed, up to 50vw) cannot bury the composer. */
  --chat-measure: min(68ch, 100%);
}

/* One padded wrapper. `.disclosure > *:not(.disclosure-summary)` pads every
   direct child, and this section has seven — without the wrapper each would
   carry its own gutter and the composer would sit inset from the log. */
.chat-body { min-width: 0; }

.chat-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.chat-scope {
  margin: 0 0 0.9rem;
  color: var(--text-muted);
  font-size: 0.86rem;
}

.chat-note {
  max-width: var(--chat-measure);
  margin: 0 0 0.9rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  color: var(--tone-info-fg);
  border: 1px solid var(--tone-info-bd);
  background: var(--tone-info-bg);
}

.chat-note--warn {
  color: var(--tone-warn-fg);
  border-color: var(--tone-warn-bd);
  background: var(--tone-warn-bg);
}

.chat-note--bad {
  color: var(--tone-bad-fg);
  border-color: var(--tone-bad-bd);
  background: var(--tone-bad-bg);
}

/* Bounded on purpose. Unbounded, the page grows as an answer streams and the
   composer walks off under the reader's cursor. */
.chat-log {
  max-width: var(--chat-measure);
  max-height: min(60vh, 720px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-log:empty { display: none; }

.chat-turn { margin-bottom: 1.1rem; }

.chat-who {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--text-muted);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-turn--user .chat-who { text-align: right; }

.chat-bubble {
  margin-left: auto;
  max-width: 90%;
  width: fit-content;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  white-space: pre-wrap;
}

/* The answer is prose, not a bubble. It is the document speaking, not a chat
   partner, and it has to sit comfortably beside the evidence tables above it. */
.chat-answer { max-width: var(--chat-measure); }
.chat-para { margin: 0 0 0.7rem; line-height: 1.55; }
.chat-list { margin: 0 0 0.7rem; padding-left: 1.1rem; line-height: 1.55; }
.chat-list li { margin-bottom: 0.3rem; }

/* A quote still waiting for its verdict. Deliberately NOT --cite-mark: that
   token means "these are the document's own words", and nothing unverified may
   wear it. */
.chat-quote.is-pending {
  border-bottom: 1px dotted var(--text-muted);
  color: var(--text-muted);
}

.chat-mark {
  background: var(--cite-mark);
  color: inherit;
  border-radius: 2px;
  padding: 0 0.1em;
}

.chat-open {
  margin-left: 0.35rem;
  font-size: 0.8rem;
}

.chat-incomplete {
  max-width: var(--chat-measure);
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.chat-copy { margin-top: 0.4rem; font-size: 0.8rem; }

.chat-thinking {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Reuses the keyframes already in this file; scoped rather than widening the
   .upload-busy selector it was written for. */
.chat-thinking .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.chat-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: var(--chat-measure);
  margin-bottom: 0.9rem;
}

/* .chip is a display element with no cursor, no hover and no focus ring, so a
   starter question built from it would look unclickable and be invisible to the
   tab key. This is the interactive variant. */
.chat-chip {
  min-height: 44px;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-chip);
  border: 1px solid var(--tone-info-bd);
  background: var(--tone-info-bg);
  color: var(--tone-info-fg);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.chat-chip:hover { border-color: var(--accent); }
.chat-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  max-width: var(--chat-measure);
}

.chat-input { flex: 1; resize: vertical; min-height: 44px; }
.chat-composer button { min-height: 44px; }

.chat-disclaimer {
  max-width: var(--chat-measure);
  margin: 0.6rem 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.chat-head-actions .clear-confirm { margin: 0; }

/* This feature adds the product's first sustained motion, so it also adds the
   stylesheet's first reduced-motion block. The streaming text itself stays —
   that is content arriving, not decoration. */
@media (prefers-reduced-motion: reduce) {
  .chat-thinking .spinner { animation: none; }
  .chat-panel * { transition: none !important; }
}

@media (max-width: 640px) {
  .chat-panel { --chat-measure: 100%; }
  .chat-bubble { max-width: 100%; }
  .chat-composer { flex-direction: column; align-items: stretch; }
}

/* Empty, error and not-found states — every one in the product, from one
 * renderer (renderState in app.js). Painted with --bg-raised plus a hairline
 * --border rather than --accent-soft: on the twotheta theme --accent and
 * --danger are the same hex, so an accent tint reads as an error. The kind modifiers move
 * only the border, so nothing here depends on colour alone. */
.state-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-5);
  background: var(--bg-raised);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
}

.state-title {
  font-family: var(--font-display);
  font-size: var(--text-4);
  font-weight: 600;
  color: var(--brand-emphasis);
}

.state-body {
  font-size: var(--text-3);
  color: var(--text-muted);
  line-height: 1.55;
  max-width: 56ch;
}

.state-block--error { border-color: var(--tone-bad-bd); }
.state-block--missing { border-color: var(--tone-warn-bd); }
.state-block .link-button { font-size: var(--text-3); }


/* ============================================================ Product shell */

/* body is a flex column and `main { flex: 1 }` is what pins the footer to the
   bottom. Inserting this wrapper between them moves that flex into a horizontal
   context, so .app-body has to claim the vertical space itself or the footer
   floats up on every short view — which is every view with little content. */
.app-body {
  flex: 1;
  display: flex;
  align-items: flex-start;
  min-height: 0;
}

.app-nav {
  flex: 0 0 232px;
  width: 232px;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-6) var(--space-3);
  border-right: 1px solid var(--border);
  /* A document view runs several screens deep. Without this the only route back
     to the dashboard is scrolling to the top. */
  position: sticky;
  top: 0;
  align-self: stretch;
}

.nav-item {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-3);
  font-weight: 600;
  text-decoration: none;
}

.nav-item:hover { color: var(--text); background: var(--bg-raised); }
.nav-item[aria-disabled="true"], .nav-item[aria-disabled="true"]:hover { color: var(--text-muted); background: transparent; cursor: default; }
.nav-coming-soon { margin-left: auto; padding-left: var(--space-2); font-size: var(--text-1); font-weight: 400; white-space: nowrap; }

/* Current section, marked with weight and a rule as well as colour. */
.nav-item[aria-current="page"] {
  color: var(--brand-emphasis);
  background: var(--bg-raised);
  box-shadow: inset 2px 0 0 var(--brand-rule);
}

.view-title {
  font-family: var(--font-display);
  font-size: var(--text-7);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--brand-emphasis);
  margin-bottom: var(--space-5);
}

/* Secondary by design — see the comment in index.html. */
.header-action {
  font: inherit;
  font-size: var(--text-2);
  font-weight: 600;
  color: var(--header-text);
  background: transparent;
  border: 1px solid currentColor;
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-4);
  min-height: 34px;
  cursor: pointer;
}

.header-action:hover { background: rgba(127, 127, 127, 0.14); }

.documents-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.documents-search { max-width: 22rem; }

.documents-cap {
  font-size: var(--text-2);
  color: var(--text-muted);
}

/* -------------------------------------------------------- upload dialog --- */

.upload-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  color: var(--text);
  padding: 0;
  width: min(38rem, 92vw);
  /* The UA centres a modal dialog with margin: auto; the global * reset zeroes
     it, which pins the dialog to the top-left corner. */
  margin: auto;
}

.upload-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

.upload-dialog-body { padding: var(--space-6); }

.upload-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}

.upload-dialog-head h2 { font-size: var(--text-5); font-weight: 700; }

.doc-type-disclosure { margin-top: var(--space-5); }

.upload-confidential {
  margin-top: var(--space-5);
  font-size: var(--text-2);
  color: var(--text-muted);
  line-height: 1.5;
}

/* --------------------------------------------- the citation moment (eng-3) - */

/*
 * viewer.js ALREADY toggles body.viewer-open — it adds it in openViewer and
 * removes it in closeViewer, including on the failed-sidecar and failed-pdf.js
 * branches. It just never had a CSS rule. So making the page reflow instead of
 * being covered is this block, not new cross-module state.
 *
 * The widths matter. At the viewer's normal min(46rem, 50vw) a 1440px screen
 * leaves 1440 - 720 - 232 - 80 = 408px of content, which is not a readable
 * evidence table — it would be worse than the overlay it replaces. Narrowing the
 * drawer and dropping the rail while it is open gives ~780px at 1440 and ~690px
 * at 1280, which is.
 *
 * Below 800px the viewer is full-screen and none of this applies.
 */
@media (min-width: 800px) {
  body.viewer-open .doc-viewer { width: min(34rem, 40vw); }
  body.viewer-open .app-body { margin-right: min(34rem, 40vw); }
  body.viewer-open .app-nav { display: none; }
}

/* --------------------------------------------------------------- a11y ----- */

/* The stylesheet defines :focus-visible on about a dozen selectors individually
   and has no global fallback, so anything new lands on the UA outline — which on
   a coloured header band may have poor contrast. */
.nav-item:focus-visible,
.header-action:focus-visible,
.documents-search:focus-visible,
.state-block .link-button:focus-visible,
#upload-dialog-close:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

@media (max-width: 800px) {
  .app-body { flex-direction: column; }
  .app-nav {
    position: static;
    flex-direction: row;
    width: 100%;
    flex: 0 0 auto;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
  }
  main { padding: var(--space-6) var(--space-5) 3rem; width: 100%; }
}

.document-state { margin-bottom: var(--space-5); }

/* ================================================================ Dashboard */

/* The lede. A sentence, not a grid — a row of tiles is the shape every
   document-workflow product ships, and prose carries the corpus caveat in a way
   a small grey sub-label does not. */
.dash-lede {
  font-family: var(--font-display);
  font-size: var(--text-5);
  line-height: 1.5;
  max-width: 62ch;
  margin-bottom: var(--space-3);
  /* The same mark .about-lede carries. A rule, not a fill — see --brand-rule. */
  border-left: 3px solid var(--brand-rule);
  padding-left: var(--space-5);
}

.dash-figure {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--brand-emphasis);
}

.dash-caveat {
  font-size: var(--text-2);
  color: var(--text-muted);
  max-width: 62ch;
  margin-bottom: var(--space-7);
  padding-left: calc(var(--space-5) + 3px);
}

/* Four columns, fixed. Tiles hide rather than render zero, so the count varies
   across states; a grid that stretches to fill would change tile width with the
   corpus. A short last row left-aligns instead. */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-7);
}

/* --bg-raised plus a hairline border, never --accent-soft: on the twotheta
   theme --accent IS --danger, so an accent tint reads as an error. NO ICONS in
   tiles — a decorative glyph in a stat card is the clearest tell that a
   dashboard came from a template. */
.tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-5);
  background: var(--bg-raised);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  min-width: 0;
  text-decoration: none;
  color: inherit;
}

.tile-label {
  font-size: var(--text-2);
  color: var(--text-muted);
  font-weight: 600;
}

.tile-value {
  font-family: var(--font-display);
  font-size: var(--text-7);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--brand-emphasis);
}

.tile-sub {
  font-size: var(--text-1);
  color: var(--text-muted);
  line-height: 1.4;
}

/* Clickability has to be visible BEFORE interaction — hover does not exist on
   touch, and half this grid navigates while half does not. */
.tile--link { position: relative; }
.tile--link:hover { border-color: var(--brand-emphasis); }
.tile-chevron {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  font-size: var(--text-2);
  color: var(--text-muted);
}
.tile--link:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

.dashboard-imports { margin-bottom: var(--space-7); }
.dashboard-imports h2 { margin: 0 0 var(--space-3); font-size: var(--text-3); }
.dashboard-imports-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.dashboard-import-title { font-weight: 600; padding-right: var(--space-5); }
@media (max-width: 640px) { .dashboard-imports-grid { grid-template-columns: minmax(0, 1fr); } }

/* -------------------------------------------------------- provenance card - */

.prov-card,
.controls-card,
.recent-card {
  background: var(--bg-raised);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
}

.prov-title {
  font-family: var(--font-display);
  font-size: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 700;
  color: var(--brand-emphasis);
  margin-bottom: var(--space-5);
}

/* One bar, four segments. As four separate tiles the requirement that they sum
   to `quoted` is asserted and the reader has to do the addition; as a bar it is
   simply visible. Each segment is labelled with a swatch AND a number AND a
   word in the key below, so nothing here is carried by colour alone. */
.prov-bar {
  display: flex;
  height: 14px;
  border-radius: var(--radius-chip);
  overflow: hidden;
  background: var(--bg-panel);
  margin-bottom: var(--space-5);
}

.prov-seg { display: block; min-width: 3px; }
.prov-seg--ok   { background: var(--tone-good-fg); }
.prov-seg--info { background: var(--tone-info-fg); }
.prov-seg--warn { background: var(--tone-warn-fg); }
.prov-seg--mute { background: var(--text-muted); }

.prov-key {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.prov-key-item {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-size: var(--text-2);
}

.prov-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: 0 0 10px;
  align-self: center;
}
.prov-swatch--ok   { background: var(--tone-good-fg); }
.prov-swatch--info { background: var(--tone-info-fg); }
.prov-swatch--warn { background: var(--tone-warn-fg); }
.prov-swatch--mute { background: var(--text-muted); }

.prov-key-n {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.prov-key-label { color: var(--text-muted); }

/* The outer ratio. Without it `quoted` is the model's own answered subset being
   used as a denominator, and the fields it declined to quote never appear. */
.prov-outer {
  font-size: var(--text-2);
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 62ch;
}

.controls-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  font-size: var(--text-3);
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 70ch;
}

.recent-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.recent-head .prov-title { margin-bottom: 0; }

@media (max-width: 1100px) {
  .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .tile-grid { grid-template-columns: minmax(0, 1fr); }
  .dash-lede { font-size: var(--text-4); }
}

.roadmap-badge {
  display: inline-block;
  font-size: var(--text-1);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tone-info-fg);
  border: 1px solid var(--tone-info-bd);
  border-radius: var(--radius-chip);
  padding: 0 var(--space-2);
  margin-right: var(--space-2);
}

.status-chip.is-exceptions { color: var(--tone-warn-fg); }

.prov-framing {
  font-size: var(--text-3);
  color: var(--text);
  line-height: 1.55;
  max-width: 66ch;
  padding-left: var(--space-4);
  border-left: 2px solid var(--card-border);
  margin-bottom: var(--space-4);
}

/* Default: the label IS the item, the glyph is redundant. Declared BEFORE the
   media query below — a bare rule placed after it would win on source order at
   equal specificity and leave the icon-only rail with empty items. */
.nav-glyph { display: none; }

/* Between 800 and 1100 the rail costs more than it is worth. A 232px rail plus
   padding leaves a 1024px laptop with ~712px of content, against the ~942px the
   page had before this change — the document view would get NARROWER on the
   most likely demo machine. Icons recover most of it. */
@media (min-width: 800px) and (max-width: 1100px) {
  .app-nav { flex: 0 0 64px; width: 64px; padding: var(--space-6) var(--space-2); }
  .nav-item { justify-content: center; padding: var(--space-2); }
  .nav-label { display: none; }
  .nav-coming-soon { display: none; }
  .nav-glyph { display: block; font-size: var(--text-5); }
  main { padding: var(--space-6) var(--space-5) 4rem; }
}


/* The receipt header only exists on paper. */
.receipt-head { display: none; }

@media print {
  /* Chrome, navigation and anything actionable is noise on paper. */
  .site-header,
  .app-nav,
  .site-footer,
  .review-bar,
  .upload-dialog,
  .doc-viewer,
  .login-overlay,
  #json-panel,
  #chat-panel,
  .citation-bar,
  .send-note { display: none !important; }

  /* Print whichever view is open, without the shell's two-column layout. */
  .app-body { display: block; margin-right: 0 !important; }
  main { max-width: none; padding: 0; }

  .receipt-head { display: block; margin-bottom: var(--space-5); }
  .receipt-meta { font-weight: 700; font-size: var(--text-4); }
  .receipt-note {
    font-size: var(--text-1);
    color: #444;
    max-width: 60ch;
    margin-top: var(--space-2);
  }

  /* Disclosures are opened by the print handler; drop the caret so they read as
     sections rather than as controls nobody can click on paper. */
  .disclosure-summary::before { display: none; }
  .disclosure,
  .panel,
  .prov-card,
  .controls-card,
  .recent-card {
    border-color: #ccc;
    break-inside: avoid;
  }

  /* A sixty-row field table splits across pages; keep rows whole and repeat the
     header so page two is still readable. */
  .field-table thead { display: table-header-group; }
  .field-table tr { break-inside: avoid; }

  a[href]::after { content: ""; }
  * { background: #fff !important; color: #000 !important; }
  .cite-text mark { background: #ffe9a8 !important; }
}

/* An automatic check that could not run is not the reader's doing — most often
   the document's stored page text has simply aged out. Muted, not an error. */
.verify-note--muted { color: var(--text-muted); }
.mail-settings { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; width: 100%; max-width: 800px; margin: 24px 0; }
.mail-settings fieldset { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 20px; min-width: 0; background: var(--bg-raised); }
.mail-settings[hidden] { display: none; }
.mail-provider-guides { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; max-width: 800px; }
.mail-provider-guides > div { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-raised); }
.mail-provider-guides h3 { margin: 0 0 8px; font-size: 0.95rem; }
.mail-provider-guides p { margin: 0; font-size: 0.9rem; color: var(--text-muted); line-height: 1.6; }
.mail-full-width { grid-column: 1 / -1; }
.mail-imap-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.mail-imap-fields[hidden] { display: none; }
@media (max-width: 680px) { .mail-provider-guides, .mail-imap-fields { grid-template-columns: minmax(0, 1fr); } }
.mail-settings label[hidden] { display: none; }
.mail-settings legend { padding: 0 6px; font-weight: 600; }
.mail-settings label { display: grid; grid-template-columns: minmax(0,1fr); align-content: start; gap: 8px; min-width: 0; font-size: 0.9rem; }
.mail-settings .mail-checkbox { display: flex; align-items: flex-start; gap: 10px; }
.mail-checkbox input { flex: 0 0 auto; margin-top: 3px; }
.mail-settings .field-input { width: 100%; min-width: 0; max-width: 100%; min-height: 42px; }
.mail-settings .mail-notifications { grid-template-columns: minmax(0,1fr); }
.mail-settings small { color: var(--text-muted); line-height: 1.6; }
.mail-actions, .mail-form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.mail-actions { margin: 20px 0; }
.mail-actions button, .mail-form-actions button { min-height: 42px; max-width: 100%; white-space: normal; }
@media (max-width: 680px) { .mail-settings fieldset { grid-template-columns: minmax(0,1fr); padding: 16px; } }
#mail-activity { overflow-x: auto; margin-top: 16px; }
#mail-activity td p { margin: 6px 0 0; font-size: 0.85rem; color: var(--text-muted); }
#mail-activity td:nth-child(3) { min-width: 180px; }
#mail-counts { color: var(--text-muted); }
#mail-notice:not(:empty), #mail-summary:not(:empty) { border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin: 16px 0; overflow-wrap: anywhere; }

/* Drive follows the existing import controls and brand tokens. */
#drive-notice:not(:empty), #drive-summary:not(:empty) {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; margin: 16px 0; overflow-wrap: anywhere;
}
.drive-browser { border: 1px solid var(--border); padding: 16px; border-radius: var(--radius-sm); margin: 12px 0; background: var(--bg-raised); }
.drive-folder, .drive-selected li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.drive-folder { justify-content: flex-start; }
.drive-folder label { display: flex; gap: 10px; align-items: center; min-width: 0; }
.drive-folder button, .drive-selected button { flex-shrink: 0; }
.drive-selected { padding: 0; list-style: none; }
#drive-breadcrumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
#drive-browser summary { cursor: pointer; padding: 12px 0; }
#drive-activity { overflow-x: auto; margin-top: 16px; }
.drive-table { border-collapse: collapse; width: 100%; text-align: left; }
.drive-table th, .drive-table td { border-bottom: 1px solid var(--border); padding: 12px; vertical-align: top; overflow-wrap: anywhere; }
.drive-table td:first-child { min-width: 180px; }
.drive-table td:last-child { min-width: 120px; }
#drive-counts { color: var(--text-muted); }
.drive-activity-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 12px 0; }
.drive-activity-filters .field-input { width: auto; max-width: 100%; min-height: 42px; }
@media (max-width: 680px) { .drive-folder, .drive-selected li { flex-wrap: wrap; } .drive-provenance { font-size: 0.9rem; } }
