/* ─── PGS Form – Frontend Styles ────────────────────────────── */

.pgs-form-wrapper {
  max-width: var(--pgs-max-width, 600px);
  margin: 0 auto;
  font-family: var(--pgs-font, inherit);
  font-size: var(--pgs-font-size, 15px);
  color: var(--pgs-text, #1f2937);
}

.pgs-form {
  background: var(--pgs-bg, #fff);
}

.pgs-form-title {
  margin: 0 0 4px;
  font-size: 1.3em;
  font-weight: 700;
  color: var(--pgs-text, #1f2937);
}

.pgs-form-description {
  margin: 0 0 20px;
  color: #6b7280;
  font-size: 0.92em;
  line-height: 1.5;
}

/* ─── Field layout ──────────────────────────────────────────── */

.pgs-form-fields {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pgs-field-gap, 16px);
}

.pgs-form-field {
  width: 100%;
  box-sizing: border-box;
}

.pgs-form-field--half {
  width: calc(50% - var(--pgs-field-gap, 16px) / 2);
}

@media (max-width: 480px) {
  .pgs-form-field--half {
    width: 100%;
  }
}

.pgs-form-field label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  font-size: 0.875em;
  color: var(--pgs-text, #1f2937);
}

/* ─── Inputs ────────────────────────────────────────────────── */

.pgs-form-field input[type="text"],
.pgs-form-field input[type="email"],
.pgs-form-field input[type="tel"],
.pgs-form-field input[type="url"],
.pgs-form-field input[type="number"],
.pgs-form-field input[type="date"],
.pgs-form-field input[type="time"],
.pgs-form-field textarea,
.pgs-form-field select {
  display: block;
  width: 100%;
  padding: var(--pgs-input-padding, 10px 12px);
  border: 1px solid var(--pgs-border, #d1d5db);
  border-radius: var(--pgs-radius, 6px);
  font-family: inherit;
  font-size: var(--pgs-input-font-size, inherit);
  /* Input text and background are intentionally decoupled from --pgs-text and
     --pgs-bg so changing the form's overall text colour does not turn the
     value inside an input invisible (e.g., white text on the default white
     input background). Override --pgs-input-text / --pgs-input-bg to theme
     inputs explicitly. */
  color: var(--pgs-input-text, #1f2937);
  background: var(--pgs-input-bg, #ffffff);
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  line-height: 1.5;
}

.pgs-form-field input::placeholder,
.pgs-form-field textarea::placeholder,
.pgs-form-field select:invalid {
  color: var(--pgs-placeholder-color, #9ca3af);
  font-size: var(--pgs-placeholder-size, inherit);
  opacity: 1;
}

/* Radio / checkbox use the Border Colour from Settings → Styling */
.pgs-form-wrapper input[type="radio"],
.pgs-form-wrapper input[type="checkbox"] {
  accent-color: var(--pgs-border, #d1d5db);
}

.pgs-form-field input:focus,
.pgs-form-field textarea:focus,
.pgs-form-field select:focus {
  outline: none;
  border-color: #6b7280;
  box-shadow: 0 0 0 2px rgba(107, 114, 128, 0.12);
}

.pgs-form-field textarea {
  resize: vertical;
  min-height: 90px;
}

.pgs-field-error {
  border-color: var(--pgs-error, #ef4444) !important;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.12) !important;
}

.pgs-required {
  color: #ef4444;
  font-weight: 600;
}

/* ─── Checkbox (single) ─────────────────────────────────────── */

.pgs-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 400;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

.pgs-checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0 6px 0 0;
  flex-shrink: 0;
  accent-color: var(--pgs-border, #d1d5db);
  vertical-align: middle;
}

/* ─── Checkbox Group & Radio Group ──────────────────────────── */

.pgs-group-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding-top: 2px;
}

.pgs-group-options--stacked {
  flex-direction: column;
  gap: 6px;
}


.pgs-group-option {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 400;
  font-size: 0.92em;
  padding: 2px 0;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

.pgs-group-option input[type="checkbox"],
.pgs-group-option input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0 6px 0 0;
  flex-shrink: 0;
  accent-color: var(--pgs-border, #d1d5db);
  cursor: pointer;
  vertical-align: middle;
}

.pgs-group-option span {
  line-height: 1.2;
}

/* ─── Conditional fields (hidden by default) ────────────────── */

.pgs-form-field[data-show-when-field] {
  display: none;
}

.pgs-form-field[data-show-when-field].pgs-field-visible {
  display: block;
}

.pgs-form-field--half[data-show-when-field].pgs-field-visible {
  display: block;
  width: calc(50% - var(--pgs-field-gap, 16px) / 2);
}

@media (max-width: 480px) {
  .pgs-form-field--half[data-show-when-field].pgs-field-visible {
    width: 100%;
  }
}

/* ─── Button ────────────────────────────────────────────────── */

.pgs-form-submit {
  margin-top: 8px;
}

.pgs-form-btn {
  display: inline-block;
  padding: var(--pgs-btn-padding, 10px 28px);
  background: var(--pgs-btn-bg, #111827);
  color: var(--pgs-btn-text, #fff);
  border: none;
  border-radius: var(--pgs-radius, 6px);
  font-family: inherit;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
  letter-spacing: 0.01em;
  line-height: 1.5;
}

.pgs-form-btn:hover {
  background: var(--pgs-btn-hover, #374151);
  opacity: 0.95;
}

.pgs-form-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pgs-form-btn--full,
.pgs-form-wrapper.pgs-form-wrapper--btn-full .pgs-form-btn {
  width: 100%;
  display: block;
  text-align: center;
}

/* ─── Messages ──────────────────────────────────────────────── */

.pgs-form-message {
  margin-top: 16px;
  padding: 10px 14px;
  border-radius: var(--pgs-radius, 6px);
  font-size: 0.92em;
  font-weight: 500;
}

.pgs-form-success {
  background: #f0fdf4;
  color: var(--pgs-success, #15803d);
  border: 1px solid #bbf7d0;
}

.pgs-form-error {
  background: #fef2f2;
  color: var(--pgs-error, #dc2626);
  border: 1px solid #fecaca;
}

.pgs-form-note {
  font-size: 0.82em;
  color: #9ca3af;
  margin-top: 4px;
}

/* ─── Honeypot ──────────────────────────────────────────────── */

.pgs-form-hp {
  position: absolute;
  left: -9999px;
  opacity: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ─── Hidden field ──────────────────────────────────────────── */

.pgs-form-field--hidden {
  display: none;
}

/* ─── Visually hidden label (kept for screen readers) ───────── */

.pgs-form-field .pgs-label--sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── Theme: wrapper ───────────────────────────────────────── */
/*
 * The wrapper theme controls labels, borders, focus rings, and
 * placeholder colours — i.e. everything around the inputs.
 *
 * The input surface itself is themed separately via
 * pgs-form-wrapper--inputs-{light|dark} so a form can have light
 * labels (on a dark hero) but still keep crisp white inputs.
 *
 * Apply via shortcode:
 *   [pgs_form id=1]                              -> light/light
 *   [pgs_form id=1 theme=dark]                   -> dark/dark (immersive)
 *   [pgs_form id=1 theme=dark inputs=light]      -> dark labels, white inputs
 */
/* Selectors are doubled (.class.class) to give them higher specificity than
 * the .pgs-form-wrapper{...} block emitted as inline CSS by the admin
 * Settings -> Styling values. Without this the admin's "Text Colour" would
 * silently override the dark theme override since both selectors have the
 * same specificity and the inline block prints after the stylesheet. */
.pgs-form-wrapper.pgs-form-wrapper--theme-dark {
  --pgs-text: #f9fafb;
  --pgs-border: rgba(255, 255, 255, 0.25);
  --pgs-placeholder-color: rgba(255, 255, 255, 0.55);
}

.pgs-form-wrapper.pgs-form-wrapper--theme-dark .pgs-form-description {
  color: rgba(249, 250, 251, 0.75);
}

.pgs-form-wrapper.pgs-form-wrapper--theme-dark .pgs-form-field input:focus,
.pgs-form-wrapper.pgs-form-wrapper--theme-dark .pgs-form-field textarea:focus,
.pgs-form-wrapper.pgs-form-wrapper--theme-dark .pgs-form-field select:focus {
  border-color: rgba(255, 255, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}

/* ─── Theme: inputs ────────────────────────────────────────── */

.pgs-form-wrapper.pgs-form-wrapper--inputs-light {
  --pgs-input-bg: #ffffff;
  --pgs-input-text: #1f2937;
  --pgs-placeholder-color: #9ca3af;
}

.pgs-form-wrapper.pgs-form-wrapper--inputs-dark {
  --pgs-input-bg: rgba(255, 255, 255, 0.08);
  --pgs-input-text: #f9fafb;
  --pgs-placeholder-color: rgba(255, 255, 255, 0.55);
}

/* Direct ::placeholder overrides scoped to the input theme.
 * Higher specificity than the variable-based rule above so they reliably
 * win over the admin's "Placeholder Colour" setting AND the wrapper theme
 * variables, regardless of source order or page-builder caches. */
.pgs-form-wrapper.pgs-form-wrapper--inputs-light .pgs-form-field input::placeholder,
.pgs-form-wrapper.pgs-form-wrapper--inputs-light .pgs-form-field textarea::placeholder {
  color: #9ca3af;
}

.pgs-form-wrapper.pgs-form-wrapper--inputs-dark .pgs-form-field input::placeholder,
.pgs-form-wrapper.pgs-form-wrapper--inputs-dark .pgs-form-field textarea::placeholder {
  color: rgba(255, 255, 255, 0.55);
}

/* Native date/time pickers use a built-in calendar/clock icon. On
 * a dark input surface the icon is invisible; invert it. */
.pgs-form-wrapper.pgs-form-wrapper--inputs-dark .pgs-form-field input[type="date"]::-webkit-calendar-picker-indicator,
.pgs-form-wrapper.pgs-form-wrapper--inputs-dark .pgs-form-field input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(1.4);
}
