/* ═══════════════════════════════════════════════════════════════════════════
   Alluvion — shared brand foundation
   Implements ../../BRANDBOOK.md. Load this BEFORE each app's own styles.css.

   Why this file exists
   --------------------
   Before it, not one of the eleven hex values in BRANDBOOK.md appeared
   anywhere in the frontend. The apps were built from Material Design defaults
   — capture on Indigo 900 (#1a237e), portal and catalog on Blue 900 (#0d47a1),
   so the two halves of the same product did not even match each other — and
   the venture logo in the page banner was drawn in the Synapse parent's navy
   (#0B1E3F) and amber (#F5A623). BRANDBOOK.md:14 exists specifically to say
   the palette must "read distinctly from the Synapse parent (navy + amber)",
   and BRANDBOOK.md:24 notes Iron Ochre is "deliberately quieter than parent
   amber to avoid parent-collision". The implementation was doing the exact
   thing the brandbook was written to prevent.

   Typography note
   ---------------
   BRANDBOOK.md specifies Fraunces / Inter / JetBrains Mono. The app runs under
   a strict CSP (backend/src/index.js: defaultSrc 'self', no fontSrc), so a
   Google Fonts link would be blocked at load — and pulling fonts from a third
   party on every page view of a PHI-adjacent clinical tool is not a trade this
   product should make silently. The stacks below name the brand faces first so
   they are used wherever they are installed locally, and fall back to a close
   system pairing. Self-hosting the webfont binaries under /shared/fonts/ is
   the correct end state and is deliberately deferred, not forgotten.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* ── Core palette (BRANDBOOK.md) ─────────────────────────────────────── */
  --riverbed-slate: #2E4A57;   /* headings, primary UI chrome */
  --silt:           #8FA6A3;   /* secondary UI, borders, chart axes */
  --deep-alluvium:  #1A2B33;   /* body text */
  --iron-ochre:     #B8763A;   /* CTAs, key highlights, chart series */
  --bone:           #F7F4EE;   /* primary background */
  --sandstone:      #E8E1D3;   /* cards, table stripes */
  --ash:            #5C6670;   /* secondary text */
  --fog:            #D9DEE0;   /* dividers */

  --valid:  #4A7C59;
  --warn:   #C99A3A;
  --reject: #9B4A3A;

  /* Derived tints. Kept few and named by role, not by shade. */
  --slate-dark:   #243A44;
  --ochre-dark:   #9C6230;
  --surface:      #FFFFFF;
  --valid-bg:     #EAF1EC;
  --warn-bg:      #F8F1E2;
  --reject-bg:    #F5E9E6;
  --info-bg:      #E9EEF0;

  /* ── Semantic roles ──────────────────────────────────────────────────── */
  --bg:            var(--bone);
  --text:          var(--deep-alluvium);
  --text-muted:    var(--ash);
  --border:        var(--fog);
  --brand:         var(--riverbed-slate);
  --accent:        var(--iron-ochre);

  /* ── Type ────────────────────────────────────────────────────────────── */
  --f-display: Fraunces, 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --f-body: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* ── Scale ───────────────────────────────────────────────────────────── */
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(26, 43, 51, .06), 0 2px 8px rgba(26, 43, 51, .05);
  --focus: 0 0 0 3px rgba(184, 118, 58, .45);
}

/* ── Reset / base ─────────────────────────────────────────────────────── */

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 {
  font-family: var(--f-display);
  color: var(--brand);
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 .6rem;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

code, pre, .mono, [data-mono] { font-family: var(--f-mono); font-size: .875em; }

a { color: var(--ochre-dark); }
a:hover { color: var(--iron-ochre); }

/* ── Focus visibility ─────────────────────────────────────────────────────
   There was previously not a single :focus rule in the entire frontend, and
   most interactive controls sit on saturated backgrounds where the UA default
   outline is invisible. WCAG 2.4.7. */

:focus-visible {
  outline: 2px solid var(--iron-ochre);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
.on-brand :focus-visible,
header :focus-visible {
  outline-color: var(--bone);
}
:focus:not(:focus-visible) { outline: none; }

/* ── Skip link ────────────────────────────────────────────────────────── */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--brand);
  color: var(--bone);
  padding: .65rem 1rem;
  border-radius: 0 0 var(--radius) 0;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus {
  left: 0;
  color: var(--bone);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ── Portfolio endorsement banner ─────────────────────────────────────────
   BRANDBOOK.md:57-63 requires this on every surface, including the mandated
   "Revenue funds neurodevelopment research grants" clause, which the previous
   two-page implementation omitted. The mark is drawn in Alluvion's own
   Riverbed Slate strata with a single Iron Ochre accretion band — not the
   parent's navy and amber. */

.portfolio-banner {
  display: flex;
  align-items: center;
  gap: .875rem;
  flex-wrap: wrap;
  padding: .75rem 1.25rem;
  background: var(--sandstone);
  border-bottom: 1px solid var(--fog);
}
.portfolio-banner .mark { flex: none; width: 40px; height: 40px; }
.portfolio-banner .wordmark {
  font-family: var(--f-display);
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--brand);
  letter-spacing: .01em;
}
.portfolio-banner .endorsement {
  font-size: .75rem;
  color: var(--ash);
  line-height: 1.4;
}
.portfolio-banner .endorsement a { color: var(--ochre-dark); text-decoration: none; }
.portfolio-banner .endorsement a:hover { text-decoration: underline; }

/* ── App chrome ───────────────────────────────────────────────────────── */

header.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  padding: .875rem 1.25rem;
  background: var(--riverbed-slate);
  color: var(--bone);
}
header.app-bar h1 { color: var(--bone); margin: 0; font-size: 1.1875rem; }

nav.app-nav { display: flex; flex-wrap: wrap; gap: .375rem; }
nav.app-nav button {
  font: inherit;
  font-size: .875rem;
  padding: .5rem .875rem;
  min-height: 44px;
  background: transparent;
  color: var(--bone);
  border: 1px solid rgba(247, 244, 238, .3);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
nav.app-nav button:hover { background: rgba(247, 244, 238, .12); }
nav.app-nav button[aria-current="page"] {
  background: var(--bone);
  color: var(--riverbed-slate);
  border-color: var(--bone);
  font-weight: 600;
}

main { padding: 1.25rem; max-width: 1200px; margin: 0 auto; }

section.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.hidden { display: none !important; }
.hint { color: var(--text-muted); font-size: .8125rem; }

/* ── Forms ────────────────────────────────────────────────────────────── */

label { display: block; font-size: .8125rem; font-weight: 600; color: var(--brand); margin-bottom: .3rem; }
.field { margin-bottom: .875rem; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
  width: 100%;
  font: inherit;
  font-size: .9375rem;
  padding: .55rem .7rem;
  min-height: 44px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--silt);
  border-radius: var(--radius-sm);
}
textarea { min-height: 6rem; resize: vertical; }
input:disabled, select:disabled, textarea:disabled, button:disabled {
  opacity: .55;
  cursor: not-allowed;
}
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--reject);
}

button, .btn {
  font: inherit;
  font-size: .9375rem;
  font-weight: 600;
  padding: .6rem 1.1rem;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--iron-ochre);
  color: #fff;
}
button:hover:not(:disabled), .btn:hover { background: var(--ochre-dark); }

button.secondary {
  background: var(--surface);
  color: var(--brand);
  border-color: var(--silt);
}
button.secondary:hover:not(:disabled) { background: var(--sandstone); }

button.link-btn {
  background: none;
  border: none;
  color: var(--ochre-dark);
  text-decoration: underline;
  padding: .35rem .2rem;
  min-height: 44px;
  font-weight: 500;
}
button.link-btn:hover:not(:disabled) { background: none; color: var(--iron-ochre); }

/* ── Status messaging ─────────────────────────────────────────────────── */

[data-status] { font-size: .875rem; margin: .6rem 0 0; padding: .55rem .7rem; border-radius: var(--radius-sm); }
[data-status=""], [data-status="none"] { display: none; }
[data-status="info"]    { background: var(--info-bg);   color: var(--brand);  border-left: 3px solid var(--silt); }
[data-status="success"] { background: var(--valid-bg);  color: #2F5A3C;       border-left: 3px solid var(--valid); }
[data-status="warn"]    { background: var(--warn-bg);   color: #6E5316;       border-left: 3px solid var(--warn); }
[data-status="error"]   { background: var(--reject-bg); color: #7A3428;       border-left: 3px solid var(--reject); }

.disclaimer {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn);
  color: #6E5316;
  padding: .7rem .9rem;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  margin-bottom: 1rem;
}

/* Status pills. Colour alone is never the only signal — each carries a
   leading glyph, per WCAG 1.4.1. */
.badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: .18rem .5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-ok, .badge-validated, .badge-signed, .badge-active, .badge-complete, .badge-delivered {
  background: var(--valid-bg); color: #2F5A3C; border-color: var(--valid);
}
.badge-ok::before, .badge-validated::before, .badge-signed::before,
.badge-active::before, .badge-complete::before, .badge-delivered::before { content: "✓ "; }

.badge-pending, .badge-validating, .badge-processing, .badge-requested,
.badge-in_progress, .badge-pending_signature, .badge-pending_approval, .badge-queued {
  background: var(--warn-bg); color: #6E5316; border-color: var(--warn);
}
.badge-pending::before, .badge-validating::before, .badge-processing::before,
.badge-requested::before, .badge-in_progress::before, .badge-pending_signature::before,
.badge-pending_approval::before, .badge-queued::before { content: "◷ "; }

.badge-failed, .badge-rejected, .badge-expired, .badge-dq_hold,
.badge-too_small, .badge-l_diversity_violation {
  background: var(--reject-bg); color: #7A3428; border-color: var(--reject);
}
.badge-failed::before, .badge-rejected::before, .badge-expired::before,
.badge-dq_hold::before, .badge-too_small::before,
.badge-l_diversity_violation::before { content: "✕ "; }

.badge-not_started, .badge-draft, .badge-received {
  background: var(--info-bg); color: var(--brand); border-color: var(--silt);
}
.badge-not_started::before, .badge-draft::before, .badge-received::before { content: "○ "; }

/* ── Tables ───────────────────────────────────────────────────────────── */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: .875rem; }
caption { text-align: left; font-size: .8125rem; color: var(--text-muted); padding-bottom: .5rem; }
th, td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--border); }
th {
  font-weight: 600;
  color: var(--brand);
  background: var(--sandstone);
  white-space: nowrap;
}
tbody tr:nth-child(even) { background: rgba(232, 225, 211, .35); }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }
td .mono { font-size: .8125rem; color: var(--ash); }

.empty-state {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: .875rem;
  background: var(--sandstone);
  border-radius: var(--radius-sm);
}

/* ── Cards / metrics ──────────────────────────────────────────────────── */

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: .875rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--iron-ochre);
  border-radius: var(--radius);
  padding: .9rem 1rem;
}
.card .metric { font-family: var(--f-display); font-size: 1.75rem; color: var(--brand); font-variant-numeric: tabular-nums; }
.card .metric-label { font-size: .75rem; color: var(--ash); text-transform: uppercase; letter-spacing: .04em; }

/* ── Loading ──────────────────────────────────────────────────────────── */

.loading { color: var(--text-muted); font-size: .875rem; padding: 1rem 0; }
.loading::after {
  content: "";
  display: inline-block;
  width: .7em; height: .7em;
  margin-left: .5em;
  border: 2px solid var(--silt);
  border-top-color: var(--iron-ochre);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -.05em;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .loading::after { animation: none; }
}

/* ── Responsive ───────────────────────────────────────────────────────────
   There was previously not one media query in the product, and the app header
   was a non-wrapping flex row containing an <h1> plus six buttons — on a phone
   the primary navigation simply clipped off-screen and was unreachable. */

@media (max-width: 760px) {
  main { padding: .875rem; }
  section.panel { padding: .9rem; }
  header.app-bar { align-items: flex-start; }
  header.app-bar h1 { font-size: 1.0625rem; }
  nav.app-nav { width: 100%; }
  nav.app-nav button { flex: 1 1 auto; }
  .card-grid { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 1.3rem; }
}

@media (max-width: 420px) {
  .card-grid { grid-template-columns: 1fr; }
  .portfolio-banner { padding: .6rem .875rem; }
}

@media print {
  header.app-bar, nav.app-nav, .portfolio-banner { display: none; }
  section.panel { box-shadow: none; border: none; }
}
