/* Design system (T036, constitution III).
 *
 * One stylesheet, token-driven, no per-view CSS. Accessibility properties are
 * design decisions here, not fixes: every text/background pair clears WCAG AA
 * 4.5:1, focus is always visible, and touch targets are ≥44px because
 * signatures are collected on a tablet in the coaching room (FR-050).
 */

:root {
  /* Contrast-checked pairs. --ink on --paper: 15.8:1. --muted on --paper: 6.4:1.
   * White on --primary: 8.2:1. --danger-ink on --danger-bg: 7.9:1. */
  --paper: #ffffff;
  --surface: #f4f5f7;
  --ink: #16202b;
  --muted: #4d5a68;
  --line: #c9d1d9;
  --primary: #1a4c8b;
  --primary-hover: #143c6e;
  --danger-ink: #8c1c2e;
  --danger-bg: #fbeef0;
  --ok-ink: #1d5c34;
  --ok-bg: #ecf6ef;
  --warn-ink: #7a4a09;
  --warn-bg: #fdf3e3;
  --focus: #b45309;

  --radius: 6px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.5rem;
  --content-width: 68rem;
}

* { box-sizing: border-box; }

html { font-size: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.55;
  color: var(--ink);
  background: var(--surface);
}

/* ---------------------------------------------------------------- focus.
 * One rule for everything. :focus-visible so mouse clicks stay quiet, but the
 * outline is thick, offset, and high-contrast when the keyboard is driving. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Skip link: first tab stop on every page. */
.skip-link {
  position: absolute;
  left: -999px;
  top: var(--space-2);
  background: var(--ink);
  color: var(--paper);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  z-index: 10;
}
.skip-link:focus { left: var(--space-2); }

/* Screen-reader-only text: present in the accessibility tree, absent from
 * the visual layout. Used where a column needs a name but no visible header. */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --------------------------------------------------------------- layout */
header.site {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.site-bar {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-2) var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--ink); text-decoration: none; }

nav.main ul {
  display: flex; gap: var(--space-2); list-style: none; margin: 0; padding: 0;
  flex-wrap: wrap;
}
nav.main a {
  display: inline-block;
  padding: var(--space-2) var(--space-3);
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--radius);
}
nav.main a:hover { background: var(--surface); }
nav.main a[aria-current="page"] {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 6px;
  text-decoration-thickness: 3px;
  text-decoration-color: var(--primary);
}

main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-3) var(--space-5);
}

h1 { font-size: 1.6rem; margin: 0 0 var(--space-3); }
h2 { font-size: 1.2rem; margin: var(--space-4) 0 var(--space-2); }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

/* --------------------------------------------------------------- tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper);
}
caption {
  text-align: left;
  font-weight: 700;
  padding: var(--space-2) 0;
}
th, td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: var(--surface); }

/* ---------------------------------------------------------------- forms.
 * Native elements only: they bring keyboard behaviour, mobile keyboards, and
 * screen-reader semantics that a rebuilt control has to reconstruct. */
form.stack { display: grid; gap: var(--space-3); max-width: 34rem; }
.field { display: grid; gap: var(--space-1); }
label { font-weight: 600; }
.hint { color: var(--muted); font-size: 0.9rem; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--muted);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  min-height: 44px;
  width: 100%;
}
input:invalid[aria-invalid="true"], .field-error input { border-color: var(--danger-ink); }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin: 0;
}
legend { font-weight: 700; padding: 0 var(--space-1); }

/* -------------------------------------------------------------- buttons */
button, .button {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--primary);
  color: #ffffff;
}
button:hover, .button:hover { background: var(--primary-hover); }
.button.secondary {
  background: var(--paper);
  color: var(--primary);
  border-color: var(--primary);
}
.button.secondary:hover { background: var(--surface); }

/* -------------------------------------------------------------- badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.badge.neutral { background: var(--surface); color: var(--muted); border-color: var(--line); }
.badge.ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.danger { background: var(--danger-bg); color: var(--danger-ink); }

/* ---------------------------------------------------- messages / errors.
 * role="alert" regions get their colour AND an icon-free textual prefix from
 * the template — colour alone is never the only signal. */
.flash, .errors {
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  border: 1px solid;
}
.flash { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-ink); }
.errors { background: var(--danger-bg); color: var(--danger-ink); border-color: var(--danger-ink); }
.errors ul { margin: var(--space-1) 0 0; padding-left: 1.2rem; }

/* ------------------------------------------------------- unit position */
.position {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.position dt { color: var(--muted); font-size: 0.9rem; margin: 0; }
.position dd { font-size: 1.3rem; font-weight: 700; margin: 0; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------- responsive / touch */
@media (max-width: 44rem) {
  .site-bar { gap: var(--space-2); }
  th, td { padding: var(--space-2); }
  .table-scroll { overflow-x: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
