/* ================================================================
   Conceito – Formulário WhatsApp  |  form.css  v1.2.0
   ================================================================ */

/* ── Overlay ──────────────────────────────────────────────────────
   BUGS iOS corrigidos:
   1. z-index alto o suficiente para ficar acima do WP Chat App
      (botão=999999999, popup=999999998) em QUALQUER contexto de
      stacking, inclusive dentro de elementos com transform/will-change.
   2. -webkit-overflow-scrolling evita que o Safari "prenda" o scroll
      do body atrás do overlay.
   3. isolation: isolate cria um novo stacking context próprio,
      impedindo que elementos externos com transform criem contextos
      que "engolam" nosso z-index.
   ────────────────────────────────────────────────────────────────*/
#cwaf-overlay {
  display: none;
  position: fixed;

  /* Fallback p/ browsers sem suporte a inset */
  top: 0; left: 0; right: 0; bottom: 0;
  /* Shorthand moderno */
  inset: 0;

  /* iOS Safari: position:fixed pode herdar stacking de elementos pai
     com transform/will-change. Movemos o overlay p/ fora de qualquer
     contexto problemático via JS (appendChild ao body) + isolation. */
  isolation: isolate;
  z-index: 2147483647; /* valor máximo possível (2^31 - 1) */

  background: rgba(0, 0, 0, 0.6);
  justify-content: center;
  align-items: flex-start; /* iOS: flex-start + padding evita o bug
                               de centralização quando o teclado sobe */
  padding: env(safe-area-inset-top, 20px) 16px
           env(safe-area-inset-bottom, 20px) 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* scroll suave no iOS */
  box-sizing: border-box;

  /* Garante que o toque no overlay (fora do modal) seja detectado */
  -webkit-tap-highlight-color: transparent;
}

#cwaf-overlay.cwaf-visible {
  display: flex;
}

/* ── Modal ────────────────────────────────────────────────────────
   BUGS iOS corrigidos:
   4. "transform: translateZ(0)" força o Safari a criar um novo layer
      de composição para o modal, resolvendo o bug onde o conteúdo do
      modal fica atrás do overlay do WP Chat App mesmo com z-index alto.
   ────────────────────────────────────────────────────────────────*/
#cwaf-modal {
  position: relative;
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px 32px;
  width: 100%;
  max-width: 420px;
  margin: auto; /* centraliza verticalmente quando há espaço */
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: cwaf-up .22s ease;
  box-sizing: border-box;
  /* Força compositing layer no iOS, evita que o modal fique atrás
     de elementos com will-change:transform do plugin original */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  /* Garante que o modal e seus filhos fiquem no topo */
  isolation: isolate;
}

@keyframes cwaf-up {
  from { opacity: 0; transform: translateZ(0) translateY(24px); }
  to   { opacity: 1; transform: translateZ(0) translateY(0);    }
}

/* ── Fechar ──────────────────────────────────────────────────────*/
#cwaf-close {
  position: absolute;
  top: 14px; right: 16px;
  background: none; border: none;
  font-size: 24px; line-height: 1;
  color: #888; cursor: pointer;
  padding: 4px 8px; border-radius: 6px;
  transition: color .15s, background .15s;
  /* iOS: área de toque mínima recomendada pela Apple = 44×44pt */
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
#cwaf-close:hover { color: #333; background: #f0f0f0; }

/* ── Cabeçalho ───────────────────────────────────────────────────*/
#cwaf-title {
  margin: 0 0 6px;
  font-size: 20px; font-weight: 700;
  color: #1a1a1a; line-height: 1.3;
}
#cwaf-subtitle {
  margin: 0 0 24px;
  font-size: 14px; color: #666; line-height: 1.5;
}

/* ── Campos ──────────────────────────────────────────────────────
   BUGS iOS corrigidos:
   5. font-size >= 16px previne o zoom automático do Safari ao focar
      num input (comportamento padrão quando font-size < 16px).
   ────────────────────────────────────────────────────────────────*/
.cwaf-field { margin-bottom: 14px; }

.cwaf-field input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px; /* mínimo para evitar zoom automático no iOS */
  border: 1.5px solid #d0d5dd;
  border-radius: 10px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  box-sizing: border-box;
  color: #1a1a1a;
  background: #fafafa;
  /* iOS Safari: remove o estilo nativo de inputs */
  -webkit-appearance: none;
  appearance: none;
}
.cwaf-field input:focus {
  border-color: #25d366;
  box-shadow: 0 0 0 3px rgba(37,211,102,.18);
  background: #fff;
}

.cwaf-error {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: #d63031;
  min-height: 16px;
}

/* ── Botão submit ────────────────────────────────────────────────*/
#cwaf-submit {
  display: flex;
  align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin-top: 10px;
  padding: 14px 20px;
  background: #25d366; color: #fff;
  border: none; border-radius: 10px;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
  box-sizing: border-box;
  /* iOS: remove estilo nativo de botões */
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  /* Área de toque confortável no iOS */
  min-height: 48px;
}
#cwaf-submit::before {
  content: '';
  display: inline-block;
  width: 20px; height: 20px; flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 0C5.373 0 0 5.373 0 12c0 2.116.552 4.105 1.519 5.833L0 24l6.335-1.493A11.93 11.93 0 0 0 12 24c6.627 0 12-5.373 12-12S18.627 0 12 0zm6.012 16.484c-.252.708-1.474 1.354-2.027 1.441-.524.082-1.179.116-1.903-.118-.44-.143-1.005-.333-1.73-.65-3.041-1.31-5.026-4.363-5.176-4.566-.15-.203-1.224-1.628-1.224-3.108 0-1.481.774-2.208 1.049-2.51.275-.301.6-.376.8-.376.2 0 .4.002.575.01.185.008.432-.07.676.516.252.607.854 2.09.929 2.241.075.15.125.326.025.526-.1.2-.15.326-.3.501-.15.176-.316.393-.45.528-.15.15-.306.312-.132.612.175.3.776 1.28 1.665 2.073 1.144 1.02 2.109 1.334 2.409 1.484.3.15.476.125.651-.075.175-.2.75-.874 1.05-1.174.175-.2.35-.15.575-.075.225.075 1.424.67 1.668.793.244.125.407.186.47.288.062.103.062.593-.19 1.168z'/%3E%3C/svg%3E");
  background-size: contain; background-repeat: no-repeat;
}
#cwaf-submit:hover:not(:disabled) { background: #1ebe5c; }
#cwaf-submit:active:not(:disabled) { background: #1aad52; }
#cwaf-submit:disabled { opacity: .65; cursor: not-allowed; }

/* ── Responsivo ──────────────────────────────────────────────────*/
@media (max-width: 480px) {
  #cwaf-overlay {
    align-items: flex-end; /* no mobile, modal sobe do fundo (mais natural) */
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #cwaf-modal {
    padding: 28px 20px 24px;
    border-radius: 20px 20px 0 0; /* estilo "sheet" no mobile */
    max-width: 100%;
    margin: 0; /* remove auto para ficar grudado no fundo */
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
  #cwaf-title { font-size: 18px; }
}
