/* =========================================================
   Chat de suporte — replica visual da referência.
   Mobile-first: widget em tela cheia; no desktop vira card
   centralizado (mesmo comportamento do original).
   Obs.: sem font-family proposital — o original usa a fonte
   padrão do navegador.
   ========================================================= */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
    background: #f0f1f3;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Estrutura do widget ---------- */

.chat {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    width: 100%;
    margin: 0 auto;
    overflow: hidden;
    background:
        linear-gradient(180deg, #d9e3fc 0%, #e6ecfc 18%, #f4f6fc 38%, #fbfcfe 55%, #ffffff 100%);
}

@media (min-width: 768px) {
    body {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .chat {
        width: 650px;
        height: 85vh;
        max-height: 700px;
        border-radius: 12px;
        box-shadow: 0 6px 30px rgba(30, 50, 90, .12);
    }
}

/* ---------- Cabeçalho flutuante ---------- */

.chat-header {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100% - 48px);
    padding: 6px 16px 6px 7px;
    background: rgba(255, 255, 255, .92);
    border-radius: 999px;
    box-shadow: 0 2px 10px rgba(30, 50, 90, .08);
}

.chat-header__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-header__info { min-width: 0; }

.chat-header__name {
    font-size: 14px;
    font-weight: 700;
    color: #16181d;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header__subtitle {
    font-size: 12px;
    color: #8a8f99;
    line-height: 1.3;
    max-width: 190px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Aviso marquee ---------- */

.chat-banner {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 72px 12px 0;
    padding: 0 10px;
    height: 34px;
    background: #dde8fd;
    border-radius: 8px;
    flex-shrink: 0;
}

.chat-banner__bell {
    width: 16px;
    height: 16px;
    color: #4d7df2;
    flex-shrink: 0;
}

.chat-banner__viewport {
    flex: 1;
    overflow: hidden;
    min-width: 0;
}

.chat-banner__track {
    display: inline-flex;
    white-space: nowrap;
    will-change: transform;
    animation: banner-scroll var(--banner-duration, 30s) linear infinite;
}

.chat-banner__text {
    font-size: 12px;
    color: #3d6ef2;
    text-decoration: underline;
    padding-right: 60px;
}

@keyframes banner-scroll {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
}

.chat-banner__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 0;
    background: none;
    color: #7d8aa5;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-banner__close svg { width: 14px; height: 14px; }

/* Sem banner: compensa o cabeçalho flutuante */
.chat--no-banner .chat-messages { padding-top: 76px; }

/* ---------- Lista de mensagens ---------- */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 16px 16px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,.18) transparent;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 4px; }

/* Divisor de horário centralizado */
.msg-divider {
    text-align: center;
    font-size: 12px;
    color: #9aa0a8;
    margin: 12px 0;
}

/* Horário pequeno acima da mensagem recebida */
.msg-time {
    font-size: 11px;
    color: #a5abb5;
    margin: 8px 0 4px 44px;
}

/* Aviso de sistema */
.msg-system {
    text-align: center;
    font-size: 12px;
    color: #9aa0a8;
    margin: 14px 24px;
}

/* Linha de mensagem recebida */
.msg-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 4px 0 10px;
}

.msg-row__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-top: 2px;
}

.msg-bubble {
    max-width: 72%;
    background: #fff;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.55;
    color: #23252b;
    box-shadow: 0 1px 3px rgba(30, 50, 90, .06);
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.msg-bubble a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}

/* Botões dentro da bolha (menu / links rápidos) */
.msg-bubble--menu {
    min-width: 240px;
    max-width: 264px;
}

.msg-btn {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 8px 10px;
    background: #f4f5f7;
    border: 0;
    border-radius: 6px;
    font-size: 13px;
    color: #262a33;
    text-align: center;
    cursor: pointer;
    transition: background .15s;
    text-decoration: none;
    line-height: 1.35;
}

.msg-btn:active,
.msg-btn:hover { background: #eaecf0; }

/* ---------- Cartão de avaliação (estrelas) ---------- */

.msg-bubble--rating {
    min-width: 240px;
    background: linear-gradient(180deg, #fff8ef 0%, #ffffff 60%);
}

.rating-q {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 14px;
    color: #23252b;
    line-height: 1.5;
}

.rating-badge {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ff9500;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}
.rating-badge svg { width: 12px; height: 12px; }

.rating-stars {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 14px;
    padding-bottom: 4px;
}

.rating-star {
    border: 0;
    background: none;
    padding: 2px;
    cursor: pointer;
    line-height: 0;
}
.rating-star svg {
    width: 30px;
    height: 30px;
    fill: #dfe1e6;
    transition: fill .12s, transform .12s;
}
.rating-star:hover svg { transform: scale(1.12); }
.rating-star.is-hover svg,
.rating-star.is-on svg { fill: #ffb400; }

.msg-bubble--rating.is-done .rating-star { cursor: default; pointer-events: none; }

/* Mensagem enviada */
.msg-row--sent {
    justify-content: flex-end;
}

.msg-row--sent .msg-bubble {
    background: #4e83f8;
    color: #fff;
    box-shadow: none;
}

.msg-row--sent .msg-bubble a { color: #fff; }

/* Mídia nas bolhas */
.msg-bubble--media {
    padding: 4px;
    background: #fff;
    line-height: 0;
}

.msg-bubble--media img,
.msg-bubble--media video {
    max-width: min(260px, 100%);
    max-height: 260px;
    border-radius: 6px;
    display: block;
}

.msg-file {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none !important;
    color: inherit;
}

.msg-file__icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #eef2fd;
    color: #4e83f8;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.msg-file__icon svg { width: 18px; height: 18px; }

.msg-file__name {
    font-size: 13px;
    line-height: 1.3;
    word-break: break-all;
}

.msg-file__size {
    font-size: 11px;
    color: #9aa0a8;
}

.msg-row--sent .msg-file__icon { background: rgba(255,255,255,.2); color: #fff; }
.msg-row--sent .msg-file__size { color: rgba(255,255,255,.75); }

/* ---------- Botão descer ---------- */

.chat-scroll-down {
    position: absolute;
    right: 22px;
    bottom: 92px;
    z-index: 25;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    color: #6b7280;
    box-shadow: 0 2px 10px rgba(30, 50, 90, .18);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}

.chat-scroll-down.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.chat-scroll-down svg { width: 18px; height: 18px; }

/* ---------- Rodapé / entrada ---------- */

.chat-footer {
    position: relative;
    flex-shrink: 0;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    background: #fff;
}

.chat-input {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    padding: 5px 7px 5px 6px;
    background: #fff;
    border: 1px solid #dbe4f8;
    border-radius: 24px;
    transition: border-color .15s;
}

.chat-input__actions {
    display: flex;
    align-items: center;
    gap: 2px;
    order: 0;
}

.chat-input__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    background: none;
    color: #565b66;
    cursor: pointer;
    border-radius: 50%;
    flex-shrink: 0;
}

.chat-input__icon svg { width: 22px; height: 22px; }

.chat-input__field {
    flex: 1;
    order: 1;
    border: 0;
    outline: none;
    resize: none;
    background: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 20px;
    color: #23252b;
    max-height: 96px;
    padding: 6px 4px;
}

.chat-input__field::placeholder { color: #b6bac2; }

.chat-input__send {
    order: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: #eef0f4;
    color: #b8bdc7;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, color .15s;
}

.chat-input__send svg { width: 16px; height: 16px; margin: 1px 1px 0 0; }

.chat-input__send:not(:disabled) {
    background: #4e83f8;
    color: #fff;
}

/* Estado expandido (campo focado / com texto) */
.chat-input.is-expanded {
    flex-wrap: wrap;
    border-color: #86a6f5;
    border-radius: 22px;
    padding: 10px 12px 8px;
}

.chat-input.is-expanded .chat-input__field {
    order: 0;
    flex: 1 1 100%;
    width: 100%;
    padding: 0 2px 8px;
}

.chat-input.is-expanded .chat-input__actions { order: 1; }

.chat-input.is-expanded .chat-input__send { margin-left: auto; order: 2; }

/* ---------- Painel de anexos (+) ---------- */

.attach-panel {
    position: absolute;
    left: 14px;
    bottom: calc(100% + 2px);
    z-index: 40;
    min-width: 150px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(30, 50, 90, .16);
    padding: 6px;
}

.attach-panel__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    background: none;
    border-radius: 8px;
    font-size: 13px;
    color: #262a33;
    cursor: pointer;
}

.attach-panel__item:hover,
.attach-panel__item:active { background: #f4f5f7; }

.attach-panel__item svg {
    width: 18px;
    height: 18px;
    color: #565b66;
    flex-shrink: 0;
}

/* ---------- Painel de emojis ---------- */

.emoji-panel {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(100% + 2px);
    z-index: 40;
    width: min(292px, calc(100vw - 24px));
    max-height: 184px;
    overflow-y: auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(30, 50, 90, .16);
    padding: 10px;
    scrollbar-width: thin;
}

.emoji-panel__grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.emoji-panel__grid button {
    border: 0;
    background: none;
    font-size: 22px;
    line-height: 34px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
}

.emoji-panel__grid button:hover { background: #f4f5f7; }
