﻿/* ============================================
   agent-modal.css — DonVito Agent
   Chat modal com layout de conversa com IA
   ============================================ */

/* ── Overlay ─────────────────────────────────────────────────── */
.agent-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 9999;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.25s ease;
    /* iOS Safari: garante que o overlay cubra toda a tela incluindo notch */
    padding-top: env(safe-area-inset-top);
}

.agent-modal-overlay.open {
    display: flex;
    opacity: 1;
}

/* ── Modal container ─────────────────────────────────────────── */
.agent-modal {
    width: 100%;
    max-width: 480px;
    height: 92dvh;
    max-height: 780px;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 -8px 60px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.07);
    transform: translateY(30px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-family: var(--font-body);
    /* iOS Safari: respeita a área segura na parte inferior (home indicator) */
    padding-bottom: env(safe-area-inset-bottom);
}

.agent-modal-overlay.open .agent-modal {
    transform: translateY(0);
}

/* Desktop: centraliza verticalmente */
@media (min-width: 640px) {
    .agent-modal-overlay {
        align-items: center;
        padding: 20px;
    }

    .agent-modal {
        border-radius: 20px;
        height: 85dvh;
    }
}

/* ── Header ──────────────────────────────────────────────────── */
.agent-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.6);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

.agent-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    border: 2px solid rgba(13, 148, 136, 0.35);
}

.agent-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    border-radius: 50%;
}

.agent-avatar svg {
    color: #0f1117;
}

.agent-avatar-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
    50%       { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}

.agent-header-info {
    flex: 1;
    min-width: 0;
}

.agent-header-name {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 700;
    color: #000000;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.agent-service-tag {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: rgba(13, 148, 136, 0.12);
    color: #0d9488;
    border: 1px solid rgba(13,148,136,0.28);
    padding: 2px 8px;
    border-radius: 99px;
}

.agent-header-status {
    font-size: 12px;
    color: #6b7280;
    font-weight: 500;
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Ponto animado "online" antes do status (Fase F6) */
.agent-header-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
    animation: online-pulse 2.5s ease-in-out infinite;
}

@keyframes online-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.55; transform: scale(0.85); }
}

.agent-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.09);
    background: rgba(0,0,0,0.03);
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
    /* Previne double-tap zoom em mobile */
    touch-action: manipulation;
}

.agent-close-btn:hover {
    background: rgba(0,0,0,0.08);
    color: #000000;
}

/* ── Messages area ───────────────────────────────────────────── */
.agent-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    /* iOS Safari: scroll suave nativo e impede propagação do rubber-band */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.agent-messages::-webkit-scrollbar { width: 4px; }
.agent-messages::-webkit-scrollbar-track { background: transparent; }
.agent-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.14);
    border-radius: 4px;
}

/* ── Individual message ──────────────────────────────────────── */
.msg {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    max-width: 88%;
    animation: msg-in 0.2s ease both;
}

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

.msg.agent { align-self: flex-start; }

.msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.msg.agent .msg-avatar {
    background: #f3f4f6;
    border: 1.5px solid rgba(13, 148, 136, 0.35);
    overflow: hidden;
    padding: 0;
    font-size: 0;
    background-image: url("../../images/donvito/foto-robo-don-vito.png");
    background-size: cover;
    background-position: center top;
}

.msg.user .msg-avatar {
    background: rgba(0,0,0,0.05);
    color: #6b7280;
    border: 1px solid rgba(0,0,0,0.1);
}

.msg-bubble {
    padding: 12px 15px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
}

.msg.agent .msg-bubble {
    background: #f3f4f6;
    color: #1f2937;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(0,0,0,0.06);
}

.msg.user .msg-bubble {
    background: linear-gradient(135deg, #1df3d0 0%, #0ea5e9 100%);
    color: #0a0f1a;
    font-weight: 500;
    border-bottom-right-radius: 4px;
}

.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul { margin: 6px 0; padding-left: 18px; }
.msg-bubble li { margin-bottom: 4px; }

.msg-bubble strong { font-weight: 700; color: #0d9488; }
.msg.user .msg-bubble strong { color: inherit; }

/* ── Typing indicator ────────────────────────────────────────── */
.msg-typing .msg-bubble {
    padding: 14px 18px;
    display: flex;
    gap: 6px;
    align-items: center;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #1df3d0;
    display: inline-block;
    animation: typing-bounce 1.4s infinite cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes typing-bounce {
    0%, 70%, 100% { transform: translateY(0);    opacity: 0.35; }
    35%            { transform: translateY(-7px); opacity: 1;    }
}

/* ── Error state (Fase F6) ───────────────────────────────────── */
.msg.error .msg-bubble {
    background: rgba(248, 113, 113, 0.08);
    border-color: rgba(248, 113, 113, 0.2);
    color: #fca5a5;
}

.msg.error .msg-bubble strong { color: #f87171; }

/* ── Suggested questions ─────────────────────────────────────── */
.suggested-questions {
    padding: 0 16px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}

.suggested-questions.hidden { display: none; }

.sq-btn {
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    color: #0d9488;
    background: rgba(13, 148, 136, 0.09);
    border: 1px solid rgba(13, 148, 136, 0.25);
    border-radius: 99px;
    padding: 6px 14px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    white-space: nowrap;
    touch-action: manipulation;
}

.sq-btn:hover {
    background: rgba(13, 148, 136, 0.16);
    border-color: rgba(13, 148, 136, 0.45);
    transform: translateY(-1px);
}

/* ── CTA adaptativo — base de cada variante ─────────────────── */
.agent-cta-bar {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.6);
    border-top: 1px solid rgba(0,0,0,0.07);
    flex-shrink: 0;
    animation: cta-in 0.25s ease both;
}

@keyframes cta-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.agent-cta-bar.hidden { display: none; }

/* Variantes com layout em coluna */
.cta-educativo,
.cta-sessao,
.cta-quente,
.cta-urgente,
.cta-erro {
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
}

/* Texto auxiliar acima dos botões */
.cta-hint {
    font-size: 12px;
    color: #6b7280;
    margin: 0;
    line-height: 1.4;
}

.cta-hint-quente {
    color: #0d9488;
    font-weight: 600;
}

/* ── Botão base ──────────────────────────────────────────────── */
.agent-cta-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s, transform 0.1s;
    text-decoration: none;
    white-space: nowrap;
    touch-action: manipulation;
}

.agent-cta-btn:hover { opacity: 0.88; transform: translateY(-1px); }

/* ── Variante FRIO: botão outline ────────────────────────────── */
.cta-btn-outline {
    background: transparent;
    color: #0d9488;
    border: 1px solid rgba(13, 148, 136, 0.4);
    flex: none;
    width: 100%;
}

.cta-btn-outline:hover {
    background: rgba(13, 148, 136, 0.08);
    border-color: rgba(13, 148, 136, 0.6);
}

.agent-cta-whatsapp {
    background: #22c55e;
    color: #fff;
    flex: none;
    padding: 10px 14px;
}

/* ── Variante QUENTE: formulário inline ──────────────────────── */
.cta-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cta-form-fields {
    display: flex;
    gap: 8px;
}

@media (max-width: 380px) {
    .cta-form-fields { flex-direction: column; }
}

.cta-input {
    flex: 1;
    min-width: 0;
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.14);
    border-radius: 8px;
    color: #1f2937;
    font-family: inherit;
    font-size: 13px;
    padding: 8px 12px;
    outline: none;
    transition: border-color 0.15s;
}

.cta-input::placeholder { color: #9ca3af; }
.cta-input:focus        { border-color: rgba(13, 148, 136, 0.5); }

.cta-form-error {
    font-size: 12px;
    color: #f87171;
    margin: 0;
}

.cta-form-btns {
    display: flex;
    gap: 8px;
}

.cta-btn-primary {
    background: linear-gradient(135deg, #1df3d0, #0ea5e9);
    color: #0a0f1a;
    font-weight: 700;
    flex: 1;
}

.cta-btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

/* ── Variante URGENTE: botão pulsante ────────────────────────── */
.cta-urgente {
    background: rgba(255, 107, 53, 0.05);
    border-top-color: rgba(255, 107, 53, 0.2);
}

.cta-btn-pulse {
    width: 100%;
    flex: none;
    background: linear-gradient(135deg, #ff6b35, #ff4b1f);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    border-radius: 10px;
    animation: btn-pulse 2s ease-in-out infinite;
}

.cta-btn-pulse:hover { opacity: 0.9; transform: translateY(-1px); animation: none; }

/* ── Variante ERRO: fallback de WhatsApp quando o chat falha ─── */
.cta-erro {
    background: rgba(239, 68, 68, 0.06);
    border-top-color: rgba(239, 68, 68, 0.2);
}

.cta-erro .agent-cta-whatsapp {
    width: 100%;
    flex: none;
}

@keyframes btn-pulse {
    0%, 100% { box-shadow: 0 0 0 0   rgba(255, 107, 53, 0.45); }
    50%       { box-shadow: 0 0 0 10px rgba(255, 107, 53, 0); }
}

/* ── Input bar ───────────────────────────────────────────────── */
.agent-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 16px 16px;
    background: rgba(255, 255, 255, 0.6);
    border-top: 1px solid rgba(0,0,0,0.08);
    flex-shrink: 0;
}

/* Wrapper: ocupa o flex: 1 e fornece contexto de posição para o contador */
.agent-input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Contador de caracteres (Fase F5) */
.agent-char-count {
    position: absolute;
    bottom: 6px;
    right: 10px;
    font-size: 11px;
    color: #9ca3af;
    pointer-events: none;
    user-select: none;
    transition: color 0.15s;
}
.agent-char-count.hidden    { display: none; }
.agent-char-count.warn      { color: #fb923c; }
.agent-char-count.over      { color: #f87171; font-weight: 700; }

.agent-input {
    width: 100%;
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: 12px;
    color: #1f2937;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    padding: 10px 14px;
    resize: none;
    outline: none;
    min-height: 42px;
    max-height: 120px;
    transition: border-color 0.15s;
}

.agent-input::placeholder { color: #9ca3af; }
.agent-input:focus { border-color: rgba(13, 148, 136, 0.5); }

.agent-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #1df3d0, #0ea5e9);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.1s;
    color: #0a0f1a;
    touch-action: manipulation;
}

.agent-send-btn:hover:not(:disabled) {
    opacity: 0.88;
    transform: scale(1.05);
}

.agent-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Handoff Screen (Fase F4) ────────────────────────────────── */
.agent-handoff-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 10px;
    padding: 24px 20px 20px;
    background: rgba(255, 255, 255, 0.6);
    border-top: 1px solid rgba(0,0,0,0.07);
    flex-shrink: 0;
    animation: cta-in 0.3s ease both;
}

.agent-handoff-screen.hidden { display: none; }

.handoff-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(13, 148, 136, 0.1);
    border: 1px solid rgba(13, 148, 136, 0.28);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
    animation: pulse-dot 2.5s infinite;
}

.handoff-title {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 700;
    color: #000000;
    margin: 0;
}

.handoff-subtitle {
    font-size: 12px;
    color: #6b7280;
    font-weight: 500;
    margin: 0;
    line-height: 1.5;
    max-width: 300px;
}