/* The Herein viewer (viewer.js). Its colours come from the page's tokens where
   they exist, with its own fallbacks, so it can be dropped into another page:
   navy for what is selected, pale blue for extracted information, and
   muted amber for the passage it was read from. */

.hv {
  --hv-ink: var(--heading, #1C2633);
  --hv-muted: var(--text-muted, #55606E);
  --hv-line: var(--border, #B5BECA);
  --hv-rule: var(--rule, #7F8B9B);
  --hv-frame: var(--frame, #3A4656);
  --hv-paper: var(--bg, #F6F3EC);
  --hv-sheet: var(--sheet, #FFFFFF);
  --hv-accent: var(--accent, #1B4F8F);
  --hv-pale: var(--extracted, #E1EBF7);
  --hv-amber: var(--source, #F4CC62);
  --hv-amber-line: var(--source-line, #A87412);
  --hv-sans: var(--font-sans, 'Inter', system-ui, sans-serif);
  --hv-serif: var(--font-serif, 'Charter', Georgia, serif);
  --hv-mono: var(--font-mono, ui-monospace, Menlo, monospace);

  position: relative;
  min-height: 24rem;
  overflow: hidden;
  border: 1px solid var(--hv-frame);
  border-radius: 4px;
  background: var(--hv-sheet);
  font-family: var(--hv-sans);
  color: var(--hv-ink);
}

/* ---- the bar across the top ---- */
.hv-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--hv-line);
  background: var(--hv-sheet);
}

.hv-file {
  font-family: var(--hv-mono);
  font-size: 0.75rem;
  color: var(--hv-ink);
}

.hv-label {
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--hv-line);
  border-radius: 3px;
  font-size: 0.74rem;
  color: var(--hv-muted);
}

.hv-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}

.hv-controls:empty {
  display: none;
}

.hv-controls-label {
  margin-right: 0.2rem;
  font-size: 0.78rem;
  color: var(--hv-muted);
}

.hv-button {
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--hv-ink);
  border-radius: 3px;
  background: var(--hv-sheet);
  color: var(--hv-ink);
  font-family: var(--hv-sans);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}

.hv-button:hover:not(:disabled) {
  background: var(--hv-ink);
  color: var(--hv-sheet);
}

.hv-button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---- the Document / Data switch, for narrow screens only ---- */
.hv-switch {
  display: none;
}

/* ---- the two sides ---- */
.hv-body {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
}

.hv-doc {
  padding: 1.75rem;
  background: var(--hv-paper);
  border-right: 1px solid var(--hv-line);
}

.hv-pagenav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.hv-pagenav:empty {
  display: none;
}

.hv-pagenav-at {
  font-family: var(--hv-mono);
  font-size: 0.75rem;
  color: var(--hv-muted);
}

/* The agreement: a page, set in the document's own serif. */
.hv-page {
  padding: 1.75rem 2rem 2rem 1rem;
  background: #FFFFFF;
  border: 1px solid var(--hv-line);
  font-family: var(--hv-serif);
  color: #1C2633;
}

.hv-running-head {
  font-family: var(--hv-mono);
  font-size: 0.66rem;
  color: var(--hv-muted);
  text-align: right;
}

.hv-heading {
  margin-top: 0.9rem;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: center;
}

.hv-subheading {
  font-size: 0.92rem;
  font-variant: small-caps;
  letter-spacing: 0.04em;
  text-align: center;
}

.hv-para {
  position: relative;
  margin-top: 1rem;
  padding-left: 2.25rem;
  font-size: 0.92rem;
  font-style: italic;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.hv-para .hv-marker-doc {
  position: absolute;
  left: 0;
  top: 0.1rem;
}

.hv-table {
  width: 100%;
  margin-top: 0.9rem;
  border-collapse: collapse;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.hv-table th {
  padding: 0 0 0.4rem;
  font-weight: 400;
  font-size: 0.78rem;
  font-style: italic;
  text-align: left;
  border-bottom: 1px solid #D3D8DF;
}

.hv-table td {
  padding: 0.42rem 0;
  overflow-wrap: anywhere;
}

.hv-table th:last-child,
.hv-table td:last-child {
  text-align: right;
}

.hv-table tfoot td {
  padding-top: 0.55rem;
  font-weight: 700;
  border-top: 1px solid #D3D8DF;
}

.hv-margin {
  width: 2.25rem;
}

/* The selected passage, and only that one, carries the amber. */
.hv-mark {
  padding: 0.05em 0.2em;
  margin: 0 -0.2em;
  border-radius: 2px;
  transition: background-color 0.3s ease;
}

.hv [data-block].is-active .hv-mark,
.hv-para.is-active {
  background-color: var(--hv-amber);
}

.hv-para.is-active {
  border-radius: 2px;
}

.hv [data-block]:focus {
  outline: none;
}

.hv [data-block]:focus-visible {
  outline: 2px solid var(--hv-accent);
  outline-offset: 2px;
}

/* Where "Show in document" lands: ringed briefly in the source colour. */
.hv [data-block].is-pointed .hv-mark,
.hv-para.is-pointed {
  animation: hv-point 0.9s ease-out 2;
}

@keyframes hv-point {
  0%   { box-shadow: 0 0 0 0 var(--hv-amber-line); }
  100% { box-shadow: 0 0 0 8px rgba(168, 116, 18, 0); }
}

/* ---- numbered markers, the same on both sides ---- */
.hv-marker {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 1px solid var(--hv-line);
  border-radius: 50%;
  background: var(--hv-sheet);
  color: var(--hv-muted);
  font-family: var(--hv-mono);
  font-size: 0.68rem;
  font-weight: 500;
  font-style: normal;
  line-height: 1;
}

.hv-marker-doc {
  cursor: pointer;
}

.hv-marker-doc:hover {
  border-color: var(--hv-accent);
  color: var(--hv-accent);
}

.hv [data-block].is-active .hv-marker-doc,
.hv-field[aria-pressed="true"] .hv-marker,
.hv-detail-head .hv-marker {
  border-color: var(--hv-accent);
  background: var(--hv-accent);
  color: #FFFFFF;
}

/* ---- the extracted data ---- */
.hv-data {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.5rem 1.5rem 1.75rem;
}

.hv-group-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--hv-ink);
}

.hv-group-context {
  font-weight: 400;
  color: var(--hv-muted);
}

.hv-group-context::before {
  content: '\00b7';
  margin-right: 0.5rem;
}

/* The fields as a table: marker, one column per value, then the source. The
   heading row and the rows share the grid, padding and border width, so the
   columns line up. Written for two values a field, as the example has. */
.hv-fields-head,
.hv-field {
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 1fr) minmax(0, 9.5rem) 4.5rem;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid transparent;
}

.hv-fields-head {
  padding-top: 0;
  padding-bottom: 0.35rem;
  border-bottom-color: var(--hv-line);
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--hv-muted);
}

.hv-fields {
  list-style: none;
  margin: 0;
  padding: 0;
}

.hv-field {
  width: 100%;
  border-bottom-color: var(--hv-line);
  background: var(--hv-sheet);
  color: var(--hv-ink);
  font-family: var(--hv-sans);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}

.hv-field:hover {
  background: var(--hv-paper);
}

.hv-field[aria-pressed="true"] {
  border-color: var(--hv-accent);
  background: var(--hv-pale);
  box-shadow: inset 3px 0 0 var(--hv-accent);
}

.hv-cell {
  min-width: 0;
  overflow-wrap: anywhere;
}

.hv-cell-amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hv-cell-source {
  text-align: right;
  font-family: var(--hv-mono);
  font-size: 0.74rem;
  color: var(--hv-accent);
}

.hv-fields-head .hv-cell-source {
  font-family: var(--hv-sans);
  font-size: inherit;
  color: inherit;
}

/* The currency, as a quiet label before the figure. */
.hv-ccy {
  font-size: 0.78em;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--hv-muted);
}

.hv-flag {
  padding: 0.05rem 0.45rem;
  border: 1px solid var(--hv-amber-line);
  border-radius: 3px;
  font-family: var(--hv-sans);
  font-size: 0.7rem;
  color: #7A5A1A;
  white-space: nowrap;
}

/* What was checked about the extraction as a whole. */
.hv-check-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--hv-line);
}

.hv-check {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: 0.1rem 0.75rem;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--hv-line);
  font-size: 0.86rem;
}

.hv-check-status {
  grid-row: span 2;
  align-self: start;
  justify-self: start;
  padding: 0.05rem 0.45rem;
  border: 1px solid var(--hv-line);
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
}

.hv-check.is-pass .hv-check-status {
  border-color: #9DB7A1;
  color: #2F5B3A;
}

.hv-check.is-missing .hv-check-status {
  color: var(--hv-muted);
}

.hv-check.is-review .hv-check-status {
  border-color: var(--hv-amber-line);
  color: #7A5A1A;
}

.hv-check-label {
  color: var(--hv-ink);
}

.hv-check-detail {
  font-size: 0.8rem;
  color: var(--hv-muted);
}

/* The selected field, set out in full. */
.hv-detail {
  margin-top: auto;
  padding: 1rem 1.1rem 1.1rem;
  border: 1px solid var(--hv-accent);
  border-radius: 4px;
  background: var(--hv-pale);
}

.hv-detail-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--hv-accent);
}

/* The values side by side, the source across the foot. */
.hv-values {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1rem;
  margin: 0.4rem 0 0;
}

.hv-values > .hv-source-row {
  grid-column: 1 / -1;
}

.hv-values > div {
  padding: 0.55rem 0;
  border-bottom: 1px solid rgba(27, 79, 143, 0.18);
}

.hv-values > div:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.hv-values dt {
  font-size: 0.76rem;
  color: var(--hv-muted);
}

.hv-values dd {
  margin: 0.1rem 0 0;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.hv-values .is-primary dd {
  font-size: 1.45rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.hv-source-row dd {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.8rem;
}

.hv-reference {
  font-family: var(--hv-mono);
  font-size: 0.82rem;
  padding: 0 0.25em;
  border-bottom: 2px solid var(--hv-amber-line);
}

.hv-source {
  padding: 0;
  border: none;
  background: none;
  color: var(--hv-accent);
  font-family: var(--hv-sans);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.hv-source::after {
  content: ' \2190';
}

/* ---- loading, empty and failed ---- */
.hv-state {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.5rem;
  min-height: 24rem;
  padding: 2rem;
  text-align: center;
}

.hv-state-title {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--hv-ink);
}

.hv-state-text {
  max-width: 28rem;
  color: var(--hv-muted);
}

.hv[data-state="loading"] .hv-state-title::after {
  content: '\2026';
}

/* ---- focus ---- */
.hv-button:focus-visible,
.hv-field:focus-visible,
.hv-marker-doc:focus-visible,
.hv-source:focus-visible,
.hv-switch-button:focus-visible {
  outline: 2px solid var(--hv-accent);
  outline-offset: 2px;
}

/* ---- narrow screens: one side at a time ---- */
@media (max-width: 760px) {
  .hv-switch {
    display: flex;
    gap: 0;
    margin: 0.75rem 1rem 0;
    border: 1px solid var(--hv-ink);
    border-radius: 999px;
    overflow: hidden;
  }

  .hv-switch-button {
    flex: 1;
    padding: 0.45rem 0.75rem;
    border: none;
    background: var(--hv-sheet);
    color: var(--hv-ink);
    font-family: var(--hv-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
  }

  .hv-switch-button[aria-pressed="true"] {
    background: var(--hv-ink);
    color: var(--hv-sheet);
  }

  .hv-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .hv[data-view="data"] .hv-doc,
  .hv[data-view="document"] .hv-data {
    display: none;
  }

  .hv-doc {
    padding: 1rem;
    border-right: none;
  }

  .hv-page {
    padding: 1.25rem 1rem 1.4rem 0.5rem;
  }

  .hv-margin {
    width: 1.9rem;
  }

  .hv-data {
    padding: 1rem;
  }

  .hv-fields-head,
  .hv-field {
    grid-template-columns: 1.4rem minmax(0, 1fr) auto 3.4rem;
    gap: 0.5rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .hv-controls {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hv-mark,
  .hv-field {
    transition: none;
  }

  .hv [data-block].is-pointed .hv-mark,
  .hv-para.is-pointed {
    animation: none;
    box-shadow: 0 0 0 2px var(--hv-amber-line);
  }
}
