/**
 * audit — the append-only trail.
 *
 * Shared primitives live in style.css and are reused rather than restated: `.toolbar`,
 * `.scroller`, `.absent`, `.muted`, `.loading`, `.view-error`, `button.primary`.
 * Everything here is scoped to `#view-audit` so no other view inherits it.
 *
 * Three rules from DESIGN.md govern most of what follows:
 *
 *  - The registration offset is the one permitted depth device and it belongs on a
 *    document plate. The register is the document this screen exists to produce, so it
 *    carries the offset and nothing else on the screen does — the filter plate above it
 *    is ruled and ticked instead. The offset is `3px 3px 0 0 var(--ink)` and it is
 *    declared once, so no breakpoint can shrink it.
 *  - Marking Orange is legal at 24px and above. The only orange on this screen is the
 *    Search button's ground, which is `button.primary` from style.css and pairs ink on
 *    orange at 5.3:1. Nothing here adds a second one, and the diff does not spend the
 *    marking signal on a value that used to be something else.
 *  - Mono is for measured values. Stamps, action keys, target ids, uids, field names and
 *    stored values set in mono; every sentence on the screen — including a stated reason
 *    and a stored string running past about six words — sets in Archivo.
 */

/* --------------------------------------------------------------------------
   Head
   -------------------------------------------------------------------------- */

#view-audit h2 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  font-variation-settings: 'wdth' 118;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  margin-bottom: var(--sm);
}

/* Permanence is the screen's whole claim, so it is printed, not implied. */
#view-audit .au-seal {
  display: inline-block;
  margin-bottom: var(--sm);
  padding: 3px 7px;
  border: 1px solid var(--ink);
  font-family: var(--mono);
  font-size: 0.5625rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
}

#view-audit .au-standfirst {
  max-width: 74ch;
  margin-bottom: var(--lg);
  padding-left: var(--md);
  border-left: 2px solid var(--ink);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
}

/* --------------------------------------------------------------------------
   The filter plate
   -------------------------------------------------------------------------- */

#view-audit .au-filters {
  position: relative;
  align-items: flex-end;
  gap: var(--md);
  padding: var(--lg) var(--md) var(--md);
  margin-bottom: var(--md);
  background: var(--paper-lit);
  border: 1px solid var(--rule);
  border-bottom: 2px solid var(--ink);
}

#view-audit .au-fieldset {
  display: flex;
  flex-direction: column;
  flex: 1 1 190px;
  min-width: 0;
}

#view-audit .au-lab {
  margin-bottom: var(--xs);
  font-family: var(--mono);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
}

#view-audit .au-control {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 0.8125rem;
  letter-spacing: -0.01em;
  background: var(--paper);
  border-color: var(--ink-secondary);
}
#view-audit .au-control::placeholder {
  color: var(--ink-secondary);
  font-family: var(--mono);
  font-size: 0.75rem;
}

#view-audit #audit-search {
  height: 40px;
  flex: 0 0 auto;
}

/* Printer's furniture. Drawn with plain borders on a pseudo-free element — never a
   gradient, and never an icon font. */
#view-audit .au-tick {
  position: absolute;
  width: 8px;
  height: 8px;
}
#view-audit .au-tick--tl {
  top: 7px;
  left: 7px;
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}
#view-audit .au-tick--tr {
  top: 7px;
  right: 7px;
  border-top: 1px solid var(--ink);
  border-right: 1px solid var(--ink);
}
#view-audit .au-tick--bl {
  bottom: 7px;
  left: 7px;
  border-bottom: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}
#view-audit .au-tick--br {
  bottom: 7px;
  right: 7px;
  border-bottom: 1px solid var(--ink);
  border-right: 1px solid var(--ink);
}

/* --------------------------------------------------------------------------
   The tally
   -------------------------------------------------------------------------- */

#view-audit .au-tally {
  max-width: 74ch;
  margin: 0 0 var(--md);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--ink-secondary);
}
#view-audit .au-n {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
#view-audit .au-filter {
  white-space: nowrap;
}
#view-audit .au-filter-word {
  margin-right: var(--xs);
}
#view-audit .au-filter .au-n {
  padding: 1px 4px;
  border: 1px solid var(--rule);
}

/* --------------------------------------------------------------------------
   The register. A document plate, and the one registration offset on this screen.
   -------------------------------------------------------------------------- */

#view-audit .au-scroll-note {
  display: none;
  max-width: 62ch;
  margin: 0 0 var(--sm);
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--ink-secondary);
}

#view-audit .au-sheet {
  position: relative;
  margin: 0 3px var(--lg) 0;
  padding-top: var(--md);
  background: var(--paper-lit);
  border: 1px solid var(--rule);
  box-shadow: 3px 3px 0 0 var(--ink);
}

#view-audit .au-register {
  margin-bottom: 0;
  border-top: 0;
  scrollbar-color: var(--ink-secondary) var(--paper-sunk);
}
#view-audit .au-register:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}
/* The scroll affordance stays visible rather than fading in on hover. */
#view-audit .au-register::-webkit-scrollbar {
  height: 10px;
}
#view-audit .au-register::-webkit-scrollbar-track {
  background: var(--paper-sunk);
  border-top: 1px solid var(--rule);
}
#view-audit .au-register::-webkit-scrollbar-thumb {
  background: var(--ink-secondary);
  border: 0;
}

#view-audit #audit-table {
  min-width: 980px;
}
#view-audit #audit-table thead tr {
  background: var(--paper-sunk);
}
#view-audit #audit-table th {
  padding: 10px var(--md);
  border-bottom: 2px solid var(--ink);
  color: var(--ink);
  vertical-align: top;
}
#view-audit #audit-table th:nth-child(1) { width: 12%; }
#view-audit #audit-table th:nth-child(2) { width: 18%; }
#view-audit #audit-table th:nth-child(3) { width: 20%; }
#view-audit #audit-table th:nth-child(4) { width: 14%; }
#view-audit #audit-table th:nth-child(5) { width: 25%; }
#view-audit #audit-table th:nth-child(6) { width: 11%; }

#view-audit .au-th-note {
  display: block;
  margin-top: var(--xs);
  max-width: 22ch;
  font-family: var(--display);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.35;
  text-transform: none;
  white-space: normal;
  color: var(--ink-secondary);
}

#view-audit #audit-table td {
  padding: 12px var(--md);
}
#view-audit .au-row:hover > td {
  background: var(--paper-sunk);
}
#view-audit .au-row--open > td {
  background: var(--paper);
  border-bottom-color: var(--ink);
}

/* --------------------------------------------------------------------------
   When
   -------------------------------------------------------------------------- */

#view-audit .au-when {
  white-space: nowrap;
}
#view-audit .au-date {
  display: block;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
#view-audit .au-time {
  display: block;
  margin-top: var(--xs);
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-secondary);
}

/* --------------------------------------------------------------------------
   Who. A stored actor string, taken apart into the three things it holds.
   -------------------------------------------------------------------------- */

#view-audit .au-identity {
  display: block;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--ink);
  overflow-wrap: anywhere;
}
#view-audit .au-role {
  display: inline-block;
  margin-top: var(--xs);
  padding: 1px 5px;
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.5625rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--ink-secondary);
}
#view-audit .au-uid {
  display: block;
  margin-top: var(--xs);
  font-family: var(--mono);
  font-size: 0.625rem;
  color: var(--ink-secondary);
  overflow-wrap: anywhere;
}

/* --------------------------------------------------------------------------
   Action. The key exactly as the system writes it, and what the route does.
   -------------------------------------------------------------------------- */

#view-audit .au-key {
  display: inline-block;
  padding: 3px 6px;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  overflow-wrap: anywhere;
}
#view-audit .au-action-note {
  display: block;
  margin-top: var(--sm);
  max-width: 30ch;
  font-family: var(--display);
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--ink-secondary);
}

/* --------------------------------------------------------------------------
   Target
   -------------------------------------------------------------------------- */

#view-audit .au-target-table {
  display: block;
  font-family: var(--mono);
  font-size: 0.625rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-secondary);
}
#view-audit .au-target-id {
  display: block;
  margin-top: var(--xs);
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}

/* --------------------------------------------------------------------------
   Why. A person's stated reason — prose, and never clipped.
   -------------------------------------------------------------------------- */

#view-audit .au-why {
  max-width: 44ch;
  font-family: var(--display);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--ink);
  overflow-wrap: break-word;
}

/* --------------------------------------------------------------------------
   Change: the control in the column, the panel underneath
   -------------------------------------------------------------------------- */

#view-audit .au-nochange {
  font-family: var(--mono);
  font-size: 0.6875rem;
}

#view-audit .au-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--sm);
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--ink-secondary);
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-align: left;
  color: var(--ink);
}
#view-audit .au-toggle:hover {
  background: var(--ink);
  color: var(--paper-lit);
  border-color: var(--ink);
}
#view-audit .au-toggle[aria-expanded='true'] {
  background: var(--ink);
  color: var(--paper-lit);
  border-color: var(--ink);
}
#view-audit .au-chevron {
  flex: none;
  transition: transform 120ms linear;
}
#view-audit .au-toggle[aria-expanded='true'] .au-chevron {
  transform: rotate(180deg);
}
#view-audit .au-toggle-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

#view-audit .au-change-hold {
  padding: 0 0 var(--md);
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
}

/* Sticky against the register's own sideways scroll, so an opened change stays on
   screen at 320px instead of sitting off the right edge of a scrolled table. */
#view-audit .au-change {
  position: sticky;
  left: var(--md);
  max-width: 46rem;
  margin-left: var(--md);
  padding: var(--md);
  background: var(--paper-lit);
  border: 1px solid var(--ink);
}

#view-audit .au-change-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sm) var(--md);
  margin: 0 0 var(--md);
  padding-bottom: var(--sm);
  border-bottom: 1px solid var(--rule);
}
#view-audit .au-change-kind {
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
}
#view-audit .au-change-n {
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-secondary);
}

#view-audit .au-change-note {
  max-width: 60ch;
  margin: var(--md) 0 0;
  font-family: var(--display);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--ink-secondary);
}
#view-audit .au-change--verbatim .au-change-note,
#view-audit .au-change--none .au-change-note {
  margin-top: 0;
  color: var(--ink);
}
#view-audit .au-change-note--quiet {
  font-size: 0.75rem;
}

/* --------------------------------------------------------------------------
   The fields of a change. Every side prints its word.
   -------------------------------------------------------------------------- */

#view-audit .au-fields {
  display: block;
  margin: 0;
}
#view-audit .au-field {
  display: grid;
  grid-template-columns: minmax(9rem, 14rem) minmax(0, 1fr);
  gap: var(--xs) var(--md);
  padding: var(--sm) 0;
  border-bottom: 1px solid var(--rule);
}
#view-audit .au-field:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

/* Field names are stored keys and print exactly as stored — never sentence-cased. */
#view-audit .au-field-name {
  margin: 0;
  padding: 2px 0 0;
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--ink);
  overflow-wrap: anywhere;
}

#view-audit .au-field-vals {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--sm) var(--md);
  margin: 0;
  font-family: inherit;
  font-size: inherit;
}

#view-audit .au-v {
  display: block;
  flex: 0 1 auto;
  min-width: 0;
  padding-left: var(--sm);
  border-left: 1px solid var(--rule);
}
#view-audit .au-v--after {
  border-left: 2px solid var(--ink);
}
#view-audit .au-v--same {
  border-left: 1px dashed var(--rule);
}

#view-audit .au-vlabel {
  display: block;
  margin-bottom: 2px;
  font-family: var(--mono);
  font-size: 0.5625rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-secondary);
}

#view-audit .au-val {
  display: block;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
  color: var(--ink);
  overflow-wrap: anywhere;
}
#view-audit .au-v--before .au-val {
  color: var(--ink-secondary);
}
/* A stored string past about six words is prose, whatever field it came out of. */
#view-audit .au-val--prose {
  font-family: var(--display);
  font-size: 0.875rem;
  line-height: 1.5;
  max-width: 46ch;
}
#view-audit .au-val--null {
  font-family: var(--mono);
  color: var(--ink-secondary);
}
#view-audit .au-val--verbatim,
#view-audit .au-verbatim {
  margin: 0;
  padding: var(--sm);
  max-width: 100%;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.6875rem;
  line-height: 1.5;
  color: var(--ink);
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#view-audit .au-verbatim {
  margin-top: var(--sm);
}

#view-audit .au-val-wrap {
  display: block;
}
/* Computed from the stored integer, and marked as a reading rather than a second field. */
#view-audit .au-gloss {
  display: block;
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-secondary);
}
#view-audit .au-gloss::before {
  content: '= ';
}

#view-audit .au-arrow {
  align-self: center;
  font-family: var(--mono);
  font-size: 0.875rem;
  color: var(--ink);
}

/* --------------------------------------------------------------------------
   Loading, empty, failure
   -------------------------------------------------------------------------- */

#view-audit .au-placeholder {
  padding: var(--lg) var(--md);
  font-family: var(--display);
}
#view-audit .au-empty-line {
  max-width: 62ch;
  margin: 0 0 var(--sm);
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--ink);
}
#view-audit .au-empty-line:last-child {
  margin-bottom: 0;
}
#view-audit .au-empty-hint {
  padding-left: var(--sm);
  border-left: 2px solid var(--rule);
  font-size: 0.875rem;
  color: var(--ink-secondary);
}

#view-audit .au-error-note {
  max-width: 62ch;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--ink);
}

/* --------------------------------------------------------------------------
   Foot
   -------------------------------------------------------------------------- */

#view-audit .au-foot {
  max-width: 74ch;
  margin-bottom: var(--lg);
  padding-top: var(--md);
  border-top: 1px solid var(--rule);
}
#view-audit .au-foot-line {
  margin: 0 0 var(--sm);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--ink-secondary);
}
#view-audit .au-foot-line:last-child {
  margin-bottom: 0;
}

/* --------------------------------------------------------------------------
   Narrow. Reviewers, ops and finance read this screen from phones in the field.
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  #view-audit .au-scroll-note {
    display: block;
  }
  #view-audit .au-filters {
    gap: var(--sm) var(--md);
  }
  #view-audit .au-fieldset {
    flex: 1 1 100%;
  }
  #view-audit #audit-search {
    width: 100%;
  }
  #view-audit .au-change {
    max-width: calc(100vw - 96px);
    margin-left: var(--sm);
    left: var(--sm);
  }
}

@media (max-width: 480px) {
  #view-audit h2 {
    font-size: 1.625rem;
  }
  #view-audit .au-standfirst {
    padding-left: var(--sm);
  }
  #view-audit .au-change {
    max-width: calc(100vw - 64px);
    padding: var(--sm);
  }
  #view-audit .au-field {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--xs);
  }
  #view-audit .au-field-vals {
    gap: var(--sm);
  }
  #view-audit .au-arrow {
    align-self: flex-start;
  }
}
