/**
 * SC Modal — Stylesheet
 * Version: 1.0.0
 */

/* =============================================================================
   Custom Properties (override in your theme to customise look & feel)
   ============================================================================= */
:root {
  --sc-modal-overlay-bg: rgba(0, 0, 0, 0.65);
  --sc-modal-bg: #ffffff;
  --sc-modal-border-radius: 0px;
  --sc-modal-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  --sc-modal-z-index: 99999;
  --sc-modal-duration: 0.28s;
  --sc-modal-header-padding: 16px 24px;
  --sc-modal-body-padding: 0px;
  --sc-modal-title-size: 1.125rem;
  --sc-modal-title-weight: 600;
  --sc-modal-close-color: #6b7280;
  --sc-modal-close-hover-bg: #f3f4f6;
  --sc-modal-header-border: 1px solid #e5e7eb;
}

/* =============================================================================
   Overlay (backdrop)
   ============================================================================= */
.sc-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--sc-modal-z-index);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--sc-modal-overlay-bg);

  /* Hidden by default — shown via opacity + visibility transition */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity var(--sc-modal-duration) ease,
    visibility var(--sc-modal-duration) ease;
}

.sc-modal-overlay.sc-is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* =============================================================================
   Container
   ============================================================================= */
.sc-modal-container {
  position: relative;
  background: var(--sc-modal-bg);
  border-radius: var(--sc-modal-border-radius);
  box-shadow: var(--sc-modal-shadow);

  /* Default width — overridden by shortcode inline style */
  width: 600px;
  max-width: min(100%, 90vw);
  max-height: 88vh;

  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Shared transition for animation variants */
  transition:
    transform var(--sc-modal-duration) ease,
    opacity var(--sc-modal-duration) ease;
}

/* =============================================================================
   Animation variants
   ============================================================================= */

/* --- fade (default) --------------------------------------------------------- */
.sc-modal--fade .sc-modal-container {
  opacity: 0;
  transform: scale(0.95);
}
.sc-modal--fade.sc-is-open .sc-modal-container {
  opacity: 1;
  transform: scale(1);
}

/* --- zoom ------------------------------------------------------------------- */
.sc-modal--zoom .sc-modal-container {
  opacity: 0;
  transform: scale(0.65);
}
.sc-modal--zoom.sc-is-open .sc-modal-container {
  opacity: 1;
  transform: scale(1);
}

/* --- slide-up --------------------------------------------------------------- */
.sc-modal--slide-up .sc-modal-container {
  opacity: 0;
  transform: translateY(48px);
}
.sc-modal--slide-up.sc-is-open .sc-modal-container {
  opacity: 1;
  transform: translateY(0);
}

/* =============================================================================
   Header
   ============================================================================= */
.sc-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: var(--sc-modal-header-padding);
  border-bottom: var(--sc-modal-header-border);
  flex-shrink: 0;
}

.sc-modal-title {
  margin: 0;
  padding: 0;
  font-size: var(--sc-modal-title-size);
  font-weight: var(--sc-modal-title-weight);
  line-height: 1.4;
  color: #111827;
  flex: 1;
  word-break: break-word;
}

/* =============================================================================
   Close button
   ============================================================================= */
.sc-modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--sc-modal-close-color);
  transition:
    color 0.15s,
    background-color 0.15s,
    border-color 0.15s;
}

.sc-modal-close:hover {
  color: #111827;
  background-color: var(--sc-modal-close-hover-bg);
  border-color: #d1d5db;
}

.sc-modal-close:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* =============================================================================
   Body
   ============================================================================= */
.sc-modal-body {
  padding: var(--sc-modal-body-padding);
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* =============================================================================
   Body-scroll lock (added to <body> when any modal is open)
   ============================================================================= */
body.sc-modal-is-open {
  overflow: hidden;
  /* iOS Safari: position fixed is required to truly block scroll. */
  position: fixed;
  width: 100%;
  /* `top` is set dynamically in JS to preserve scroll position. */
}

/* =============================================================================
   Responsive — Tablet  (≤ 768 px)
   ============================================================================= */
@media (max-width: 768px) {
  .sc-modal-overlay {
    padding: 16px;
  }

  .sc-modal-container {
    max-height: 86vh;
  }
}

/* =============================================================================
   Responsive — Mobile  (≤ 480 px)
   Bottom-sheet pattern: slides up from the bottom edge.
   User-defined width / height are ignored on this breakpoint.
   ============================================================================= */
@media (max-width: 480px) {
  .sc-modal-overlay {
    padding: 0;
    align-items: flex-end;
    /* Prevent the overlay padding from cutting into the sheet */
    overflow-y: hidden;
  }

  /* Force full-width bottom sheet regardless of shortcode size attrs */
  .sc-modal-container {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: 92dvh; /* dvh = dynamic viewport height (iOS safe area aware) */
    max-height: 92vh; /* Fallback for browsers without dvh support */
    border-radius: 18px 18px 0 0;
  }

  /* Unified bottom-sheet animation — overrides all desktop animation variants */
  .sc-modal-overlay .sc-modal-container {
    opacity: 1 !important;
    transform: translateY(100%) !important;
  }

  .sc-modal-overlay.sc-is-open .sc-modal-container {
    transform: translateY(0) !important;
  }

  .sc-modal-header {
    padding: 14px 18px;
    /* Drag handle hint */
    position: relative;
  }

  .sc-modal-header::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #d1d5db;
  }

  .sc-modal-body {
    padding: 16px 18px;
    overflow-y: auto;
    max-height: calc(92vh - 64px);
  }
}

