/**
 * SOLID Mailings - Forms
 *
 * The form inherits from the theme by default: the font, the colours and
 * the button come from the page it sits on, so it looks like it belongs
 * there without anyone setting anything.
 *
 * What a customer sets in wp-admin (maximum width, space around a
 * heading) arrives as custom properties on that one form; the two
 * colours arrive as rules with the id of the form. Both are written by
 * the renderer, so they override what is below without affecting any
 * other form.
 *
 * The layout reacts to the room the form gets, not to the width of the
 * screen: the wrapper around the form is a CSS container. A form in a
 * narrow footer column on a wide screen is treated like a form on a phone.
 *
 * @package SolidMailings
 */

/* ---------------------------------------------------------------- */
/* Wrapper and form                                                  */
/* ---------------------------------------------------------------- */

.solidmailings-wrap
{
   container-type: inline-size;
   container-name: solidmailings;
   width: 100%;
}

.solidmailings-form
{
   /* Fixed values; the Custom CSS field is there to change them. */
   --solidmailings-gap: 0.9em;
   --solidmailings-padding: 0.6em 0.8em;
   --solidmailings-radius: 4px;

   /*
    * A muted version of the surrounding text colour, so the border stays
    * visible on a light and on a dark theme. Browsers without color-mix
    * fall back to the rule below this block.
    */
   --solidmailings-border: color-mix(in srgb, currentColor 30%, transparent);

   /* How the heading, checkboxes, captcha and button line up. */
   --solidmailings-justify: flex-start;
   --solidmailings-text-align: left;

   box-sizing: border-box;
   width: 100%;
   max-width: var(--solidmailings-width, 100%);
   margin: 0;
   font-family: inherit;
   color: inherit;
}

@supports not (color: color-mix(in srgb, currentColor 30%, transparent))
{
   .solidmailings-form
   {
      --solidmailings-border: currentColor;
   }
}

.solidmailings-form *,
.solidmailings-form *::before,
.solidmailings-form *::after
{
   box-sizing: inherit;
}

/* ---------------------------------------------------------------- */
/* Alignment                                                         */
/* ---------------------------------------------------------------- */

.solidmailings-form--align-center
{
   margin-left: auto;
   margin-right: auto;

   --solidmailings-justify: center;
   --solidmailings-text-align: center;
}

.solidmailings-form--align-right
{
   margin-left: auto;
   margin-right: 0;

   --solidmailings-justify: flex-end;
   --solidmailings-text-align: right;
}

/* ---------------------------------------------------------------- */
/* Fields                                                            */
/* ---------------------------------------------------------------- */

/* The fields always take the full width and stay left-aligned,
   whatever the alignment of the form. */
.solidmailings-fields
{
   display: flex;
   flex-direction: column;
   gap: var(--solidmailings-gap);
   text-align: left;
}

.solidmailings-field
{
   display: flex;
   flex-direction: column;
   gap: 0.3em;
   min-width: 0;
}

.solidmailings-label
{
   font-size: 0.95em;
   line-height: 1.3;
}

.solidmailings-required
{
   opacity: 0.7;
}

.solidmailings-form .solidmailings-input,
.solidmailings-form input.solidmailings-input,
.solidmailings-form select.solidmailings-select
{
   width: 100%;
   max-width: 100%;
   margin: 0;
   padding: var(--solidmailings-padding);
   font-family: inherit;
   font-size: inherit;
   line-height: 1.4;
   color: inherit;
   background: transparent;
   border: 1px solid var(--solidmailings-border);
   border-radius: var(--solidmailings-radius);
}

.solidmailings-form .solidmailings-input:focus-visible
{
   outline: 2px solid currentColor;
   outline-offset: 2px;
}

/* ---------------------------------------------------------------- */
/* Headings and their blocks of fields                               */
/* ---------------------------------------------------------------- */

.solidmailings-group
{
   /*
    * The space above a heading is the whole distance to what comes before
    * it. The gap between the fields is already there, so only the rest is
    * added as a margin.
    */
   margin: calc(var(--solidmailings-heading-above, 30px) - var(--solidmailings-gap)) 0 0;
   padding: 0;
   border: 0;
   min-width: 0;
}

/* A block right at the top of the form needs no space above it. */
.solidmailings-fields > .solidmailings-group:first-child
{
   margin-top: 0;
}

/*
 * A legend is drawn on the border of its fieldset by default, where it
 * ignores alignment and margins. Floating it makes it an ordinary block.
 */
.solidmailings-group-title
{
   float: left;
   width: 100%;
   padding: 0;
   margin: 0 0 var(--solidmailings-heading-below, 18px);
   font-size: 1em;
   font-weight: 600;
   line-height: 1.3;
   text-align: var(--solidmailings-text-align);
}

.solidmailings-group-fields
{
   clear: both;
   display: flex;
   flex-direction: column;
   gap: var(--solidmailings-gap);
}

/* ---------------------------------------------------------------- */
/* Fields with choices                                               */
/* ---------------------------------------------------------------- */

.solidmailings-choices
{
   display: flex;
   flex-wrap: wrap;
   gap: 4px 18px;
   padding-top: 4px;
}

.solidmailings-choice
{
   display: inline-flex;
   align-items: center;
   gap: 6px;
   font-weight: normal;
}

.solidmailings-choice input
{
   margin: 0;
}

/* Longer answers are easier to read one per line. */
.solidmailings-choices--stacked
{
   flex-direction: column;
   gap: 4px;
}

/* ---------------------------------------------------------------- */
/* Checkboxes under the fields                                       */
/* ---------------------------------------------------------------- */

/*
 * The block follows the alignment of the form, but the text inside it
 * stays left-aligned: centred text over two lines next to a checkbox
 * reads badly.
 */
.solidmailings-form .solidmailings-field--consent,
.solidmailings-form .solidmailings-field--newsletter
{
   flex-direction: row;
   justify-content: var(--solidmailings-justify);
   margin-top: var(--solidmailings-gap);
}

.solidmailings-checkbox
{
   display: flex;
   align-items: flex-start;
   gap: 0.5em;
   max-width: 100%;
   font-size: 0.95em;
   line-height: 1.4;
   text-align: left;
   cursor: pointer;
}

.solidmailings-checkbox input[type="checkbox"]
{
   flex: 0 0 auto;
   margin: 0.2em 0 0;
}

/* ---------------------------------------------------------------- */
/* Captcha                                                           */
/* ---------------------------------------------------------------- */

/* The widget itself is an iframe of Cloudflare or Google and is not
   touched; only its place on the form is set here. */
.solidmailings-captcha
{
   display: flex;
   justify-content: var(--solidmailings-justify);
   margin-top: var(--solidmailings-gap);
}

/* The invisible variant of reCAPTCHA v2 shows nothing, so a margin would
   only leave an empty space. */
.solidmailings-captcha--invisible
{
   margin-top: 0;
}

/* ---------------------------------------------------------------- */
/* Button                                                            */
/* ---------------------------------------------------------------- */

.solidmailings-actions
{
   display: flex;
   justify-content: var(--solidmailings-justify);
   margin-top: var(--solidmailings-gap);
}

/*
 * The button gets no styling from this file: colours, shape, padding,
 * font size and hover all come from the theme, exactly like the other
 * buttons on the website. Only the cursor is set. With a text colour
 * set in wp-admin the renderer turns it into an outlined button.
 */
.solidmailings-form .solidmailings-button
{
   cursor: pointer;
}

.solidmailings-form.is-busy .solidmailings-button
{
   cursor: progress;
}

/*
 * While the form is being sent, a small spinning circle appears next to
 * the text of the button. It takes the text colour of the button, so it
 * fits the theme or the colours set in wp-admin without any setting.
 */
.solidmailings-form.is-busy .solidmailings-button::after
{
   content: "";
   display: inline-block;
   flex: 0 0 auto;
   width: 0.9em;
   height: 0.9em;
   margin-left: 0.6em;
   vertical-align: -0.12em;
   border: 2px solid currentColor;
   border-right-color: transparent;
   border-radius: 50%;
   animation: solidmailings-spin 0.7s linear infinite;
}

@keyframes solidmailings-spin
{
   to
   {
      transform: rotate(360deg);
   }
}

/* Visitors who asked their system for less motion get a slower turn. */
@media (prefers-reduced-motion: reduce)
{
   .solidmailings-form.is-busy .solidmailings-button::after
   {
      animation-duration: 2s;
   }
}

/* ---------------------------------------------------------------- */
/* Side by side                                                      */
/* ---------------------------------------------------------------- */

.solidmailings-form--inline .solidmailings-fields,
.solidmailings-form--inline .solidmailings-group-fields
{
   flex-direction: row;
   flex-wrap: wrap;
   align-items: flex-end;
}

/* The e-mail address is usually the longest answer, so it gets a little
   more room than the other fields: roughly 60/40 next to one other field. */
.solidmailings-form--inline .solidmailings-field
{
   flex: 2 1 9em;
}

.solidmailings-form--inline .solidmailings-field--email
{
   flex: 3 1 12em;
}

/* A heading and its fields always start on a row of their own. */
.solidmailings-form--inline .solidmailings-group
{
   flex: 1 1 100%;
}

/* The button at the end of the row of fields, without a margin above it. */
.solidmailings-form--button-in-row .solidmailings-fields .solidmailings-actions
{
   flex: 0 0 auto;
   margin-top: 0;
}

/* ---------------------------------------------------------------- */
/* Narrow: a phone, or a narrow column                               */
/* ---------------------------------------------------------------- */

@container solidmailings (max-width: 480px)
{
   /* Side by side becomes below each other, each field at full width. */
   .solidmailings-form--inline .solidmailings-fields,
   .solidmailings-form--inline .solidmailings-group-fields
   {
      flex-direction: column;
      flex-wrap: nowrap;
      align-items: stretch;
   }

   .solidmailings-form--inline .solidmailings-field,
   .solidmailings-form--inline .solidmailings-field--email,
   .solidmailings-form--inline .solidmailings-group
   {
      flex: 0 0 auto;
   }

   /* The button that was in the row goes under the fields, like the rest. */
   .solidmailings-form--button-in-row .solidmailings-fields .solidmailings-actions
   {
      margin-top: 0;
   }

   /* Right-aligned text reads badly on a narrow width, next to a
      checkbox above all, so right becomes left. Centred stays centred. */
   .solidmailings-form--align-right
   {
      margin-left: 0;

      --solidmailings-justify: flex-start;
      --solidmailings-text-align: left;
   }
}

/* ---------------------------------------------------------------- */
/* Messages                                                          */
/* ---------------------------------------------------------------- */

.solidmailings-message
{
   margin-top: var(--solidmailings-gap);
   line-height: 1.5;
   text-align: var(--solidmailings-text-align, left);
}

.solidmailings-message:empty
{
   margin-top: 0;
}

.solidmailings-message--success,
.solidmailings-message--error
{
   padding: 0.8em 1em;
   border-left: 3px solid currentColor;
   text-align: left;
}

.solidmailings-message--error
{
   opacity: 0.9;
}

.solidmailings-message--standalone
{
   margin-top: 0;
   margin-bottom: var(--solidmailings-gap, 0.9em);
}

/* The form is replaced by its message once it has been sent. */
.solidmailings-form.is-done .solidmailings-fields,
.solidmailings-form.is-done .solidmailings-actions,
.solidmailings-form.is-done .solidmailings-field--consent,
.solidmailings-form.is-done .solidmailings-field--newsletter,
.solidmailings-form.is-done .solidmailings-captcha
{
   display: none;
}

/* ---------------------------------------------------------------- */
/* Notices for the site editor                                       */
/* ---------------------------------------------------------------- */

.solidmailings-notice
{
   padding: 0.8em 1em;
   margin: 0 0 1em;
   border: 1px dashed currentColor;
   border-radius: 4px;
   font-size: 0.95em;
   opacity: 0.85;
}

/* The honeypot, for the rare case where inline styles are stripped. */
.solidmailings-hp
{
   position: absolute !important;
   left: -9999px !important;
   width: 1px !important;
   height: 1px !important;
   overflow: hidden !important;
}
