/*
   Newsletter signup popup (CMS popup type "Newsletter Signup").
   Markup: resources/views/Frontend/layouts/common/partials/site_popup_newsletter.blade.php
   Behaviour: public/frontend/js/popup-newsletter.js

   Sizes follow the designer's build of the Figma popup
   (s3.datasight.biz/designs/the8palm, .newsletter-modal): a 900px white card
   with an even 26px border, the photo and text in a 1 : 1.08 grid, 54px
   field and button. Phones stack the photo above the form. Open/close
   animation comes from .site-popup-modal in style.css.
*/

.site-popup-modal .popup-newsletter__dialog {
  max-width: 900px;
  width: calc(100% - 2rem);
  margin-left: auto;
  margin-right: auto;
}

.popup-newsletter {
  position: relative;
  display: grid; /* overrides Bootstrap's flex column on .modal-content */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
  padding: 26px; /* the same white border on every side of the photo */
  background: #fff;
  border: 0;
  border-radius: 0;
  box-shadow: 0 24px 70px rgba(18, 14, 24, 0.3);
  color: var(--primary-color, #2E273B);
  font-family: 'Vignette Sans', sans-serif;
}

.popup-newsletter--no-image {
  grid-template-columns: minmax(0, 1fr);
}

/* ---- Close ---- */

.popup-newsletter__close {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #000;
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.popup-newsletter__close svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

.popup-newsletter__close:hover {
  opacity: 0.75;
}

.popup-newsletter__close:focus-visible {
  opacity: 1;
  outline: 2px solid var(--secondary-color, #5F2836);
  outline-offset: 2px;
}

/* ---- Photo ---- */

.popup-newsletter__media {
  min-height: 370px;
  overflow: hidden;
  background: #e9e4df;
}

.popup-newsletter__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---- Copy + form ---- */

.popup-newsletter__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-block: 10px 0;
  padding-inline: 34px 28px;
}

.popup-newsletter--no-image .popup-newsletter__body {
  padding-inline: 8px 40px; /* keeps the title clear of the close button */
}

.popup-newsletter__title {
  margin: 0 0 16px;
  color: var(--primary-color, #2E273B);
  font-family: 'Vignette Sans', sans-serif;
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: 0;
  text-transform: none;
}

.popup-newsletter__text {
  max-width: 430px;
  margin: 0 0 34px;
  color: rgba(46, 39, 59, 0.78);
  font-size: 0.82rem;
  line-height: 1.55;
}

.popup-newsletter__text p {
  margin: 0;
  color: inherit;
  line-height: inherit;
}

.popup-newsletter__text p + p {
  margin-top: 8px;
}

.popup-newsletter__text a {
  color: var(--secondary-color, #5F2836);
  text-decoration: underline;
}

/* Spaced with margins rather than a grid gap: an empty message line would
   otherwise still add a gap below the button, and the thank-you box could
   not match the form's height exactly. */
.popup-newsletter__form {
  display: grid;
}

.popup-newsletter__input {
  display: block;
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  border: 1px solid rgba(46, 39, 59, 0.45);
  border-radius: 0;
  background: #fff;
  color: var(--primary-color, #2E273B);
  font-family: inherit;
  font-size: 0.85rem;
  text-align: center;
  box-shadow: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

.popup-newsletter__input::placeholder {
  color: rgba(33, 37, 41, 0.75);
  opacity: 1;
}

.popup-newsletter__input:focus {
  outline: none;
  border-color: var(--secondary-color, #5F2836);
  box-shadow: 0 0 0 0.2rem rgba(95, 40, 54, 0.1);
}

.popup-newsletter__input.is-invalid {
  border-color: #b3261e;
}

.popup-newsletter__input.is-invalid:focus {
  box-shadow: 0 0 0 0.2rem rgba(179, 38, 30, 0.12);
}

/* Look and hover come from the site's .btn-custom.btn-primary-custom. */
.popup-newsletter__submit.btn-custom {
  display: flex;
  width: 100%;
  min-height: 54px;
  margin-top: 10px;
  justify-content: center;
  border: 0;
  box-shadow: none;
  cursor: pointer;
}

.popup-newsletter__submit.btn-custom:focus-visible {
  outline: 2px solid var(--secondary-color, #5F2836);
  outline-offset: 3px;
}

.popup-newsletter__submit.btn-custom:disabled {
  opacity: 0.7;
  cursor: progress;
  transform: none;
}

/* Visible to sighted users only once there is something to say; always in
   the accessibility tree so the live region announces changes. */
.popup-newsletter__feedback {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.45;
}

.popup-newsletter__feedback:not(:empty) {
  margin-top: 10px;
}

.popup-newsletter__feedback:focus {
  outline: none;
}

.popup-newsletter__feedback.is-error {
  color: #b3261e;
}

/* Success stays in the brand palette rather than system green: the field and
   button giving way to the message already say it worked, and the site's
   other confirmations (newsletter-confirm.blade.php) use the same plum on
   blush with a burgundy accent. Errors keep their red - that one has to read
   as a problem at a glance. */
.popup-newsletter__feedback.is-success {
  color: var(--primary-color, #2E273B);
}

/*
   After a successful signup (timings in popup-newsletter.js):
     1. is-subscribed       the field + button give way to the thank-you
                            message, which fades in;
     2. is-message-leaving  the message fades out;
     3. is-restoring        the field + button fade back in, so the popup
                            looks as it did at first, then it closes.
   The message box is exactly as tall as the field + gap + button it replaces
   (54 + 10 + 54), so nothing around it moves when they swap.
*/
.popup-newsletter__form.is-subscribed .popup-newsletter__input,
.popup-newsletter__form.is-subscribed .popup-newsletter__submit {
  display: none;
}

.popup-newsletter__form.is-subscribed .popup-newsletter__feedback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 118px;
  margin-top: 0;
  padding: 14px 16px;
  border: 1px solid rgba(95, 40, 54, 0.16);
  background: var(--light-bg, #F4EDE9);
  font-size: 0.9rem;
  text-align: center;
  animation: popup-newsletter-fade-in 0.3s ease both;
}

/* Burgundy check beside the message (Bootstrap Icons "check2-circle", loaded
   site-wide). Beside rather than above, so a longer CMS message still fits
   the 118px box without the popup changing height. */
.popup-newsletter__form.is-subscribed .popup-newsletter__feedback::before {
  content: "\f270";
  flex-shrink: 0;
  color: var(--secondary-color, #5F2836);
  font-family: bootstrap-icons;
  font-size: 1.35rem;
  line-height: 1;
}

.popup-newsletter__form.is-message-leaving .popup-newsletter__feedback {
  animation: popup-newsletter-fade-out 0.3s ease both;
}

.popup-newsletter__form.is-restoring .popup-newsletter__input,
.popup-newsletter__form.is-restoring .popup-newsletter__submit {
  animation: popup-newsletter-fade-in 0.3s ease both;
}

/* Winding down: nothing to click or type into any more. */
.popup-newsletter__form.is-closing {
  pointer-events: none;
}

@keyframes popup-newsletter-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popup-newsletter-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/*
   A slower, softer close than Bootstrap's 0.15s. Bootstrap waits for the
   .modal fade before hiding it, so lengthening it also lets the dialog's own
   0.5s ease-down (.site-popup-modal in style.css) play out instead of being
   cut short. Bootstrap fades the backdrop after the card, so it gets a
   shorter fade to keep the whole close under a second. The backdrop lives on
   <body>, outside the modal, so popup-newsletter.js flags <body> while this
   popup is open.
*/
@media (prefers-reduced-motion: no-preference) {
  .site-popup-modal--newsletter.fade {
    transition: opacity 0.45s ease;
  }

  body.popup-newsletter-active .modal-backdrop.fade {
    transition: opacity 0.3s ease;
  }
}

@media (prefers-reduced-motion: reduce) {
  .popup-newsletter__form .popup-newsletter__feedback,
  .popup-newsletter__form .popup-newsletter__input,
  .popup-newsletter__form .popup-newsletter__submit {
    animation: none !important;
  }
}

/* Honeypot: off-screen rather than display:none, which some bots skip. */
.popup-newsletter__hp {
  position: absolute !important;
  left: -10000px !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.popup-newsletter__footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-top: auto;
  padding-top: 28px;
}

.popup-newsletter__privacy {
  margin: 0;
  color: rgba(46, 39, 59, 0.64);
  font-size: 0.7rem;
  line-height: 1.4;
}

.popup-newsletter__logo {
  flex: 0 0 auto;
  width: 54px;
  height: auto;
}

/* Arabic: letter-spacing breaks the joins between Arabic letters... */
[dir="rtl"] .popup-newsletter__submit {
  letter-spacing: 0;
}

/* ...and the arrow points the way the text reads. */
[dir="rtl"] .popup-newsletter__submit .bi {
  transform: scaleX(-1);
}

/* ---- Phone: photo on top, form below ---- */

@media (max-width: 767.98px) {
  .site-popup-modal .popup-newsletter__dialog {
    width: calc(100% - 36px);
    margin: 18px auto;
  }

  .popup-newsletter {
    grid-template-columns: minmax(0, 1fr);
    padding: 18px;
  }

  .popup-newsletter__media {
    min-height: 0;
    height: 220px;
  }

  /* Sits over the photo corner, so it gets its own backing to stay legible. */
  .popup-newsletter__close {
    top: 24px;
    inset-inline-end: 24px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    opacity: 1;
  }

  .popup-newsletter--no-image .popup-newsletter__close {
    top: 8px;
    inset-inline-end: 8px;
    box-shadow: none;
  }

  .popup-newsletter__body,
  .popup-newsletter--no-image .popup-newsletter__body {
    padding: 28px 6px 4px;
  }

  .popup-newsletter__text {
    max-width: none;
    margin-bottom: 22px;
  }

  /* 16px stops iOS Safari zooming the page when the field is focused. */
  .popup-newsletter__input {
    font-size: 16px;
  }

  .popup-newsletter__footer {
    padding-top: 22px;
  }
}

/* Phones in landscape: there's no room for the photo above the form, and
   without it the card only needs the form's width. */
@media (max-height: 540px) and (max-width: 991.98px) {
  .site-popup-modal .popup-newsletter__dialog {
    max-width: 460px;
  }

  .popup-newsletter {
    grid-template-columns: minmax(0, 1fr);
  }

  .popup-newsletter__media {
    display: none;
  }

  .popup-newsletter__close {
    top: 8px;
    inset-inline-end: 8px;
    width: 28px;
    height: 28px;
    background: transparent;
    box-shadow: none;
    opacity: 0.5;
  }

  .popup-newsletter__body {
    padding: 12px 6px 4px;
  }
}
