/* ==========================================================================
   FuneralOS member self-registration — premium onboarding design system.
   Colors are 100% tenant-driven via CSS custom properties (see
   applyThemeFromDataset() in member-register.js, fed by data-theme-* attrs
   which come from _brand_context() in solutions/funeralos/public_views.py).
   Everything else in this file (spacing, radius, shadow, type, motion) is
   the shared premium visual system for every tenant.
   ========================================================================== */

:root {
  --primary-color: #7c1d35;
  --secondary-color: #c9a227;
  --accent-color: #14b8a6;
  --background-color: #08111f;
  --surface-color: #f8fafc;
  --text-color: #0f172a;
  --primary-soft: color-mix(in srgb, var(--primary-color) 12%, white);
  --secondary-soft: color-mix(in srgb, var(--secondary-color) 20%, white);

  /* spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;

  /* radius scale */
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --radius-xl: 32px;

  /* elevation */
  --shadow-sm: 0 6px 16px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 18px 40px rgba(15, 23, 42, 0.14);
  --shadow-lg: 0 28px 70px rgba(2, 6, 23, 0.32);

  /* type scale */
  --fs-xs: 0.78rem;
  --fs-sm: 0.88rem;
  --fs-md: 1rem;
  --fs-lg: 1.15rem;
  --fs-xl: clamp(1.5rem, 2.6vw, 2rem);
  --fs-2xl: clamp(2.1rem, 5vw, 3.6rem);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.portal-body {
  background:
    radial-gradient(circle at 10% 0%, color-mix(in srgb, var(--primary-color) 22%, transparent), transparent 32rem),
    radial-gradient(circle at 92% 30%, color-mix(in srgb, var(--accent-color) 16%, transparent), transparent 34rem),
    var(--background-color);
  color: #fff;
}

body.portal-body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.1;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.35) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(circle at 20% 0%, black, transparent 65%);
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button {
  font-family: inherit;
}

::selection {
  background: color-mix(in srgb, var(--accent-color) 40%, transparent);
}

/* ---------- shell / layout ---------- */

.portal-body {
  padding: var(--sp-6) var(--sp-4) 96px;
}

.portal-shell {
  max-width: 1320px;
  margin: 0 auto;
  display: grid;
  gap: var(--sp-6);
  position: relative;
}

/* Grid items default to min-width:auto, i.e. their content's min-content
   size — a single non-shrinking descendant anywhere inside (long readonly
   URL, a nowrap row, ...) can silently force the whole item, and the page,
   wider than the viewport. min-width:0 lets each item actually shrink to
   the grid track's real (viewport-constrained) width instead. */
.portal-identity,
.portal-hero,
.portal-card {
  min-width: 0;
}

/* Mobile-first stacking: the form (.portal-card) comes right after the
   compact identity header, ahead of the marketing panel (.portal-hero) —
   an applicant on a phone shouldn't have to scroll past a hero image and
   a benefits list before reaching the first field. Desktop restores the
   original hero-left / card-right layout via `order` at 960px below,
   without needing to duplicate any markup. */
.portal-card {
  order: 1;
}

.portal-hero {
  order: 2;
}

@keyframes portal-rise-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.portal-identity,
.portal-hero {
  animation: portal-rise-in 0.55s var(--ease-out) both;
}

/* .portal-card intentionally does NOT keep `both` fill-mode: a lingering
   `transform` (even the identity matrix an animation's final frame leaves
   behind) creates a new containing block for position:fixed descendants.
   That silently broke the mobile sticky .portal-actions bar inside forms —
   it was "fixed" relative to .portal-card instead of the viewport, so it
   scrolled away with the card instead of staying pinned to the bottom.
   Without `both`, the animation still plays once on load but the element
   reverts to its un-animated (transform: none) base style afterwards. */
.portal-card {
  animation: portal-rise-in 0.55s var(--ease-out);
}

.portal-identity,
.portal-hero,
.portal-card,
.success-card {
  border: 1px solid color-mix(in srgb, var(--secondary-color) 26%, rgba(255, 255, 255, 0.08));
  background: rgba(5, 12, 24, 0.72);
  box-shadow: var(--shadow-lg);
}

.portal-identity,
.portal-hero,
.success-card {
  /* .portal-card is intentionally excluded: its own (nearly opaque) surface
     background below makes the blur invisible anyway, and backdrop-filter
     on an ancestor creates a new containing block for position:fixed
     descendants — which broke the mobile sticky .portal-actions bar (it
     was "fixed" relative to .portal-card and scrolled away with it instead
     of staying pinned to the viewport). */
  backdrop-filter: blur(20px);
}

.portal-identity,
.portal-hero,
.portal-card {
  border-radius: var(--radius-xl);
  padding: clamp(24px, 4vw, 40px);
}

/* Slim always-first header (logo + brand name + tagline) — spans the full
   shell width at every size, so the applicant sees who they're registering
   with before anything else, without the rest of the marketing panel
   (benefits/trust/hero image) pushing the form below the fold on mobile. */
.portal-identity {
  grid-column: 1 / -1;
  padding: clamp(18px, 3vw, 28px) clamp(20px, 4vw, 40px);
}

/* ---------- hero (marketing panel — reassurance content, not first on mobile) ---------- */

.portal-badge,
.portal-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--secondary-color);
  background: rgba(255, 255, 255, 0.06);
}

.portal-badge svg,
.portal-eyebrow svg {
  width: 14px;
  height: 14px;
  flex: none;
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  margin-top: var(--sp-5);
}

.portal-logo {
  width: 88px;
  height: 88px;
  border-radius: var(--radius-lg);
  object-fit: cover;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: var(--shadow-sm);
}

.portal-logo-fallback {
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 34px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
}

.portal-title {
  margin: 0;
  font-size: var(--fs-2xl);
  line-height: 1.03;
  letter-spacing: -0.02em;
}

.portal-tagline {
  margin: var(--sp-3) 0 0;
  max-width: 52rem;
  color: rgba(255, 255, 255, 0.76);
  font-size: var(--fs-md);
  line-height: 1.7;
}

.portal-hero-media {
  margin-top: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 260px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.portal-hero-gradient {
  display: grid;
  align-items: end;
  padding: var(--sp-7);
  background:
    linear-gradient(180deg, transparent, rgba(2, 6, 23, 0.88)),
    radial-gradient(circle at top left, color-mix(in srgb, var(--secondary-color) 26%, transparent), transparent 35%),
    linear-gradient(135deg, color-mix(in srgb, var(--primary-color) 50%, #09111f), color-mix(in srgb, var(--accent-color) 30%, #09111f));
}

.portal-hero-copy h2 {
  margin: 0 0 var(--sp-2);
  font-size: var(--fs-xl);
}

.portal-hero-copy p {
  margin: 0;
  max-width: 40rem;
  color: rgba(255, 255, 255, 0.74);
}

.portal-hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* benefit rail — "sell while registering" */

.portal-benefits {
  margin-top: var(--sp-7);
}

.portal-benefits h2,
.portal-support-card h3,
.success-next-steps h2 {
  margin: 0 0 var(--sp-4);
  font-size: var(--fs-lg);
}

.portal-benefits ul,
.success-next-steps ul,
.portal-document-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--sp-3);
}

.portal-benefits li {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  color: rgba(255, 255, 255, 0.84);
  font-size: var(--fs-sm);
}

/* .portal-document-list and .success-next-steps render inside the light
   .portal-card / .success-card surface, unlike .portal-benefits which
   renders in the dark hero — they need dark, not light, body text. */
.portal-document-list li,
.success-next-steps li {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  color: #475569;
  font-size: var(--fs-sm);
}

.portal-benefit-icon,
.portal-document-list li::before {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: #fff;
  flex: none;
}

.portal-benefit-icon {
  background: color-mix(in srgb, var(--accent-color) 30%, transparent);
}

.portal-benefit-icon svg {
  width: 13px;
  height: 13px;
}

.portal-document-list li::before {
  content: "✓";
  font-size: 12px;
  font-weight: 800;
  background: var(--accent-color);
}

.portal-trust {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-6);
}

.portal-trust span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.78);
  font-size: var(--fs-sm);
}

.portal-trust svg {
  width: 13px;
  height: 13px;
  color: var(--accent-color);
}

/* rotating "sell" chip strip */

.portal-sell-strip {
  margin-top: var(--sp-6);
  position: relative;
  height: 34px;
  overflow: hidden;
}

.portal-sell-chip {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: #fff;
  background: color-mix(in srgb, var(--primary-color) 38%, rgba(255, 255, 255, 0.05));
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out);
}

.portal-sell-chip.is-active {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- card (right column / form surface) ---------- */

.portal-card {
  color: var(--text-color);
  background: color-mix(in srgb, var(--surface-color) 95%, white);
}

.portal-card-header,
.portal-beneficiary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

.portal-card-header h2,
.success-card h1 {
  margin: 6px 0 0;
  font-size: var(--fs-xl);
  line-height: 1.1;
  color: #07111f;
}

.portal-save-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-color);
  font-size: var(--fs-sm);
  font-weight: 700;
  white-space: nowrap;
}

.portal-save-status[data-state="saving"] {
  color: #92400e;
  background: #fef3c7;
}

.portal-save-status[data-state="saved"] {
  color: #065f46;
  background: #d1fae5;
}

.portal-save-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}

/* stepper */

.portal-stepper {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
  margin: var(--sp-6) 0 0;
  padding: 0 0 var(--sp-5);
  list-style: none;
  border-bottom: 1px solid #e2e8f0;
}

.portal-progress-track {
  height: 4px;
  border-radius: 999px;
  background: #e2e8f0;
  margin-top: var(--sp-5);
  overflow: hidden;
}

.portal-progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
  transition: width 0.6s var(--ease-out);
}

.portal-step {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #fff;
  border: 1px solid #e2e8f0;
  transition: border-color 0.25s ease, background 0.25s ease;
}

.portal-step-index {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #e2e8f0;
  font-weight: 700;
  font-size: var(--fs-sm);
  flex: none;
  transition: background 0.25s ease, color 0.25s ease;
}

.portal-step.is-active {
  border-color: color-mix(in srgb, var(--primary-color) 40%, #e2e8f0);
  background: var(--primary-soft);
}

.portal-step.is-active .portal-step-index,
.portal-step.is-complete .portal-step-index {
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  color: #fff;
}

.portal-step-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: #0f172a;
}

/* Compact "Personal → Cover → Family → Documents → Review → Complete"
   strip — the outer 6 stages shown at every size (mobile relies on this
   instead of the detailed .portal-stepper; desktop shows both). */
.portal-outer-stepper {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: var(--sp-5) 0 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
}

.portal-outer-stepper::-webkit-scrollbar {
  display: none;
}

.portal-outer-step {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  color: rgba(15, 23, 42, 0.4);
}

.portal-outer-step .portal-step-index {
  width: 24px;
  height: 24px;
  font-size: var(--fs-xs);
  background: #e2e8f0;
}

.portal-outer-step.is-active .portal-step-index,
.portal-outer-step.is-complete .portal-step-index {
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  color: #fff;
}

.portal-outer-step-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  white-space: nowrap;
}

.portal-outer-step.is-active .portal-outer-step-label {
  color: #0f172a;
}

.portal-outer-step:not(:last-child)::after {
  content: "";
  width: 14px;
  height: 1px;
  background: #e2e8f0;
  margin-left: var(--sp-2);
  flex: none;
}

.portal-substep {
  font-weight: 500;
  color: rgba(15, 23, 42, 0.5);
  font-size: 0.8em;
}

.portal-step-intro {
  margin: 0 0 var(--sp-5);
  color: rgba(15, 23, 42, 0.68);
  font-size: var(--fs-md);
}

/* resume / support / copy panels */

.portal-resume,
.portal-support-card,
.portal-copy {
  margin-top: var(--sp-5);
  padding: var(--sp-5);
  border-radius: var(--radius-md);
  background: #fff;
  border: 1px solid #e2e8f0;
}

.portal-resume strong,
.portal-support-card strong {
  display: block;
}

.portal-resume p,
.portal-support-card p,
.portal-copy p,
.success-card p {
  margin: var(--sp-2) 0 0;
  color: #475569;
  line-height: 1.7;
}

.portal-resume-row {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.portal-resume-input {
  margin-top: 0;
  flex: 1;
  /* A flex item's automatic min-width is its content size by default —
     for a text input whose readonly value is a long URL, that let it
     refuse to shrink below ~600px and forced the whole page to overflow
     horizontally on every screen narrower than that. min-width:0 lets
     `flex:1` actually shrink it, and text-overflow below keeps the
     truncated value legible instead of just clipping mid-character. */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-copy-list {
  margin: var(--sp-2) 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.portal-copy-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #475569;
  font-size: var(--fs-sm);
}

.portal-copy-list .portal-step-index {
  width: 24px;
  height: 24px;
  font-size: 11px;
  background: var(--primary-soft);
  color: var(--primary-color);
}

/* ---------- forms / fields ---------- */

.portal-form {
  margin-top: var(--sp-6);
  /* No `both` fill-mode — same containing-block reasoning as .portal-card
     above. .portal-form is the direct ancestor of .portal-actions (the
     mobile sticky CTA bar), so this one matters even more. */
  animation: portal-rise-in 0.4s var(--ease-out);
}

.portal-grid,
.portal-upload-grid,
.success-grid {
  display: grid;
  gap: var(--sp-4);
}

.portal-grid {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

.portal-field {
  position: relative;
}

/* Fields inside .portal-grid get spacing from its `gap` — but the review
   step's digital_signature and signature-pad fields sit directly in
   .portal-form with no grid wrapper, so with no gap of their own they'd
   run flush into each other. That's barely noticeable normally, but once
   an error hint appears below a field (only 6px margin-top) it visually
   crowds right up against the next field's label — easy to misread as
   one broken block instead of two separate fields needing attention. */
.portal-form > .portal-field {
  margin-bottom: var(--sp-5);
}

.portal-field label {
  position: absolute;
  left: 17px;
  top: 17px;
  font-size: var(--fs-md);
  font-weight: 600;
  color: #64748b;
  background: #fff;
  padding: 0 4px;
  pointer-events: none;
  transform-origin: left top;
  transition: transform 0.18s var(--ease-out), color 0.18s ease;
}

/* Selects and native date inputs keep a static label above instead of
   floating. Native date inputs never match :placeholder-shown (they
   don't support a functional placeholder at all), so without this
   exclusion the floating-label rule below would treat them as
   permanently "filled" and float/colour the label even when empty. */
.portal-field:has(select) label,
.portal-field-static label {
  position: static;
  display: block;
  background: none;
  padding: 0 0 8px;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: #0f172a;
  transform: none;
}

.portal-field:not(.portal-field-static):has(input:focus) label,
.portal-field:not(.portal-field-static):has(input:not(:placeholder-shown)) label,
.portal-field:has(textarea:focus) label,
.portal-field:has(textarea:not(:placeholder-shown)) label {
  transform: translateY(-27px) scale(0.82);
  color: var(--primary-color);
}

.portal-input,
.portal-file-input,
textarea.portal-input {
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid #cbd5e1;
  background: #fff;
  padding: 17px 16px;
  font-size: var(--fs-md);
  color: #0f172a;
  outline: none;
  min-height: 52px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select.portal-input {
  padding: 15px 16px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2364748b'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

.portal-input:focus,
.portal-file-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary-color) 14%, white);
}

.portal-field.has-error .portal-input,
.portal-field.has-error .portal-file-input {
  border-color: #e11d48;
  background: #fff1f2;
}

.portal-field-hint {
  display: none;
  margin-top: 6px;
  font-size: var(--fs-xs);
  color: #be123c;
  align-items: center;
  gap: 6px;
}

.portal-field.has-error .portal-field-hint {
  display: flex;
}

.portal-help {
  margin: 10px 0 0;
  color: #64748b;
  font-size: var(--fs-sm);
}

/* mobile OTP verification (Contact step) */

.portal-otp {
  padding: var(--sp-4);
  border-radius: var(--radius-md);
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.portal-otp > label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: #0f172a;
}

.portal-otp-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: center;
  margin-top: var(--sp-3);
}

/* Author styles win over the browser's default [hidden]{display:none} —
   setting `display: flex` unconditionally above means the `hidden`
   attribute JS toggles on this element would otherwise be silently
   ignored and the row would stay visible regardless of its state. */
.portal-otp-row[hidden] {
  display: none;
}

.portal-otp-row .portal-input {
  width: auto;
  flex: 1;
  min-width: 140px;
}

.portal-otp-verified {
  margin: var(--sp-3) 0 0;
  color: #065f46;
  font-weight: 700;
  font-size: var(--fs-sm);
}

.portal-actions,
.portal-inline-actions,
.portal-support-links,
.portal-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: center;
}

.portal-actions {
  position: sticky;
  bottom: 14px;
  margin-top: var(--sp-6);
  padding-top: var(--sp-4);
  background: linear-gradient(180deg, rgba(248, 250, 252, 0), rgba(248, 250, 252, 0.95) 40%);
}

.portal-button,
.portal-link-button {
  appearance: none;
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  font: inherit;
}

.portal-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 22px;
  font-weight: 700;
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.portal-button:active {
  transform: translateY(1px) scale(0.99);
}

.portal-button-primary {
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  color: #fff;
  box-shadow: 0 14px 28px color-mix(in srgb, var(--primary-color) 22%, transparent);
}

.portal-button-primary:hover {
  filter: brightness(1.05);
}

.portal-button-secondary {
  background: #fff;
  color: #0f172a;
  border: 1px solid #cbd5e1;
}

.portal-button-ghost {
  background: var(--primary-soft);
  color: var(--primary-color);
}

.portal-button-chip {
  min-height: 40px;
  padding: 0 16px;
  font-size: var(--fs-sm);
  background: #fff;
  color: var(--primary-color);
  border: 1px dashed color-mix(in srgb, var(--primary-color) 45%, #cbd5e1);
}

.portal-link-button {
  background: none;
  color: var(--primary-color);
  font-weight: 700;
  padding: 6px 4px;
}

.portal-errors,
.portal-field ul.errorlist,
.portal-upload-card ul.errorlist {
  margin: 10px 0 0;
  padding: 12px 14px;
  list-style: none;
  border-radius: var(--radius-sm);
  background: #fff1f2;
  color: #be123c;
  font-size: var(--fs-sm);
}

.portal-field ul.errorlist,
.portal-upload-card ul.errorlist {
  margin-top: 6px;
}

.portal-login-link {
  margin: var(--sp-5) 0 0;
  color: #475569;
}

.portal-login-link a,
.portal-support-links a,
.portal-footer-links a {
  color: var(--primary-color);
  font-weight: 700;
}

/* ---------- beneficiaries: summary cards + quick add + dialog ---------- */

.portal-beneficiary-list {
  display: grid;
  gap: var(--sp-4);
}

.portal-summary-card {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4);
  border-radius: var(--radius-md);
  border: 1px solid #dbe4f0;
  background: #fff;
  box-shadow: var(--shadow-sm);
  animation: portal-rise-in 0.35s var(--ease-out) both;
}

.portal-summary-avatar {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  flex: none;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
}

.portal-summary-body {
  flex: 1;
  min-width: 0;
}

.portal-summary-name {
  font-weight: 700;
  color: #0f172a;
}

.portal-summary-meta {
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: var(--fs-xs);
  color: #64748b;
}

.portal-summary-badge {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-color);
  font-weight: 700;
}

.portal-summary-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.portal-icon-button {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.portal-icon-button svg {
  width: 16px;
  height: 16px;
}

.portal-icon-button:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.portal-quick-add {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

.portal-allocation-meter {
  margin-top: var(--sp-4);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: #0f172a;
}

.portal-allocation-meter .track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.portal-allocation-meter .fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
  transition: width 0.3s var(--ease-out), background 0.3s ease;
}

.portal-allocation-meter.is-complete .fill {
  background: #10b981;
}

/* native <dialog> modal — zero-dependency */

.portal-dialog {
  border: 0;
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(92vw, 560px);
  max-height: min(88vh, 720px);
  box-shadow: var(--shadow-lg);
  color: var(--text-color);
}

.portal-dialog::backdrop {
  background: rgba(4, 9, 20, 0.6);
  backdrop-filter: blur(3px);
}

.portal-dialog[open] {
  animation: portal-dialog-in 0.28s var(--ease-out) both;
}

@keyframes portal-dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.portal-dialog-inner {
  padding: var(--sp-6);
  max-height: inherit;
  overflow-y: auto;
}

.portal-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  margin: calc(var(--sp-6) * -1) calc(var(--sp-6) * -1) var(--sp-5);
  padding: var(--sp-6) var(--sp-6) var(--sp-5);
  /* Sticky so the title/close button stay reachable while the form body
     scrolls underneath — without this, a tall family-member form on a
     short phone screen pushes the close control off the top of the
     dialog's scroll area. */
  position: sticky;
  top: calc(var(--sp-6) * -1);
  z-index: 2;
  background: #fff;
}

.portal-dialog-header h3 {
  margin: 0;
  font-size: var(--fs-lg);
}

.portal-dialog-actions {
  /* Sticky so Save/Cancel stay reachable at the bottom of the dialog
     instead of requiring the user to discover they can scroll a modal
     to find them — the #1 mobile complaint with tall forms in dialogs. */
  position: sticky;
  bottom: calc(var(--sp-6) * -1);
  z-index: 2;
  background: #fff;
  margin: var(--sp-5) calc(var(--sp-6) * -1) calc(var(--sp-6) * -1);
  padding: var(--sp-4) var(--sp-6) var(--sp-6);
  box-shadow: 0 -8px 16px rgba(15, 23, 42, 0.06);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}

.portal-empty-state {
  padding: var(--sp-7) var(--sp-5);
  border-radius: var(--radius-md);
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  text-align: center;
  color: #64748b;
  display: none;
}

.portal-empty-state.is-visible {
  display: block;
}

.portal-empty-state svg {
  width: 34px;
  height: 34px;
  color: #94a3b8;
  margin: 0 auto var(--sp-3);
}

/* ---------- plan selection ---------- */

.portal-plan-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: var(--sp-4);
}

.plan-card {
  position: relative;
  display: grid;
  gap: var(--sp-3);
  padding: var(--sp-5);
  border-radius: var(--radius-lg);
  border: 1.5px solid #e2e8f0;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.plan-card:hover {
  border-color: color-mix(in srgb, var(--primary-color) 45%, #e2e8f0);
}

.plan-card input {
  position: absolute;
  top: var(--sp-5);
  right: var(--sp-5);
  width: 20px;
  height: 20px;
  accent-color: var(--primary-color);
}

.plan-card:has(input:checked) {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary-color) 14%, white);
}

.plan-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-right: 30px;
}

.plan-card-name {
  font-size: var(--fs-lg);
  font-weight: 800;
  color: #0f172a;
}

.plan-card-premium {
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--primary-color);
}

.plan-card-premium span {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: #64748b;
}

.plan-card-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
}

.plan-card-stats div {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #f8fafc;
}

.plan-card-stats span {
  display: block;
  font-size: var(--fs-xs);
  color: #64748b;
}

.plan-card-stats strong {
  display: block;
  margin-top: 2px;
  color: #0f172a;
}

.plan-card-benefits {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.plan-card-benefits li {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #475569;
  font-size: var(--fs-sm);
}

.plan-card-benefits svg {
  color: var(--accent-color);
  flex: none;
}

.plan-card-select {
  justify-self: start;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--primary-color);
  background: var(--primary-soft);
}

.plan-card:has(input:checked) .plan-card-select {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
}

/* ---------- payment method ---------- */

.portal-payment-methods {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: var(--sp-3);
}

.payment-method-card {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--radius-md);
  border: 1.5px solid #e2e8f0;
  background: #fff;
  cursor: pointer;
  font-weight: 700;
  color: #0f172a;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.payment-method-card:hover {
  border-color: color-mix(in srgb, var(--primary-color) 45%, #e2e8f0);
}

.payment-method-card:has(input:checked) {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary-color) 14%, white);
  color: var(--primary-color);
}

.payment-method-card input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary-color);
  flex: none;
}

.portal-debit-fields {
  border: 0;
  margin: var(--sp-5) 0 0;
  padding: 0;
  animation: portal-rise-in 0.3s var(--ease-out) both;
}

/* ---------- documents: dropzone ---------- */

.portal-upload-grid {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

.portal-upload-card {
  position: relative;
  padding: var(--sp-5);
  border-radius: var(--radius-lg);
  border: 1.5px dashed #cbd5e1;
  background: #fbfcfe;
  cursor: pointer;
  display: grid;
  gap: 10px;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}

.portal-upload-card:hover {
  border-color: var(--primary-color);
}

.portal-upload-card.is-dragover {
  border-color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 6%, #fbfcfe);
  transform: scale(1.01);
}

.portal-upload-card.is-uploaded {
  border-style: solid;
  border-color: var(--accent-color);
  background: #fff;
}

.portal-upload-card input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.portal-upload-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary-color);
}

.portal-upload-icon svg {
  width: 18px;
  height: 18px;
}

.portal-upload-card.is-uploaded .portal-upload-icon {
  background: color-mix(in srgb, var(--accent-color) 18%, transparent);
  color: #0f766e;
}

.portal-upload-title {
  display: block;
  color: #0f172a;
  font-weight: 700;
}

.portal-upload-note {
  display: block;
  color: #64748b;
  font-size: var(--fs-sm);
}

.portal-upload-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}

.portal-upload-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid #e2e8f0;
  background: #fff;
}

.portal-upload-filename {
  font-size: var(--fs-xs);
  color: #0f766e;
  font-weight: 700;
  word-break: break-all;
}

.portal-upload-skeleton {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 37%, #e2e8f0 63%);
  background-size: 400% 100%;
  animation: portal-shimmer 1.2s ease infinite;
}

@keyframes portal-shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* ---------- review ---------- */

.portal-review {
  display: grid;
  gap: var(--sp-4);
}

.portal-review details {
  border-radius: var(--radius-md);
  border: 1px solid #dbe4f0;
  background: #fff;
  padding: var(--sp-4) 18px;
}

.portal-review summary {
  cursor: pointer;
  font-weight: 800;
  color: #0f172a;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.portal-review-grid,
.portal-review-beneficiaries {
  display: grid;
  gap: 10px;
  margin-top: var(--sp-4);
  color: #475569;
}

.portal-checkbox {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  margin-top: var(--sp-5);
  padding: var(--sp-4);
  border-radius: var(--radius-md);
  background: #f8fafc;
  color: #334155;
  font-size: var(--fs-sm);
}

.portal-checkbox.has-error {
  background: #fff1f2;
  outline: 1px solid #e11d48;
}

.portal-checkbox input {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  accent-color: var(--primary-color);
  flex: none;
}

/* ---------- footer ---------- */

.portal-footer {
  margin-top: var(--sp-6);
  padding-top: var(--sp-5);
  border-top: 1px solid #dbe4f0;
}

.portal-footer p {
  margin: 0;
  color: #64748b;
  font-size: var(--fs-sm);
}

/* ---------- toasts ---------- */

.portal-toast-region {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: grid;
  gap: 10px;
  z-index: 60;
  width: min(92vw, 380px);
  pointer-events: none;
}

.portal-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  background: #0f172a;
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s var(--ease-out), transform 0.25s var(--ease-out);
}

.portal-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.portal-toast[data-tone="error"] {
  background: #7f1d1d;
}

.portal-toast[data-tone="success"] {
  background: #064e3b;
}

/* ---------- success page ---------- */

.success-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-6) var(--sp-4);
}

.success-card {
  width: min(100%, 760px);
  border-radius: var(--radius-xl);
  padding: clamp(28px, 5vw, 44px);
  background: color-mix(in srgb, var(--surface-color) 95%, white);
  color: var(--text-color);
  /* No `both` fill-mode — see .portal-card's comment above; this card also
     contains a .portal-actions bar that needs to stay fixed to the
     viewport, not to this element. */
  animation: portal-rise-in 0.5s var(--ease-out);
}

.success-mark {
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  box-shadow: 0 18px 42px color-mix(in srgb, var(--accent-color) 30%, transparent);
}

.success-mark svg {
  width: 40px;
  height: 40px;
  /* stroke/fill/dasharray are inheritable SVG properties, so setting them
     here (not on the <path>) is what actually reaches the <path> that
     lives inside the <symbol> referenced via <use> — a descendant
     selector like ".success-mark svg path" cannot cross that shadow
     boundary and would silently match nothing. */
  fill: none;
  stroke: #fff;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 40;
  stroke-dashoffset: 40;
  animation: portal-check-draw 0.6s 0.35s var(--ease-out) forwards;
}

@keyframes portal-check-draw {
  to {
    stroke-dashoffset: 0;
  }
}

.success-grid {
  grid-template-columns: repeat(1, minmax(0, 1fr));
  margin-top: var(--sp-6);
}

.success-grid div {
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  background: #fff;
  border: 1px solid #dbe4f0;
}

.success-grid span {
  display: block;
  color: #64748b;
  font-size: var(--fs-sm);
}

.success-grid strong {
  display: block;
  margin-top: var(--sp-2);
  font-size: var(--fs-md);
}

.success-next-steps {
  margin-top: var(--sp-6);
}

/* ---------- responsive ---------- */

@media (min-width: 720px) {
  .portal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .portal-field-full {
    grid-column: 1 / -1;
  }

  .portal-upload-grid,
  .success-grid,
  .portal-plan-grid,
  .portal-payment-methods {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 960px) {
  .portal-shell {
    grid-template-columns: 1.02fr 0.98fr;
    align-items: start;
  }

  /* Restore the original hero-left / card-right reading order now that
     there's room for two columns — mobile keeps the form first (see the
     base `order` rules above .portal-shell). */
  .portal-hero {
    order: 1;
  }

  .portal-card {
    order: 2;
    position: sticky;
    top: 20px;
  }

  .portal-stepper {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  /* The detailed sub-step list is desktop-only real estate; mobile relies
     on the compact "Step X of 6 · Stage" header + .portal-outer-stepper
     pills instead, so the progress UI never eats the whole first screen. */
  .portal-outer-stepper {
    display: none;
  }
}

@media (max-width: 959px) {
  /* Below the two-column breakpoint, the full 8-item sub-stepper (with
     labels for every Personal/Cover sub-screen) is too much chrome for a
     phone — collapse it to the 6-pill outer-stage strip instead. */
  .portal-stepper {
    display: none;
  }
}

@media (max-width: 719px) {
  .portal-body {
    padding: var(--sp-4) var(--sp-3) 110px;
  }

  .portal-identity,
  .portal-hero,
  .portal-card {
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
  }

  .portal-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.08);
    z-index: 40;
  }

  .portal-actions .portal-button {
    flex: 1;
  }

  .portal-form {
    padding-bottom: 8px;
  }
}

@media (max-width: 380px) {
  /* Smallest phones (iPhone SE / older Android, ~320-360px) — tighten
     padding and shrink the outer-stage pills further so nothing clips or
     forces horizontal scroll. */
  .portal-body {
    padding: var(--sp-3) var(--sp-2) 104px;
  }

  .portal-identity,
  .portal-hero,
  .portal-card {
    padding: var(--sp-4);
  }

  .portal-title {
    font-size: clamp(1.6rem, 8vw, 2.1rem);
  }

  .portal-outer-step-label {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .portal-hero,
  .portal-card,
  .portal-form,
  .portal-summary-card,
  .success-card,
  .success-mark svg path {
    animation: none !important;
  }

  .portal-button,
  .portal-toast,
  .portal-progress-fill {
    transition: none !important;
  }
}

.portal-signature-pad {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

#signature-canvas {
  width: 100%;
  max-width: 600px;
  height: 180px;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
}

#signature-canvas.has-error {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px color-mix(in srgb, #dc2626 15%, transparent);
}

.portal-signature-clear {
  padding: 6px 14px;
  font-size: 0.85rem;
}
