/* =========================================================================
   AMAV — Formulário de opt-in (modal)
   Espelha a separação de arquivos do formulário do montevillaconsorcios:
   estrutura e comportamento em arquivo próprio. Carregado só na
   institucional, depois de /style.css — usa os tokens definidos lá
   (--amav-*, --accent-fg, --heading etc.) e não redefine nada global.
   ========================================================================= */

.inst-modal {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.inst-modal-backdrop {
    position: absolute;
    inset: 0;
    background-color: rgba(81, 45, 31, 0.55);
    opacity: 0;
    transition: opacity .24s ease-out;
}

.inst-modal.is-open .inst-modal-backdrop {
    opacity: 1;
}

/* Mobile: folha em tela cheia subindo de baixo. O modal é sempre bege,
   então fixa --text/--heading/--accent-fg locais: sem isso, qualquer
   regra que leia essas variáveis (rótulo de campo, título) herdava o
   ambiente verde do body e sumia contra o próprio fundo bege do modal. */
.inst-modal-box {
    position: relative;
    width: 100%;
    max-height: 92dvh;
    overflow-y: auto;
    padding: 28px 22px 32px;
    background-color: var(--amav-bege);
    border-radius: var(--inst-radius-lg) var(--inst-radius-lg) 0 0;
    box-shadow: 0 -12px 44px rgba(81, 45, 31, 0.3);
    transform: translateY(100%);
    transition: transform .24s ease-out;
    --text: var(--amav-marrom);
    --heading: var(--amav-verde);
    --accent-fg: var(--amav-laranja-escuro);
    --border: var(--amav-linha-bege);
    color: var(--amav-marrom);
}

.inst-modal.is-open .inst-modal-box {
    transform: translateY(0);
}

.inst-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 0;
    border-radius: 10px;
    color: var(--amav-marrom);
    cursor: pointer;
}

.inst-modal-title {
    font-size: clamp(1.5rem, 5vw, 1.875rem);
    margin-bottom: 8px;
    padding-right: 44px;
}

.inst-modal-sub {
    font-size: 0.9375rem;
    margin-bottom: 20px;
    opacity: 0.85;
}

/* --- Progresso das 2 etapas --- */
.inst-form-progress {
    height: 4px;
    margin-bottom: 24px;
    background-color: rgba(81, 45, 31, 0.12);
    border-radius: 999px;
    overflow: hidden;
}

.inst-form-progress-fill {
    height: 100%;
    width: 50%;
    background-color: var(--amav-laranja);
    border-radius: 999px;
    transition: width .3s ease;
}

/* --- Botão de voltar da etapa 2 --- */
.inst-form-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    margin-bottom: 8px;
    padding: 0;
    font-family: var(--font-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--heading);
    background: none;
    border: 0;
    cursor: pointer;
}

.inst-field {
    margin-bottom: 16px;
}

.inst-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--heading);
}

.inst-field input {
    width: 100%;
    min-height: 52px;
    padding: 13px 15px;
    font-family: var(--font-secondary);
    /* 16px: abaixo disso o iOS dá zoom ao focar o campo */
    font-size: 1rem;
    color: var(--amav-marrom);
    background-color: #FFFFFF;
    border: 1px solid rgba(81, 45, 31, 0.28);
    border-radius: var(--inst-radius);
    transition: border-color .2s ease;
}

.inst-field input:focus {
    border-color: var(--amav-laranja);
}

.inst-field input::placeholder {
    color: rgba(81, 45, 31, 0.42);
}

.inst-field.has-error input {
    border-color: #A32B1F;
}

/* --- Cidade: botões de opção, sigla do estado à direita ---
   A quarta opção não é um botão: é um input com a mesma moldura das
   outras três, placeholder "Outros" e o selo BR fixo à direita. Digitar
   nele seleciona a quarta e limpa os botões; clicar num botão limpa o
   input. */
.inst-cidade-field {
    border: 0;
    padding: 0;
    margin: 0 0 16px;
    min-width: 0;
}

.inst-cidade-field legend {
    display: block;
    width: 100%;
    padding: 0;
    margin-bottom: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--heading);
}

/* Empilhados: um botão embaixo do outro, não em grade */
.inst-cidade-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.inst-cidade-opt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 52px;
    padding: 12px 14px;
    font-family: var(--font-secondary);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--amav-marrom);
    background-color: #FFFFFF;
    border: 1px solid rgba(81, 45, 31, 0.28);
    border-radius: var(--inst-radius);
    transition: border-color .2s ease, background-color .2s ease;
}

button.inst-cidade-opt {
    cursor: pointer;
}

button.inst-cidade-opt.is-selected {
    border-color: var(--amav-laranja);
    background-color: rgba(207, 82, 26, 0.08);
}

.inst-cidade-sigla {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    padding: 3px 7px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--amav-marrom);
    background-color: rgba(81, 45, 31, 0.1);
    border-radius: 6px;
}

.inst-cidade-opt.is-selected .inst-cidade-sigla {
    color: #FFFFFF;
    background-color: var(--amav-laranja);
}

.inst-cidade-opt--outros {
    padding: 0 0 0 14px;
}

.inst-cidade-opt--outros input {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    min-height: 52px;
    padding: 12px 0;
    font-family: var(--font-secondary);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--amav-marrom);
    background: none;
    border: 0;
}

.inst-cidade-opt--outros .inst-cidade-sigla {
    margin-right: 14px;
}

.inst-field.has-error .inst-cidade-group {
    outline: 2px solid #A32B1F;
    outline-offset: 4px;
    border-radius: var(--inst-radius);
}

/* --- Etapa 2 (opt-in): mesmo padrão de
   criatividados.com/corretor/forms — sem rótulo visível (o placeholder
   faz esse papel; aria-label cobre a acessibilidade), seletor de país no
   telefone, botão desabilitado até os três campos ficarem válidos. A
   paleta é a da AMAV; a estrutura e o comportamento são os de lá.
   .inst-text-field tem mais especificidade que .inst-field input pra não
   herdar a moldura genérica meio a meio com o wrapper do telefone. */
.inst-field .inst-text-field {
    width: 100%;
    min-height: 52px;
    padding: 13px 16px;
    font-family: var(--font-secondary);
    font-size: 1rem;
    color: var(--amav-marrom);
    background-color: #FFFFFF;
    border: 1px solid rgba(81, 45, 31, 0.28);
    border-radius: var(--inst-radius);
    transition: border-color .2s ease;
}

.inst-field .inst-text-field:focus {
    outline: none;
    border-color: var(--amav-laranja);
}

.inst-field .inst-text-field::placeholder {
    color: rgba(81, 45, 31, 0.42);
}

.inst-phone-group {
    position: relative;
}

.inst-phone-field {
    display: flex;
    align-items: center;
    background-color: #FFFFFF;
    border: 1px solid rgba(81, 45, 31, 0.28);
    border-radius: var(--inst-radius);
    overflow: hidden;
    transition: border-color .2s ease;
}

.inst-phone-field:focus-within {
    border-color: var(--amav-laranja);
}

.inst-country-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    height: 52px;
    padding: 0 10px 0 14px;
    background: none;
    border: 0;
    border-right: 1px solid rgba(81, 45, 31, 0.18);
    color: var(--amav-marrom);
    cursor: pointer;
}

.inst-country-flag {
    font-size: 1.2rem;
    line-height: 1;
}

.inst-country-chevron {
    width: 10px;
    height: 10px;
    transition: transform .2s ease;
}

.inst-country-toggle[aria-expanded="true"] .inst-country-chevron {
    transform: rotate(180deg);
}

.inst-country-code {
    flex-shrink: 0;
    padding: 0 4px 0 10px;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--amav-marrom);
    white-space: nowrap;
}

.inst-field .inst-text-field-phone {
    flex: 1 1 auto;
    min-width: 0;
    padding-left: 8px;
    background: none;
    border: 0;
    border-radius: 0;
}

.inst-country-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 10;
    background-color: #FFFFFF;
    border: 1px solid rgba(81, 45, 31, 0.18);
    border-radius: var(--inst-radius);
    box-shadow: var(--inst-shadow-lg);
    overflow: hidden;
}

.inst-country-dropdown.is-open {
    display: block;
}

.inst-country-search-wrap {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(81, 45, 31, 0.12);
}

.inst-field .inst-country-search {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    font-family: var(--font-secondary);
    font-size: 0.875rem;
    color: var(--amav-marrom);
    background-color: var(--amav-bege-claro);
    border: 1px solid rgba(81, 45, 31, 0.18);
    border-radius: 8px;
}

.inst-field .inst-country-search:focus {
    outline: none;
    border-color: var(--amav-laranja);
}

.inst-country-list {
    list-style: none;
    margin: 0;
    padding: 4px 0;
    max-height: 200px;
    overflow-y: auto;
}

.inst-country-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 0.875rem;
    color: var(--amav-marrom);
    cursor: pointer;
    transition: background-color .15s ease;
}

.inst-country-item:hover {
    background-color: var(--amav-bege-claro);
}

.inst-country-item.is-active {
    background-color: rgba(207, 82, 26, 0.1);
}

.inst-country-item-name {
    flex: 1 1 auto;
}

.inst-country-item-code {
    color: rgba(81, 45, 31, 0.5);
    font-size: 0.8125rem;
}

.inst-form-error {
    margin-bottom: 14px;
    padding: 11px 14px;
    font-size: 0.875rem;
    color: #7E2118;
    background-color: rgba(163, 43, 31, 0.09);
    border-radius: 10px;
}

#instFormSubmit[data-loading="true"] {
    opacity: 0.75;
    pointer-events: none;
}

#instFormSubmit:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.inst-form-microcopy {
    text-align: center;
}

/* Honeypot: fora da tela, mas não display:none, pra bot preencher */
.inst-hp {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

body.inst-modal-open {
    overflow: hidden;
}

/* Desktop: caixa centrada */
@media (min-width: 640px) {
    .inst-modal {
        align-items: center;
        padding: 24px;
    }

    .inst-modal-box {
        max-width: 480px;
        max-height: 88dvh;
        padding: 40px 36px;
        border-radius: var(--inst-radius-lg);
        transform: translateY(16px) scale(0.98);
        opacity: 0;
        transition: transform .2s ease-out, opacity .2s ease-out;
    }

    .inst-modal.is-open .inst-modal-box {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {

    .inst-modal-backdrop,
    .inst-modal-box {
        transition: none;
    }
}
