/* Usuários online e chat (src/js/chat.js). Linkado depois do CSS da página:
   tudo fica sob .chat-raiz e redefine o que importa dos botões, porque
   app.css e admin.css têm estilos de <button> diferentes. Cores só de
   tokens.css, para acompanhar os dois temas. */

.chat-raiz {
    font-family: var(--fonte);
    color: var(--texto);
}

.chat-raiz [hidden] {
    display: none !important;
}

.chat-raiz button {
    font-family: inherit;
    cursor: pointer;
    transition: background-color .15s, color .15s, opacity .15s;
}

.chat-raiz button:focus-visible,
.chat-raiz textarea:focus-visible {
    outline: 2px solid var(--azul);
    outline-offset: 2px;
}

.chat-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* --- Botão flutuante ------------------------------------------------------ */

.chat-botao {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9000;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 46px;
    padding: 10px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--azul);
    color: var(--sobre-azul);
    font-size: var(--fs-base);
    font-weight: 600;
    box-shadow: var(--sombra-2);
}

.chat-botao:hover {
    background: var(--azul-escuro);
}

.chat-botao-online {
    font-size: var(--fs-sm);
    font-weight: 500;
    opacity: .85;
}

.chat-botao-online:empty {
    display: none;
}

.chat-contador {
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--superficie);
    color: var(--azul);
    font-family: var(--fonte-mono);
    font-size: var(--fs-xs);
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

/* --- Painel --------------------------------------------------------------- */

.chat-painel {
    position: fixed;
    right: 20px;
    bottom: 78px;
    z-index: 9001;
    display: flex;
    flex-direction: column;
    width: min(380px, calc(100vw - 40px));
    height: min(560px, calc(100vh - 110px));
    background: var(--superficie);
    border: 1px solid var(--borda);
    border-radius: 16px;
    box-shadow: var(--sombra-3);
    overflow: hidden;
}

.chat-cabecalho {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 12px 12px 16px;
    border-bottom: 1px solid var(--borda);
}

.chat-cabecalho-texto {
    flex: 1;
    min-width: 0;
}

.chat-cabecalho h2 {
    margin: 0;
    font-family: var(--fonte-display);
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--texto);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-subtitulo {
    margin: 2px 0 0;
    font-size: var(--fs-sm);
    color: var(--muted);
}

.chat-raiz .chat-icone {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--texto);
    font-size: 20px;
    line-height: 1;
}

.chat-raiz .chat-icone:hover {
    background: var(--hover-sutil);
}

.chat-aviso {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 10px;
    padding: 8px 16px;
    background: var(--alerta-bg);
    color: var(--alerta-texto);
    font-size: var(--fs-sm);
}

.chat-raiz .chat-link {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font-size: inherit;
    font-weight: 700;
    text-decoration: underline;
}

/* --- Lista de pessoas ------------------------------------------------------ */

.chat-lista {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px 8px 12px;
}

.chat-secao {
    margin: 14px 10px 4px;
    font-family: var(--fonte-mono);
    font-size: var(--fs-xs);
    font-weight: 500;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
}

.chat-itens {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chat-raiz .chat-pessoa {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    padding: 8px 10px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--texto);
    text-align: left;
    font-weight: 400;
}

.chat-raiz .chat-pessoa:hover {
    background: var(--hover-sutil);
}

.chat-ponto {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--borda);
}

.chat-ponto.online {
    border-color: var(--ok);
    background: var(--ok);
}

/* Mantém o alinhamento com as pessoas, sem status. */
.chat-ponto.sala {
    border-color: transparent;
}

.chat-pessoa-textos {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-pessoa-nome {
    font-size: var(--fs-base);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-pessoa-detalhe {
    font-size: var(--fs-sm);
    color: var(--muted);
}

.chat-selo {
    margin-left: auto;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--azul);
    color: var(--sobre-azul);
    font-size: var(--fs-xs);
    font-weight: 700;
    line-height: 18px;
}

.chat-vazio {
    margin: 0;
    padding: 12px 10px;
    font-size: 13px;
    color: var(--muted);
    text-align: center;
    list-style: none;
}

/* --- Conversa ------------------------------------------------------------- */

.chat-conversa {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.chat-dica {
    margin: 0;
    padding: 8px 16px;
    background: var(--info-bg);
    color: var(--nevoa-texto);
    font-size: var(--fs-sm);
}

.chat-mensagens {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    list-style: none;
    margin: 0;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg {
    align-self: flex-start;
    max-width: 85%;
    padding: 8px 11px;
    background: var(--superficie-2);
    border: 1px solid var(--borda);
    border-radius: 12px 12px 12px 4px;
}

.chat-msg.minha {
    align-self: flex-end;
    background: var(--azul-nevoa);
    border-color: transparent;
    border-radius: 12px 12px 4px 12px;
}

.chat-msg-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: var(--fs-xs);
    color: var(--muted);
}

.chat-msg-meta strong {
    color: var(--label);
    font-weight: 600;
}

.chat-msg-texto {
    margin: 3px 0 0;
    font-size: var(--fs-base);
    line-height: 1.4;
    color: var(--texto);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-form {
    padding: 10px 12px 12px;
    border-top: 1px solid var(--borda);
}

.chat-form textarea {
    display: block;
    box-sizing: border-box;
    width: 100%;
    min-height: 44px;
    max-height: 120px;
    padding: 9px 11px;
    border: 1px solid var(--borda);
    border-radius: 10px;
    background: var(--superficie-2);
    color: var(--texto);
    font: inherit;
    font-size: var(--fs-base);
    resize: vertical;
}

.chat-form-rodape {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
}

.chat-restante {
    font-size: var(--fs-xs);
    color: var(--muted);
}

.chat-raiz .chat-enviar {
    min-height: 40px;
    padding: 8px 18px;
    border: 0;
    border-radius: 10px;
    background: var(--azul);
    color: var(--sobre-azul);
    font-size: var(--fs-base);
    font-weight: 600;
}

.chat-raiz .chat-enviar:hover:not(:disabled) {
    background: var(--azul-escuro);
}

.chat-raiz .chat-enviar:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.chat-erro {
    margin: 6px 0 0;
    font-size: var(--fs-sm);
    color: var(--erro);
}

.chat-erro:empty {
    display: none;
}

/* --- Celular: painel em tela cheia, alvos de toque maiores ----------------- */

@media (max-width: 600px) {
    .chat-botao {
        right: 16px;
        bottom: 16px;
    }

    .chat-painel {
        inset: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        border: 0;
        border-radius: 0;
    }

    .chat-aberto .chat-botao {
        display: none;
    }

    /* O botão de tema (theme.js) flutua acima de tudo e cobriria a lista. */
    .chat-aberto #theme-toggle-btn {
        visibility: hidden;
    }

    .chat-raiz .chat-icone {
        width: 44px;
        height: 44px;
    }

    .chat-msg {
        max-width: 92%;
    }

    /* 16px evita o zoom automático do iOS ao focar o campo. */
    .chat-form textarea {
        font-size: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-raiz button {
        transition: none;
    }
}

@media print {
    .chat-raiz {
        display: none;
    }
}
