/* ──────────────────────────────────────────────────────────────
   Spiga Modals — Frontend
   ────────────────────────────────────────────────────────────── */

/* Base modal shell */
.spiga-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

.spiga-modal[hidden] {
  display: none !important;
}

/* Backdrop */
.spiga-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
}

/* Container */
.spiga-modal__container {
  position: relative;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  max-height: min(90vh, calc(100dvh - 32px));
  overflow: hidden;
  width: 100%;
  overscroll-behavior: contain;
}

/* Hide scrollbar UI while preserving scroll behavior in modal areas. */
.spiga-modal__container,
.spiga-modal__content-col,
.spiga-modal__form--scroll,
.spiga-modal__inner--scroll-layout {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.spiga-modal__container::-webkit-scrollbar,
.spiga-modal__content-col::-webkit-scrollbar,
.spiga-modal__form--scroll::-webkit-scrollbar,
.spiga-modal__inner--scroll-layout::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* Size variants */
.spiga-modal--sm  .spiga-modal__container { max-width: 400px; }
.spiga-modal--md  .spiga-modal__container { max-width: 560px; }
.spiga-modal--lg  .spiga-modal__container { max-width: 760px; }
.spiga-modal--xl  .spiga-modal__container { max-width: 980px; }

/* Close button */
.spiga-modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 24px;
  line-height: 0.9;
  color: #1d2327;
  padding: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.06);
  transition: box-shadow 0.15s, background 0.15s;
}

.spiga-modal__close > span {
  display: block;
  line-height: 1;
  transform: translateY(-1px);
}

.spiga-modal__close:hover {
  background: #f9f9f9;
  box-shadow: 0 2px 6px rgba(0,0,0,0.16), 0 0 0 1px rgba(0,0,0,0.08);
}

.spiga-modal__close:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.20);
}

/* Inner content wrapper */
.spiga-modal__inner {
  padding: 32px;
}

.spiga-modal__inner--scroll-layout {
  display: block;
  min-height: 0;
  height: auto;
  overflow: visible;
  overscroll-behavior: contain;
}

.spiga-modal__header {
  padding: 0;
}

.spiga-modal__body {
  min-height: 0;
  padding: 0;
}

.spiga-modal__header + .spiga-modal__body {
  margin-top: 20px;
}

.spiga-modal__title {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.3;
  color: #1d2327;
}

.spiga-modal__content {
  font-size: 1rem;
  line-height: 1.5;
  color: #3c434a;
}

.spiga-modal__content h2,
.spiga-modal__content h3,
.spiga-modal__content h4 {
  margin: 0 0 0.5rem;
  color: #111827;
  font-weight: 700;
}

.spiga-modal__content h2 {
  font-size: 1.5rem;
  line-height: 2rem;
}

.spiga-modal__content h3 {
  font-size: 1.25rem;
  line-height: 1.75rem;
}

.spiga-modal__content h4 {
  font-size: 1.125rem;
  line-height: 1.75rem;
}

.spiga-modal__content :is(h2, h3, h4):not(:first-child) {
  margin-top: 0.875rem;
}

.spiga-modal__content p {
  margin: 0 0 0.75rem;
  line-height: 1.5;
}

.spiga-modal__content p:last-child { margin-bottom: 0; }

.spiga-modal__form {
  margin-top: 20px;
}

.spiga-modal__body > :first-child {
  margin-top: 0;
}

/* CTA */
.spiga-modal__cta {
  margin-top: 24px;
}

.spiga-modal__cta-btn {
  display: inline-block;
  padding: 12px 28px;
  background: #2271b1;
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 600;
  transition: background 0.15s;
}

.spiga-modal__cta-btn:hover,
.spiga-modal__cta-btn:focus-visible {
  background: #135e96;
  outline: 2px solid #2271b1;
  outline-offset: 2px;
}

.spiga-modal--simple .spiga-modal__container {
  /* auto height — grows with content up to max-height from base rule, then scrolls */
  height: auto;
  overflow-y: auto;
}

/* Reserve space for the close button (40 px wide at right:12px) */
.spiga-modal--simple .spiga-modal__inner {
  padding-right: 60px;
}

/* ──────────────────────────────────────────────────────────────
   Layout B — Split
   ────────────────────────────────────────────────────────────── */
.spiga-modal--split .spiga-modal__container {
  display: grid;
  overflow: hidden;
  height: auto;
  max-height: min(88vh, calc(100dvh - 32px));
}

.spiga-modal__split-grid {
  display: grid;
  grid-template-rows: auto;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: auto;
  max-height: none;
  align-items: stretch;
  overflow: hidden;
}

/* Ratio presets */
.spiga-modal__split-grid.ratio-50-50 { grid-template-columns: 1fr 1fr; }
.spiga-modal__split-grid.ratio-40-60 { grid-template-columns: 2fr 3fr; }
.spiga-modal__split-grid.ratio-60-40 { grid-template-columns: 3fr 2fr; }

/* Media on right */
.spiga-modal__split-grid.media-right .spiga-modal__media-col  { order: 2; }
.spiga-modal__split-grid.media-right .spiga-modal__content-col { order: 1; }

.spiga-modal__media-col {
  display: flex;
  overflow: hidden;
  position: relative;
  min-height: 0;
  height: 100%;
  max-height: none;
  align-self: stretch;
}

.spiga-modal__picture {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 100%;
}

.spiga-modal__media-video {
  display: flex;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
}

.spiga-modal__media-img {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: cover;
  display: block;
}

.spiga-modal__media-video-el {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: cover;
}

.spiga-modal__content-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  height: auto;
  max-height: min(88vh, calc(100dvh - 32px));
  overflow-y: auto;
  align-self: stretch;
}

.spiga-modal__content-col--with-form {
  overflow-y: auto;
}

.spiga-modal__inner--with-form {
  min-height: 0;
  height: auto;
}

.spiga-modal--split .spiga-modal__inner {
  width: min(100%, 720px);
  margin: auto;
}

.spiga-modal__body--with-form {
  min-width: 0;
}

.spiga-modal__form--scroll {
  overflow: visible;
}

/* Mobile: stack */
@media (max-width: 767px) {
  .spiga-modal--split .spiga-modal__container {
    display: block;
    height: auto;
    overflow-y: auto;
  }
  .spiga-modal__split-grid,
  .spiga-modal__split-grid.ratio-50-50,
  .spiga-modal__split-grid.ratio-40-60,
  .spiga-modal__split-grid.ratio-60-40 {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
  }
  .spiga-modal__split-grid.media-right .spiga-modal__media-col  { order: 0; }
  .spiga-modal__split-grid.media-right .spiga-modal__content-col { order: 1; }
  .spiga-modal__media-col {
    display: block;
    height: auto;
    max-height: 220px;
    align-self: start;
  }

  .spiga-modal__picture,
  .spiga-modal__media-img {
    height: auto;
    min-height: 0;
  }
  .spiga-modal__content-col {
    height: auto;
    max-height: none;
    overflow: visible;
    justify-content: flex-start;
  }

  .spiga-modal__content-col--with-form {
    overflow: visible;
  }

  .spiga-modal__inner--scroll-layout,
  .spiga-modal__inner--with-form,
  .spiga-modal__body,
  .spiga-modal__form--scroll {
    min-height: auto;
    height: auto;
    overflow: visible;
  }

  .spiga-modal--split .spiga-modal__inner {
    width: 100%;
    margin: 0;
  }

  .spiga-modal__header {
    padding: 0;
  }

  .spiga-modal__inner {
    padding: 24px;
  }

  .spiga-modal__body .spiga-form-shell {
    padding: 0;
  }

  .spiga-modal__header + .spiga-modal__body {
    margin-top: 16px;
  }
}

/* ──────────────────────────────────────────────────────────────
   Layout C — Background
   ────────────────────────────────────────────────────────────── */
.spiga-modal--background .spiga-modal__container {
  background: transparent;
  overflow: hidden;
}

.spiga-modal__bg-media {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  z-index: 0;
}

.spiga-modal__bg-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  z-index: 0;
}

.spiga-modal__bg-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, var(--modal-overlay-opacity, 0.35));
  z-index: 1;
}

.spiga-modal--background .spiga-modal__close {
  z-index: 30;
}

.spiga-modal--background .spiga-modal__inner {
  position: relative;
  z-index: 20;
  /* Do NOT set color here — it would cascade into child form elements.
     Color is set specifically on .spiga-modal__title and .spiga-modal__content only. */
}

.spiga-modal--background .spiga-modal__title { color: #fff; }
.spiga-modal--background .spiga-modal__content { color: rgba(255, 255, 255, 0.9); }

/* ──────────────────────────────────────────────────────────────
   Layout D — Image Link
   ────────────────────────────────────────────────────────────── */
.spiga-modal--image-link .spiga-modal__container {
  background: transparent;
  width: auto;
  max-width: min(980px, calc(100vw - 32px));
  height: auto;
  overflow: visible;
  box-shadow: none;
}

.spiga-modal--image-link.spiga-modal--sm .spiga-modal__container { max-width: min(400px, calc(100vw - 32px)); }
.spiga-modal--image-link.spiga-modal--md .spiga-modal__container { max-width: min(560px, calc(100vw - 32px)); }
.spiga-modal--image-link.spiga-modal--lg .spiga-modal__container { max-width: min(760px, calc(100vw - 32px)); }
.spiga-modal--image-link.spiga-modal--xl .spiga-modal__container { max-width: min(980px, calc(100vw - 32px)); }

.spiga-modal--image-link .spiga-modal__image-link {
  display: block;
  line-height: 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  background: #fff;
}

.spiga-modal--image-link .spiga-modal__image-link-picture {
  display: block;
}

.spiga-modal--image-link .spiga-modal__image-link-img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(90vh, calc(100dvh - 32px));
  height: auto;
  object-fit: contain;
}

.spiga-modal--image-link .spiga-modal__close {
  top: 10px;
  right: 10px;
}

/* Isolate the embedded form from any modal color/typography cascade.
   spiga-forms has its own stylesheet; we must not override it. */
.spiga-modal__form {
  color: revert;
  font-size: revert;
  line-height: revert;
}

/* ──────────────────────────────────────────────────────────────
   Animations
   ────────────────────────────────────────────────────────────── */
.spiga-modal.anim-fade-in  { animation: spigaFadeIn  0.25s ease-out both; }
.spiga-modal.anim-fade-out { animation: spigaFadeOut 0.2s  ease-in  both; }
.spiga-modal.anim-slide-up   { animation: spigaSlideUp   0.3s cubic-bezier(0.22, 1, 0.36, 1) both; }
.spiga-modal.anim-slide-down { animation: spigaSlideDown 0.2s ease-in both; }
.spiga-modal.anim-scale-in  { animation: spigaScaleIn  0.25s cubic-bezier(0.22, 1, 0.36, 1) both; }
.spiga-modal.anim-scale-out { animation: spigaScaleOut 0.2s ease-in both; }

@keyframes spigaFadeIn   { from { opacity: 0; } to { opacity: 1; } }
@keyframes spigaFadeOut  { from { opacity: 1; } to { opacity: 0; } }
@keyframes spigaSlideUp   { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spigaSlideDown { from { opacity: 1; transform: translateY(0); }   to { opacity: 0; transform: translateY(24px); } }
@keyframes spigaScaleIn  { from { opacity: 0; transform: scale(0.93); } to { opacity: 1; transform: scale(1); } }
@keyframes spigaScaleOut { from { opacity: 1; transform: scale(1); }    to { opacity: 0; transform: scale(0.93); } }

/* Body scroll lock helper (applied via JS) */
body.spiga-modal-open {
  overflow: hidden;
}

/* Accessibility: focus ring for modal UI elements only.
   Exclude native form controls — spiga-forms manages their focus styles. */
.spiga-modal *:focus-visible:not(input):not(select):not(textarea):not([contenteditable]) {
  outline: 2px solid #2271b1;
  outline-offset: 2px;
}
