/**
 * SFWEB Popup - Joomla 5/6 + YOOtheme Pro (UIkit 3)
 * Author: Sergio Di Mare - SFWEB (https://www.sfweb.it)
 * License: GNU General Public License v2 or later
 */

/* ==========================================================================
   1. Native <dialog> Base, Scroll Containment & Top-Layer Transitions
   ========================================================================== */

dialog.sfweb-popup-dialog {
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  /* Override UIkit/YOOtheme rules like `.uk-panel > :last-child { margin-bottom: 0 }` */
  margin: auto !important;
  padding: 0 !important;
  border: 0;
  background: transparent;
  color: inherit;
  width: min(var(--sfweb-popup-max-width, 640px), calc(100vw - 2rem));
  width: min(var(--sfweb-popup-max-width, 640px), calc(100dvw - 2rem));
  height: fit-content;
  max-width: none;
  max-height: 92vh;
  max-block-size: 92dvh;
  overflow: auto;
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.28s;
  transition-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
  transition-behavior: allow-discrete;
}

/* Viewport placement options */
dialog.sfweb-popup-dialog.sfweb-popup-pos-center {
  margin: auto !important;
}

dialog.sfweb-popup-dialog.sfweb-popup-pos-top-center {
  margin: var(--sfweb-popup-offset, 24px) auto auto auto !important;
}

dialog.sfweb-popup-dialog.sfweb-popup-pos-bottom-center {
  margin: auto auto var(--sfweb-popup-offset, 24px) auto !important;
}

dialog.sfweb-popup-dialog.sfweb-popup-pos-top-left {
  margin: var(--sfweb-popup-offset, 24px) auto auto var(--sfweb-popup-offset, 24px) !important;
}

dialog.sfweb-popup-dialog.sfweb-popup-pos-top-right {
  margin: var(--sfweb-popup-offset, 24px) var(--sfweb-popup-offset, 24px) auto auto !important;
}

dialog.sfweb-popup-dialog.sfweb-popup-pos-bottom-left {
  margin: auto auto var(--sfweb-popup-offset, 24px) var(--sfweb-popup-offset, 24px) !important;
}

dialog.sfweb-popup-dialog.sfweb-popup-pos-bottom-right {
  margin: auto var(--sfweb-popup-offset, 24px) var(--sfweb-popup-offset, 24px) auto !important;
}

/* Scope display strictly to [open] so the closed state is never overridden */
dialog.sfweb-popup-dialog[open] {
  display: flex;
  flex-direction: column;
}

/* Prevent scroll gestures inside modal or over backdrop from scrolling the page */
dialog.sfweb-popup-dialog:modal {
  overscroll-behavior: contain;
}

dialog.sfweb-popup-dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: transparent;
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  transition-property: background-color, backdrop-filter, display, overlay;
  transition-duration: 0.28s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

/* Motion transforms strictly gated behind no-preference */
@media (prefers-reduced-motion: no-preference) {
  dialog.sfweb-popup-dialog.sfweb-popup-anim-scale {
    transform: scale(0.94);
  }

  dialog.sfweb-popup-dialog.sfweb-popup-anim-slide-up {
    transform: translateY(24px);
  }
}

/* Open state (supports both native exit transitions and data-closing fallback) */
:is(dialog.sfweb-popup-dialog[open]):where(:not([data-closing])) {
  opacity: 1;

  @starting-style {
    opacity: 0;
  }

  @media (prefers-reduced-motion: no-preference) {
    transform: none;

    &.sfweb-popup-anim-scale {
      @starting-style {
        transform: scale(0.94);
      }
    }

    &.sfweb-popup-anim-slide-up {
      @starting-style {
        transform: translateY(24px);
      }
    }
  }

  &::backdrop {
    background-color: var(--sfweb-popup-backdrop-bg, rgba(0, 0, 0, 0.6));

    @starting-style {
      background-color: transparent;
    }
  }

  &.sfweb-popup-backdrop-blur::backdrop {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);

    @starting-style {
      backdrop-filter: blur(0px);
      -webkit-backdrop-filter: blur(0px);
    }
  }
}

dialog.sfweb-popup-dialog.sfweb-popup-anim-none,
dialog.sfweb-popup-dialog.sfweb-popup-anim-none::backdrop {
  transition-duration: 0s;
}

@media (prefers-reduced-motion: reduce) {
  dialog.sfweb-popup-dialog,
  dialog.sfweb-popup-dialog::backdrop {
    transition-duration: 0.1s;
  }
}

/* ==========================================================================
   2. Surface & YOOtheme / UIkit Integration (zero-specificity fallbacks)
   ========================================================================== */

:where(.sfweb-popup-surface.uk-card-default) {
  background-color: #ffffff;
  color: #1f2937;
}

:where(.sfweb-popup-surface.uk-card-primary) {
  background-color: #1e87f0;
  color: #ffffff;
}

:where(.sfweb-popup-surface.uk-card-secondary) {
  background-color: #111827;
  color: #ffffff;
}

:where(.sfweb-popup-surface.uk-section-muted) {
  background-color: #f8fafc;
  color: #1f2937;
}

dialog.sfweb-popup-dialog.sfweb-popup-radius-custom {
  border-radius: var(--sfweb-popup-radius, 12px);
}

.sfweb-popup-surface {
  position: relative;
  width: 100%;
  min-height: var(--sfweb-popup-min-height, auto);
  border-radius: inherit;
  overflow: hidden;
  box-sizing: border-box;
  isolation: isolate;
  container-type: inline-size;
  container-name: sfweb-popup;
}

.sfweb-popup-surface.sfweb-popup-surface-custom {
  background-color: var(--sfweb-popup-bg, #ffffff);
}

/* Ensure light/dark helper contrast also applies cleanly without UIkit */
:where(.sfweb-popup-surface.uk-light) {
  color: #ffffff;
}

:where(.sfweb-popup-surface.uk-dark) {
  color: #1f2937;
}

/* ==========================================================================
   3. Close Button (accessible target >= 40x40px, 44x44px touch)
   ========================================================================== */

.sfweb-popup-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: 40px;
  min-block-size: 40px;
  padding: 8px;
  border: 0;
  cursor: pointer;
  line-height: 1;
  transition: transform 0.18s ease, background-color 0.18s ease, opacity 0.18s ease;
}

@media (pointer: coarse) {
  .sfweb-popup-close {
    min-inline-size: 44px;
    min-block-size: 44px;
  }
}

.sfweb-popup-close-floating-circle {
  border-radius: 9999px;
  background-color: rgba(15, 23, 42, 0.42);
  color: #ffffff;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.sfweb-popup-close-floating-circle:hover {
  background-color: rgba(15, 23, 42, 0.72);
  transform: scale(1.06);
}

.sfweb-popup-close-minimal {
  border-radius: 6px;
  background-color: transparent;
  color: currentColor;
  opacity: 0.75;
}

.sfweb-popup-close-minimal:hover {
  opacity: 1;
  background-color: rgba(128, 128, 128, 0.14);
}

.sfweb-popup-close-contrast-pill {
  border-radius: 9999px;
  background-color: #ffffff;
  color: #111827;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.sfweb-popup-close-contrast-pill:hover {
  background-color: #f3f4f6;
  transform: scale(1.06);
}

.sfweb-popup-close:focus-visible,
.sfweb-popup-surface :where(a, button):focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.sfweb-popup-close-icon {
  display: block;
  pointer-events: none;
}

/* ==========================================================================
   4. Layout Modes (Background, Split Left/Right, Top/Bottom, Content-Only)
   ========================================================================== */

/* Shared picture & media styling */
.sfweb-popup-picture {
  display: block;
  width: 100%;
  height: 100%;
}

.sfweb-popup-bg-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.sfweb-popup-bg-img,
.sfweb-popup-media-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: var(--sfweb-popup-img-fit, cover);
  object-position: var(--sfweb-popup-img-pos, center center);
}

/* Overlay gradients on background image */
.sfweb-popup-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.sfweb-popup-overlay-solid {
  background-color: var(--sfweb-popup-overlay-color, rgba(15, 23, 42, 0.55));
}

.sfweb-popup-overlay-bottom {
  background-image: linear-gradient(
    to top,
    var(--sfweb-popup-overlay-color, rgba(15, 23, 42, 0.85)) 0%,
    rgba(0, 0, 0, 0) 78%
  );
}

.sfweb-popup-overlay-top {
  background-image: linear-gradient(
    to bottom,
    var(--sfweb-popup-overlay-color, rgba(15, 23, 42, 0.85)) 0%,
    rgba(0, 0, 0, 0) 78%
  );
}

.sfweb-popup-overlay-left {
  background-image: linear-gradient(
    to right,
    var(--sfweb-popup-overlay-color, rgba(15, 23, 42, 0.88)) 0%,
    rgba(0, 0, 0, 0) 80%
  );
}

.sfweb-popup-overlay-right {
  background-image: linear-gradient(
    to left,
    var(--sfweb-popup-overlay-color, rgba(15, 23, 42, 0.88)) 0%,
    rgba(0, 0, 0, 0) 80%
  );
}

/* Layout: Background */
.sfweb-popup-layout-background {
  display: flex;
  flex-direction: column;
  min-height: var(--sfweb-popup-min-height, 360px);
}

.sfweb-popup-layout-background .sfweb-popup-body {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

/* Layout: Split Left / Right */
.sfweb-popup-layout-image_left,
.sfweb-popup-layout-image_right {
  display: grid;
  grid-template-columns: var(--sfweb-popup-split-cols, 1fr 1fr);
}

.sfweb-popup-layout-image_left .sfweb-popup-media,
.sfweb-popup-layout-image_right .sfweb-popup-media {
  position: relative;
  min-height: 260px;
  overflow: hidden;
}

.sfweb-popup-layout-image_left .sfweb-popup-body,
.sfweb-popup-layout-image_right .sfweb-popup-body {
  display: flex;
  flex-direction: column;
}

/* Layout: Top / Bottom */
.sfweb-popup-layout-image_top,
.sfweb-popup-layout-image_bottom {
  display: flex;
  flex-direction: column;
}

.sfweb-popup-layout-image_top .sfweb-popup-media,
.sfweb-popup-layout-image_bottom .sfweb-popup-media {
  position: relative;
  height: var(--sfweb-popup-banner-height, 240px);
  flex: 0 0 auto;
  overflow: hidden;
}

/* Layout: None (content only) */
.sfweb-popup-layout-none {
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   5. Content Alignment, Padding & Optional Text Card Box over Background
   ========================================================================== */

.sfweb-popup-pad-small .sfweb-popup-body {
  padding: clamp(1.125rem, 3.5cqi, 1.75rem);
}

.sfweb-popup-pad-medium .sfweb-popup-body {
  padding: clamp(1.5rem, 5cqi, 2.75rem);
}

.sfweb-popup-pad-large .sfweb-popup-body {
  padding: clamp(2rem, 6.5cqi, 3.75rem);
}

/* Extra breathing room at top-right so close button never overlaps text */
.sfweb-popup-valign-start .sfweb-popup-body,
.sfweb-popup-layout-image_bottom .sfweb-popup-body,
.sfweb-popup-layout-none .sfweb-popup-body {
  padding-top: max(3.25rem, clamp(1.5rem, 5cqi, 2.75rem));
}

.sfweb-popup-valign-start .sfweb-popup-body {
  justify-content: flex-start;
}

.sfweb-popup-valign-center .sfweb-popup-body {
  justify-content: center;
}

.sfweb-popup-valign-end .sfweb-popup-body {
  justify-content: flex-end;
}

.sfweb-popup-halign-left .sfweb-popup-body {
  align-items: flex-start;
  text-align: left;
}

.sfweb-popup-halign-center .sfweb-popup-body {
  align-items: center;
  text-align: center;
}

.sfweb-popup-halign-right .sfweb-popup-body {
  align-items: flex-end;
  text-align: right;
}

.sfweb-popup-content-inner {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* Optional semi-transparent card panel over background image */
.sfweb-popup-has-content-box .sfweb-popup-content-inner {
  width: auto;
  max-width: min(100%, 540px);
  padding: clamp(1.25rem, 4cqi, 2.25rem);
  background-color: var(--sfweb-popup-content-box-bg, rgba(255, 255, 255, 0.9));
  border-radius: calc(max(var(--sfweb-popup-radius, 12px) - 4px, 4px));
}

.sfweb-popup-content-box-blur .sfweb-popup-content-inner {
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* ==========================================================================
   6. Typography, Preview Badge & Buttons
   ========================================================================== */

.sfweb-popup-preview-badge {
  display: inline-block;
  margin-bottom: 0.75rem;
  padding: 0.2rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 9999px;
  background-color: #f59e0b;
  color: #111827;
}

.sfweb-popup-eyebrow {
  margin: 0 0 0.5rem 0;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.85;
}

.sfweb-popup-title {
  margin: 0 0 0.875rem 0;
  line-height: 1.2;
}

.sfweb-popup-text {
  margin: 0 0 1.25rem 0;
}

.sfweb-popup-text > :first-child {
  margin-top: 0;
}

.sfweb-popup-text > :last-child {
  margin-bottom: 0;
}

.sfweb-popup-content-inner > :last-child {
  margin-bottom: 0;
}

/* Action buttons */
.sfweb-popup-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 1.25rem;
}

.sfweb-popup-actions-gap-small {
  gap: 0.625rem;
}

.sfweb-popup-actions-gap-medium {
  gap: 1rem;
}

.sfweb-popup-halign-left .sfweb-popup-actions-align-inherit,
.sfweb-popup-actions-align-left {
  justify-content: flex-start;
}

.sfweb-popup-halign-center .sfweb-popup-actions-align-inherit,
.sfweb-popup-actions-align-center {
  justify-content: center;
}

.sfweb-popup-halign-right .sfweb-popup-actions-align-inherit,
.sfweb-popup-actions-align-right {
  justify-content: flex-end;
}

.sfweb-popup-actions-align-stack {
  flex-direction: column;
  align-items: stretch;
}

.sfweb-popup-actions-align-stack .sfweb-popup-btn {
  width: 100%;
}

.sfweb-popup-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  box-sizing: border-box;
  text-decoration: none;
}

/* Prevent double arrow on YOOtheme styles (e.g. Master Paladin) when icon is explicitly added */
.sfweb-popup-btn-has-icon.uk-button-text::after {
  display: none;
}

.sfweb-popup-btn-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

/* Zero-specificity button fallback when YOOtheme/UIkit CSS is absent */
:where(.sfweb-popup-btn.uk-button) {
  padding: 0.7rem 1.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
}

:where(.sfweb-popup-btn.uk-button-primary) {
  background-color: #1e87f0;
  color: #ffffff;
}

:where(.sfweb-popup-btn.uk-button-secondary) {
  background-color: #111827;
  color: #ffffff;
}

:where(.sfweb-popup-btn.uk-button-default) {
  background-color: transparent;
  color: currentColor;
  border-color: currentColor;
}

:where(.sfweb-popup-btn.uk-button-danger) {
  background-color: #f0506e;
  color: #ffffff;
}

:where(.sfweb-popup-btn.uk-button-small) {
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
}

:where(.sfweb-popup-btn.uk-button-large) {
  padding: 0.9rem 1.75rem;
  font-size: 1.05rem;
}

/* ==========================================================================
   7. Countdown Component (inherits UIkit 3 typography + custom presets)
   ========================================================================== */

.sfweb-popup-countdown {
  margin: 1rem 0 1.25rem;
}

.sfweb-popup-countdown[hidden],
.sfweb-popup-countdown-grid[hidden],
.sfweb-popup-countdown-expired[hidden] {
  display: none;
}

.sfweb-popup-countdown-grid {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.65rem;
}

.sfweb-popup-halign-left .sfweb-popup-countdown-grid {
  justify-content: flex-start;
}

.sfweb-popup-halign-right .sfweb-popup-countdown-grid {
  justify-content: flex-end;
}

.sfweb-popup-countdown-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.4rem;
}

.sfweb-popup-countdown-number {
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.35rem, 1rem + 3cqi, 2.35rem);
  font-weight: 700;
  line-height: 1.05;
}

.sfweb-popup-countdown-label {
  margin-top: 0.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.8;
}

.sfweb-popup-countdown-sep {
  font-size: clamp(1.15rem, 0.9rem + 2cqi, 1.85rem);
  font-weight: 600;
  line-height: 1;
  opacity: 0.65;
  align-self: flex-start;
  padding-top: 0.15em;
}

/* Preset: Cards */
.sfweb-popup-countdown-cards .sfweb-popup-countdown-unit {
  padding: 0.65rem 0.85rem;
  min-width: 4.1rem;
  border-radius: 8px;
  background-color: rgba(128, 128, 128, 0.14);
  border: 1px solid rgba(128, 128, 128, 0.22);
}

.uk-light .sfweb-popup-countdown-cards .sfweb-popup-countdown-unit {
  background-color: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.22);
}

.sfweb-popup-countdown-cards .sfweb-popup-countdown-sep {
  padding-top: 0.55rem;
}

/* Preset: Pills */
.sfweb-popup-countdown-pills .sfweb-popup-countdown-unit {
  flex-direction: row;
  gap: 0.35rem;
  min-width: auto;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  background-color: rgba(128, 128, 128, 0.15);
}

.uk-light .sfweb-popup-countdown-pills .sfweb-popup-countdown-unit {
  background-color: rgba(255, 255, 255, 0.16);
}

.sfweb-popup-countdown-pills .sfweb-popup-countdown-number {
  font-size: clamp(1rem, 0.85rem + 1.4cqi, 1.35rem);
}

.sfweb-popup-countdown-pills .sfweb-popup-countdown-label {
  margin-top: 0;
}

.sfweb-popup-countdown-pills .sfweb-popup-countdown-sep {
  display: none;
}

.sfweb-popup-countdown-expired {
  margin: 0;
  font-weight: 600;
}

/* ==========================================================================
   8. Container & Viewport Responsive Rules
   ========================================================================== */

@container sfweb-popup (max-width: 559px) {
  .sfweb-popup-layout-image_left,
  .sfweb-popup-layout-image_right {
    grid-template-columns: 1fr;
  }

  /* Place image on top when stacked vertically on narrow containers */
  .sfweb-popup-layout-image_right .sfweb-popup-media {
    order: -1;
  }

  .sfweb-popup-layout-image_left .sfweb-popup-media,
  .sfweb-popup-layout-image_right .sfweb-popup-media {
    min-height: 0;
    aspect-ratio: 16 / 9;
    max-height: 220px;
  }

  .sfweb-popup-countdown-cards .sfweb-popup-countdown-unit {
    min-width: 3.35rem;
    padding: 0.5rem 0.6rem;
  }
}

@media (max-width: 639px) {
  dialog.sfweb-popup-dialog {
    width: calc(100vw - 1.25rem);
    width: calc(100dvw - 1.25rem);
    max-height: 94vh;
    max-block-size: 94dvh;
  }

  dialog.sfweb-popup-dialog.sfweb-popup-pos-top-center,
  dialog.sfweb-popup-dialog.sfweb-popup-pos-top-left,
  dialog.sfweb-popup-dialog.sfweb-popup-pos-top-right {
    margin: 0.75rem auto auto auto !important;
  }

  dialog.sfweb-popup-dialog.sfweb-popup-pos-bottom-center,
  dialog.sfweb-popup-dialog.sfweb-popup-pos-bottom-left,
  dialog.sfweb-popup-dialog.sfweb-popup-pos-bottom-right {
    margin: auto auto 0.75rem auto !important;
  }

  .sfweb-popup-hide-img-mobile .sfweb-popup-media {
    display: none;
  }

  .sfweb-popup-layout-image_top .sfweb-popup-media,
  .sfweb-popup-layout-image_bottom .sfweb-popup-media {
    height: min(var(--sfweb-popup-banner-height, 240px), 200px);
  }
}
