/* FORMS
   Shared form primitives for the newsletter CTA, the "Got a Story?" form and the contact form.
   Field borders meet 3:1 non-text contrast (WCAG 1.4.11) in both colour schemes. */


/* Tokens */

:root {
  --color-field-border: #949494;
  --color-error: #b3261e;
  --color-success: #1e6b3a;
}

html.theme-dark {
  --color-field-border: #6f6b68;
  --color-error: #f2b8b5;
  --color-success: #8fd4a6;
}


/* Layout */

.mews-form {
  display: grid;
  gap: 1.25rem;
  position: relative;
}

.form-row {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 720px) {
  .form-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-row--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.form-field {
  min-width: 0;
}

/* Conditional blocks are toggled with the hidden attribute; layout rules must not override it */
.mews-form [hidden] {
  display: none !important;
}

/* Native date pickers and radios follow the colour scheme */
html.theme-dark .mews-form {
  color-scheme: dark;
}


/* Field groups (conditional details) */

.form-group {
  border: 1px solid var(--color-lightest);
  display: grid;
  gap: 1.25rem;
  margin: 0;
  min-width: 0;
  padding: 1.25rem 1.25rem 1.5rem;
}

.form-group-legend {
  color: var(--color-titles);
  font-family: var(--font-accent);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  margin-left: -0.5rem;
  padding: 0 0.5rem;
  text-transform: uppercase;
}

.form-group-context {
  text-transform: none;
}

.has-submission-type .form-group-context {
  display: none;
}

.form-choice-group {
  border: 0;
  margin: 0;
  min-width: 0;
  padding: 0;
}

.form-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}

.form-choices--stacked {
  flex-direction: column;
}

/* A conditional group inside another (e.g. embargo details) */
.form-group--nested {
  border-style: dashed;
  padding: 1rem 1rem 1.25rem;
}

.form-choice {
  align-items: center;
  color: var(--color-body-text);
  cursor: pointer;
  display: inline-flex;
  font-family: var(--font-accent);
  font-size: 0.875rem;
  gap: 0.5rem;
}

.form-choice input {
  accent-color: var(--color-titles);
  height: 1rem;
  margin: 0;
  width: 1rem;
}

.form-choice input:focus-visible {
  outline: 2px solid var(--color-titles);
  outline-offset: 2px;
}


/* Labels */

.form-label {
  color: var(--color-titles);
  display: block;
  font-family: var(--font-accent);
  font-size: 0.875rem;
  line-height: 1.4;
  margin-bottom: 0.5rem;
}

.form-label--caps {
  color: var(--color-lighter);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.form-required {
  color: var(--color-error);
  margin-left: 0.25em;
}

.form-legend {
  color: var(--color-lighter);
  font-family: var(--font-accent);
  font-size: 0.75rem;
}


/* Controls */

.form-input,
.form-select,
.form-textarea {
  background-color: var(--color-body-bg);
  border: 1px solid var(--color-field-border);
  border-radius: 0;
  color: var(--color-body-text);
  display: block;
  font-family: var(--font-accent);
  font-size: 0.875rem;
  line-height: 1.5;
  padding: 0.75rem 1rem;
  transition: border-color 0.15s ease-out;
  width: 100%;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-lighter);
  opacity: 1;
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
  border-color: var(--color-body-text);
}

.form-input:focus-visible,
.form-select:focus-visible,
.form-textarea:focus-visible {
  border-color: var(--color-titles);
  outline: 2px solid var(--color-titles);
  outline-offset: 2px;
}

.form-textarea {
  min-height: 8rem;
  resize: vertical;
}

.form-textarea--short {
  min-height: 5rem;
}

.form-select-wrap {
  color: var(--color-body-text);
  position: relative;
}

.form-select {
  appearance: none;
  cursor: pointer;
  padding-right: 2.75rem;
}

/* Chevron drawn with borders so it follows the text colour in both schemes */
.form-select-wrap::after {
  border-bottom: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
  content: '';
  height: 0.45rem;
  pointer-events: none;
  position: absolute;
  right: 1.1rem;
  top: 50%;
  transform: translateY(-70%) rotate(45deg);
  width: 0.45rem;
}

.mews-form [aria-invalid="true"] {
  border-color: var(--color-error);
}


/* Messages */

.form-error {
  color: var(--color-error);
  font-family: var(--font-accent);
  font-size: 0.8125rem;
  line-height: 1.4;
  margin-top: 0.375rem;
}

.form-status {
  font-family: var(--font-accent);
  font-size: 0.875rem;
  line-height: 1.5;
  margin-bottom: 0;
}

.form-status[data-state="success"] {
  color: var(--color-success);
}

.form-status[data-state="error"] {
  color: var(--color-error);
}

/* Field errors are only referenced via aria-describedby, so they can leave the layout */
.form-error:empty {
  display: none;
}

/* Status regions must stay in the accessibility tree while empty, or the first message
   written into them may not be announced. Hide them visually and out of the grid flow. */
.form-status:empty {
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.form-note {
  color: var(--color-lighter);
  font-family: var(--font-accent);
  font-size: 0.75rem;
  line-height: 1.5;
  margin-bottom: 0;
}

.form-hint {
  color: var(--color-lighter);
  font-family: var(--font-accent);
  font-size: 0.8125rem;
  line-height: 1.5;
  margin: 0.375rem 0 0;
}

.mews-form > .form-hint {
  margin-top: -0.5rem;
}

/* Editorial disclaimer under the story form: a little more prominent than other notes */
.form-disclaimer {
  color: var(--color-body-text);
  font-weight: 500;
}

.form-note a {
  color: inherit;
  text-decoration: underline;
}

.form-note > :last-child {
  margin-bottom: 0;
}


/* Submit */

.btn.btn-form {
  align-items: center;
  display: inline-flex;
  font-size: 0.875rem;
  font-weight: 600;
  gap: 0.5rem;
  justify-content: center;
  letter-spacing: 0.01em;
  padding: 0.875rem 1.75rem;
  text-transform: none;
}

.btn.btn-form svg {
  flex-shrink: 0;
  height: 0.875rem;
  width: 0.875rem;
}

.btn.btn-form:focus-visible {
  outline: 2px solid var(--color-titles);
  outline-offset: 2px;
}

/* !important: the vendor .btn rule pins opacity to 1 with !important */
.mews-form[aria-busy="true"] .btn-form,
.mews-form.loading .btn-form {
  cursor: progress;
  opacity: 0.7!important;
}

.form-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
}

@media (max-width: 479.98px) {
  .form-actions .btn-form {
    width: 100%;
  }
}


@media (min-width: 720px) {
  .form-field--narrow {
    max-width: 20rem;
  }
}




/* Spam trap: off-screen, hidden from assistive tech and skipped by keyboard */

.form-honeypot {
  height: 1px;
  left: -10000px;
  overflow: hidden;
  position: absolute;
  width: 1px;
}


@media (prefers-reduced-motion: reduce) {
  .form-input,
  .form-select,
  .form-textarea {
    transition: none;
  }
}
