:root {
    --n8n-primary: var(--neon-blue, #00ffea);
    --n8n-secondary: var(--dashboard-bg, #0b0c10);
    --n8n-accent: var(--neon-orange, #ff4d1d);
    --n8n-text: var(--text-main, #c5c6c7);
    --n8n-bg-dark: var(--surface-2, #1f2833);
    --n8n-user-bubble: var(--neon-blue, #00ffea);
    --n8n-bot-bubble: var(--surface-1, #2c3e50);
    --n8n-shadow: rgba(0, 255, 234, 0.4);
    --n8n-shadow-warm: rgba(255, 77, 29, 0.35);
    --n8n-card-radius: 0;
    --n8n-card-border: var(--border-strong, rgba(0, 255, 234, 0.25));
    --n8n-glass-border: rgba(255, 255, 255, 0.16);
    --n8n-chat-clip: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
    --n8n-muted: rgba(232, 241, 255, 0.72);
    /* opaco: o texto do hero não pode aparecer por trás das mensagens */
    --n8n-surface-glass: linear-gradient(160deg, #060c12, #0c1117);
    --n8n-glass-bg: rgba(0, 255, 234, 0.09);
    --n8n-card-clip: polygon(16px 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%, 0 16px);
    /* Distância do botão até as bordas, sempre DENTRO da área segura do aparelho. */
    --n8n-btn-gap: 16px;
}

/* ------------------------------------------------------------------
   Botão flutuante
   - fica na área segura (notch/barra de gestos: env(safe-area-inset-*));
   - --n8n-chat-desvio (n8n_chat.js) sobe o botão quando há um botão,
     link ou indicador do carrossel embaixo dele;
   - sem animação contínua: só uma chamada curta na 1ª página da visita.
   ------------------------------------------------------------------ */
.n8n-chat-btn {
    position: fixed;
    right: calc(var(--n8n-btn-gap) + env(safe-area-inset-right, 0px));
    bottom: calc(var(--n8n-btn-gap) + env(safe-area-inset-bottom, 0px));
    z-index: var(--vn-z-chat, 1035);
    display: inline-flex;
    align-items: center;
    gap: 0;
    min-width: 52px;
    min-height: 52px;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: #fff;
    cursor: pointer;
    transform: translateY(calc(-1 * var(--n8n-chat-desvio, 0px)));
    transition: transform 0.25s ease, opacity 0.2s ease, visibility 0.2s;
    font-family: "Orbitron", sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    -webkit-tap-highlight-color: transparent;
}

.n8n-chat-btn::before,
.n8n-chat-btn::after {
    display: none;
    content: none;
}

.n8n-chat-brand {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 52px;
    width: 52px;
    height: 52px;
    background: linear-gradient(160deg, rgba(255, 77, 29, 0.95), rgba(230, 60, 20, 0.92));
    clip-path: var(--n8n-chat-clip);
    box-shadow: 0 6px 18px rgba(255, 77, 29, 0.35);
    transition: background 0.2s ease;
}

.n8n-chat-brand__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.45rem;
    line-height: 1;
    color: #111827;
}

/* Aberto, o botão vira "fechar" (X), como o X do cabeçalho do chat. */
.n8n-chat-brand__icon--fechar,
.n8n-chat-btn.is-open .n8n-chat-brand__icon--abrir {
    display: none;
}

.n8n-chat-btn.is-open .n8n-chat-brand__icon--fechar {
    display: flex;
    font-size: 1.25rem;
}

/* Rótulo "Ajuda": visível do tablet para cima, ao lado do ícone. */
.n8n-chat-btn-label {
    display: none;
}

@media (min-width: 768px) {
    .n8n-chat-btn {
        --n8n-btn-gap: 20px;
        background: rgba(7, 14, 24, 0.92);
        border: 1px solid rgba(255, 77, 29, 0.7);
        clip-path: var(--n8n-chat-clip);
        padding: 0 18px 0 0;
        gap: 12px;
        box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
    }

    .n8n-chat-btn .n8n-chat-brand {
        flex-basis: 50px;
        width: 50px;
        height: 50px;
        clip-path: none;
        box-shadow: none;
    }

    .n8n-chat-btn-label {
        display: inline;
        color: #fff;
    }

    .n8n-chat-btn.is-open .n8n-chat-btn-label,
    .n8n-chat-btn.n8n-chat-btn--compacto .n8n-chat-btn-label {
        display: none;
    }

    /* Compacto: só o ícone (52 px) enquanto o rótulo cobriria a ponta de um campo ou
       card que está embaixo; volta a mostrar "Ajuda" quando a área fica livre. */
    .n8n-chat-btn.is-open,
    .n8n-chat-btn.n8n-chat-btn--compacto {
        padding-right: 0;
        gap: 0;
    }

    /* O clip-path cortaria o contorno externo: no tablet/desktop o foco fica por dentro. */
    .n8n-chat-btn:focus-visible {
        outline-offset: -6px !important;
    }
}

.n8n-chat-btn:hover .n8n-chat-brand,
.n8n-chat-btn:focus-visible .n8n-chat-brand {
    background: linear-gradient(160deg, #ff6b3d, #ff4d1d);
}

.n8n-chat-btn:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
}

.n8n-chat-btn:focus:not(:focus-visible) {
    outline: none;
}

/* Chamada de atenção: 2 pulsos na primeira página da visita (sem loop infinito). */
.n8n-chat-btn--chamada .n8n-chat-brand {
    animation: n8n-chat-chamada 1.1s ease-out 0.8s 2;
}

@keyframes n8n-chat-chamada {
    0% { box-shadow: 0 6px 18px rgba(255, 77, 29, 0.35), 0 0 0 0 rgba(255, 77, 29, 0.55); }
    70% { box-shadow: 0 6px 18px rgba(255, 77, 29, 0.35), 0 0 0 14px rgba(255, 77, 29, 0); }
    100% { box-shadow: 0 6px 18px rgba(255, 77, 29, 0.35), 0 0 0 0 rgba(255, 77, 29, 0); }
}

/* Estados em que o botão sai do caminho. */
body.mobile-menu-open .n8n-chat-btn,
body.mobile-menu-open .n8n-chat-container {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

@media (max-width: 991.98px) {
    /* Durante a rolagem (cobria CTAs de largura total) e com um campo em edição
       (o teclado sobe e o botão ficaria por cima do campo). */
    body.n8n-chat-scroll-hide .n8n-chat-btn:not(.is-open),
    body.n8n-chat-campo-ativo .n8n-chat-btn:not(.is-open) {
        opacity: 0;
        pointer-events: none;
        visibility: hidden;
    }
}

/* ------------------------------------------------------------------
   Janela do chat
   ------------------------------------------------------------------ */
.n8n-chat-container {
    position: fixed;
    right: calc(20px + env(safe-area-inset-right, 0px));
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    z-index: calc(var(--vn-z-chat, 1035) + 1);
    width: min(390px, calc(100vw - 40px));
    height: min(600px, calc(100vh - 120px));
    height: min(600px, calc(100dvh - 120px));
    font-family: "Barlow", "Roboto", Arial, sans-serif;
    animation: n8n-entra 0.25s ease-out;
    background-color: transparent;
}

@keyframes n8n-entra {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.n8n-chat-card {
    width: 100%;
    height: 100%;
    background: var(--n8n-surface-glass);
    border: 1px solid rgba(0, 255, 234, 0.35);
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 24px rgba(0, 255, 234, 0.12);
    overflow: hidden;
    clip-path: var(--n8n-card-clip);
}

.n8n-chat-header {
    padding: 10px 8px 10px 16px;
    background: linear-gradient(135deg, rgba(0, 255, 234, 0.14), rgba(255, 77, 29, 0.1));
    border-bottom: 1px solid var(--n8n-glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.n8n-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.n8n-avatar {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    background: var(--n8n-primary);
    clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #031314;
    font-size: 1.1rem;
}

.n8n-title {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

body.dark-theme .n8n-agent-name,
.n8n-agent-name {
    margin: 0;
    color: #fff !important;
    font-family: "Orbitron", sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 1px;
    line-height: 1.2;
}

.n8n-agent-name:focus {
    outline: none;
}

.n8n-status {
    color: var(--n8n-muted);
    font-size: 0.8rem;
    line-height: 1.3;
}

.n8n-header-actions {
    display: flex;
    flex: 0 0 auto;
}

.n8n-header-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    font-size: 1.15rem;
    transition: color 0.2s, background 0.2s;
}

.n8n-header-actions button:hover,
.n8n-header-actions button:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.n8n-header-actions button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* .n8n-acao e o Enviar são chanfrados (clip-path): o contorno por fora seria cortado,
   então o foco fica POR DENTRO do botão. */
.n8n-acao:focus-visible,
.n8n-input-wrapper button:focus-visible {
    outline: 3px solid #fff;
    outline-offset: -5px;
}

.n8n-acao:not(.n8n-acao--principal):focus-visible {
    background: rgba(0, 255, 234, 0.12);
    color: #fff !important;
}

/* Corpo */
.n8n-chat-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scrollbar-width: thin;
}

/* Apresentação por etapa (visitante x cliente logado) */
.n8n-intro {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border: 1px solid rgba(0, 255, 234, 0.22);
    background: rgba(0, 255, 234, 0.05);
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
    color: #e8f1ff;
    font-size: 0.95rem;
    line-height: 1.45;
}

.n8n-intro p {
    margin: 0;
}

.n8n-intro__oi {
    font-weight: 700;
    color: #fff;
}

.n8n-intro__texto {
    color: rgba(232, 241, 255, 0.85);
}

.n8n-intro__texto--humano {
    margin-top: 4px !important;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.n8n-intro__acoes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.n8n-intro__acoes--linha {
    flex-direction: row;
    flex-wrap: wrap;
}

.n8n-intro__acoes--linha .n8n-acao {
    flex: 1 1 150px;
}

.n8n-intro__privacidade {
    display: flex;
    gap: 6px;
    align-items: flex-start;
    font-size: 0.82rem;
    color: var(--n8n-muted);
}

.n8n-acao {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px 14px;
    border: 1px solid rgba(0, 255, 234, 0.55);
    background: transparent;
    color: var(--n8n-primary) !important;
    font-family: "Barlow", "Roboto", Arial, sans-serif;
    font-size: 0.92rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
    transition: background 0.2s ease, color 0.2s ease;
}

.n8n-acao:hover {
    background: rgba(0, 255, 234, 0.12);
    color: #fff !important;
}

.n8n-acao--principal {
    border-color: transparent;
    background: var(--vn-btn-primary-bg, #ff4d1d);
    color: var(--vn-btn-primary-fg, #111827) !important;
}

.n8n-acao--principal:hover {
    background: #ff6b3d;
    color: #111827 !important;
}

.n8n-msg {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    position: relative;
    animation: n8n-msg-entra 0.25s ease;
}

@keyframes n8n-msg-entra {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.n8n-msg-content {
    padding: 10px 14px;
    font-size: 0.95rem;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.typing-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.typing-dots .dot {
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    animation: n8n-dot-bounce 1s infinite ease-in-out;
}

.typing-dots .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes n8n-dot-bounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1.2); opacity: 1; }
}

.n8n-msg-bot {
    align-self: flex-start;
}

.n8n-msg-bot .n8n-msg-content {
    background: rgba(19, 35, 50, 0.95);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%);
}

.n8n-msg-user {
    align-self: flex-end;
}

.n8n-msg-user .n8n-msg-content {
    background: var(--n8n-user-bubble);
    color: #031314;
    font-weight: 500;
    clip-path: polygon(8px 0, 100% 0, 100% 100%, 0 100%, 0 8px);
}

.n8n-msg-time {
    font-size: 0.72rem;
    color: var(--n8n-muted);
    margin-top: 4px;
    align-self: flex-end;
}

.n8n-msg-bot .n8n-msg-time {
    align-self: flex-start;
}

/* Rodapé e campo */
.n8n-chat-footer {
    padding: 12px 12px 10px;
    background: rgba(12, 20, 30, 0.98);
    border-top: 1px solid var(--n8n-glass-border);
}

.n8n-respostas {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.n8n-respostas[hidden] {
    display: none;
}

.n8n-respostas .n8n-acao {
    flex: 1 1 0;
}

.n8n-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 4px 4px 12px;
    border: 1px solid rgba(0, 243, 255, 0.3);
}

.n8n-input-wrapper:focus-within {
    border-color: rgba(0, 255, 234, 0.7);
}

body.dark-theme .n8n-input-wrapper textarea,
.n8n-input-wrapper textarea {
    flex: 1;
    min-height: 44px;
    padding: 11px 0 !important;
    background: transparent !important;
    border: none !important;
    color: #fff !important;
    resize: none;
    font-family: inherit;
    /* 16 px: o iOS não dá zoom ao focar */
    font-size: 16px;
    max-height: 120px;
    outline: none;
    line-height: 1.35;
    box-shadow: none !important;
}

.n8n-input-wrapper textarea::placeholder {
    color: rgba(232, 241, 255, 0.6);
}

.n8n-input-wrapper button {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    background: var(--vn-btn-primary-bg, #ff4d1d);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #111827;
    font-size: 1.05rem;
    clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
    transition: opacity 0.2s;
}

.n8n-input-wrapper button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.n8n-input-wrapper button:hover:not(:disabled) {
    background: #ff6b3d;
}

.n8n-input-wrapper button[aria-busy="true"] {
    opacity: 0.75;
}

.n8n-footer-branding {
    margin: 2px 0 0;
    text-align: center;
    font-size: 0.78rem;
    color: var(--n8n-muted);
}

/* Alvo de toque de 44 px sem aumentar a fonte. */
.n8n-footer-branding a {
    color: var(--n8n-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 6px;
}

.n8n-footer-branding a:hover,
.n8n-footer-branding a:focus-visible {
    color: #fff;
}

.n8n-footer-branding a:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -2px;
    background: rgba(0, 255, 234, 0.12);
}

/* Caminhos para uma pessoa (Área do Cliente, WhatsApp, 0800) repetidos logo depois
   de uma resposta que manda o visitante para lá (n8n_chat.js). */
.n8n-caminhos {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-self: stretch;
}

.n8n-caminhos .n8n-acao {
    flex: 1 1 140px;
}

.n8n-caminhos .n8n-acao--principal {
    flex-basis: 100%;
}

.n8n-empty-state {
    color: var(--n8n-muted);
    font-size: 0.85rem;
    text-align: center;
    border: 1px dashed var(--n8n-glass-border);
    padding: 10px;
}

/* Celular: o chat ocupa a tela toda, respeitando notch e barra de gestos.
   O botão flutuante some (o X do cabeçalho fecha) para não cobrir o campo e o Enviar. */
@media (max-width: 480px) {
    .n8n-chat-card {
        background: #070d14;
    }

    .n8n-chat-container {
        inset: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        max-height: none;
        right: 0;
        bottom: 0;
    }

    .n8n-chat-card {
        border: none;
        clip-path: none;
    }

    .n8n-chat-header {
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
        padding-left: calc(16px + env(safe-area-inset-left, 0px));
        padding-right: calc(8px + env(safe-area-inset-right, 0px));
    }

    .n8n-chat-footer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        padding-left: calc(12px + env(safe-area-inset-left, 0px));
        padding-right: calc(12px + env(safe-area-inset-right, 0px));
    }

    .n8n-chat-btn.is-open {
        display: none;
    }

    body.n8n-chat-aberto {
        overflow: hidden;
    }
}

@media (prefers-reduced-motion: reduce) {
    .n8n-chat-btn,
    .n8n-chat-brand,
    .n8n-chat-container,
    .n8n-msg {
        transition: none !important;
        animation: none !important;
    }

    .typing-dots .dot {
        animation: none;
        opacity: 0.8;
    }
}

@media (forced-colors: active) {
    .n8n-chat-brand,
    .n8n-acao,
    .n8n-chat-card {
        border: 2px solid ButtonText;
    }
}

@media (max-width: 991px) {
    body.dashboard-body .n8n-chat-btn,
    body.dashboard-body .n8n-chat-container {
        display: none !important;
    }
}
