/* Chat interno (recurso do centro XAF-Blazor/v26.1.5/Components/Chat): variáveis, botões flutuantes (FAB), chat e
   janela flutuante. A cor de destaque acompanha o tema Fluent (--dxds-primary-*). */
/* =========================================================
   ACTIVESOURCE — cores de marca
   ========================================================= */
:root {
    --as-dark: #14181d;
    --as-dark-2: #1b2026;
    /* cor do tema ativo (por omissão Rust); o valor fixo serve enquanto o tema não carregou */
    --as-accent: var(--dxds-primary-90, #da3b01);
    --as-accent-soft: var(--dxds-primary-60, #f96d48);
    --as-text: #39404b;
    --as-muted: #6b7280;
    /* Linha de baixo dos editores (Light) */
    --as-line: #aab0b9;
    --as-line-soft: #d3d7dd;
}

/* Tema escuro do Fluent */
body.dxbl-theme-dark {
    --as-line: rgba(255,255,255,.38);
    --as-line-soft: rgba(255,255,255,.20);
}
/* =========================================================
   Botões flutuantes (ditado por voz e anexos) — js/voz.js, js/anexos.js
   ========================================================= */
.as-fab {
    position: fixed;
    right: 18px;
    /* acima da barra do fundo das fichas (Gravar e fechar / Cancelar), para não a tapar */
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    z-index: 8990;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    align-items: flex-end;
}

.as-fab-btn {
    min-width: 52px;
    height: 52px;
    padding: 0 15px;
    border: 0;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #fff;
    background: #1b2026;
    box-shadow: 0 8px 22px rgba(0,0,0,.30);
    cursor: pointer;
    transition: transform .12s, background-color .12s;
}

    .as-fab-btn:hover { transform: translateY(-2px); background: var(--as-accent); }
    .as-fab-btn.a-gravar { background: #d64545; animation: as-pulse-rec 1.4s ease-in-out infinite; }
    .as-fab-btn.a-processar { background: #6b7280; cursor: progress; }

body.dxbl-theme-dark .as-fab-btn { background: var(--as-accent); }
body.dxbl-theme-dark .as-fab-btn.a-gravar { background: #d64545; }

/* =========================================================
   Chat interno (Components/ChatPainel.razor)
   ========================================================= */
.as-fab-chat { position: relative; }
.as-fab-badge { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: #d64545; color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px #fff; }
body.dxbl-theme-dark .as-fab-badge { box-shadow: 0 0 0 2px #252525; }

/* Paleta do chat — no espírito do Teams / Google Chat: as minhas mensagens num tom suave da cor de marca
   com texto escuro, as dos outros em cinzento neutro; a cor forte fica só para pormenores. */
.as-chat {
    --chat-fundo: #f7f8fa;
    --chat-minha: #dbe8f6;
    --chat-minha-texto: #1b2a3a;
    --chat-outra: #ffffff;
    --chat-outra-texto: #1f242c;
    --chat-outra-borda: #e3e6ea;
    --chat-meta: rgba(27,42,58,.55);
    --chat-visto: var(--as-accent);
    --chat-chip: rgba(27,42,58,.07);
}

body.dxbl-theme-dark .as-chat {
    --chat-fundo: #1f2023;
    --chat-minha: #2a3f57;
    --chat-minha-texto: #e9eef5;
    --chat-outra: #2e3034;
    --chat-outra-texto: #e6e7e9;
    --chat-outra-borda: #3a3d42;
    --chat-meta: rgba(233,238,245,.55);
    --chat-visto: #7db7f0;
    --chat-chip: rgba(255,255,255,.08);
}

.as-chat { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; height: calc(100vh - 130px); min-height: 420px; margin: 10px clamp(8px, 1.2vw, 18px) 0; border: 1px solid rgba(128,128,128,.22); border-radius: 14px; overflow: hidden; }

.as-chat-lista { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid rgba(128,128,128,.22); background: rgba(128,128,128,.05); }
.as-chat-lista-topo { display: flex; align-items: center; gap: 6px; padding: 10px 12px; }
    .as-chat-lista-topo .as-kb-input { flex: 1 1 auto; min-width: 0; }
.as-chat-conversas { flex: 1 1 auto; overflow-y: auto; }

.as-chat-icone { width: 36px; height: 36px; flex: none; border: 0; border-radius: 50%; background: transparent; color: inherit; font-size: 18px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
    .as-chat-icone:hover { background: rgba(128,128,128,.18); }

.as-chat-item { display: flex; gap: 10px; align-items: center; padding: 10px 12px; cursor: pointer; border-left: 3px solid transparent; }
    .as-chat-item:hover { background: rgba(128,128,128,.10); }
    .as-chat-item.ativa { background: rgba(218,59,1,.10); border-left-color: var(--as-accent); }
    body.dxbl-theme-dark .as-chat-item.ativa { background: rgba(125,183,240,.12); border-left-color: var(--as-accent-soft); }
.as-chat-item-corpo { min-width: 0; flex: 1 1 auto; }
.as-chat-item-linha { display: flex; align-items: center; gap: 8px; }
.as-chat-item-titulo { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; }
.as-chat-item-hora { font-size: 11px; opacity: .55; flex: none; }
.as-chat-item-previa { font-size: 12px; opacity: .65; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; }
.as-chat-badge { flex: none; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--as-accent); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

.as-chat-avatar { width: 36px; height: 36px; flex: none; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff; background: #6b7280; }
    .as-chat-avatar.grupo { background: #1f9d8b; font-size: 16px; }

.as-chat-conversa { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.as-chat-cabecalho { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid rgba(128,128,128,.22); }
.as-chat-cab-texto { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.as-chat-titulo { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.as-chat-sub { font-size: 11.5px; opacity: .6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.as-chat-ticket { flex: none; border: 1px solid var(--as-accent); color: var(--as-accent); background: transparent; border-radius: 999px; padding: 4px 12px; font-size: 12px; font-weight: 600; cursor: pointer; }
body.dxbl-theme-dark .as-chat-ticket { border-color: var(--as-accent-soft); color: var(--as-accent-soft); }
.as-chat-voltar { display: none; }

.as-chat-mensagens { background: var(--chat-fundo); flex: 1 1 auto; overflow-y: auto; padding: 14px clamp(10px, 2vw, 26px); display: flex; flex-direction: column; gap: 4px; }
.as-chat-antigas { align-self: center; margin-bottom: 8px; border: 0; background: rgba(128,128,128,.15); color: inherit; border-radius: 999px; padding: 5px 14px; font-size: 12px; cursor: pointer; }
.as-chat-dia { display: flex; justify-content: center; margin: 10px 0 6px; }
    .as-chat-dia span { font-size: 11px; font-weight: 600; padding: 3px 12px; border-radius: 999px; background: var(--chat-chip); color: var(--chat-meta); }

.as-chat-msg { display: flex; flex-direction: column; align-items: flex-start; max-width: min(78%, 640px); }
    .as-chat-msg.minha { align-self: flex-end; align-items: flex-end; }
.as-chat-autor { font-size: 11px; font-weight: 700; opacity: .65; margin: 6px 0 2px 10px; }
.as-chat-balao { position: relative; width: fit-content; max-width: 100%; padding: 7px 11px 5px; border-radius: 14px 14px 14px 4px; background: var(--chat-outra); color: var(--chat-outra-texto); border: 1px solid var(--chat-outra-borda); box-shadow: 0 1px 1px rgba(0,0,0,.04); font-size: 13.5px; line-height: 1.4; min-width: 70px; }
    .as-chat-msg.minha .as-chat-balao { border-radius: 14px 14px 4px 14px; background: var(--chat-minha); color: var(--chat-minha-texto); border-color: transparent; }
    .as-chat-balao.eliminada { opacity: .55; }
.as-chat-texto { white-space: pre-wrap; overflow-wrap: anywhere; }
.as-chat-meta { display: flex; justify-content: flex-end; align-items: center; gap: 5px; margin-top: 2px; font-size: 10.5px; color: var(--chat-meta); }
.as-chat-lida { color: var(--chat-visto); font-weight: 700; }
.as-chat-apagar { display: none; border: 0; background: transparent; color: inherit; font-size: 10px; cursor: pointer; padding: 0 2px; }
    .as-chat-balao:hover .as-chat-apagar { display: inline; }
.as-chat-img { display: block; max-width: min(320px, 100%); max-height: 300px; border-radius: 10px; margin-bottom: 4px; }
.as-chat-ficheiro { display: flex; align-items: center; gap: 8px; padding: 6px 8px; margin-bottom: 4px; border-radius: 10px; background: var(--chat-chip); color: inherit; text-decoration: none; }
    .as-chat-ficheiro:hover { text-decoration: none; filter: brightness(.96); }
.as-chat-ficheiro-nome { font-weight: 600; overflow-wrap: anywhere; }
.as-chat-ficheiro-tam { font-size: 11px; opacity: .7; white-space: nowrap; }
.as-chat-escreve { font-size: 12px; font-style: italic; opacity: .6; padding: 4px 8px; }

.as-chat-compor { display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid rgba(128,128,128,.22); }
.as-chat-input { flex: 1 1 auto; resize: none; min-height: 38px; max-height: 160px; padding: 9px 14px; border-radius: 18px; border: 1px solid var(--as-line-soft); background: transparent; color: inherit; font: inherit; font-size: 13.5px; outline: none; }
    .as-chat-input:focus { border-color: var(--as-accent); }
.as-chat-enviar { width: 38px; height: 38px; flex: none; border: 0; border-radius: 50%; background: var(--as-accent); color: #fff; font-size: 16px; cursor: pointer; }
    .as-chat-enviar:disabled { opacity: .5; cursor: progress; }

.as-chat-adicionar { padding: 12px 16px; border-bottom: 1px solid rgba(128,128,128,.22); background: rgba(128,128,128,.06); display: flex; flex-direction: column; gap: 2px; max-height: 45%; overflow-y: auto; font-size: 13px; }
.as-chat-adicionar-botoes { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.as-chat-conversa.a-largar { outline: 2px dashed var(--as-accent); outline-offset: -6px; background: rgba(218,59,1,.08); }
.as-chat-vazio { padding: 26px 16px; text-align: center; font-size: 13px; opacity: .6; line-height: 1.6; }
.as-chat-centro { margin: auto; }
.as-chat-nota { margin-top: 10px; font-size: 11.5px; opacity: .8; }
.as-chat-novo { padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.as-chat-pessoa { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; cursor: pointer; font-size: 13.5px; }
    .as-chat-pessoa:hover { background: rgba(128,128,128,.12); }
    .as-chat-pessoa input { accent-color: var(--as-accent); }

@media (max-width: 820px) {
    .as-chat { grid-template-columns: 1fr; height: calc(100vh - 110px); margin: 0; border-radius: 0; border-width: 1px 0 0; }
    .as-chat .as-chat-conversa { display: none; }
    .as-chat.com-conversa .as-chat-lista { display: none; }
    .as-chat.com-conversa .as-chat-conversa { display: flex; }
    .as-chat-voltar { display: inline-flex; }
    .as-chat-msg { max-width: 88%; }
}

/* No ecrã do chat os botões flutuantes sobem para não taparem o botão de enviar */
body:has(.as-chat-pagina) .as-fab { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }

/* Chat: vídeo, áudio, progresso de envio e gravador de vídeo (js/chat-video.js) */
.as-chat-video { display: block; width: 360px; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 4px; background: #000; }
.as-chat-audio { display: block; width: min(300px, 100%); margin-bottom: 4px; }

.as-chat-progresso { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 9150; width: min(420px, calc(100vw - 40px)); padding: 10px 16px 12px; border-radius: 12px; background: #1b2026; color: #fff; font-size: 12.5px; box-shadow: 0 10px 28px rgba(0,0,0,.35); }
    .as-chat-progresso span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 7px; }
    .as-chat-progresso div { height: 5px; border-radius: 999px; background: rgba(255,255,255,.18); overflow: hidden; }
    .as-chat-progresso i { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--as-accent-soft); transition: width .15s linear; }

.as-vid { position: fixed; inset: 0; z-index: 9300; display: flex; align-items: center; justify-content: center; background: rgba(10,12,15,.78); padding: 16px; }
.as-vid-caixa { width: min(720px, 100%); border-radius: 16px; background: #1b2026; color: #fff; padding: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.5); }
.as-vid-titulo { font-weight: 700; font-size: 14px; margin-bottom: 12px; }
.as-vid video { width: 100%; max-height: 60vh; border-radius: 10px; background: #000; margin-bottom: 12px; }
.as-vid-botoes { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
    .as-vid-botoes button { border: 0; border-radius: 8px; padding: 9px 18px; font-weight: 700; font-size: 13px; cursor: pointer; }
    .as-vid-botoes .as-push-ok { background: var(--as-accent); color: #fff; }
    .as-vid-botoes .as-push-no { background: transparent; color: rgba(255,255,255,.75); }
    .as-vid-botoes .as-vid-parar { background: #d64545; color: #fff; }

/* =========================================================
   Chat em janela flutuante (Components/ChatFlutuante.razor)
   ========================================================= */
.as-chatpop { position: fixed; right: 84px; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); z-index: 8980; container: chatpop / inline-size; width: var(--chatpop-w, 400px); height: var(--chatpop-h, 600px); min-width: 320px; min-height: 380px; max-width: calc(100vw - 100px); max-height: calc(100vh - 36px); display: none; flex-direction: column; border-radius: 16px; overflow: hidden; border: 1px solid rgba(128,128,128,.28); background: var(--dxds-color-surface-neutral-default-rest, #fff); box-shadow: 0 18px 50px rgba(0,0,0,.30); animation: splash-rise .2s both; }
body.dxbl-theme-dark .as-chatpop { background: #252525; }
    .as-chatpop.aberto { display: flex; }
.as-chatpop-topo { display: flex; align-items: center; gap: 4px; padding: 4px 6px 4px 14px; background: #1b2026; color: #fff; }
    .as-chatpop-topo .as-chat-icone { color: #fff; width: 32px; height: 32px; font-size: 15px; }
.as-chatpop-titulo { flex: 1 1 auto; font-weight: 700; font-size: 13.5px; }

/* Maximizada: ocupa quase o ecrã todo; o botão do topo (ou duplo clique na barra) volta ao tamanho normal */
.as-chatpop.max { width: min(1280px, calc(100vw - 100px)); height: calc(100vh - 36px); }

/* Pegas de redimensionamento: a janela está ancorada em baixo à direita, por isso cresce para cima e para a esquerda */
.as-chatpop-redim { position: absolute; z-index: 3; }
    .as-chatpop-redim[data-dir="n"] { top: 0; left: 14px; right: 0; height: 6px; cursor: ns-resize; }
    .as-chatpop-redim[data-dir="w"] { top: 14px; left: 0; bottom: 0; width: 6px; cursor: ew-resize; }
    .as-chatpop-redim[data-dir="nw"] { top: 0; left: 0; width: 16px; height: 16px; cursor: nwse-resize; }
    .as-chatpop-redim[data-dir="nw"]::after { content: ""; position: absolute; top: 4px; left: 4px; width: 7px; height: 7px; border-top: 2px solid rgba(255,255,255,.55); border-left: 2px solid rgba(255,255,255,.55); border-radius: 2px 0 0 0; }
    .as-chatpop.max .as-chatpop-redim { display: none; }
body.as-chatpop-a-redimensionar { user-select: none; cursor: nwse-resize; }
    body.as-chatpop-a-redimensionar iframe, body.as-chatpop-a-redimensionar video { pointer-events: none; }
.as-chatpop-topo { cursor: default; user-select: none; }

/* dentro da janela: um painel de cada vez enquanto for estreita… */
.as-chat.compacto { grid-template-columns: 1fr; flex: 1 1 auto; min-height: 0; height: auto; margin: 0; border: 0; border-radius: 0; }
    .as-chat.compacto .as-chat-conversa { display: none; }
    .as-chat.compacto.com-conversa .as-chat-lista { display: none; }
    .as-chat.compacto.com-conversa .as-chat-conversa { display: flex; }
    .as-chat.compacto .as-chat-voltar { display: inline-flex; }
    .as-chat.compacto .as-chat-msg { max-width: 88%; }
    .as-chat.compacto .as-chat-video { width: 260px; }
    .as-chat.compacto .as-chat-input::placeholder { color: transparent; }

/* …e lista + conversa lado a lado quando é alargada ou maximizada */
@container chatpop (min-width: 680px) {
    .as-chat.compacto { grid-template-columns: minmax(230px, 320px) 1fr; }
        .as-chat.compacto .as-chat-lista,
        .as-chat.compacto.com-conversa .as-chat-lista { display: flex; }
        .as-chat.compacto .as-chat-conversa,
        .as-chat.compacto.com-conversa .as-chat-conversa { display: flex; }
        .as-chat.compacto .as-chat-voltar { display: none; }
        .as-chat.compacto .as-chat-msg { max-width: min(78%, 640px); }
        .as-chat.compacto .as-chat-video { width: 360px; }
        .as-chat.compacto .as-chat-input::placeholder { color: inherit; opacity: .5; }
}

/* no ecrã completo do chat a janela não faz falta */
body:has(.as-chat-pagina) .as-chatpop { display: none !important; }

@media (max-width: 820px) {
    .as-chatpop, .as-chatpop.max { inset: 0; width: auto; height: auto; min-width: 0; min-height: 0; max-width: none; max-height: none; border-radius: 0; border: 0; z-index: 9250; }
    .as-chatpop-redim { display: none; }
}

/* Mensagem de erro no painel */
.as-kb-erro { padding: 8px 12px; border-radius: 6px; background: rgba(192,57,43,.14); color: #C0392B; font-size: 13px; }

/* Caixa de pesquisa */
.as-kb-input {
    height: 32px;
    padding: 0 10px;
    border: 0;
    border-bottom: 1px solid var(--as-line);
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 13px;
    min-width: 150px;
    outline: none;
}

    .as-kb-input:focus { border-bottom-color: var(--as-accent); box-shadow: inset 0 -1px 0 var(--as-accent); }
    .as-kb-input option { color: #1b2026; }

/* Avisos (window.asFab.aviso) */
.as-fab-toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 9100;
    max-width: min(560px, calc(100vw - 120px));
    padding: 10px 18px;
    border-radius: 10px;
    background: #1b2026;
    color: #fff;
    font-size: 13px;
    box-shadow: 0 10px 28px rgba(0,0,0,.35);
    animation: splash-rise .25s both;
}

    .as-fab-toast.ok { background: #2f7d40; }
    .as-fab-toast.erro { background: #b83a3a; }

@keyframes splash-rise { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }
