/*
 * Formogram public forms (ADR 0010, decision 62). Mobile first, system fonts, Formogram's tokens (ADR 0004): small
 * radius, flat surfaces with borders. The owner's formStyle arrives as --fg-* custom properties on .fg-page
 * (docs/public-forms/form-style.md); each is used with the stylesheet's own value as the fallback.
 */

:root {
  --fg-text: #1d1c1d;
  --fg-muted: #5e5e5e;
  --fg-primary: #1264a3;
  --fg-primary-dark: #0b4c7f;
  --fg-danger: #de4e2b;
  --fg-danger-text: #b5371b;
  --fg-line: #d4d4d4;
  --fg-line-strong: #868686;
  --fg-surface: #fff;
  --fg-canvas: #f8f8f8;
  --fg-tint: #f2f7fb;
  --fg-accent: #f7c46c;
  --fg-radius: 4px;
  --fg-system-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* hidden wins over the display of a class: the embed's payment box, an edit link's file input before Remove. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--fg-canvas);
  color: var(--fg-text);
  font-family: var(--fg-system-font);
  font-size: 1rem;
  line-height: 1.5;
}

/* The page: the owner's background colour and image. */
.fg-page {
  min-height: 100vh;
  padding: 0 0 1.5rem;
  background-color: var(--fg-page-bg, var(--fg-canvas));
  background-image: var(--fg-page-bg-image, none);
  background-repeat: var(--fg-page-bg-repeat, repeat);
  background-position: var(--fg-page-bg-position, left top);
  background-attachment: var(--fg-page-bg-attachment, scroll);
  font-family: var(--fg-font, var(--fg-system-font));
}

/* The card: edge to edge on a phone, a centred column with the owner's border from 40rem. */
.fg-card {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 1.5rem;
  background: var(--fg-surface);
  border-bottom: 1px solid var(--fg-line);
  overflow-wrap: anywhere;
  /* The field title placement below follows the card's width, so an embed and the builder's canvas get it too. */
  container-type: inline-size;
}

@media (min-width: 42rem) {
  .fg-page {
    padding: 2.5rem 1rem;
  }

  .fg-card {
    padding: 2rem 2.5rem 2.25rem;
    border: var(--fg-border, 1px solid var(--fg-line));
    border-radius: var(--fg-radius);
  }
}

.fg-card img {
  max-width: 100%;
  height: auto;
}

.fg-card a {
  color: var(--fg-primary);
}

.fg-card table {
  border-collapse: collapse;
  max-width: 100%;
}

/* Header and footer texts (owner HTML). */
.fg-title {
  margin: 0 0 0.5rem;
  color: var(--fg-title-color, inherit);
  font-size: var(--fg-title-size, 1.625rem);
  font-weight: var(--fg-title-weight, 700);
  line-height: 1.25;
}

.fg-description {
  margin-bottom: 1.5rem;
  color: var(--fg-description-color, inherit);
  font-size: var(--fg-description-size, 1rem);
  font-weight: var(--fg-description-weight, inherit);
}

.fg-description > :first-child,
.fg-footer > :first-child,
.fg-message > :first-child,
.fg-help > :first-child,
.fg-section-text > :first-child {
  margin-top: 0;
}

.fg-description > :last-child,
.fg-footer > :last-child,
.fg-message > :last-child,
.fg-help > :last-child,
.fg-section-text > :last-child,
.fg-label-text > :last-child,
.fg-section-title > :last-child {
  margin-bottom: 0;
}

.fg-label-text > :first-child,
.fg-section-title > :first-child {
  margin-top: 0;
}

.fg-footer {
  margin-top: 1.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--fg-line);
  color: var(--fg-muted);
  font-size: 0.9375rem;
}

/* A closed page: the message alone. */
.fg-message {
  padding: 0.5rem 0;
}

.fg-message h1,
.fg-message h2 {
  font-size: 1.375rem;
  line-height: 1.3;
}

/* Fields. */
.fg-form {
  margin: 0;
}

.fg-field {
  margin: 0 0 1.375rem;
  padding: 0;
  border: 0;
  min-width: 0;
}

.fg-label {
  display: block;
  margin: 0 0 0.375rem;
  padding: 0;
  color: var(--fg-label-color, inherit);
  font-size: var(--fg-label-size, 1rem);
  font-weight: var(--fg-label-weight, 600);
  line-height: 1.35;
}

.fg-label-text > p {
  display: inline;
  margin: 0;
}

.fg-required {
  margin-left: 0.25rem;
  color: var(--fg-danger);
  font-weight: 700;
}

.fg-help {
  margin: -0.125rem 0 0.5rem;
  color: var(--fg-help-color, var(--fg-muted));
  font-size: var(--fg-help-size, 0.9375rem);
  font-weight: var(--fg-help-weight, inherit);
}

.fg-notes {
  margin-top: 0.375rem;
  color: var(--fg-muted);
  font-size: 0.875rem;
}

.fg-note {
  margin: 0.125rem 0 0;
}

.fg-input {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  margin: 0;
  padding: 0.5rem 0.75rem;
  background: var(--fg-surface);
  border: 1px solid var(--fg-line-strong);
  border-radius: var(--fg-radius);
  color: var(--fg-input-color, var(--fg-text));
  font: inherit;
  font-size: var(--fg-input-size, 1rem);
  font-weight: var(--fg-input-weight, 400);
  line-height: 1.4;
}

/* On the control only: a field's wrapper carries its type as a class too (fg-textarea, fg-pnumber). */
.fg-input.fg-textarea {
  min-height: 7.5rem;
  resize: vertical;
}

.fg-select {
  appearance: none;
  padding-right: 2.25rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-muted) 50%),
    linear-gradient(135deg, var(--fg-muted) 50%, transparent 50%);
  background-position:
    right 1.125rem top 50%,
    right 0.8125rem top 50%;
  background-size: 0.3125rem 0.3125rem;
  background-repeat: no-repeat;
}

.fg-input.fg-number,
.fg-input.fg-date,
.fg-input.fg-pnumber {
  max-width: 14rem;
}

.fg-file-input {
  padding: 0.5rem;
}

.fg-input:focus-visible,
.fg-option input:focus-visible,
.fg-submit:focus-visible {
  outline: 3px solid var(--fg-accent);
  outline-offset: 1px;
}

.fg-input:focus {
  border-color: var(--fg-primary);
}

.fg-input[aria-invalid="true"] {
  border-color: var(--fg-danger);
  box-shadow: inset 3px 0 0 var(--fg-danger);
}

/* A field's error, added by the script (web/public-form) after its label and help. The text colour is the danger
   colour darkened for contrast on white. */
.fg-error {
  margin: -0.125rem 0 0.5rem;
  color: var(--fg-danger-text);
  font-size: 0.9375rem;
  font-weight: 600;
}

.fg-choice[aria-invalid="true"] .fg-option {
  border-color: var(--fg-danger);
}

/* A rejected POST's summary at the top of the card (ADR 0011): what to fix, each item linking to its field. */
.fg-errors {
  margin: 0 0 1.25rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--fg-danger);
  border-left-width: 4px;
  border-radius: var(--fg-radius);
  background: var(--fg-surface);
  color: var(--fg-text);
}

.fg-errors:focus {
  outline: 3px solid var(--fg-accent);
  outline-offset: 1px;
}

.fg-errors-title {
  margin: 0 0 0.25rem;
  color: var(--fg-danger-text);
  font-size: 1.125rem;
}

.fg-errors p,
.fg-errors ul {
  margin: 0.25rem 0;
}

.fg-errors ul {
  padding-left: 1.25rem;
}

.fg-errors a {
  color: var(--fg-danger-text);
  font-weight: 600;
}

/* Option groups: a whole row is the touch target. */
.fg-options {
  display: grid;
  gap: 0.375rem;
}

.fg-option {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.625rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--fg-line);
  border-radius: var(--fg-radius);
}

.fg-option:has(input:checked) {
  border-color: var(--fg-primary);
  background: var(--fg-tint);
}

.fg-option input[type="radio"],
.fg-option input[type="checkbox"] {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: var(--fg-primary);
}

.fg-option label {
  flex: 1;
  min-width: 0;
  color: var(--fg-option-color, inherit);
  font-size: var(--fg-option-size, 1rem);
  font-weight: var(--fg-option-weight, inherit);
  cursor: pointer;
}

.fg-option-full {
  background: var(--fg-canvas);
}

.fg-option-full label {
  color: var(--fg-muted);
  cursor: default;
}

.fg-remaining {
  color: var(--fg-muted);
  font-size: 0.875em;
  white-space: nowrap;
}

.fg-other-text {
  flex: 1 1 100%;
  min-height: 2.5rem;
}

/* Evaluation: a scale in one row. */
.fg-evaluation .fg-options {
  grid-template-columns: repeat(auto-fit, minmax(3rem, 1fr));
}

.fg-evaluation .fg-option {
  justify-content: center;
  padding: 0.5rem 0.25rem;
}

.fg-evaluation .fg-option label {
  flex: none;
}

.fg-full {
  padding: 0.625rem 0.75rem;
  background: var(--fg-canvas);
  border: 1px solid var(--fg-line);
  border-radius: var(--fg-radius);
}

.fg-file a {
  font-weight: 600;
}

/* Field title placement (formSettings.titleAlign): top (PHP's default, and an empty value), or left and right, the
   title in a column beside the field, its text aligned left or right in that column as PHP's leftAlign and
   rightAlign. Beside needs room: on a narrow card (a phone) the title stays above the field. The title is floated
   so a fieldset's legend joins the field's flow; everything else in the field is indented past it. */
@container (min-width: 30rem) {
  .fg-align-left .fg-field,
  .fg-align-right .fg-field {
    display: flow-root;
  }

  .fg-align-left .fg-label,
  .fg-align-right .fg-label {
    float: left;
    width: 31%;
    margin: 0;
    padding-top: calc(0.5rem + 1px);
  }

  .fg-align-right .fg-label {
    text-align: right;
  }

  .fg-align-left .fg-field > :not(.fg-label),
  .fg-align-right .fg-field > :not(.fg-label) {
    margin-left: calc(31% + 1rem);
  }

  .fg-align-left .fg-field > .fg-input,
  .fg-align-right .fg-field > .fg-input {
    width: calc(69% - 1rem);
  }

  .fg-align-left .fg-recaptcha,
  .fg-align-right .fg-recaptcha,
  .fg-align-left .fg-actions,
  .fg-align-right .fg-actions {
    padding-left: calc(31% + 1rem);
  }
}

/* Sections. */
.fg-section {
  margin: 2rem 0 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--fg-line);
}

.fg-form > .fg-section:first-of-type:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.fg-section-title {
  margin: 0 0 0.375rem;
  color: var(--fg-section-title-color, inherit);
  font-size: var(--fg-section-title-size, 1.25rem);
  font-weight: var(--fg-section-title-weight, 700);
  line-height: 1.3;
}

.fg-section-text {
  color: var(--fg-section-text-color, var(--fg-muted));
  font-size: var(--fg-section-text-size, 1rem);
  font-weight: var(--fg-section-text-weight, inherit);
}

/* reCAPTCHA, payment, submit. */
.fg-recaptcha {
  margin: 0 0 1.375rem;
}

.fg-payment {
  margin: 0 0 1.375rem;
  padding: 1rem;
  background: var(--fg-canvas);
  border: 1px solid var(--fg-line);
  border-radius: var(--fg-radius);
  font-size: 0.9375rem;
}

.fg-payment-total {
  margin: 0 0 0.5rem;
  font-size: 1.0625rem;
}

.fg-payment-total small {
  color: var(--fg-muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

.fg-order-items {
  margin: 0 0 0.75rem;
  padding: 0;
  list-style: none;
  color: var(--fg-muted);
}

.fg-order-items:empty {
  display: none;
}

.fg-payment-info {
  margin: 0.5rem 0 0;
}

.fg-actions {
  margin-top: 1.75rem;
}

.fg-submit {
  display: block;
  width: 100%;
  min-height: 3rem;
  padding: 0.75rem 1.5rem;
  background: var(--fg-primary);
  border: 1px solid var(--fg-primary);
  border-radius: var(--fg-radius);
  color: var(--fg-submit-color, #fff);
  font: inherit;
  font-size: var(--fg-submit-size, 1.0625rem);
  font-weight: var(--fg-submit-weight, 600);
  cursor: pointer;
}

/* The embed's link to Stripe Checkout (Pages/_Checkout.cshtml, decision 75) looks like the submit button. */
a.fg-submit {
  box-sizing: border-box;
  text-align: center;
  text-decoration: none;
}

.fg-submit:hover {
  background: var(--fg-primary-dark);
  border-color: var(--fg-primary-dark);
}

.fg-submit:disabled {
  opacity: 0.7;
  cursor: progress;
}

@media (min-width: 42rem) {
  .fg-submit {
    display: inline-block;
    width: auto;
    min-width: 12rem;
  }
}

.fg-brand {
  max-width: 40rem;
  margin: 0.75rem auto 0;
  padding: 0 1rem;
  text-align: right;
  font-size: 0.8125rem;
}

.fg-brand a {
  color: var(--fg-muted);
  text-decoration: none;
}

.fg-brand a:hover {
  text-decoration: underline;
}

/* The embed page (decision 71): no page background or outer frame; it fills the iframe and scrolls inside it. */
.fg-embedded {
  background: transparent;
}

.fg-embedded .fg-page {
  height: 100vh;
  min-height: 0;
  padding: 0;
  overflow-y: auto;
  background: none;
}

.fg-embedded .fg-card {
  max-width: none;
  border: 0;
  border-radius: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .fg-option {
    transition: border-color 0.12s, background-color 0.12s;
  }
}

/* The embed's brand line sits inside the card, so the height the script posts includes it. */
.fg-embedded .fg-brand {
  max-width: none;
  margin: 1.5rem 0 0;
  padding: 0;
}

/* An edit link's stored file: the link, and Remove once the script runs. */
.fg-file-stored {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

.fg-file-remove {
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--fg-line-strong);
  border-radius: 4px;
  background: var(--fg-surface);
  color: var(--fg-danger-text);
  font: inherit;
  cursor: pointer;
}

.fg-file-remove:hover {
  border-color: var(--fg-danger);
}

.fg-file-remove:focus-visible {
  outline: 3px solid var(--fg-accent);
  outline-offset: 1px;
}
