/*
 * Shared layout and form styles for every page. Page-specific rules live in their own files
 * (auth.css, history.css, two-factor.css) and load only where used.
 * Direction: calm public-service form design (GOV.UK Design System as reference): white paper,
 * near-black ink, one file-folder blue for actions, a yellow focus ring that is impossible to miss.
 */

:root {
  --ink: #1f2328;
  --muted: #57606a;
  --paper: #ffffff;
  --surface: #f3f5f7;
  --line: #c4ccd4;
  --primary: #1f4e79;
  --primary-dark: #163a5a;
  --focus: #ffbf47;
  --error: #b3261e;
  --success: #1e6b3a;
  --info: #1f4e79;
  --radius: 4px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}

h1, h2 { line-height: 1.25; margin: 0 0 1rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3125rem; margin-top: 2.5rem; }
p { margin: 0 0 1rem; }

a { color: var(--primary); text-underline-offset: 0.15em; }
a:hover { color: var(--primary-dark); text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 0;
  box-shadow: 0 0 0 5px var(--ink);
}
a:focus-visible { background: var(--focus); color: var(--ink); box-shadow: 0 3px 0 var(--ink); outline: none; }

.visually-hidden {
  position: absolute !important; /* unslop-ignore: accessibility utility must win over component rules */
  width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

.skip-link { position: absolute; left: -999px; top: 0; padding: 0.5rem 1rem; background: var(--focus); color: var(--ink); z-index: 10; }
.skip-link:focus { left: 0; }

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

/* Header and navigation ------------------------------------------------- */

.site-header { background: var(--primary); color: #fff; border-bottom: 4px solid var(--primary-dark); }
.site-header__inner, .site-nav ul { max-width: 52rem; margin: 0 auto; padding: 0 1rem; }
.site-header__inner { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 1.5rem; padding-top: 0.75rem; padding-bottom: 0.5rem; }
.site-header__brand { color: #fff; font-weight: 700; font-size: 1.125rem; text-decoration: none; }
.site-header__brand:hover { color: #fff; text-decoration: underline; }
.site-header__tenant { margin: 0; color: #dfe8f1; }
.site-header__tenant a { color: #fff; margin-left: 0.5rem; }

.site-nav { background: var(--primary-dark); }
.site-nav ul { list-style: none; display: flex; flex-wrap: wrap; gap: 0 1.25rem; }
.site-nav a, .site-nav .link-button { display: inline-block; padding: 0.6rem 0; color: #fff; text-decoration: none; border-bottom: 3px solid transparent; }
.site-nav a:hover, .site-nav .link-button:hover { color: #fff; border-bottom-color: #9fb9d3; }
.site-nav a[aria-current="page"] { border-bottom-color: #fff; font-weight: 600; }
.site-nav li:last-child { margin-left: auto; }
.site-nav form { margin: 0; }

.link-button { font: inherit; background: none; border: 0; padding: 0; cursor: pointer; color: var(--primary); text-decoration: underline; }

/* Page ------------------------------------------------------------------- */

.page { display: block; max-width: 52rem; margin: 0 auto; padding: 2rem 1rem 4rem; }
.page:focus { outline: none; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

/* Messages --------------------------------------------------------------- */

.notice { border-left: 5px solid var(--info); background: var(--surface); padding: 0.75rem 1rem; }
.notice--success { border-left-color: var(--success); }
.notice--error { border-left-color: var(--error); color: var(--ink); }

/* Buttons ---------------------------------------------------------------- */

.button {
  display: inline-block;
  font: inherit; font-weight: 600; line-height: 1.25;
  padding: 0.6rem 1.1rem;
  border: 2px solid var(--primary); border-radius: var(--radius);
  background: var(--primary); color: #fff;
  text-decoration: none; cursor: pointer;
  box-shadow: 0 2px 0 var(--primary-dark);
}
.button:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.button:active { transform: translateY(2px); box-shadow: none; }
.button--secondary { background: var(--paper); color: var(--primary); }
.button--secondary:hover { background: var(--surface); color: var(--primary-dark); }
.button--danger { background: var(--error); border-color: var(--error); box-shadow: 0 2px 0 #7d1a15; }
.button--danger:hover { background: #8f1e18; border-color: #8f1e18; }
.button--small { padding: 0.3rem 0.7rem; font-size: 0.9375rem; }

/* Forms ------------------------------------------------------------------ */

.form { max-width: 32rem; margin-bottom: 2rem; }
.form--wide { max-width: 40rem; }
.field { margin: 0 0 1.5rem; padding: 0; border: 0; }
.field label, .field legend { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.field legend { padding: 0; }
.hint { color: var(--muted); margin: 0 0 0.4rem; font-size: 0.9375rem; }
.field__error { color: var(--error); font-weight: 600; margin: 0 0 0.4rem; }
.field--error { border-left: 4px solid var(--error); padding-left: 0.9rem; }

input[type="text"], input[type="email"], input[type="password"], input:not([type]), textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  padding: 0.5rem 0.6rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
}
textarea { min-height: 6rem; resize: vertical; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--error); }
.input--code { max-width: 9rem; font-size: 1.375rem; letter-spacing: 0.2em; font-variant-numeric: tabular-nums; }

.choice { display: flex; align-items: center; gap: 0.6rem; font-weight: 400; margin: 0.4rem 0; }
.field .choice { font-weight: 400; }
.choice input { width: 1.4rem; height: 1.4rem; margin: 0; accent-color: var(--primary); }

.form__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem; }

.danger-zone { border-top: 1px solid var(--line); padding-top: 1.5rem; }

/* Tables and records ----------------------------------------------------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; margin-bottom: 1.5rem; }
.table th, .table td { text-align: left; vertical-align: top; padding: 0.7rem 0.75rem 0.7rem 0; border-bottom: 1px solid var(--line); }
.table thead th { border-bottom: 2px solid var(--ink); font-size: 0.9375rem; }
.table tbody th { font-weight: 600; }
.table tbody th .muted { font-weight: 400; }
.table__actions { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; }
.table__actions form { margin: 0; }
.table tr.is-active th, .table tr.is-active td { background: var(--surface); }

.badge { display: inline-block; font-size: 0.8125rem; font-weight: 600; padding: 0 0.4rem; border: 1px solid var(--primary); color: var(--primary); border-radius: var(--radius); }

.record { margin: 0 0 2rem; border-top: 1px solid var(--line); }
.record__row { padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
.record dt { font-weight: 600; }
.record dd { margin: 0.2rem 0 0; white-space: pre-line; overflow-wrap: anywhere; }

/* Below 40rem a stacked table shows each row as a block, cells labelled by data-label. */
@media (max-width: 39.99rem) {
  .table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table--stack tr { display: block; padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
  .table--stack th, .table--stack td { display: block; border: 0; padding: 0.1rem 0; }
  .table--stack td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); }
  .table--stack .table__actions { padding-top: 0.5rem; }
}

@media (min-width: 40rem) {
  h1 { font-size: 2rem; }
  .record__row { display: grid; grid-template-columns: 15rem 1fr; gap: 1.5rem; }
  .record dd { margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .button:active { transform: none; }
}
