/**
 * Kommo Lead Form — Estilos
 *
 * CSS adaptável ao tema: herda font-family, color e variáveis CSS do tema ativo.
 * Mobile-first, responsivo e com animações sutis para feedback visual.
 *
 * @package KommoLeadForm
 */

/* ========================================
   Container & Layout
   ======================================== */

.kommo-form {
  --kommo-radius: 8px;
  --kommo-gap: 16px;
  --kommo-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --kommo-accent: var(
    --wp--preset--color--primary,
    var(--theme-primary, #2563eb)
  );
  --kommo-accent-hover: var(--wp--preset--color--primary-dark, #1d4ed8);
  --kommo-error: #dc2626;
  --kommo-success: #16a34a;
  --kommo-border: var(--wp--preset--color--border, #d1d5db);
  --kommo-bg: var(--wp--preset--color--background, transparent);
  --kommo-text: var(--wp--preset--color--foreground, inherit);

  font-family: inherit;
  color: var(--kommo-text);
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

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

.kommo-form__inner {
  display: flex;
  flex-direction: column;
  gap: var(--kommo-gap);
}

/* ========================================
   Título
   ======================================== */

.kommo-form__title {
  font-family: inherit;
  font-size: 1.35em;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 8px 0;
  color: inherit;
  text-align: center;
}

/* ========================================
   Campos
   ======================================== */

.kommo-form__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.kommo-form__label {
  font-family: inherit;
  font-size: 0.875em;
  font-weight: 600;
  color: inherit;
  opacity: 0.85;
}

.kommo-form__input {
  font-family: inherit;
  font-size: 1em;
  color: inherit;
  background-color: var(--kommo-bg);
  border: 1.5px solid var(--kommo-border);
  border-radius: var(--kommo-radius);
  padding: 12px 14px;
  width: 100%;
  transition:
    border-color var(--kommo-transition),
    box-shadow var(--kommo-transition);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.kommo-form__input::placeholder {
  color: inherit;
  opacity: 0.4;
}

.kommo-form__input:focus {
  border-color: var(--kommo-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Estado de erro */
.kommo-form__field--has-error .kommo-form__input {
  border-color: var(--kommo-error);
}

.kommo-form__field--has-error .kommo-form__input:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.kommo-form__error {
  font-size: 0.8em;
  color: var(--kommo-error);
  min-height: 0;
  overflow: hidden;
  transition:
    min-height var(--kommo-transition),
    opacity var(--kommo-transition);
  opacity: 0;
}

.kommo-form__field--has-error .kommo-form__error {
  min-height: 1.3em;
  opacity: 1;
}

/* ========================================
   Campo de Telefone (intl-tel-input override)
   ======================================== */

.kommo-form__field--phone .iti {
  width: 100%;
}

.kommo-form__field--phone .iti__selected-dial-code {
  font-family: inherit;
  font-size: 0.95em;
}

.kommo-form__field--phone .iti__country-list {
  font-family: inherit;
  border-radius: var(--kommo-radius);
  border: 1.5px solid var(--kommo-border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-height: 220px;
}

.kommo-form__field--phone .iti__country-list .iti__country {
  padding: 8px 12px;
}

.kommo-form__field--phone .iti__country-list .iti__country--highlight {
  background-color: var(--kommo-accent);
  color: #fff;
}

/* Garante que o input do telefone não quebre com o intl-tel-input */
.kommo-form__phone-input {
  padding-left: 90px !important;
}

/* ========================================
   Botão Submit
   ======================================== */

.kommo-form__submit {
  font-family: inherit;
  font-size: 1em;
  font-weight: 700;
  color: #ffffff;
  background-color: var(--kommo-accent);
  border: none;
  border-radius: var(--kommo-radius);
  padding: 14px 24px;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition:
    background-color var(--kommo-transition),
    transform var(--kommo-transition),
    box-shadow var(--kommo-transition);
  position: relative;
  overflow: hidden;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.kommo-form__submit:hover {
  background-color: var(--kommo-accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.kommo-form__submit:active {
  transform: translateY(0);
  box-shadow: none;
}

.kommo-form__submit:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Loading spinner */
.kommo-form__submit-loading {
  display: none;
  width: 20px;
  height: 20px;
}

.kommo-form__spinner {
  width: 20px;
  height: 20px;
  animation: kommo-spin 1s linear infinite;
}

.kommo-form--loading .kommo-form__submit-text {
  opacity: 0.6;
}

.kommo-form--loading .kommo-form__submit-loading {
  display: inline-flex;
}

@keyframes kommo-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* ========================================
   Feedback (sucesso / erro)
   ======================================== */

.kommo-form__feedback {
  font-family: inherit;
  font-size: 0.9em;
  font-weight: 500;
  text-align: center;
  padding: 0;
  border-radius: var(--kommo-radius);
  transition: all var(--kommo-transition);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
}

.kommo-form__feedback--visible {
  padding: 14px 18px;
  max-height: 200px;
  opacity: 1;
  margin-top: 4px;
}

.kommo-form__feedback--success {
  background-color: rgba(22, 163, 74, 0.08);
  color: var(--kommo-success);
  border: 1px solid rgba(22, 163, 74, 0.2);
}

.kommo-form__feedback--error {
  background-color: rgba(220, 38, 38, 0.08);
  color: var(--kommo-error);
  border: 1px solid rgba(220, 38, 38, 0.2);
}

/* ========================================
   Estado Sucesso (formulário oculto)
   ======================================== */

.kommo-form--success .kommo-form__inner {
  display: none;
}

.kommo-form--success .kommo-form__feedback {
  font-size: 1.05em;
}

/* ========================================
   Responsividade
   ======================================== */

@media (max-width: 480px) {
  .kommo-form {
    --kommo-gap: 12px;
    padding: 0 4px;
  }

  .kommo-form__title {
    font-size: 1.15em;
  }

  .kommo-form__input {
    padding: 10px 12px;
    font-size: 16px; /* previne zoom em iOS */
  }

  .kommo-form__submit {
    padding: 12px 20px;
  }

  .kommo-form__phone-input {
    padding-left: 80px !important;
  }
}

/* ========================================
   Animação de entrada (opcional)
   ======================================== */

.kommo-form {
  animation: kommo-fadeIn 0.5s ease-out;
}

@keyframes kommo-fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   Print: oculta o formulário
   ======================================== */

@media print {
  .kommo-form {
    display: none !important;
  }
}
