/* =================================================================
   NLI Portal — App Shell & Components
   "The Record" — layout primitives, chrome, nav, tables, forms,
   buttons, status treatments. Built entirely from tokens.css custom
   properties: this file introduces NO new colour literals.

   THE GOLD RULE (see tokens.css): brand gold is 2.18:1 on paper and
   fails AA + the 3:1 UI threshold. It appears in exactly one place
   below — .seal-badge — as a FILL under navy text (7.85:1). Every
   other status/accent in this file uses --ok / --danger / --ink-muted
   or gold-ink (TEXT only, never a border/rule on a light surface).
   ================================================================= */

/* ---------- Skip link ---------- */
.skip-link {
  position: absolute;
  left: -999px;
  top: auto;
  z-index: 100;
  background: var(--navy-900);
  color: var(--ink-inverse);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-sm);
}
.skip-link:focus {
  left: var(--s-4);
  top: var(--s-4);
}

/* ---------- Layout primitives ---------- */
.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
.shell-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.view {
  flex: 1;
  min-width: 0;
  padding: var(--s-5) var(--s-4) var(--s-8);
}
.view-inner {
  max-width: var(--shell-w);
  margin: 0 auto;
}
.view:focus-visible {
  outline: none;
}
@media (min-width: 56.25rem) {
  .shell-body { flex-direction: row; }
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--navy-900);
  color: var(--ink-inverse);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--lift-2);
}
.nav-toggle {
  appearance: none;
  background: transparent;
  border: var(--hair) solid var(--navy-500);
  color: var(--ink-inverse);
  border-radius: var(--r-sm);
  width: 2.25rem;
  height: 2.25rem;
  font-size: var(--t-md);
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.nav-toggle:hover { background: var(--navy-700); }
@media (min-width: 56.25rem) {
  .nav-toggle { display: none; }
}
.wordmark {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  color: var(--ink-inverse);
  text-decoration: none;
  min-width: 0;
}
.wordmark b {
  font-family: var(--font-display);
  font-size: var(--t-md);
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wordmark span {
  font-size: var(--t-xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--navy-300);
  white-space: nowrap;
}
.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  font-size: var(--t-sm);
  color: var(--navy-300);
  white-space: nowrap;
}
.topbar-user b { color: var(--ink-inverse); font-weight: 600; }

/* ---------- Sidebar nav (desktop) / drawer (mobile) ---------- */
.nav {
  position: fixed;
  inset: 0 auto 0 0;
  width: 16rem;
  max-width: 82vw;
  background: var(--navy-800);
  padding: var(--s-6) var(--s-4);
  transform: translateX(-100%);
  transition: transform var(--dur-base) var(--ease-out);
  z-index: 30;
  overflow-y: auto;
}
.nav.is-open { transform: translateX(0); box-shadow: var(--lift-3); }
.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}
.nav-list a {
  display: block;
  padding: var(--s-3) var(--s-3);
  border-radius: var(--r-sm);
  color: var(--navy-300);
  text-decoration: none;
  font-size: var(--t-sm);
  font-weight: 600;
  border-left: 2px solid transparent;
}
.nav-list a:hover { background: var(--navy-700); color: var(--ink-inverse); }
.nav-list a[aria-current="page"] {
  color: var(--ink-inverse);
  background: var(--navy-700);
  border-left-color: var(--blue-500);
}
.nav-scrim {
  position: fixed;
  inset: 0;
  background: rgba(15, 26, 46, 0.5);
  z-index: 25;
}
@media (min-width: 56.25rem) {
  .nav {
    position: static;
    width: 14rem;
    max-width: none;
    flex: none;
    transform: none;
    box-shadow: none;
    padding: var(--s-6) var(--s-3);
  }
  .nav-scrim { display: none; }
}

/* ---------- Notice pages (403 / 404) ---------- */
.notice-page {
  max-width: 34rem;
  margin: var(--s-8) auto;
  text-align: center;
  padding: var(--s-6);
}
.notice-page h1 { font-size: var(--t-xl); margin: var(--s-2) 0 var(--s-3); }
.notice-page p { color: var(--ink-muted); margin: 0 0 var(--s-5); }
.notice-page .label { color: var(--danger); }

/* ---------- States: loading / empty / error ---------- */
.state {
  padding: var(--s-6) var(--s-4);
  text-align: center;
  color: var(--ink-muted);
  border: var(--hair) dashed var(--rule-strong);
  border-radius: var(--r-md);
}
.state p { margin: 0; }
.state-error { border-color: var(--danger); color: var(--danger); }
.state-error .btn { margin-top: var(--s-4); }

/* ---------- Ledger tables ---------- */
.table-wrap { overflow-x: auto; }
table.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sm);
  background: var(--paper-raised);
}
.ledger caption { text-align: left; padding-bottom: var(--s-2); }
.ledger thead th {
  background: var(--paper-sunk);
  text-align: left;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: var(--s-3) var(--s-4);
  border-bottom: var(--hair) solid var(--rule-strong);
}
.ledger thead th.num { text-align: right; }
.ledger tbody tr { border-bottom: var(--hair) solid var(--rule); }
.ledger tbody tr:hover { background: var(--paper-sunk); }
.ledger td {
  padding: var(--s-3) var(--s-4);
  vertical-align: top;
}

/* Mobile-first: rows collapse to labelled record blocks below 900px.
   thead is clipped (not display:none) so it stays in the a11y tree. */
.ledger thead {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.ledger tbody tr {
  display: block;
  padding: var(--s-3) var(--s-4);
}
.ledger td {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s-4);
  padding: var(--s-2) 0;
  text-align: right;
}
.ledger td::before {
  content: attr(data-label);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: left;
  flex: none;
}

@media (min-width: 56.25rem) {
  .ledger thead {
    position: static;
    width: auto; height: auto;
    padding: 0; margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }
  .ledger tbody tr { display: table-row; padding: 0; }
  .ledger td {
    display: table-cell;
    text-align: left;
    padding: var(--s-3) var(--s-4);
  }
  .ledger td::before { content: none; }
  .ledger td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
}

.load-more { display: flex; justify-content: center; margin-top: var(--s-5); }

/* ---------- Status (typographic, not a rainbow of pills) ----------
   Default: small-caps label + a hairline left rule in the semantic
   colour. Only --ok / --danger get a filled-adjacent rule; gold never
   appears here as a rule or border (fails 3:1 on paper). */
.status {
  display: inline-flex;
  align-items: center;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-muted);
  padding-left: var(--s-2);
  border-left: 2px solid var(--rule-strong);
  line-height: 1.3;
}
.status--ok { color: var(--ok); border-left-color: var(--ok); }
.status--danger { color: var(--danger); border-left-color: var(--danger); }

/* The one gold usage in this file: a FILLED pill, navy text on gold
   fill (7.85:1) — legal per the gold rule. Reserved for a verified
   credential / signed agreement / active-registration mark. */
.seal-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-size: var(--t-xs);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--navy-900);
  background: var(--gold-500);
  padding: 0.2rem var(--s-2);
  border-radius: var(--r-sm);
  line-height: 1.4;
}

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--s-2); margin-bottom: var(--s-4); }
.field input,
.field select,
.field textarea {
  font: inherit;
  font-size: var(--t-base);
  padding: 0.6rem 0.75rem;
  color: var(--ink);
  background: var(--paper);
  border: var(--hair) solid var(--rule-strong);
  border-radius: var(--r-sm);
  transition: border-color 140ms var(--ease-out), background 140ms var(--ease-out);
}
.field input:hover, .field select:hover { border-color: var(--navy-400); }
.field input:focus, .field select:focus, .field textarea:focus {
  background: var(--paper-raised);
  border-color: var(--blue-500);
}
.field .hint { font-size: var(--t-xs); color: var(--ink-faint); }
.form-error {
  font-size: var(--t-sm);
  color: var(--danger);
  background: var(--danger-050);
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-4);
  margin: 0 0 var(--s-4);
}

/* ---------- Buttons ---------- */
.actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-3);
  margin-top: var(--s-5);
}
.btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  font-size: var(--t-sm);
  cursor: pointer;
  padding: 0.65rem 1.4rem;
  border-radius: var(--r-sm);
  border: var(--hair) solid transparent;
  transition: background 140ms var(--ease-out), transform 140ms var(--ease-out);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: 0.65; transform: none; }
.btn-primary { background: var(--navy-700); color: var(--ink-inverse); box-shadow: var(--lift-1); }
.btn-primary:hover:not(:disabled) { background: var(--navy-600); }
.btn-quiet { background: transparent; color: var(--ink-muted); border-color: var(--rule-strong); }
.btn-quiet:hover:not(:disabled) { background: var(--paper-sunk); }
.btn-block { width: 100%; }

/* ---------- Toast ---------- */
.toast-region {
  position: fixed;
  bottom: var(--s-4);
  right: var(--s-4);
  left: var(--s-4);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  pointer-events: none;
}
@media (min-width: 56.25rem) {
  .toast-region { left: auto; width: 22rem; }
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  background: var(--navy-900);
  color: var(--ink-inverse);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  box-shadow: var(--lift-3);
  font-size: var(--t-sm);
  animation: toast-in var(--dur-base) var(--ease-out) both;
}
.toast p { margin: 0; }
.toast--error { border-left: 3px solid var(--danger); }
.toast--success { border-left: 3px solid var(--ok); }
.toast-dismiss {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--navy-300);
  font-size: var(--t-md);
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.toast-dismiss:hover { color: var(--ink-inverse); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Auth page (login) — navy frame, paper document card ----------
   Mirrors the approved onboarding prototype's .frame/.doc/.doc-band
   treatment so the two unauthenticated surfaces read as one system. */
.auth-page { background: var(--navy-900); }
.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s-6) var(--s-4);
}
.auth-card {
  width: 100%;
  max-width: 26rem;
  background: var(--paper-raised);
  border-radius: var(--r-lg);
  box-shadow: var(--lift-3);
  overflow: hidden;
  animation: rise var(--dur-slow) var(--ease-out) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
.auth-card-band {
  height: 3px;
  background: linear-gradient(90deg, var(--gold-500) 0%, var(--gold-600) 32%, var(--navy-600) 32%, var(--navy-700) 100%);
}
.auth-card-body { padding: var(--s-6); }
.auth-card-body h1 { font-size: var(--t-xl); margin: var(--s-2) 0 var(--s-3); }
.auth-lede { color: var(--ink-muted); margin: 0 0 var(--s-5); }
.auth-footer {
  margin-top: var(--s-5);
  color: var(--navy-300);
  font-size: var(--t-sm);
  text-align: center;
}
.auth-footer a { color: var(--navy-300); }

/* ---------- Small utilities ---------- */
.view-inner h1 { font-size: var(--t-xl); margin: var(--s-2) 0 var(--s-5); }
.stub-page { max-width: var(--measure); }
.stub-page p { color: var(--ink-muted); }
