/* ============================================
   InfluenceHub – Profile edit form a11y
   - WCAG AA contrast for .profile-avatar-preview
     and .profile-form-message in both light and
     dark mode.
   - prefers-reduced-motion guard: disables any
     transitions/animations on the avatar preview
     and the form message so users who prefer
     reduced motion are not exposed to motion.
   - 44px minimum touch target (WCAG 2.5.5) for
     the avatar preview.
   - Focus-visible ring for keyboard users.
   - Forced-colors (Windows High Contrast) support.
   ============================================ */

/* ---------- Avatar preview – base contrast (WCAG AA) ----------
   The avatar preview is a rounded square that shows the creator's
   photo (or a fallback gradient). Re-assert the surface colors so
   generic utilities cannot reduce the contrast of the fallback
   content below AA.

   Light mode:
     - preview surface: #f1f5f9 (slate-100)
     - fallback text: #475569 on #f1f5f9 = 7.5:1 (passes AA)
   Dark mode:
     - preview surface: #1e293b (slate-800)
     - fallback text: #cbd5e1 on #1e293b = 9.6:1 (passes AA)
*/

.profile-avatar-preview {
  background-color: #f1f5f9 !important;
  color: #475569 !important;
  border: 1px solid #e2e8f0;
}

.dark .profile-avatar-preview {
  background-color: #1e293b !important;
  color: #cbd5e1 !important;
  border-color: #334155;
}

/* Fallback content (initials / icon) inside the preview must keep
   its AA contrast even when the image fails to load. */
.profile-avatar-preview > * {
  color: inherit;
}

/* ---------- Form message – base contrast (WCAG AA) ----------
   The form message is a rose-tinted error banner. Re-assert the
   surface and text colors so generic utilities cannot reduce the
   contrast below AA.

   Light mode:
     - message surface: #fff1f2 (rose-50)
     - message text: #be123c on #fff1f2 = 6.9:1 (passes AA)
   Dark mode:
     - message surface: rgba(76, 5, 25, 0.4) over #0f172a
     - message text: #fda4af on the surface ≈ 8.4:1 (passes AA)
*/

.profile-form-message {
  background-color: #fff1f2 !important;
  color: #be123c !important;
  border: 1px solid #fecdd3;
}

.dark .profile-form-message {
  background-color: rgba(76, 5, 25, 0.4) !important;
  color: #fda4af !important;
  border-color: rgba(190, 18, 60, 0.4);
}

/* Success variant – keep the emerald palette readable in both modes. */
.profile-form-message.is-success {
  background-color: #ecfdf5 !important;
  color: #047857 !important;
  border-color: #a7f3d0;
}

.dark .profile-form-message.is-success {
  background-color: rgba(6, 78, 59, 0.4) !important;
  color: #6ee7b7 !important;
  border-color: rgba(16, 185, 129, 0.4);
}

/* ---------- 44px minimum touch target ---------- */

.profile-avatar-preview {
  /* WCAG 2.5.5 – minimum 44x44px touch target for mobile users */
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Focus-visible ring (keyboard) ---------- */

.profile-avatar-preview:focus-visible {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
  box-shadow:
    0 0 0 2px #ffffff,
    0 0 0 6px rgba(124, 58, 237, 0.35);
}

.dark .profile-avatar-preview:focus-visible {
  outline-color: #c4b5fd;
  box-shadow:
    0 0 0 2px #0f172a,
    0 0 0 6px rgba(196, 181, 253, 0.45);
}

/* ---------- Fallback for browsers without :focus-visible ---------- */

@supports not selector(:focus-visible) {
  .profile-avatar-preview:focus {
    outline: 2px solid #7c3aed;
    outline-offset: 2px;
    box-shadow:
      0 0 0 2px #ffffff,
      0 0 0 6px rgba(124, 58, 237, 0.35);
  }

  .dark .profile-avatar-preview:focus {
    outline-color: #c4b5fd;
    box-shadow:
      0 0 0 2px #0f172a,
      0 0 0 6px rgba(196, 181, 253, 0.45);
  }
}

/* ---------- prefers-reduced-motion guard ----------
   The avatar preview may animate when the image URL changes and the
   form message may fade/slide in when it appears. Users who prefer
   reduced motion should see state changes instantly, with no motion. */

@media (prefers-reduced-motion: reduce) {
  .profile-avatar-preview,
  .profile-form-message {
    transition: none !important;
    animation: none !important;
    transform: none !important;
    scroll-behavior: auto !important;
  }

  /* Neutralise any hover/focus/active transform on the preview */
  .profile-avatar-preview:hover,
  .profile-avatar-preview:focus,
  .profile-avatar-preview:focus-visible,
  .profile-avatar-preview:active {
    transform: none !important;
    transition: none !important;
  }

  /* Children of the preview (image, initials, icon) must not animate */
  .profile-avatar-preview *,
  .profile-avatar-preview *::before,
  .profile-avatar-preview *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transform: none !important;
  }

  /* The form message must appear instantly, without fade/slide */
  .profile-form-message,
  .profile-form-message::before,
  .profile-form-message::after {
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }

  /* Keep the focus ring visible but static (no animated halo) */
  .profile-avatar-preview:focus-visible {
    box-shadow:
      0 0 0 2px #ffffff,
      0 0 0 6px rgba(124, 58, 237, 0.35) !important;
  }

  .dark .profile-avatar-preview:focus-visible {
    box-shadow:
      0 0 0 2px #0f172a,
      0 0 0 6px rgba(196, 181, 253, 0.45) !important;
  }
}

/* ---------- Forced colors (Windows High Contrast) ---------- */

@media (forced-colors: active) {
  .profile-avatar-preview {
    background: Canvas !important;
    color: CanvasText !important;
    border: 1px solid CanvasText !important;
  }

  .profile-avatar-preview:focus-visible,
  .profile-avatar-preview:focus {
    outline: 2px solid Highlight;
    outline-offset: 2px;
    box-shadow: none !important;
  }

  .profile-form-message {
    background: Canvas !important;
    color: CanvasText !important;
    border: 1px solid CanvasText !important;
  }
}
