/* ============================================
   InfluenceHub – Modal a11y audit styles
   - Ensures every modal panel is scrollable on
     small viewports (320px – 480px) without
     horizontal overflow.
   - Guarantees a visible focus ring on the modal
     panel fallback (when no focusable child exists).
   - Respects prefers-reduced-motion.
   - Forced-colors (Windows High Contrast) support.
   ============================================ */

/* ---------- Modal panel scroll safety ---------- */

#auth-modal .auth-panel,
#profile-modal .auth-panel,
#profile-form-modal .auth-panel,
#request-modal .auth-panel,
#birthday-modal .auth-panel,
#confirm-modal .confirm-modal-panel {
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ---------- Modal body scroll safety ---------- */

#profile-modal-body,
#profile-form form,
#request-form,
#birthday-form {
  max-height: calc(100vh - 12rem);
  max-height: calc(100dvh - 12rem);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ---------- Focus ring on the modal panel fallback ---------- */

#auth-modal .auth-panel:focus-visible,
#profile-modal .auth-panel:focus-visible,
#profile-form-modal .auth-panel:focus-visible,
#request-modal .auth-panel:focus-visible,
#birthday-modal .auth-panel:focus-visible,
#confirm-modal .confirm-modal-panel:focus-visible {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.25);
}

.dark #auth-modal .auth-panel:focus-visible,
.dark #profile-modal .auth-panel:focus-visible,
.dark #profile-form-modal .auth-panel:focus-visible,
.dark #request-modal .auth-panel:focus-visible,
.dark #birthday-modal .auth-panel:focus-visible,
.dark #confirm-modal .confirm-modal-panel:focus-visible {
  outline-color: #c4b5fd;
  box-shadow: 0 0 0 4px rgba(196, 181, 253, 0.35);
}

/* ---------- Prevent body scroll when a modal is open ---------- */

body.modal-open {
  overflow: hidden;
}

/* ---------- Small screens: ensure modals fit ---------- */

@media (max-width: 480px) {
  #auth-modal .auth-panel,
  #profile-modal .auth-panel,
  #profile-form-modal .auth-panel,
  #request-modal .auth-panel,
  #birthday-modal .auth-panel,
  #confirm-modal .confirm-modal-panel {
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
    border-radius: 1.25rem;
  }

  #profile-modal-body,
  #profile-form form,
  #request-form,
  #birthday-form {
    max-height: calc(100vh - 10rem);
    max-height: calc(100dvh - 10rem);
  }
}

/* ---------- Very small screens (320px) ---------- */

@media (max-width: 360px) {
  #auth-modal .auth-panel,
  #profile-modal .auth-panel,
  #profile-form-modal .auth-panel,
  #request-modal .auth-panel,
  #birthday-modal .auth-panel,
  #confirm-modal .confirm-modal-panel {
    max-height: calc(100vh - 0.5rem);
    max-height: calc(100dvh - 0.5rem);
    border-radius: 1rem;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  #auth-modal,
  #profile-modal,
  #profile-form-modal,
  #request-modal,
  #birthday-modal,
  #confirm-modal,
  #auth-modal *,
  #profile-modal *,
  #profile-form-modal *,
  #request-modal *,
  #birthday-modal *,
  #confirm-modal * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

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

@media (forced-colors: active) {
  #auth-modal .auth-panel,
  #profile-modal .auth-panel,
  #profile-form-modal .auth-panel,
  #request-modal .auth-panel,
  #birthday-modal .auth-panel,
  #confirm-modal .confirm-modal-panel {
    border: 1px solid CanvasText;
    background: Canvas;
    color: CanvasText;
  }

  #auth-modal .auth-panel:focus-visible,
  #profile-modal .auth-panel:focus-visible,
  #profile-form-modal .auth-panel:focus-visible,
  #request-modal .auth-panel:focus-visible,
  #birthday-modal .auth-panel:focus-visible,
  #confirm-modal .confirm-modal-panel:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
    box-shadow: none;
  }
}
