/* ============================================================
   M8 WELFARE AND INTEGRITY DASHBOARD
   All selectors emitted by welfare.js, views-welfare.js,
   views-passport.js (identity panel), and live-race.js (band).
   Colors: ONLY tokens.css custom properties.
   --amber used for the welfare elevated state (distinct from --gold,
   which is reserved for honors only).
   Alpha overlays use rgba() of the token's known RGB values (light-warm palette):
     --green   = rgb(233,108,78)   /* coral fill */
     --amber   = rgb(155,94,0)     /* welfare text */
     --crimson = rgb(216,27,96)    /* alert/HR text */
     --muted   = rgb(132,126,108)
   ============================================================ */

/* ============================================================
   WELFARE BAND (live leaderboard row augmentation, F-01/F-04/F-05)
   A 4px inline-start edge band keyed off the state class.
   Color is NEVER the only signal: .welfare-label always accompanies.
   ============================================================ */
.welfare-band {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-inline-start: 10px;
  border-inline-start: 4px solid var(--muted);
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 72px;
  transition: border-color .25s, color .25s, background .25s;
}

.welfare-band.green {
  border-inline-start-color: var(--green);
  color: var(--green);
  background: rgba(233,108,78,.05);
}

.welfare-band.amber {
  border-inline-start-color: var(--amber);
  color: var(--amber);
  background: rgba(181,115,10,.07);
}

.welfare-band.red {
  border-inline-start-color: var(--crimson);
  color: var(--crimson);
  background: rgba(216,27,96,.07);
}

.welfare-band.noSignal {
  border-inline-start-color: var(--muted);
  color: var(--muted);
  background: transparent;
}

/* data-state attribute variant (also applied by JS) */
.welfare-band[data-state="green"]    { border-inline-start-color: var(--green);   color: var(--green);   background: rgba(233,108,78,.05); }
.welfare-band[data-state="amber"]    { border-inline-start-color: var(--amber);   color: var(--amber);   background: rgba(181,115,10,.07); }
.welfare-band[data-state="red"]      { border-inline-start-color: var(--crimson); color: var(--crimson); background: rgba(216,27,96,.07); }
.welfare-band[data-state="noSignal"] { border-inline-start-color: var(--muted);   color: var(--muted);   background: transparent; }

/* no-signal icon (F-05: neutral grey, never red) */
.welfare-band.noSignal::before,
.welfare-band[data-state="noSignal"]::before {
  content: "\25CC"; /* dashed circle */
  font-size: .8em;
  opacity: .7;
}

/* The always-present text label (F-04: never color-only) */
.welfare-label {
  font-family: var(--f-display);
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .03em;
  unicode-bidi: isolate;
}

/* Post-finish welfare-hold badge on red finishers' leaderboard rows */
.welfare-hold-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--crimson);
  background: rgba(216,27,96,.08);
  color: var(--crimson);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
}

/* Recovery countdown number (LTR even in RTL layout, telemetry convention) */
.welfare-countdown {
  font-family: var(--f-mono);
  font-size: .8rem;
  color: var(--crimson);
  unicode-bidi: isolate;
  direction: ltr;
}

/* High contrast: stronger band edge */
@media (prefers-contrast: more) {
  .welfare-band { border-inline-start-width: 6px; }
}

/* Reduced motion: no fade transition on band state changes */
@media (prefers-reduced-motion: reduce) {
  .welfare-band { transition: none; }
}

/* ============================================================
   PRE-RACE CLEARANCE WALL (AC#2, #/welfare/clearance)
   Per-camel card grid with four sequential check rows.
   iframe-embeddable layout for stadium display.
   ============================================================ */
.welfare-clearance {
  padding-block: 32px 64px;
}

.welfare-clearance h1 {
  margin-block-end: 8px;
}

/* iframe-embed layout: fills the viewport fully, used by stadium displays */
/* background pinned to stable dark: --night is now warm-white (light theme token) */
.iframe-embed {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--theater);
  padding: 24px var(--gutter);
  box-sizing: border-box;
}

/* Heat selector */
.clearance-heat-select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  padding: 7px 12px;
  font-size: .9rem;
  margin-block-end: 24px;
}

/* Card grid: one card per camel, auto-fill responsive */
.clearance-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  margin-block-start: 16px;
}

/* Individual camel clearance card */
.clearance-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

.clearance-card__name {
  font-weight: 700;
  color: var(--text-strong);
  font-size: 1rem;
}

.clearance-card__num {
  font-family: var(--f-mono);
  font-size: .8rem;
  color: var(--muted);
  unicode-bidi: isolate;
  direction: ltr;
}

/* Card-level state: allClear = green border, flagged = crimson, pending = amber */
.clearance-card.state--allClear {
  border-color: var(--green);
  background: rgba(233,108,78,.04);
}
.clearance-card.state--flagged {
  border-color: var(--crimson);
  background: rgba(216,27,96,.04);
}
.clearance-card.state--pending {
  border-color: var(--amber);
}

/* Allclear seal (top-end corner) */
.clearance-card.state--allClear::after {
  content: "\2713";
  position: absolute;
  inset-block-start: 10px;
  inset-inline-end: 14px;
  font-size: 1rem;
  color: var(--green);
  font-weight: 900;
}

/* Four sequential check rows */
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: rgba(0,0,0,.04);
}

.check-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .8rem;
  flex-shrink: 0;
}

.check-icon--confirmed {
  background: rgba(233,108,78,.16);
  color: var(--green);
  border: 1px solid var(--green);
}
.check-icon--confirmed::before { content: "\2713"; }

.check-icon--flagged {
  background: rgba(216,27,96,.15);
  color: var(--crimson);
  border: 1px solid var(--crimson);
}
.check-icon--flagged::before { content: "\2717"; }

.check-icon--pending {
  background: rgba(181,115,10,.12);
  color: var(--amber);
  border: 1px solid var(--amber);
}
.check-icon--pending::before { content: "\25CB"; }

.check-label {
  font-size: .82rem;
  color: var(--text);
  flex: 1;
}

.check-value {
  font-size: .78rem;
  font-weight: 600;
}

.check-value--confirmed { color: var(--green); }
.check-value--flagged   { color: var(--crimson); }
.check-value--pending   { color: var(--amber); }

/* High contrast */
@media (prefers-contrast: more) {
  .clearance-card { border-width: 2px; }
  .check-row { border-width: 2px; }
}

/* ============================================================
   POST-RACE WELFARE CERTIFICATE (AC#3)
   Slide-in over the result podium. RTL-aware.
   ============================================================ */

/* Overlay backdrop */
.certificate-overlay {
  position: relative;
  z-index: 10;
}

/* Slide-in animation */
@keyframes cert-slide-in {
  from { transform: translateY(32px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.certificate.slide-in {
  animation: cert-slide-in .38s var(--ease-out, ease-out) both;
}

@media (prefers-reduced-motion: reduce) {
  .certificate.slide-in { animation: none; }
}

/* Certificate card */
.certificate {
  background: linear-gradient(160deg, var(--surface-2), var(--ink));
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 680px;
  margin-inline: auto;
}

.certificate h1 {
  font-size: clamp(1.4rem, 3vw, 2rem);
  margin-block-end: 4px;
}

.certificate__meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  font-size: .84rem;
  color: var(--sand-dim);
}

.certificate__body.card {
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 20px;
  background: rgba(0,0,0,.04);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.certificate__badges {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.certificate__stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.certificate__stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.certificate__stat .v {
  font-family: var(--f-mono);
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-strong);
  unicode-bidi: isolate;
  direction: ltr;
}

.certificate__stat .k {
  font-size: .74rem;
  color: var(--muted);
}

.certificate__recovery-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.certificate__recovery-label {
  font-size: .78rem;
  color: var(--muted);
}

/* SVG recovery curve container */
.certificate__recovery-wrap svg {
  width: 100%;
  height: 80px;
  display: block;
  border-radius: var(--r-sm);
  background: rgba(0,0,0,.04);
}

.certificate__download {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Race Fit badge: gold family as a federation honor (BUILD-SPEC: gold = honors only).
   Selector is intentionally narrowed to the fit-only classes (.badge--gold) so
   the NOT-Race-Fit span (.badge--ghost .badge--race-fit) never receives gold styling. */
.badge--race-fit.badge--gold,
.race-fit.badge--gold {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--gold-deep);
  background: linear-gradient(120deg, rgba(236,138,46,.12), rgba(236,138,46,.05));
  color: var(--gold);
  font-family: var(--f-calig);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .04em;
}

/* Reform story link (F-27: persistent, one-tap, on every welfare-facing view) */
.welfare-reform-link {
  border-block-start: 1px solid var(--line-soft);
  padding-block-start: 12px;
  margin-block-start: 4px;
}

.reform-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  color: var(--sand-dim);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.reform-link:hover {
  color: var(--sand);
}

/* Reform link on leaderboard and identity panel (compact variant) */
.welfare-reform-inline {
  display: block;
  font-size: .72rem;
  color: var(--muted);
  text-align: center;
  padding-block: 4px;
  border-block-start: 1px dashed var(--line-soft);
  margin-block-start: 8px;
}

.welfare-reform-inline a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.welfare-reform-inline a:hover {
  color: var(--sand-dim);
}

/* ============================================================
   CAMEL IDENTITY CREDENTIAL PANEL (F-15, views-passport.js)
   ============================================================ */

/* Section wrapper already uses .identity-credential + .identity-panel */
.identity-panel,
.identity-credential {
  margin-block-start: 32px;
}

/* Credential card uses existing .card + .credential-card selectors */
.credential-card {
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Each identity row: label / value pair */
.identity-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-block-end: 1px solid var(--line-soft);
  font-size: .88rem;
}

.identity-row:last-of-type {
  border-block-end: none;
}

.identity-row__label {
  color: var(--muted);
  font-size: .78rem;
  flex-shrink: 0;
  min-width: 120px;
}

.identity-row__value {
  color: var(--text);
  font-weight: 600;
  text-align: end;
  word-break: break-all;
}

/* Mono for UIDs and registry IDs (always LTR) */
.identity-row__value.num {
  font-family: var(--f-mono);
  unicode-bidi: isolate;
  direction: ltr;
}

/* Pending enrollment: amber, no badge (F-18 enforced) */
.identity-row__value--pending {
  color: var(--amber);
  font-style: italic;
}

/* Verified state */
.identity-row__value--verified {
  color: var(--green);
}

/* QR placeholder (F-15: offline-scan placeholder, never a real QR) */
.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--r-sm);
  background: rgba(0,0,0,.04);
  min-height: 80px;
}

.qr-placeholder__icon {
  font-size: 2rem;
  color: var(--muted);
  line-height: 1;
}

.qr-placeholder__text {
  font-family: var(--f-mono);
  font-size: .68rem;
  color: var(--muted);
  unicode-bidi: isolate;
  direction: ltr;
  word-break: break-all;
  text-align: center;
}

/* Concept note inside the credential card */
.welfare__concept {
  display: block;
  font-size: .72rem;
  color: var(--muted);
  margin-block-start: 8px;
  padding-block-start: 8px;
  border-block-start: 1px dashed var(--line-soft);
}

/* High contrast */
@media (prefers-contrast: more) {
  .identity-row { border-block-end-width: 2px; }
  .qr-placeholder { border-width: 2px; }
  .check-icon--confirmed,
  .check-icon--flagged,
  .check-icon--pending { border-width: 2px; }
}
