/* ============================================================
   Chat Bubble – Assistente IA  |  v2
   ============================================================ */

/* ---- Botão Flutuante (FAB) ---- */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--cor-primaria, #284093), color-mix(in srgb, var(--cor-primaria, #284093) 65%, #000));
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(0,0,0,0.28), 0 0 0 0 color-mix(in srgb, var(--cor-primaria, #284093) 35%, transparent);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), box-shadow 0.3s ease;
    animation: chatFabPulse 3.5s ease-in-out infinite;
    overflow: hidden;
}
.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 32px rgba(0,0,0,0.32);
    animation: none;
}
.chat-fab.active {
    animation: none;
}

/* Imagem do capacete/avatar no FAB */
.chat-fab > img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    transition: opacity 0.25s ease, transform 0.3s cubic-bezier(.34,1.56,.64,1);
    position: absolute;
}
.chat-fab-emoji {
    font-size: 28px;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.25s ease, transform 0.3s cubic-bezier(.34,1.56,.64,1);
}
.chat-fab .fab-close-icon {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.5) rotate(-45deg);
    transition: opacity 0.25s ease, transform 0.3s cubic-bezier(.34,1.56,.64,1);
    color: #fff;
}
.chat-fab .fab-close-icon svg { width: 22px; height: 22px; }

.chat-fab.active > img         { opacity: 0; transform: scale(0.5) rotate(45deg); }
.chat-fab.active .chat-fab-emoji { opacity: 0; transform: scale(0.5) rotate(45deg); }
.chat-fab.active .fab-close-icon { opacity: 1; transform: scale(1) rotate(0deg); }

@keyframes chatFabPulse {
    0%, 100% { box-shadow: 0 6px 24px rgba(0,0,0,0.28), 0 0 0 0 color-mix(in srgb, var(--cor-primaria, #284093) 35%, transparent); }
    50%       { box-shadow: 0 6px 24px rgba(0,0,0,0.28), 0 0 0 14px transparent; }
}

/* ---- Badge de notificação ---- */
.chat-fab-badge {
    position: absolute;
    top: 0;
    right: 0;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #fff;
    display: none;
}
.chat-fab-badge.visible { display: block; }

/* ---- Janela do Chat ---- */
.chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    max-height: 580px;
    height: calc(100vh - 140px);
    background-color: #f0f2f7;   /* fundo base da área de mensagens */
    border-radius: 22px;
    box-shadow: 0 16px 56px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.06);
    z-index: 9997;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
}
.chat-window.open {
    display: flex;
    animation: chatWindowIn 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes chatWindowIn {
    from { opacity: 0; transform: scale(0.82) translateY(24px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---- Header ---- */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--cor-primaria, #284093), color-mix(in srgb, var(--cor-primaria, #284093) 70%, #000 30%));
    color: #fff;
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    border: 1.5px solid rgba(255,255,255,0.25);
    font-size: 20px; /* Para o emoji */
}
.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}
.chat-header-info strong {
    display: block;
    font-size: 0.96rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-header-info span {
    font-size: 0.75rem;
    opacity: 0.80;
}
.chat-header-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.chat-status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 2px rgba(74,222,128,0.3);
    animation: statusPulse 2s ease-in-out infinite;
}
@keyframes statusPulse {
    0%, 100% { box-shadow: 0 0 0 2px rgba(74,222,128,0.3); }
    50%       { box-shadow: 0 0 0 5px rgba(74,222,128,0.1); }
}

/* Botões de ação no header */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.chat-header-btn {
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    height: 34px;
    border-radius: 9px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.18s ease, transform 0.15s ease;
    flex-shrink: 0;
}
.chat-header-close { width: 34px; }
.chat-new-conv-btn {
    padding: 0 10px;
    gap: 6px;
}
.chat-new-conv-btn span {
    font-size: 0.8rem;
    font-weight: 500;
}
.chat-header-btn svg { width: 16px; height: 16px; }
.chat-header-btn:hover {
    background: rgba(255,255,255,0.24);
    transform: scale(1.08);
}
.chat-header-btn:active { transform: scale(0.95); }

/* ---- Chat Body (mensagens + typing, mesmo fundo) ---- */
.chat-body {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background-color: #f0f2f7;
    scroll-behavior: smooth;
    padding: 14px 14px 6px;
    gap: 0;
}
.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb { background: #c9cdd8; border-radius: 10px; }

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

/* ---- Bolha de Mensagem ---- */
.chat-msg {
    display: flex;
    gap: 8px;
    max-width: 90%;
    animation: chatMsgIn 0.28s ease;
}
.chat-msg.bot  { align-self: flex-start; }
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }

@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(10px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Avatar das mensagens */
.chat-msg-avatar {
    width: 30px;
    height: 30px;
    min-width: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    margin-top: 2px;
    overflow: hidden;
    flex-shrink: 0;
}
/* Avatar do bot: fundo da cor primária */
.chat-msg.bot .chat-msg-avatar {
    background: linear-gradient(135deg, var(--cor-primaria, #284093), color-mix(in srgb, var(--cor-primaria, #284093) 70%, #000));
    border: 1.5px solid rgba(255,255,255,0.5);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 14px;
}
.chat-msg.bot .chat-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
/* Avatar do usuário */
.chat-msg.user .chat-msg-avatar {
    background: #fff;
    border: 1.5px solid #e0e3ea;
    color: var(--cor-primaria, #284093);
    font-size: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.chat-msg.user .chat-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Bubble */
.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.875rem;
    line-height: 1.6;
    word-break: break-word;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.chat-msg.bot .chat-msg-bubble {
    background: #fff;
    color: #1f2937;
    border-top-left-radius: 5px;
    border: 1px solid #e8eaef;
}
.chat-msg.user .chat-msg-bubble {
    background: linear-gradient(135deg, var(--cor-primaria, #284093), color-mix(in srgb, var(--cor-primaria, #284093) 78%, #000));
    color: #fff;
    border-top-right-radius: 5px;
}

/* Markdown */
.chat-msg-bubble p               { margin: 0 0 7px; }
.chat-msg-bubble p:last-child    { margin-bottom: 0; }
.chat-msg-bubble strong          { font-weight: 700; }
.chat-msg-bubble em              { font-style: italic; }
.chat-msg-bubble ul, .chat-msg-bubble ol { margin: 4px 0; padding-left: 18px; }
.chat-msg-bubble li              { margin-bottom: 3px; }
.chat-msg-bubble a               { color: var(--cor-primaria, #284093); text-decoration: underline; text-underline-offset: 2px; }
.chat-msg.user .chat-msg-bubble a { color: rgba(255,255,255,0.9); }
.chat-msg-bubble code            { background: rgba(0,0,0,0.07); padding: 1px 5px; border-radius: 4px; font-size: 0.82em; }

/* ---- Rich Elements ---- */
.chat-rich-buttons-wrap {
    align-self: flex-start;
    padding-left: 38px;
    max-width: 90%;
    animation: chatMsgIn 0.28s ease;
    margin-top: 2px;
}
.chat-rich-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.chat-rich-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 20px;
    font-size: 0.81rem;
    font-weight: 500;
    border: 1.5px solid var(--cor-primaria, #284093);
    color: var(--cor-primaria, #284093);
    background: color-mix(in srgb, var(--cor-primaria, #284093) 6%, #fff);
    text-decoration: none;
    transition: all 0.18s ease;
}
.chat-rich-btn i { font-size: 0.72rem; }
.chat-rich-btn:hover { background: var(--cor-primaria, #284093); color: #fff; transform: translateY(-1px); }

.chat-rich-image {
    align-self: flex-start;
    margin-left: 38px;
    margin-top: 4px;
    border-radius: 12px;
    overflow: hidden;
    max-width: 240px;
    border: 1px solid #e0e3ea;
    animation: chatMsgIn 0.28s ease;
    cursor: pointer;
    transition: transform 0.2s ease;
}
.chat-rich-image:hover { transform: scale(1.02); }
.chat-rich-image img { display: block; width: 100%; max-height: 180px; object-fit: cover; }
.chat-rich-caption { display: block; padding: 5px 10px 7px; font-size: 0.75rem; color: #6b7280; background: #f9fafb; }

/* Card de equipamento (recomendação vinda do catálogo real da unidade) */
.chat-rich-equipment-card {
    align-self: flex-start;
    margin-left: 38px;
    margin-top: 4px;
    max-width: 260px;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid #e0e3ea;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    animation: chatMsgIn 0.28s ease;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.chat-rich-equipment-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    color: inherit;
    text-decoration: none;
}
.chat-rich-equipment-card img {
    display: block;
    width: 100%;
    height: 140px;
    object-fit: cover;
    background: #f3f4f6;
}
.chat-rich-equipment-card-noimg {
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    color: #b0b5c0;
    font-size: 1.8rem;
}
.chat-rich-equipment-card-info {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.chat-rich-equipment-card-info strong {
    font-size: 0.85rem;
    line-height: 1.3;
    color: #1f2937;
}
.chat-rich-equipment-card-price {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--cor-primaria, #284093);
}
.chat-rich-equipment-card-link {
    margin-top: 4px;
    font-size: 0.72rem;
    font-weight: 500;
    color: #6b7280;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.chat-rich-equipment-card-link i { font-size: 0.65rem; }

/* ---- Typing Indicator ---- */
/* Agora fica dentro de .chat-body, com o mesmo background #f0f2f7 */
.chat-typing {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 0 6px;
    margin-top: 4px;
    animation: chatMsgIn 0.28s ease;
}
.chat-typing.visible { display: flex; }

.chat-typing-avatar {
    width: 30px;
    height: 30px;
    min-width: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--cor-primaria, #284093), color-mix(in srgb, var(--cor-primaria, #284093) 70%, #000));
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    flex-shrink: 0;
    font-size: 14px;
}
.chat-typing-avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat-typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #fff;
    padding: 10px 14px;
    border-radius: 18px;
    border-top-left-radius: 5px;
    border: 1px solid #e8eaef;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.chat-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--cor-primaria, #284093) 50%, #9ca3af);
    animation: typingBounce 1.4s infinite ease-in-out;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.18s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0);   opacity: 0.4; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---- Aviso IA ---- */
.chat-ai-disclaimer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 3px 14px 1px;
    background: transparent;
    color: #a1a1aa; /* Cinza bem sutil */
    font-size: 0.58rem;
    text-align: center;
    opacity: 0.8;
}
.chat-ai-disclaimer svg {
    width: 10px;
    height: 10px;
    color: #a1a1aa;
}

/* ---- Input Area ---- */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid #e4e7ef;
    background: #fff;
    flex-shrink: 0;
}
.chat-input-wrapper { flex: 1; }
.chat-input {
    width: 100%;
    border: 1.5px solid #e0e3ea;
    border-radius: 14px;
    padding: 10px 14px;
    font-size: 0.875rem;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.45;
    outline: none;
    background: #f7f8fc;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    overflow-y: auto;
    color: #1f2937;
}
.chat-input:focus {
    border-color: var(--cor-primaria, #284093);
    background: #fff;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--cor-primaria, #284093) 10%, transparent);
}
.chat-input::placeholder { color: #adb5bd; }

.chat-send-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 13px;
    border: none;
    background: linear-gradient(135deg, var(--cor-primaria, #284093), color-mix(in srgb, var(--cor-primaria, #284093) 78%, #000));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.2s cubic-bezier(.34,1.56,.64,1), box-shadow 0.2s;
    box-shadow: 0 3px 10px color-mix(in srgb, var(--cor-primaria, #284093) 35%, transparent);
}
.chat-send-btn:hover { transform: scale(1.08); box-shadow: 0 5px 16px color-mix(in srgb, var(--cor-primaria, #284093) 45%, transparent); }
.chat-send-btn:disabled { opacity: 0.38; cursor: not-allowed; transform: none; box-shadow: none; }
.chat-send-btn svg { width: 17px; height: 17px; }

/* ---- Preview Message ---- */
.chat-preview {
    position: fixed;
    bottom: 96px;
    right: 24px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.13), 0 0 0 1px rgba(0,0,0,0.05);
    padding: 12px 18px 12px 14px;
    font-size: 0.85rem;
    color: #374151;
    max-width: 260px;
    z-index: 9996;
    display: none;
    cursor: pointer;
    border: 1px solid #e5e7eb;
}
.chat-preview.visible { display: block; animation: chatPreviewIn 0.3s ease; }
.chat-preview-close {
    position: absolute;
    top: -7px; right: -7px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #6b7280;
    color: #fff;
    border: none;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.chat-preview-close:hover { background: #4b5563; }

@keyframes chatPreviewIn {
    from { opacity: 0; transform: translateY(10px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Modal de confirmação "Nova conversa" ---- */
.chat-confirm-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 20, 40, 0.55);
    backdrop-filter: blur(4px);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 22px;
    animation: chatMsgIn 0.2s ease;
}
.chat-confirm-box {
    background: #fff;
    border-radius: 16px;
    padding: 24px 22px;
    text-align: center;
    max-width: 280px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.chat-confirm-box p {
    margin: 0 0 18px;
    font-size: 0.9rem;
    color: #374151;
    line-height: 1.5;
}
.chat-confirm-box strong { color: #111827; }
.chat-confirm-actions { display: flex; gap: 10px; justify-content: center; }
.chat-confirm-cancel {
    padding: 9px 20px;
    border-radius: 10px;
    border: 1.5px solid #e0e3ea;
    background: #fff;
    color: #6b7280;
    font-size: 0.87rem;
    cursor: pointer;
    transition: all 0.15s;
}
.chat-confirm-cancel:hover { background: #f3f4f6; color: #374151; }
.chat-confirm-ok {
    padding: 9px 20px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, var(--cor-primaria, #284093), color-mix(in srgb, var(--cor-primaria, #284093) 78%, #000));
    color: #fff;
    font-size: 0.87rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s;
}
.chat-confirm-ok:hover { opacity: 0.9; transform: scale(1.03); }

/* ---- Responsive ---- */
@media (max-width: 480px) {
    .chat-window {
        bottom: 0; right: 0; left: 0;
        width: 100%;
        max-height: 100dvh;
        height: 100dvh;
        border-radius: 0;
    }
    .chat-fab { bottom: 16px; right: 16px; width: 56px; height: 56px; }
    .chat-fab > img { width: 34px; height: 34px; }
    .chat-preview { right: 16px; bottom: 82px; }
}
