/* ============================================================
   popups.css — okresowe popupy Villa Verdi
   Warianty: image-only | image-bg | text-only | split
   Tła:      default | alt | dark | black (jak section--*)
   Wspólny system tokenów z base.css.
   ============================================================ */

/* ===== 1. OVERLAY + ROOT WRAPPER ===== */

.popup {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* Wartości startowe — finalne wartości ustawia GSAP. 
     Bez GSAP popup jest „odpalany" przez klasę .popup--is-open. */
}

.popup--is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.popup__overlay {
  position: absolute;
  inset: 0;
  background: rgba(2, 3, 4, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
}

/* ===== 2. DIALOG (kontener treści) ===== */

.popup__dialog {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - var(--space-8));
  max-height: calc(100dvh - var(--space-8));
  background: var(--color-bg);
  color: var(--color-text);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== 3. CLOSE BUTTON ===== */

.popup__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 2;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(250, 247, 242, 0.9);
  color: var(--color-text);
  border-radius: 50%;
  font-size: var(--fs-lg);
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition),
              color var(--transition),
              transform var(--transition);
}

.popup__close:hover {
  background: var(--color-accent);
  transform: rotate(90deg);
}

.popup__close:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

/* Ikona X — czysty SVG, bez zależności */
.popup__close::before {
  content: '';
  width: 16px;
  height: 16px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/></svg>") center / contain no-repeat;
}

/* ===== 4. WSPÓLNE ELEMENTY TREŚCI ===== */

.popup__media {
  position: relative;
  overflow: hidden;
  background: var(--color-bg-soft);
  flex-shrink: 0;
}

.popup__media img,
.popup__media picture {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.popup__body {
  padding: var(--space-12) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  overflow-y: auto;
  flex: 1;
}

.popup__label {
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--color-accent);
  margin: 0;
}

.popup__title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 400;
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text);
  margin: 0;
}

.popup__lead {
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--color-text-soft);
  margin: 0;
}

.popup__divider {
  width: 60px;
  height: 1px;
  background: var(--color-accent);
  border: 0;
  margin: var(--space-2) 0;
}

.popup__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.popup__actions .btn {
  flex: 1 1 auto;
  min-width: 0;
}

/* ============================================================
   5. WARIANT: image-only — wyłącznie obrazek (plakat)
   ============================================================ */

.popup--image-only .popup__dialog {
  background: transparent;
  box-shadow: var(--shadow-lg);
  max-width: 640px;
  aspect-ratio: 4 / 5;
  max-height: calc(100vh - var(--space-8));
  max-height: calc(100dvh - var(--space-8));
}

.popup--image-only .popup__media {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-lg);
  cursor: pointer; /* cały plakat klikalny, jeśli ma link */
}

.popup--image-only.popup--has-link .popup__media::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.25) 0%, transparent 35%);
  pointer-events: none;
}

/* ============================================================
   6. WARIANT: image-bg — obrazek jako tło + tekst na obrazku
   ============================================================ */

.popup--image-bg .popup__dialog {
  max-width: 640px;
  aspect-ratio: 4 / 5;
  max-height: calc(100vh - var(--space-8));
  max-height: calc(100dvh - var(--space-8));
  color: var(--color-text-invert);
}

.popup--image-bg .popup__media {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.popup--image-bg .popup__media::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    160deg,
    rgba(2, 3, 4, 0.15) 0%,
    rgba(2, 3, 4, 0.55) 60%,
    rgba(2, 3, 4, 0.85) 100%
  );
}

.popup--image-bg .popup__body {
  position: relative;
  z-index: 1;
  justify-content: flex-end;
  padding: var(--space-12) var(--space-8) var(--space-8);
  background: transparent;
}

.popup--image-bg .popup__title { color: var(--color-text-invert); }
.popup--image-bg .popup__lead  { color: rgba(250, 247, 242, 0.85); }
.popup--image-bg .popup__label { color: var(--color-accent); }
.popup--image-bg .popup__divider { background: var(--color-accent); }

.popup--image-bg .popup__close {
  background: rgba(250, 247, 242, 0.15);
  color: var(--color-text-invert);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.popup--image-bg .popup__close:hover {
  background: var(--color-accent);
  color: var(--color-text);
}

/* ============================================================
   7. WARIANT: text-only — klasyczny popup, sam tekst
   ============================================================ */

.popup--text-only .popup__dialog {
  max-width: 520px;
}

.popup--text-only .popup__body {
  padding: clamp(2rem, 5vw, 3.5rem) clamp(1.5rem, 4vw, 3rem);
  text-align: center;
  align-items: center;
}

.popup--text-only .popup__divider {
  margin-inline: auto;
}

.popup--text-only .popup__actions {
  justify-content: center;
  width: 100%;
}

/* ============================================================
   8. WARIANT: split — obrazek 50% + tekst 50%
   ============================================================ */

.popup--split .popup__dialog {
  max-width: 880px;
  flex-direction: row;
  max-height: min(560px, calc(100vh - var(--space-8)));
  max-height: min(560px, calc(100dvh - var(--space-8)));
}

.popup--split .popup__media {
  flex: 1 1 50%;
  min-height: 100%;
}

.popup--split .popup__body {
  flex: 1 1 50%;
  padding: var(--space-12) var(--space-8);
  justify-content: center;
}

/* ============================================================
   9. MODYFIKATORY TŁA (parytet z section--*)
   Nie dotyczy wariantów --image-only / --image-bg
   (one mają własne tła z obrazka).
   ============================================================ */

.popup--alt .popup__dialog {
  background: var(--color-bg-alt);
}

.popup--dark .popup__dialog {
  background: var(--color-bg-dark);
  color: var(--color-text-invert);
}
.popup--dark .popup__title { color: var(--color-text-invert); }
.popup--dark .popup__lead  { color: rgba(250, 247, 242, 0.8); }
.popup--dark .popup__label { color: var(--color-accent); }
.popup--dark .popup__close {
  background: rgba(250, 247, 242, 0.12);
  color: var(--color-text-invert);
}
.popup--dark .popup__close:hover {
  background: var(--color-accent);
  color: var(--color-text);
}

.popup--black .popup__dialog {
  background: var(--color-bg-black);
  color: var(--color-text-invert);
}
.popup--black .popup__title { color: var(--color-text-invert); }
.popup--black .popup__lead  { color: rgba(250, 247, 242, 0.75); }
.popup--black .popup__label { color: var(--color-accent); }
.popup--black .popup__close {
  background: rgba(250, 247, 242, 0.12);
  color: var(--color-text-invert);
}
.popup--black .popup__close:hover {
  background: var(--color-accent);
  color: var(--color-text);
}

/* ============================================================
   10. SCROLL LOCK — klasa wstrzykiwana na <html> przez JS
   
   Kompensacja scrollbara (Chrome/Edge na Windows):
   - JS ustawia CSS var --scrollbar-width na <html> (np. 17px).
   - JS ustawia inline padding-right na <body> dla treści w flow.
   - CSS poniżej kompensuje elementy position:fixed (header itd.),
     które padding na body NIE dosięga.
   
   Firefox stabilizuje gutter natywnie (scrollbar-gutter: stable
   w User Agent stylesheet), dlatego tam tego skoku nie ma.
   ============================================================ */

html.popup-is-open {
  overflow: hidden;
}

/* Kompensacja elementów position:fixed.
   
   .header — fixed; left:0; right:0 → gdy scrollbar znika, header
   rozciąga się o jego szerokość. Używamy `right` (nie `padding-right`),
   bo header ma `padding: var(--space-2) 0` (shorthand bez right), które
   nadpisałoby nasz longhand niezależnie od kolejności reguł.
   
   .lang-holder — fixed; right:0 → przesuwa się w prawo o szerokość
   scrollbara gdy ten znika. Trzymamy go w miejscu przez `right`.
   
   !important jako asekuracja: nie wiemy, w jakiej kolejności
   sections.css i popups.css są ładowane w <head>; ta reguła musi
   wygrać bezwarunkowo. */

html.popup-is-open .header {
  right: var(--scrollbar-width, 0px) !important;
}

html.popup-is-open .lang-holder {
  right: var(--scrollbar-width, 0px) !important;
}

/* Jeśli kiedyś dojdą inne elementy fixed/sticky widoczne nad popupem
   (np. floating CTA, cookie bar), dodaj je tutaj według tego samego wzoru:
   
   html.popup-is-open .floating-cta { right: var(--scrollbar-width, 0px) !important; }
*/

/* ============================================================
   11. RESPONSIVE — MOBILE (≤768px)
   ============================================================ */

@media (max-width: 768px) {

  .popup {
    padding: var(--space-3);
    align-items: flex-end; /* mobile: bottom sheet feel */
  }

  .popup__dialog {
    max-width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .popup__close {
    width: 36px;
    height: 36px;
    top: var(--space-2);
    right: var(--space-2);
  }

  .popup__close::before {
    width: 14px;
    height: 14px;
  }

  .popup__body {
    padding: var(--space-8) var(--space-6);
  }

  /* image-only — mobile: zachowaj aspect ratio, ale niżej */
  .popup--image-only .popup__dialog {
    aspect-ratio: 3 / 4;
    max-height: 80vh;
    max-height: 80dvh;
  }

  /* image-bg — mobile: niższy aspect, więcej miejsca na tekst */
  .popup--image-bg .popup__dialog {
    aspect-ratio: 3 / 4;
    max-height: 85vh;
    max-height: 85dvh;
  }

  .popup--image-bg .popup__body {
    padding: var(--space-8) var(--space-6) var(--space-6);
  }

  /* split — mobile: stackuje się pionowo (obrazek na górze, tekst pod) */
  .popup--split .popup__dialog {
    flex-direction: column;
    max-height: 90vh;
    max-height: 90dvh;
  }

  .popup--split .popup__media {
    flex: 0 0 auto;
    height: 220px;
    min-height: 0;
  }

  .popup--split .popup__body {
    flex: 1 1 auto;
    padding: var(--space-6);
  }

  /* text-only — mobile: mniej paddingu */
  .popup--text-only .popup__body {
    padding: var(--space-8) var(--space-6);
  }

  /* Actions: stack przycisków na wąskich ekranach */
  .popup__actions {
    flex-direction: column;
  }

  .popup__actions .btn {
    width: 100%;
  }
}

/* ============================================================
   12. PREFERS-REDUCED-MOTION
   Pomijamy własne transitions; GSAP samo respektuje to przez 
   gsap.matchMedia w popups.js (opcjonalnie), ale tu robimy backup.
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .popup__close { transition: none; }
  .popup__close:hover { transform: none; }
}
