/*
 * DF26 Community Code — avatar picker + name entry.
 *
 * Two screens, styled to echo the Salesforce look (no SLDS/TDS here): light
 * background, centered container, Salesforce-blue Neutraface-ish headings.
 * Screen 1 is a responsive grid of circular avatar tiles (select-then-Continue);
 * screen 2 is the first/last name form. Navigation between them animates via the
 * cross-document View Transitions API (see @view-transition below).
 */

:root {
  --sf-ink: #181818;          /* SLDS text color */
  --sf-midnight: #032d60;     /* tds-color_midnight — headings + names */
  --sf-neutral: #706e6b;      /* SLDS neutral-70 — taglines/subheading */
  --sf-border: #dddbda;       /* SLDS card border */
  --sf-bg: #ffffff;           /* page background (white, per designer) */
  --sf-card: #ffffff;

  /* The avatar is the layout's base unit: the grid gap and the heading scale
   * are all derived from it, so tuning one size keeps everything in
   * proportion. */
  --avatar-size: 6rem;       /* 96px */
  /* Two adjacent tiles both scale to 1.18 on hover/select, growing ~0.18× the
   * size toward each other, and each carries a fixed 3–4px focus ring. So the
   * gap = proportional growth + a fixed ring/margin allowance, keeping scaled
   * neighbors clear at any --avatar-size. ~1.8rem at 6rem. */
  --avatar-gap: calc(var(--avatar-size) * 0.24 + 0.4rem);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Salesforce Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  color: var(--sf-ink);
  background: var(--sf-bg);
  min-height: 100vh;
}

/* ── Shared page shell (all screens) ──────────────────────────────────────── */
#avatar-selection,
#name-entry,
#signed-in,
#logged-out {
  max-width: 56rem;
  margin: 0 auto;
  padding: 3rem 1.5rem 6rem; /* bottom room for the sticky Continue bar */
  text-align: center;
}

/* Wide enough for the 6-across avatar grid (69rem) plus the 1.5rem side padding.
 * Total 72rem (1152px) sits comfortably under a 1280px laptop floor; narrower
 * viewports simply wrap the grid to fewer columns. */
#avatar-selection {
  max-width: 72rem;
}

.avatar-selection__heading,
.name-entry__heading {
  margin: 0 0 0.4rem;
  /* Fixed — independent of --avatar-size, so shrinking the avatars doesn't
   * shrink the title. */
  font-size: 2rem;
  line-height: 1.1;
  font-weight: 700;
  color: var(--sf-midnight);
}

.avatar-selection__subheading,
.name-entry__subheading {
  margin: 0 0 calc(var(--avatar-gap) * 1.1);
  font-size: 1rem;
  line-height: 1.3;
  font-weight: 400;
  color: var(--sf-midnight);
}

/* ── Screen 1: avatar grid ────────────────────────────────────────────────── */
/* Flexbox (not grid) so an incomplete final row is centered rather than left-
 * aligned in fixed column tracks. Tiles are fixed-width, so wrapping rows stay
 * evenly spaced and each row — full or partial — centers as a group. */
.avatar-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  /* --avatar-gap is sized (see :root) so two adjacent scaled tiles — a selected
   * one next to a hovered one — stay clear, rings included. */
  gap: var(--avatar-gap);
  /* Cap at exactly 6 tiles wide: 6 avatars + 5 gaps. A 7th can't fit, so rows
   * are 6-across on wide viewports and wrap fewer below. */
  max-width: calc(var(--avatar-size) * 6 + var(--avatar-gap) * 5);
  margin: 0 auto;
}

/* Circular tile buttons — select only (Continue submits). */
.avatar-tile {
  position: relative;
  flex: 0 0 auto;
  width: var(--avatar-size);
  height: var(--avatar-size);
  padding: 0;
  border: 0;
  background: none;
  border-radius: 50%;
  cursor: pointer;
  transform: scale(1);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  /* Staggered load-in so the gallery "assembles". Fade only — animating
   * transform here would keep overriding the :hover/selected scale (a finished
   * `forwards` animation wins over normal declarations in the cascade). */
  opacity: 0;
  animation: tile-in 0.35s ease forwards;
  animation-delay: calc(var(--i, 0) * 18ms);
}

.avatar-tile__img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  filter: saturate(0.9);
  transition: filter 0.15s ease;
}

/* Hover/focus expands the icon; it returns to normal on hover-out. */
.avatar-tile:hover,
.avatar-tile:focus-visible {
  transform: scale(1.18);
  outline: none;
}

.avatar-tile:hover .avatar-tile__img,
.avatar-tile:focus-visible .avatar-tile__img {
  filter: saturate(1);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25), 0 0 0 3px #1b96ff;
}

/* Play the staggered entrance exactly once. `intro-done` is set by JS after the
 * animation finishes (or on first interaction) and never removed, so toggling a
 * selection can't re-trigger the animation (removing a class that gated it would
 * make the browser replay "none → tile-in"). `has-selection` is also matched so
 * a Back-restore render (which loads with a selection) skips the entrance with
 * no flash before JS runs. */
.avatar-grid.intro-done .avatar-tile,
.avatar-grid.has-selection .avatar-tile {
  opacity: 1;
  animation: none;
}

/* When a selection exists, dim the unpicked tiles. */
.avatar-grid.has-selection .avatar-tile:not(.is-selected) {
  opacity: 0.55;
}

/* The selected tile stays expanded even when not hovered. */
.avatar-tile.is-selected {
  transform: scale(1.18);
}

.avatar-tile.is-selected .avatar-tile__img {
  filter: saturate(1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), 0 0 0 4px #1b96ff;
  /* Shared element: this avatar morphs into the name screen's header. */
  view-transition-name: chosen-avatar;
}

/* The corner ✓ badge, shown only on the selected tile. */
.avatar-tile__check {
  position: absolute;
  right: 0.1rem;
  bottom: 0.1rem;
  width: 1.6rem;
  height: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #1b96ff;
  color: #fff;
  font-size: 0.9rem;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.avatar-tile.is-selected .avatar-tile__check {
  opacity: 1;
  transform: scale(1);
}

@keyframes tile-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* No-JS fallback grid: plain submit buttons, always full-color. */
.avatar-grid--noscript .avatar-tile {
  opacity: 1;
  animation: none;
}

/* Continue bar (screen 1) — button hidden until a selection exists.
 * Sticky, not fixed: on a tall screen it sits naturally spaced below the last
 * row; on a short screen where the grid overflows it pins to the viewport
 * bottom so it stays reachable while scrolling. */
.avatar-actions {
  position: sticky;
  bottom: 0;
  margin-top: 2.5rem;
  padding: 1rem 1rem 1.5rem;
  display: flex;
  justify-content: center;
  background: linear-gradient(to top, var(--sf-bg) 65%, rgba(255, 255, 255, 0));
}

/* ── Continue button (both screens) ───────────────────────────────────────── */
.btn-continue {
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  background: #0176d3;      /* Salesforce blue */
  border: 1px solid #0176d3;
  border-radius: 0.25rem;
  padding: 0.75rem 2rem;
  cursor: pointer;
  transition: background 0.1s ease, opacity 0.1s ease, transform 0.1s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.btn-continue:hover:not(:disabled) {
  background: #014486;
  transform: translateY(-1px);
}

/* Disabled: stays visible (both screens) but clearly inactive until the
 * completion condition is met — greyed, no shadow, not-allowed cursor. */
.btn-continue:disabled {
  background: #c9c7c5;
  border-color: #c9c7c5;
  color: #fff;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-continue:focus-visible {
  outline: 2px solid #1b96ff;
  outline-offset: 2px;
}

/* ── Screen 2: name entry ─────────────────────────────────────────────────── */
.name-entry__avatar-wrap {
  margin-bottom: 1.5rem;
}

.name-entry__avatar {
  width: 8rem;
  height: 8rem;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25), 0 0 0 4px #1b96ff;
  /* Matches the selected tile's name so it morphs in from screen 1. */
  view-transition-name: chosen-avatar;
}

.name-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 26rem;
  margin: 0 auto;
  text-align: left;
}

.name-form__label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--sf-neutral);
  margin-top: 0.75rem;
}

.name-form__input {
  font: inherit;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--sf-border);
  border-radius: 0.25rem;
  background: var(--sf-card);
  color: var(--sf-ink);
}

.name-form__input:focus {
  outline: none;
  border-color: #1b96ff;
  box-shadow: 0 0 0 1px #1b96ff;
}

/* Back + Continue sit on one centered row below the fields. */
.name-form__actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.name-form__actions .btn-continue {
  margin-top: 0;
}

/* Secondary "Back to avatar picker" button — neutral, echoes the primary. */
.btn-back {
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  color: var(--sf-midnight);
  background: var(--sf-card);
  border: 1px solid var(--sf-border);
  border-radius: 0.25rem;
  padding: 0.75rem 1.5rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.1s ease, border-color 0.1s ease, transform 0.1s ease;
}

.btn-back:hover {
  background: #f3f2f2;
  border-color: #c9c7c5;
  transform: translateY(-1px);
}

.btn-back:focus-visible {
  outline: 2px solid #1b96ff;
  outline-offset: 2px;
}

.name-entry__error {
  color: #c23934;
  font-weight: 600;
  margin: 0 0 1rem;
}

/* ── Signed-in interstitial (root, live session) ──────────────────────────── */
.signed-in__actions {
  margin-top: 2rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 1rem;
}

.signed-in__actions form {
  margin: 0;
}

/* ── Logged-out confirmation ──────────────────────────────────────────────── */
.logged-out__actions {
  margin-top: 2rem;
  display: flex;
  justify-content: center;
}

/* btn-continue rendered as a link (Start over / Back) needs the underline off. */
a.btn-continue {
  text-decoration: none;
  display: inline-block;
}

/* ── Cross-document View Transitions opt-in ───────────────────────────────── */
@view-transition {
  navigation: auto;
}

/* -------------------------------------------------------------------------- */
/* SAML redirect interstitial + auto-POST (saml_post.erb,                     */
/* persona_interstitial.erb) — same light theme.                              */
/* -------------------------------------------------------------------------- */
.redirecting {
  display: flex;
  align-items: center;
  justify-content: center;
}

.redirect-card {
  text-align: center;
  color: var(--sf-midnight);
  padding: 3rem;
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 1.25rem;
  border: 4px solid rgba(3, 45, 96, 0.2);
  border-top-color: #1b96ff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
