/* ==========================================================================
   Widget flutuante do Harv — bolha arrastável + painel de chat.
   Consumido por templates/harv/_widget.html (via base.html). Só desktop.
   Posição: nasce acima do card de notificações do WhatsApp (bottom:1rem, z 1045)
   e ABAIXO dele no empilhamento — alerta de cliente vence o assistente; o modal
   do Bootstrap (1055) vence os dois. Cores de texto sobre indigo em hex fixo
   (WCAG — o acento clareia no dark e o branco reprovaria).
   ========================================================================== */
.harv-widget {
    position: fixed;
    right: 1rem;
    bottom: 6rem;
    z-index: 1035;
    --harv-indigo: #5A4FE8;
    --harv-indigo-escuro: #4238c7;
    --harv-navy: #1B2140;
}

.harv-bolha {
    position: relative;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: var(--harv-indigo);
    color: #fff;
    box-shadow: 0 .5rem 1.25rem rgba(27, 33, 64, .35);
    cursor: grab;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 1.35rem;
    letter-spacing: .02em;
    touch-action: none;
    user-select: none;
    transition: transform .15s ease, box-shadow .15s ease;
}
.harv-bolha:hover { transform: scale(1.05); box-shadow: 0 .75rem 1.5rem rgba(27, 33, 64, .4); }
.harv-bolha:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.harv-widget.harv-arrastando .harv-bolha { cursor: grabbing; transform: scale(1.08); }

.harv-bolha__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #dc3545;
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    border: 2px solid var(--card-bg, #fff);
}

.harv-painel {
    position: absolute;
    bottom: calc(56px + .75rem);
    right: 0;
    width: min(400px, calc(100vw - 2rem));
    height: min(560px, calc(100vh - 8rem));
    display: flex;
    flex-direction: column;
    background: var(--card-bg, #fff);
    color: var(--text-color, #1B2140);
    border: 1px solid var(--border-color, #dcdfeb);
    border-radius: .75rem;
    box-shadow: 0 1rem 2.5rem rgba(27, 33, 64, .3);
    overflow: hidden;
}
.harv-widget.harv-lado-esquerdo .harv-painel { right: auto; left: 0; }
.harv-widget.harv-lado-topo .harv-painel { bottom: auto; top: calc(56px + .75rem); }

.harv-painel__cabecalho {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .6rem .75rem;
    background: var(--harv-navy);
    color: #fff;
}
.harv-painel__titulo { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.harv-painel__titulo small { display: block; opacity: .75; font-size: .72rem; }
.harv-painel__avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--harv-indigo); color: #fff; font-weight: 800;
    display: grid; place-items: center; flex-shrink: 0;
}
.harv-painel__acoes { display: flex; gap: .15rem; }
.harv-icone {
    border: 0; background: transparent; color: inherit; opacity: .8;
    width: 32px; height: 32px; border-radius: .4rem; display: grid; place-items: center;
}
.harv-icone:hover, .harv-icone[aria-pressed="true"] { opacity: 1; background: rgba(255, 255, 255, .12); }
.harv-form .harv-icone { color: var(--text-color, #1B2140); }
.harv-form .harv-icone:hover { background: var(--hover-bg, rgba(0, 0, 0, .06)); }

.harv-aba { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.harv-mensagens {
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
    padding: .75rem; display: flex; flex-direction: column; gap: .5rem;
    background: var(--bg-color, #f7f7fb);
}
.harv-msg {
    max-width: 88%; padding: .5rem .7rem; border-radius: .7rem;
    font-size: .9rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word;
}
.harv-msg--user { align-self: flex-end; background: var(--harv-indigo); color: #fff; border-bottom-right-radius: .2rem; }
.harv-msg--harv { align-self: flex-start; background: var(--card-bg, #fff); border: 1px solid var(--border-color, #dcdfeb); border-bottom-left-radius: .2rem; }
.harv-msg--erro { align-self: stretch; background: var(--bs-danger-bg-subtle, #fdecec); color: var(--bs-danger-text-emphasis, #b91c1c); }
.harv-msg ul { margin: .25rem 0 .25rem 1.1rem; padding: 0; }
.harv-msg--digitando { color: var(--text-muted, #5b6078); font-style: italic; }
.harv-vazio { color: var(--text-muted, #5b6078); font-size: .85rem; text-align: center; padding: 1rem; }

.harv-form {
    display: flex; align-items: flex-end; gap: .35rem;
    padding: .5rem; border-top: 1px solid var(--border-color, #dcdfeb);
    background: var(--card-bg, #fff);
}
.harv-entrada {
    flex: 1 1 auto; min-width: 0; resize: none; max-height: 120px;
    border: 1px solid var(--border-color, #dcdfeb); border-radius: .5rem; padding: .45rem .6rem;
    background: var(--bg-color, #f7f7fb); color: inherit; font: inherit; font-size: .9rem;
}
.harv-entrada:focus { outline: 2px solid var(--harv-indigo); outline-offset: 0; }
.harv-enviar {
    border: 0; background: var(--harv-indigo); color: #fff; width: 38px; height: 38px;
    border-radius: .5rem; display: grid; place-items: center; flex-shrink: 0;
}
.harv-enviar:hover { background: var(--harv-indigo-escuro); }
.harv-enviar:disabled { opacity: .6; }

.harv-insights { flex: 1 1 auto; overflow-y: auto; padding: .75rem; display: flex; flex-direction: column; gap: .5rem; }
.harv-insight {
    border: 1px solid var(--border-color, #dcdfeb); border-left: 4px solid var(--harv-indigo);
    border-radius: .5rem; padding: .5rem .7rem; background: var(--card-bg, #fff); font-size: .88rem;
}
.harv-insight--novo { border-left-color: #dc3545; }
.harv-insight__topo { display: flex; justify-content: space-between; gap: .5rem; font-size: .72rem; color: var(--text-muted, #5b6078); }
.harv-insight__titulo { font-weight: 700; margin: .15rem 0; }
.harv-insight__texto { white-space: pre-wrap; }

html.em-modal-painel .harv-widget { display: none !important; }
@media (max-width: 991.98px) { .harv-widget { display: none !important; } }
@media print { .harv-widget { display: none !important; } }
@media (prefers-reduced-motion: reduce) { .harv-bolha, .harv-widget.harv-arrastando .harv-bolha { transition: none; transform: none; } }

/* Gráfico enviado pelo Harv no chat (imagem gerada pelo servidor) */
.harv-msg--grafico { padding: 4px; }
.harv-msg--grafico img { display: block; width: 100%; height: auto; border-radius: 6px; }
