/**
 * Farmerbit Forms — stili frontend.
 *
 * Tutto è confinato in `.fbf` e costruito su flexbox: nessun framework CSS,
 * nessuna griglia esterna. Per personalizzare basta ridefinire le variabili
 * qui sotto sul contenitore `.fbf` (o su :root).
 */

.fbf {
  --fbf-gap: 20px;
  --fbf-font: inherit;
  --fbf-radius: 8px;
  --fbf-text: #1d2327;
  --fbf-muted: #6b7280;
  --fbf-bg: transparent;
  --fbf-field-bg: #fff;
  --fbf-border: #d0d5dd;
  --fbf-border-hover: #98a2b3;
  --fbf-accent: #1f6feb;
  --fbf-accent-contrast: #fff;
  --fbf-error: #b42318;
  --fbf-error-bg: #fef3f2;
  --fbf-success: #067647;
  --fbf-success-bg: #ecfdf3;
  --fbf-focus-ring: rgba(31, 111, 235, 0.18);
  --fbf-control-height: 46px;
  --fbf-mark-size: 20px;
  --fbf-font-size: 16px;

  position: relative;
  box-sizing: border-box;
  color: var(--fbf-text);
  font-family: var(--fbf-font);
  font-size: var(--fbf-font-size);
  background: var(--fbf-bg);
}

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

/* ------------------------------------------------------- isolamento dal tema

   Temi e page builder impaginano spesso i selettori generici (`form`, `label`)
   con specificità da ID, es. `#aipb-b_5 .form-col form { display: grid }`:
   riscrivono il layout del plugin e non c'è specificità che li superi.
   Qui difendiamo solo le proprietà strutturali dei nostri elementi; aspetto,
   colori, font e spaziature restano liberamente sovrascrivibili dal tema. */

.fbf .fbf-form {
  display: block !important;
  float: none !important;
  gap: 0 !important;
  width: auto !important;
  max-width: none !important;
}

.fbf .fbf-choice {
  display: flex !important;
}

.fbf .fbf-choice-mark {
  display: block !important;
  flex: 0 0 auto !important;
  width: var(--fbf-mark-size) !important;
  height: var(--fbf-mark-size) !important;
}

.fbf--theme-dark {
  --fbf-text: #f2f4f7;
  --fbf-muted: #98a2b3;
  --fbf-field-bg: rgba(255, 255, 255, 0.06);
  --fbf-border: rgba(255, 255, 255, 0.24);
  --fbf-border-hover: rgba(255, 255, 255, 0.45);
  --fbf-accent: #f2f4f7;
  --fbf-accent-contrast: #101828;
  --fbf-error: #fda29b;
  --fbf-error-bg: rgba(240, 68, 56, 0.12);
  --fbf-success: #75e0a7;
  --fbf-success-bg: rgba(18, 183, 106, 0.12);
  --fbf-focus-ring: rgba(255, 255, 255, 0.22);
}

/* ---------------------------------------------------------------- layout */

.fbf-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--fbf-gap);
  align-items: flex-start;
  margin: 0;
}

.fbf-col {
  /* La base sottrae la quota di gap che spetta alla colonna, così le
     percentuali tornano esatte anche con più colonne per riga. */
  flex: 0 0 calc(var(--fbf-w, 100%) - var(--fbf-gap) * var(--fbf-k, 0));
  min-width: 0;
  max-width: 100%;
}

.fbf-col[hidden] {
  display: none;
}

@media (max-width: 700px) {
  .fbf-col {
    flex: 0 0 100%;
  }
}

.fbf-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* --------------------------------------------------------------- etichette */

.fbf-label {
  display: block;
  font-size: 0.875em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--fbf-label-color, var(--fbf-text));
}

.fbf-req {
  color: var(--fbf-error);
  margin-left: 2px;
}

.fbf--labels-hidden .fbf-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.fbf-help {
  margin: 0;
  font-size: 0.8125em;
  line-height: 1.4;
  color: var(--fbf-muted);
}

.fbf-error {
  margin: 0;
  font-size: 0.8125em;
  line-height: 1.4;
  color: var(--fbf-error);
}

/* ---------------------------------------------------------------- controlli */

.fbf-input,
.fbf-select {
  width: 100%;
  min-height: var(--fbf-control-height);
  padding: 11px 14px;
  font-family: inherit;
  font-size: 1em;
  line-height: 1.4;
  color: var(--fbf-text);
  background-color: var(--fbf-field-bg);
  border: 1px solid var(--fbf-border);
  border-radius: var(--fbf-radius);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
  -webkit-appearance: none;
}

.fbf-input::placeholder {
  color: var(--fbf-muted);
  opacity: 1;
}

.fbf-input:hover,
.fbf-select:hover {
  border-color: var(--fbf-border-hover);
}

.fbf-input:focus,
.fbf-select:focus,
.fbf-choice-input:focus-visible + .fbf-choice-mark {
  border-color: var(--fbf-accent);
  box-shadow: 0 0 0 3px var(--fbf-focus-ring);
}

.fbf-input[aria-invalid='true'] {
  border-color: var(--fbf-error);
}

textarea.fbf-input {
  min-height: 120px;
  resize: vertical;
}

.fbf-select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.fbf-select[multiple] {
  padding: 8px;
  background-image: none;
  min-height: auto;
}

.fbf-select[multiple] option {
  padding: 6px 8px;
  border-radius: 4px;
}

.fbf--theme-dark .fbf-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%2398a2b3' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.fbf-input[type='date'],
.fbf-input[type='time'],
.fbf-input[type='datetime-local'] {
  min-height: var(--fbf-control-height);
}

.fbf--theme-dark .fbf-input[type='date']::-webkit-calendar-picker-indicator,
.fbf--theme-dark .fbf-input[type='time']::-webkit-calendar-picker-indicator,
.fbf--theme-dark .fbf-input[type='datetime-local']::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

/* ------------------------------------------------------------------ scelte */

.fbf-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fbf-choices--inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 10px 20px;
}

.fbf-choice {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  line-height: 1.45;
  font-size: 0.9375em;
}

.fbf-choice-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  margin: 0;
}

.fbf-choice-mark {
  flex: 0 0 auto;
  width: var(--fbf-mark-size);
  height: var(--fbf-mark-size);
  margin-top: 1px;
  border: 1px solid var(--fbf-border);
  border-radius: 5px;
  background-color: var(--fbf-field-bg);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 13px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.fbf-choice:hover .fbf-choice-mark {
  border-color: var(--fbf-border-hover);
}

input[type='radio'].fbf-choice-input + .fbf-choice-mark {
  border-radius: 50%;
}

.fbf-choice-input:checked + .fbf-choice-mark {
  border-color: var(--fbf-accent);
  background-color: var(--fbf-accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 13 13' fill='none'%3E%3Cpath d='M2 6.8l3 3L11 3' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

input[type='radio'].fbf-choice-input:checked + .fbf-choice-mark {
  background-image: none;
  box-shadow: inset 0 0 0 4px var(--fbf-field-bg);
}

.fbf-choice-label a {
  color: inherit;
  text-decoration: underline;
}

.fbf-field--checkbox .fbf-choice-label {
  font-size: 0.9375em;
  color: var(--fbf-muted);
}

/* ------------------------------------------------------------------- file */

.fbf-file {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fbf-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.fbf-file-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--fbf-control-height);
  padding: 11px 16px;
  cursor: pointer;
  border: 1px dashed var(--fbf-border);
  border-radius: var(--fbf-radius);
  background-color: var(--fbf-field-bg);
  color: var(--fbf-muted);
  font-size: 0.9375em;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.fbf-file-label:hover,
.fbf-file-input:focus-visible + .fbf-file-label {
  border-color: var(--fbf-accent);
  color: var(--fbf-text);
}

.fbf-file-icon {
  font-size: 1.1em;
  line-height: 1;
}

.fbf-file-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.fbf-file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 0.875em;
  border: 1px solid var(--fbf-border);
  border-radius: 6px;
  background-color: var(--fbf-field-bg);
}

.fbf-file-item-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fbf-file-item-size {
  flex: 0 0 auto;
  color: var(--fbf-muted);
  font-variant-numeric: tabular-nums;
}

.fbf-file-remove {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: var(--fbf-muted);
  background: transparent;
}

.fbf-file-remove:hover {
  color: var(--fbf-error);
  background: var(--fbf-error-bg);
}

.fbf-file-hint {
  margin: 0;
  font-size: 0.75em;
  color: var(--fbf-muted);
}

/* --------------------------------------------------------- range e colore */

.fbf-range-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.fbf-range {
  flex: 1 1 auto;
  width: 100%;
  height: 4px;
  padding: 0;
  border-radius: 999px;
  background: var(--fbf-border);
  appearance: none;
  -webkit-appearance: none;
  outline: none;
}

.fbf-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: var(--fbf-accent);
  cursor: pointer;
}

.fbf-range::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: var(--fbf-accent);
  cursor: pointer;
}

.fbf-range-value {
  flex: 0 0 auto;
  min-width: 3ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.9375em;
}

.fbf-color {
  width: 56px;
  height: var(--fbf-control-height);
  padding: 4px;
  border: 1px solid var(--fbf-border);
  border-radius: var(--fbf-radius);
  background: var(--fbf-field-bg);
  cursor: pointer;
}

/* ---------------------------------------------------------------- password */

.fbf-password {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fbf-password .fbf-input {
  padding-right: 46px;
}

.fbf-password-toggle {
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: var(--fbf-control-height);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  opacity: 0.55;
}

.fbf-password-toggle:hover {
  opacity: 1;
}

.fbf-strength {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75em;
  color: var(--fbf-muted);
}

.fbf-strength-bar {
  position: relative;
  flex: 1 1 auto;
  height: 4px;
  border-radius: 999px;
  background: var(--fbf-border);
  overflow: hidden;
}

.fbf-strength-bar::after {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--fbf-strength, 0%);
  background: var(--fbf-strength-color, var(--fbf-accent));
  transition: width 0.2s ease, background-color 0.2s ease;
}

/* ------------------------------------------------------- titoli e struttura */

.fbf-title {
  margin: 0;
  font-size: 1.125em;
  line-height: 1.3;
}

.fbf-html {
  font-size: 0.9375em;
  line-height: 1.55;
}

.fbf-html > *:first-child {
  margin-top: 0;
}

.fbf-html > *:last-child {
  margin-bottom: 0;
}

.fbf-separator {
  width: 100%;
  height: 1px;
  margin: 4px 0;
  border: 0;
  background: var(--fbf-border);
}

/* ---------------------------------------------------------------- pulsante */

.fbf-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--fbf-control-height);
  padding: 12px 28px;
  font-family: inherit;
  font-size: 0.9375em;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--fbf-accent);
  border-radius: var(--fbf-radius);
  background-color: var(--fbf-accent);
  color: var(--fbf-accent-contrast);
  transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.fbf-button:hover:not(:disabled) {
  opacity: 0.88;
}

.fbf-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--fbf-focus-ring);
}

.fbf-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.fbf-button--outline {
  background-color: transparent;
  color: var(--fbf-accent);
}

.fbf-button--text {
  padding-left: 0;
  padding-right: 0;
  border-color: transparent;
  background-color: transparent;
  color: var(--fbf-accent);
  text-decoration: underline;
}

.fbf-button.is-rounded {
  border-radius: 999px;
}

.fbf-button--align-center {
  margin-left: auto;
  margin-right: auto;
}

.fbf-button--align-right {
  margin-left: auto;
}

.fbf-button--align-full {
  width: 100%;
}

/* La colonna diventa flex così gli allineamenti del pulsante (margin auto)
   funzionano anche quando occupa tutta la riga. */
.fbf-col--button {
  display: flex;
  align-items: center;
}

.fbf-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: fbf-spin 0.7s linear infinite;
}

.fbf-form.is-loading .fbf-spinner {
  display: inline-block;
}

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

@media (prefers-reduced-motion: reduce) {
  .fbf-spinner {
    animation-duration: 2s;
  }

  .fbf *,
  .fbf *::before,
  .fbf *::after {
    transition-duration: 0.01ms !important;
  }
}

/* ----------------------------------------------------------------- messaggi */

.fbf-message {
  display: none;
  margin-top: var(--fbf-gap);
  padding: 14px 16px;
  border: 1px solid transparent;
  border-radius: var(--fbf-radius);
  font-size: 0.9375em;
  line-height: 1.5;
}

.fbf-message.is-visible {
  display: block;
}

.fbf-message.is-success {
  color: var(--fbf-success);
  background-color: var(--fbf-success-bg);
  border-color: currentColor;
}

.fbf-message.is-error {
  color: var(--fbf-error);
  background-color: var(--fbf-error-bg);
  border-color: currentColor;
}

/* ------------------------------------------------------------------- extra */

/* Il campo trappola deve restare nel DOM e nel POST, ma fuori dal flusso:
   nessuna altezza, nessun margine, nessun gap ereditato. Niente offset
   negativi (creerebbero scroll orizzontale): basta ritagliarlo a zero. */
.fbf-hp {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

.fbf-notice {
  padding: 12px 16px;
  border: 1px dashed var(--fbf-border);
  border-radius: var(--fbf-radius);
  color: var(--fbf-muted);
  font-size: 0.875em;
}
