/*
  pp/newsletter-popup — Figma "newsletter-popup" (4378:17557): a translucent
  violet panel docked to the right edge (only its left corners are rounded),
  slides in from the right. The form inside is the footer's WPForms form,
  moved in while open — every form rule here is scoped to the popup, so the
  footer's own form styling is untouched.
*/

.newsletter-popup {
  /* Top layer (showModal), docked to the right edge, lower part of the screen. */
  position: fixed;
  inset: auto 0 var(--space-3xl) auto;
  margin: 0;
  inline-size: min(35.625rem, 100% - var(--page-inset)); /* 570px */
  max-block-size: calc(100dvh - 2 * var(--space-xl));
  overflow-y: auto;
  padding: var(--space-xl);
  border: 0;
  border-radius: var(--radius-xl) 0 0 var(--radius-xl);
  background-color: color-mix(in srgb, var(--color-veilchen-80) 80%, transparent);
  backdrop-filter: blur(6px);
  color: var(--color-neutral-0);

  /* Slide in from the right edge. */
  translate: 100% 0;
  opacity: 0;
  transition:
    translate var(--transition-movement),
    opacity var(--transition-movement),
    overlay var(--transition-movement) allow-discrete,
    display var(--transition-movement) allow-discrete;

  &[open] {
    translate: 0 0;
    opacity: 1;

    @starting-style {
      translate: 100% 0;
      opacity: 0;
    }
  }

  &::backdrop {
    background-color: color-mix(in srgb, var(--color-neutral-100) 20%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .newsletter-popup {
    transition: none;
  }
}

.newsletter-popup__head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-l);
  margin-block-end: var(--space-section-s);
}

.newsletter-popup__intro {
  flex: 1;
  min-inline-size: 0;
}

.newsletter-popup__title {
  margin: 0 0 var(--space-m);
  font-size: var(--size-heading-2xl);
  font-weight: var(--font-bold);
  line-height: var(--leading-standard);
  color: inherit;
}

.newsletter-popup__text {
  margin: 0;
  font-size: var(--size-body);
  line-height: var(--leading-loose);
}

/* 43px outlined circle with the close icon. */

.newsletter-popup__close {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  inline-size: 2.6875rem;
  block-size: 2.6875rem;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;

  &::before {
    content: "";
    inline-size: 1.5rem;
    block-size: 1.5rem;
    background-color: currentColor;
    -webkit-mask: url(../../assets/icons/close.svg) center / contain no-repeat;
    mask: url(../../assets/icons/close.svg) center / contain no-repeat;
  }

  &:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
  }
}

/*
  The moved-in WPForms form: a white pill (email) with a raspberry round
  submit flush right, the privacy checkbox below. The field container is
  dissolved (display: contents) so email, submit and consent share one grid.
*/

.newsletter-popup .wpforms-container .wpforms-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "email submit"
    "consent consent";
  row-gap: var(--space-l);
  margin: 0;

  & .wpforms-field-container {
    display: contents;
  }

  /* Focus ring around the whole pill — email field AND round submit — as one
     shape: a layer over the first grid row, shown while the field has focus. */
  &::after {
    content: "";
    grid-row: 1;
    grid-column: 1 / -1;
    z-index: 2;
    border-radius: var(--radius-pill);
    outline: 2px solid var(--color-himbeere-60);
    outline-offset: 2px;
    opacity: 0;
    pointer-events: none;
  }

  &:has(.wpforms-field-email input:focus-visible)::after {
    opacity: 1;
  }

  /* Invalid email: the same ring in the error colour, around field and
     submit together (not the input's own border, which stops at the
     submit). */
  &:has(.wpforms-field-email.wpforms-has-error)::after {
    opacity: 1;
    outline-color: var(--input-border-color-error, var(--color-error));
  }

  /* Room for the validation message (it sits absolutely under the pill):
     the consent row moves down while it is shown. */
  &:has(.wpforms-field-email.wpforms-has-error) {
    row-gap: calc(var(--space-l) + 1.5rem);
  }

  & .wpforms-field {
    margin: 0;
    padding: 0;
  }

  & .wpforms-field-email {
    grid-area: email;
    display: flex;
    align-items: center;
    min-block-size: 3.5rem; /* 56px */
    border-radius: var(--radius-pill) 0 0 var(--radius-pill);
    background-color: var(--color-neutral-0);

    & > .wpforms-field-label {
      position: absolute;
      inline-size: 1px;
      block-size: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }

    /*
      The theme's global form styles use a floating label (input padding-top
      for the label, placeholder hidden). Here the label is visually hidden and
      the design shows the placeholder instead, so both are reset.
    */
    & input {
      inline-size: 100%;
      min-block-size: 3.5rem;
      padding-block: 0;
      padding-inline: var(--space-l);
      border: 0;
      border-radius: inherit;
      background: transparent;
      color: var(--color-text);
      font: inherit;
      font-size: var(--size-body);

      &::placeholder {
        color: var(--color-neutral-60);
        opacity: 1;
      }

      /* The ring is drawn around the whole pill (field + submit), below. */
      &:focus-visible {
        outline: none;
      }
    }

    /* (0,7,2): the reset above loses to form.css's field rule (0,5,1) and
       its floating-label shift (text sat low in the pill); same fix as the
       footer form. */
    & input[type="email"]:is(*, :focus, :not(:placeholder-shown)) {
      padding-block: 0;
      line-height: 3.5rem;
    }

    /* No border or inset ring on the field itself in any state (form.css
       paints error/focus there); the pill-wide ring above takes over. */
    & input[type="email"]:is(*, :focus, :invalid, .wpforms-error) {
      border: 0;
      box-shadow: none;
    }

    /* No (!) in the field: the submit sits right next to it. */
    &.wpforms-has-error::after {
      display: none;
    }

    /* Validation message sits under the pill, on the violet. */
    & em.wpforms-error,
    & label.wpforms-error {
      position: absolute;
      transform: translateY(2.25rem);
      padding-inline: var(--space-l);
      color: var(--color-neutral-0);
      font-size: var(--size-body-xs);
    }
  }

  & .wpforms-submit-container {
    grid-area: submit;
    display: flex;
    margin: 0;
    padding: 0;
    border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
    background-color: var(--color-neutral-0);
  }

  /*
    Round raspberry submit with the arrow. The "Anmelden" label stays in the
    DOM as the accessible name but is collapsed (flex keeps the zero-size text
    from adding a row the way a grid track would).
  */
  & button[type="submit"] {
    /* WPForms paints the label with these (its rule
       `div.wpforms-container-full button[type=submit]:not(:hover):not(:active)`
       outranks this one), so the hidden "Anmelden" showed over the arrow. */
    --wpforms-button-text-color: transparent;
    --button-text: transparent;
    --button-text-hover: transparent;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    inline-size: 3.5rem;
    block-size: 3.5rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background-color: var(--color-himbeere-60);
    color: transparent;
    /* Label hidden but kept as accessible name; not font-size: 0, which a
       browser minimum font size would still draw. */
    white-space: nowrap;
    text-indent: 200%;
    overflow: hidden;
    cursor: pointer;
    transition: background-color var(--transition-base);

    &::before {
      content: "";
      /* Absolute, so the text-indent that hides the label can't move it. */
      position: absolute;
      inset: 0;
      margin: auto;
      flex-shrink: 0;
      inline-size: 1.25rem;
      block-size: 1.25rem;
      background-color: var(--color-neutral-0);
      -webkit-mask: url(../../assets/icons/arrow-right.svg) center / contain no-repeat;
      mask: url(../../assets/icons/arrow-right.svg) center / contain no-repeat;
    }

    &:hover {
      background-color: var(--color-himbeere-80);
    }

    &:focus-visible {
      outline: 2px solid var(--color-neutral-0);
      outline-offset: 2px;
    }
  }

  & .wpforms-newsletter-consent,
  & .wpforms-field-checkbox {
    grid-area: consent;
    padding-inline-start: var(--space-s);

    & fieldset {
      margin: 0;
      padding: 0;
      border: 0;
    }

    & legend.wpforms-label-hide {
      position: absolute;
      inline-size: 1px;
      block-size: 1px;
      overflow: hidden;
      clip-path: inset(50%);
    }

    & ul {
      margin: 0;
      padding: 0;
      list-style: none;
    }

    & li {
      display: flex;
      align-items: flex-start;
      gap: var(--space-m);
    }

    & input[type="checkbox"] {
      appearance: none;
      flex-shrink: 0;
      display: grid;
      place-items: center;
      inline-size: 1.25rem;
      block-size: 1.25rem;
      margin: 0.1em 0 0;
      border-radius: var(--radius-s);
      background-color: var(--color-neutral-0);
      cursor: pointer;

      &::before {
        content: "";
        inline-size: 0.875rem;
        block-size: 0.875rem;
        background-color: var(--color-veilchen-80);
        -webkit-mask: url(../../assets/icons/check.svg) center / contain no-repeat;
        mask: url(../../assets/icons/check.svg) center / contain no-repeat;
        scale: 0;
        transition: scale var(--transition-base);
      }

      &:checked::before {
        scale: 1;
      }

      &:focus-visible {
        outline: 2px solid var(--color-neutral-0);
        outline-offset: 2px;
      }
    }

    & .wpforms-field-label-inline {
      font-size: var(--size-body-s);
      line-height: var(--leading-loose);
      letter-spacing: 0.01em;
      color: var(--color-neutral-0);

      & a {
        color: inherit;
        font-weight: var(--font-semibold);
        text-decoration: none;

        &:hover,
        &:focus-visible {
          text-decoration: underline;
        }
      }
    }

    & em.wpforms-error,
    & label.wpforms-error {
      display: block;
      margin-block-start: var(--space-s);
      color: var(--color-neutral-0);
      font-size: var(--size-body-xs);
    }
  }

  /* WPForms' own noscript notice and hidden helpers stay hidden. */
  & #wpforms-error-noscript {
    display: none;
  }
}

