/* ===========================================================================
 * Portal components — the "Assurance Dossier" visual language.
 * ===========================================================================
 * Every value here is a token from `src/design/tokens.generated.css`, which is
 * itself generated from `design/tokens.json`. No literal colours, spacing or
 * durations appear below: `tests/unit/tokens-sync.test.ts` fails the build if a
 * raw hex value does, and the token file is the single source of truth.
 *
 * The three devices that make this not look like every other trust portal
 * (see the design brief §3.1):
 *
 *   1. Layered substrate — depth comes from *material change and rules*, never
 *      from drop shadows. Only the overlay level casts a shadow.
 *   2. The ledger rail — a monospace left gutter carrying item number, date and
 *      status, which makes a document list read as a register rather than a
 *      card grid.
 *   3. The evidence keyline — a verdigris rule present only on asserted
 *      evidence, absent from chrome, so a visitor learns in seconds that a
 *      keyline means "there is a file behind this".
 * =========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-surface-ground);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base-size);
  line-height: var(--text-base-line);
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------------------
 * Chrome — the dark bar. Signals "official record" and frames the light content.
 * ------------------------------------------------------------------------- */
.chrome {
  background: var(--color-surface-void);
  color: var(--color-text-primary);
  /* Text on the void needs the dark theme's foreground, not the light one. */
  color-scheme: dark;
}

.chrome__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-5);
  min-height: 56px;
}

.chrome__brand {
  font-family: var(--font-mono);
  font-size: var(--text-2xs-size);
  letter-spacing: var(--type-allcaps-letter-spacing);
  text-transform: uppercase;
  color: var(--palette-verdigris-400);
}

.chrome__title {
  font-family: var(--font-display);
  font-size: var(--text-md-size);
  margin: 0;
  color: var(--palette-bone-0);
}

.chrome__spacer {
  flex: 1;
}

.chrome__nav {
  font-size: var(--text-sm-size);
}

.chrome__nav a {
  color: var(--palette-bone-200);
  text-decoration: none;
  border-bottom: var(--border-hairline) solid transparent;
  padding-bottom: 2px;
}

.chrome__nav a:hover,
.chrome__nav a:focus-visible {
  border-bottom-color: var(--palette-verdigris-400);
}

/* ---------------------------------------------------------------------------
 * Top navigation — sticky, because the two things a returning visitor came for
 * (sign in, create a portal) should not require scrolling back up to find.
 *
 * The links **wrap** rather than collapsing into a menu button. A hidden menu
 * needs either script or a `:target` hack, and these pages carry no JavaScript
 * at all — wrapping keeps every destination reachable at every width, which is
 * the accessibility property that matters more than the tidier bar.
 * ------------------------------------------------------------------------- */
.chrome--nav {
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: var(--border-hairline) solid var(--color-border-strong);
}

.chrome__home {
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
}

.chrome__links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-5);
}

/* Sign in, set apart from the content links but not competing with the CTA. */
.chrome__signin {
  color: var(--palette-bone-0);
  font-size: var(--text-sm-size);
  text-decoration: none;
  border-bottom: var(--border-hairline) solid transparent;
  padding-bottom: 2px;
}

.chrome__signin:hover,
.chrome__signin:focus-visible {
  border-bottom-color: var(--palette-verdigris-400);
}

.chrome__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
}

/* The bar's own call to action, sized down from the hero's buttons. */
.chrome__cta {
  padding: var(--space-2) var(--space-4);
}

@media (max-width: 720px) {
  .chrome__inner {
    flex-wrap: wrap;
    gap: var(--space-3);
  }

  /* The spacer only exists to push the right-hand group over; once the bar wraps
     it becomes an empty line. */
  .chrome__spacer {
    display: none;
  }
}

/* ---------------------------------------------------------------------------
 * Page frame
 * ------------------------------------------------------------------------- */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-10) var(--space-6) var(--space-13);
}

/* ---------------------------------------------------------------------------
 * Hero — asymmetric, never centred. The ledger sits beside it, not below: the
 * summary is content, not decoration.
 * ------------------------------------------------------------------------- */
.hero {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: var(--space-10);
  align-items: start;
  padding-bottom: var(--space-10);
  border-bottom: var(--border-hairline) solid var(--color-border-hairline);
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
    gap: var(--space-7);
  }
}

.hero__name {
  font-family: var(--font-display);
  font-size: var(--display-lg-size);
  line-height: var(--display-lg-line);
  letter-spacing: var(--type-display-letter-spacing);
  margin: 0 0 var(--space-5);
  text-wrap: balance;
}

.hero__summary {
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
  color: var(--color-text-secondary);
  max-width: var(--type-body-measure);
  text-wrap: pretty;
  margin: 0 0 var(--space-6);
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

/* ---------------------------------------------------------------------------
 * Posture ledger — rows, not stat cards.
 * ------------------------------------------------------------------------- */
.ledger {
  background: var(--color-surface-plane);
  border: var(--border-hairline) solid var(--color-border-hairline);
  border-radius: var(--radius-md);
  padding: var(--space-5) var(--space-5) var(--space-4);
}

.ledger__heading {
  font-family: var(--font-mono);
  font-size: var(--text-2xs-size);
  letter-spacing: var(--type-allcaps-letter-spacing);
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-4);
}

.ledger__row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-2) 0;
  border-bottom: var(--border-hairline) solid var(--color-border-hairline);
  font-family: var(--font-mono);
  font-size: var(--text-sm-size);
  /* Tabular figures so the numbers line up as a column. */
  font-variant-numeric: tabular-nums;
}

.ledger__row:last-child {
  border-bottom: 0;
}

.ledger__key {
  color: var(--color-text-muted);
}

.ledger__value {
  color: var(--color-text-primary);
  text-align: right;
}

/* ---------------------------------------------------------------------------
 * Sections
 * ------------------------------------------------------------------------- */
.section {
  padding-top: var(--density-section-gap);
}

.section__label {
  font-family: var(--font-mono);
  font-size: var(--text-2xs-size);
  letter-spacing: var(--type-allcaps-letter-spacing);
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-3);
}

.section__title {
  font-family: var(--font-display);
  font-size: var(--text-xl-size);
  line-height: var(--text-xl-line);
  margin: 0 0 var(--space-3);
}

.section__lead {
  color: var(--color-text-secondary);
  max-width: var(--type-body-measure);
  margin: 0 0 var(--space-6);
  text-wrap: pretty;
}

/* ---------------------------------------------------------------------------
 * Attestation grid — the rule grid IS the gap; tiles carry no border of their
 * own, so the hairline never doubles up.
 * ------------------------------------------------------------------------- */
.attest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: var(--border-hairline);
  background: var(--color-border-hairline);
  border: var(--border-hairline) solid var(--color-border-hairline);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.attest {
  background: var(--color-surface-plane);
  padding: var(--space-5) var(--space-5) var(--space-6);
  min-height: 148px;
  /* The evidence keyline: a left rule that marks asserted evidence. Transparent
     by default so the material does not shift when it appears. */
  border-left: var(--border-keyline) solid transparent;
}

.attest:hover,
.attest:focus-within {
  border-left-color: var(--color-border-keyline);
  background: var(--color-surface-slab);
}

.attest__line {
  font-family: var(--font-mono);
  font-size: var(--text-2xs-size);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: var(--space-2);
}

.attest__name {
  font-family: var(--font-display);
  font-size: var(--text-lg-size);
  line-height: var(--text-lg-line);
  margin: 0 0 var(--space-3);
}

.attest__status {
  font-family: var(--font-mono);
  font-size: var(--text-xs-size);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Status is never colour-only: each state pairs a colour with a word. */
.status--current { color: var(--color-success-text); }
.status--in-progress { color: var(--color-info-text); }
.status--expired { color: var(--color-critical-text); }

/* ---------------------------------------------------------------------------
 * Document register — a table of rows with a monospace ledger gutter.
 * ------------------------------------------------------------------------- */
.register {
  border: var(--border-hairline) solid var(--color-border-hairline);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface-plane);
}

.register__head,
.register__row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 160px 168px;
  align-items: center;
  gap: var(--space-4);
  padding: var(--density-row-pad-y) var(--density-row-pad-x);
}

.register__head {
  background: var(--color-surface-slab);
  border-bottom: var(--border-strong) solid var(--color-border-strong);
  font-family: var(--font-mono);
  font-size: var(--text-2xs-size);
  letter-spacing: var(--type-allcaps-letter-spacing);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.register__row {
  border-bottom: var(--border-hairline) solid var(--color-border-hairline);
  /* Every document is asserted evidence, so the keyline is the row's identity. */
  border-left: var(--border-keyline) solid var(--color-border-keyline);
}

.register__row:last-child {
  border-bottom: 0;
}

.register__item {
  font-family: var(--font-mono);
  font-size: var(--text-2xs-size);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.register__name {
  font-weight: 500;
  font-size: var(--text-sm-size);
  min-width: 0;
  overflow-wrap: anywhere;
}

.register__meta {
  display: block;
  font-size: var(--text-xs-size);
  color: var(--color-text-muted);
  font-weight: 400;
}

.register__kind,
.register__version {
  font-family: var(--font-mono);
  font-size: var(--text-xs-size);
  color: var(--color-text-secondary);
}

@media (max-width: 720px) {
  .register__head {
    display: none;
  }

  .register__row {
    grid-template-columns: 48px minmax(0, 1fr);
    row-gap: var(--space-2);
  }

  .register__kind,
  .register__version {
    grid-column: 2;
  }
}

/* Access chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-family: var(--font-mono);
  font-size: var(--text-2xs-size);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  border: var(--border-hairline) solid var(--color-border-hairline);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.chip--gated {
  border-color: var(--color-attention-border);
  color: var(--color-attention-text);
}

.chip--public {
  border-color: var(--color-border-keyline);
  color: var(--color-text-accent);
}

.chip__reason {
  display: block;
  font-size: var(--text-2xs-size);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
  font-family: var(--font-sans);
  white-space: normal;
}

/* ---------------------------------------------------------------------------
 * Buttons
 * ------------------------------------------------------------------------- */
.button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-sm-size);
  font-weight: 500;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  /* 24x24 minimum target; these are comfortably larger. */
  min-height: 24px;
}

.button--primary {
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  border: var(--border-hairline) solid var(--color-accent);
}

.button--primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

.button--secondary {
  background: transparent;
  color: var(--color-text-accent);
  border: var(--border-keyline) solid var(--color-border-keyline);
}

.button--secondary:hover {
  background: var(--color-surface-slab);
}

/* ---------------------------------------------------------------------------
 * Empty state — honest, specific, actionable. Never a dead end.
 * ------------------------------------------------------------------------- */
.empty {
  border: var(--border-hairline) solid var(--color-border-hairline);
  border-radius: var(--radius-md);
  background: var(--color-surface-slab);
  padding: var(--space-7) var(--space-6);
  text-align: left;
}

.empty__text {
  margin: 0 0 var(--space-4);
  color: var(--color-text-secondary);
}

/* ---------------------------------------------------------------------------
 * Focus — visible, and never removed without a replacement.
 * ------------------------------------------------------------------------- */
:focus-visible {
  outline: var(--border-focus) solid var(--color-accent-focus-ring);
  outline-offset: var(--border-focus-offset);
}

/* ---------------------------------------------------------------------------
 * Access page — forms.
 *
 * The register above is zero-JavaScript and static; this page is the one place a
 * third-party script (Turnstile) is loaded, because these are the only forms that
 * cause a message to be sent to a stranger. The cost is contained here rather than
 * spent on the page most visitors see.
 * ------------------------------------------------------------------------- */
.page--narrow {
  max-width: 720px;
}

.access__forms {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  margin-bottom: var(--space-5);
}

.card {
  border: var(--border-hairline) solid var(--color-border-hairline);
  border-radius: var(--radius-md);
  background: var(--color-surface-plane);
  padding: var(--space-6);
  margin: 0 0 var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.access__forms .card {
  margin: 0;
}

.card__title {
  margin: 0;
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
}

.card__lead {
  margin: 0;
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  color: var(--color-text-secondary);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field__label {
  font-size: var(--text-sm-size);
  font-weight: 500;
  color: var(--color-text-secondary);
}

.field__input {
  font-family: var(--font-sans);
  font-size: var(--text-base-size);
  line-height: var(--text-base-line);
  color: var(--color-text-primary);
  background: var(--color-surface-plane);
  border: var(--border-hairline) solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  /* 44px target: comfortably above the 24px minimum. */
  min-height: 44px;
  width: 100%;
}

.field__input--code {
  font-family: var(--font-mono);
  letter-spacing: 0.2em;
}

.field__input--area {
  min-height: 88px;
  resize: vertical;
}

/* A file input is a control with its own native chrome, so the padding and the
   fixed height would fight it. Keep the border and let the browser draw the rest. */
.field__input[type='file'] {
  padding: var(--space-2);
  min-height: 0;
  background: var(--color-surface-slab);
  cursor: pointer;
}

.field__input[type='file']::file-selector-button {
  font-family: var(--font-sans);
  font-size: var(--text-sm-size);
  padding: var(--space-2) var(--space-3);
  margin-right: var(--space-3);
  border: var(--border-hairline) solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface-plane);
  color: var(--color-text-primary);
  cursor: pointer;
}

/* Two or three controls side by side on a wide screen, stacked on a narrow one.
   `auto-fit` rather than a media query so it responds to the card's own width. */
.field-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.field__hint {
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  color: var(--color-text-muted);
}

/* The checkbox and its label on one line, with the whole thing a comfortable
   target rather than a bare 13px box. */
.field__check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm-size);
  color: var(--color-text-secondary);
  cursor: pointer;
}

.field__check input {
  width: 18px;
  height: 18px;
  accent-color: var(--color-accent);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.card__actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

/* Delete sits outside the edit form: a destructive submit must not be reachable
   by pressing Enter in a text field, and must not be part of the save payload. */
.card__danger {
  margin: calc(-1 * var(--space-4)) 0 var(--space-6);
  padding: 0 var(--space-6) var(--space-4);
  display: flex;
  justify-content: flex-end;
}

.field__input:focus-visible {
  outline: var(--border-focus) solid var(--color-accent-focus-ring);
  outline-offset: var(--border-focus-offset);
}

.card .button {
  align-self: flex-start;
}

.access__signout {
  margin-top: var(--space-5);
}

.access__back {
  margin-top: var(--space-7);
  font-size: var(--text-sm-size);
}

/* The focused answer form is visually anchored to the register it belongs to, so an
   operator deep in a filtered list can tell which row they opened. */
.card--focused {
  border-left: var(--border-keyline) solid var(--color-accent);
}

.filter {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
  border: var(--border-hairline) solid var(--color-border-hairline);
  border-radius: var(--radius-md);
  background: var(--color-surface-slab);
  padding: var(--space-5);
  margin: 0 0 var(--space-5);
}

.filter .card__actions {
  grid-column: 1 / -1;
}

.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-top: var(--space-5);
  flex-wrap: wrap;
}

.pagination__status {
  font-family: var(--font-mono);
  font-size: var(--text-xs-size);
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------------
 * Controls — the disclosed statement of position.
 *
 * `<details>` gives a real disclosure widget with no JavaScript, which is what
 * keeps this page consistent with the rest of the portal. The marker is left in
 * place: it is the affordance, and hiding it would make a collapsed row
 * indistinguishable from a static one.
 * ------------------------------------------------------------------------- */
.controls__group {
  margin-bottom: var(--space-7);
}

.controls__framework {
  font-family: var(--font-mono);
  font-size: var(--text-xs-size);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  border-bottom: var(--border-hairline) solid var(--color-border-hairline);
  padding-bottom: var(--space-2);
  margin: 0 0 var(--space-3);
}

.control {
  border-bottom: var(--border-hairline) solid var(--color-border-hairline);
}

.control__summary {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2);
  cursor: pointer;
  /* Above the 24px minimum target, so this is comfortable on a phone. */
  min-height: 44px;
}

.control__summary:hover {
  background: var(--color-surface-slab);
}

.control__ref {
  font-family: var(--font-mono);
  font-size: var(--text-xs-size);
  color: var(--color-text-accent);
  min-width: 5.5rem;
  flex: none;
}

.control__title {
  flex: 1 1 auto;
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
}

.control__status {
  flex: none;
  font-size: var(--text-xs-size);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.control__body {
  padding: 0 var(--space-2) var(--space-5) calc(5.5rem + var(--space-3));
}

.control__category {
  font-family: var(--font-mono);
  font-size: var(--text-2xs-size);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-2);
}

.control__answer {
  margin: 0 0 var(--space-3);
  font-size: var(--text-sm-size);
  line-height: var(--text-base-line);
  /* Answers are operator-authored prose; preserve their paragraph breaks so a
     multi-paragraph answer does not collapse into one unreadable block. */
  white-space: pre-wrap;
}

.control__meta {
  margin: 0;
  font-size: var(--text-xs-size);
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------------
 * Notice — status is carried by a word, never by colour alone.
 * ------------------------------------------------------------------------- */
.notice {
  border: var(--border-hairline) solid var(--color-border-hairline);
  border-left: var(--border-keyline) solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-4) var(--space-5);
  margin: 0 0 var(--space-5);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  background: var(--color-surface-slab);
}

.notice > p:first-child {
  margin-top: 0;
}

.notice > p:last-child {
  margin-bottom: 0;
}

.notice--success {
  border-left-color: var(--color-success-text);
  color: var(--color-success-text);
}

.notice--error {
  border-left-color: var(--color-critical-border);
  color: var(--color-critical-text);
}

.notice--info {
  border-left-color: var(--color-info-border);
  color: var(--color-info-text);
}

/* ---------------------------------------------------------------------------
 * Footer
 * ------------------------------------------------------------------------- */
.footer {
  border-top: var(--border-hairline) solid var(--color-border-hairline);
  padding: var(--space-7) var(--space-6) var(--space-10);
  max-width: 1200px;
  margin: 0 auto;
  font-size: var(--text-xs-size);
  color: var(--color-text-muted);
}

.footer__stamp {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Footer links carry the muted ground colour by default, which would leave them
   in the browser's default blue and off the token palette entirely. */
.footer a {
  color: var(--color-text-secondary);
  text-decoration: none;
  border-bottom: var(--border-hairline) solid var(--color-border-hairline);
}

.footer a:hover,
.footer a:focus-visible {
  color: var(--color-text-primary);
  border-bottom-color: var(--color-border-strong);
}

/* Skip link — the first tab stop on every public page. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  padding: var(--space-3) var(--space-4);
  z-index: 10;
}

.skip-link:focus {
  left: var(--space-4);
  top: var(--space-4);
}

/* Honour reduced motion at the component layer too, so nothing animates even if
   a component opts out of the token. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
