#chat-toast-container { position: fixed; top: 16px; right: 16px; z-index: 200000; display: flex; flex-direction: column; gap: 10px; pointer-events: none; max-width: 380px; }
.chat-toast { pointer-events: auto; background: #fff; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,0.18); padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start; cursor: pointer; animation: chatToastIn 0.35s ease; border-left: 4px solid #25D366; }
.chat-toast.wa-prioridade { box-shadow: 0 10px 36px rgba(37, 211, 102, 0.35); border-left-width: 6px; animation: chatToastIn 0.35s ease, waPulse 1.4s ease-in-out 2; }
.chat-toast.hide { animation: chatToastOut 0.3s ease forwards; }
.wa-prio-badge { display: inline-block; font-size: 9px; font-weight: 800; letter-spacing: 0.03em; color: #fff; background: #16A34A; border-radius: 4px; padding: 1px 5px; vertical-align: middle; margin-left: 4px; }
@keyframes waPulse {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-3px); }
  60% { transform: translateX(3px); }
}
@keyframes chatToastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes chatToastOut { to { opacity: 0; transform: translateX(40px); } }
.chat-toast-avatar { width: 42px; height: 42px; border-radius: 50%; background: #0f172a; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; flex-shrink: 0; }
.chat-toast-body { flex: 1; min-width: 0; }
.chat-toast-title { font-size: 13px; font-weight: 800; color: #0f172a; margin-bottom: 2px; }
.chat-toast-preview { font-size: 12px; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-toast-time { font-size: 10px; color: #94a3b8; margin-top: 4px; }

.ci-layout { display: flex; flex: 1; min-height: 0; border: 1px solid #e2e8f0; border-radius: 12px; overflow: hidden; background: #fff; }
.ci-sidebar { width: 300px; border-right: 1px solid #e2e8f0; display: flex; flex-direction: column; background: #fff; min-height: 0; overflow: hidden; flex-shrink: 0; }
.ci-sidebar-head { padding: 14px 16px; border-bottom: 1px solid #e2e8f0; font-weight: 800; color: #0f172a; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.ci-search-wrap { padding: 10px 12px; background: #fff; border-bottom: 1px solid #e2e8f0; flex-shrink: 0; }
.ci-search-bar { background: #f0f2f5; border-radius: 8px; padding: 8px 12px; display: flex; align-items: center; gap: 10px; color: #64748b; font-size: 14px; }
.ci-search-bar input { border: none; background: transparent; outline: none; flex: 1; font-size: 13px; color: #0f172a; min-width: 0; }
.ci-search-bar input::placeholder { color: #94a3b8; }
.ci-list { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.ci-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #f1f5f9; cursor: pointer; transition: background 0.15s; }
.ci-item:hover, .ci-item.active { background: #f8fafc; }
.ci-item-avatar { width: 44px; height: 44px; border-radius: 50%; background: #0f172a; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; position: relative; overflow: hidden; }
.ci-item-avatar.avatar-foto { padding: 0; background: #e2e8f0; }
.ci-item-avatar.avatar-foto img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.ci-item-avatar.grupo { background: #2563eb; }
.ci-item-avatar-wrap { position: relative; flex-shrink: 0; width: 44px; height: 44px; }
.ci-presenca-dot { position: absolute; bottom: 0; right: 0; width: 11px; height: 11px; border: 2px solid #fff; border-radius: 50%; z-index: 2; }
.ci-presenca-dot.online { background: #22c55e; }
.ci-presenca-dot.busy { background: #f59e0b; }
.ci-presenca-text { color: #94a3b8; font-size: 11px; }
.ci-item-info { flex: 1; min-width: 0; }
.ci-item-name { font-size: 14px; font-weight: 700; color: #0f172a; }
.ci-item-preview { font-size: 12px; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-badge { background: #25D366; color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: flex; align-items: center; justify-content: center; padding: 0 6px; }
.ci-main { flex: 1; display: flex; flex-direction: column; background: #efeae2; min-width: 0; min-height: 0; overflow: hidden; }
.ci-main-head { padding: 12px 16px; background: #f0f2f5; border-bottom: 1px solid #e2e8f0; font-weight: 700; color: #0f172a; flex-shrink: 0; }
.ci-msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png'); background-size: cover; -webkit-overflow-scrolling: touch; }
.ci-bubble { max-width: 75%; padding: 8px 12px; border-radius: 8px; font-size: 13px; line-height: 1.4; box-shadow: 0 1px 1px rgba(0,0,0,0.08); }
.ci-bubble.out { background: #d9fdd3; align-self: flex-end; border-top-right-radius: 0; }
.ci-bubble.in { background: #fff; align-self: flex-start; border-top-left-radius: 0; }
.ci-bubble-meta { font-size: 10px; color: #667781; margin-top: 4px; }
.ci-input-row { display: flex; gap: 8px; padding: 10px 12px; background: #f0f2f5; border-top: 1px solid #e2e8f0; flex-shrink: 0; align-items: center; }
.ci-input-row input[type="text"] { flex: 1; border: none; border-radius: 24px; padding: 10px 16px; outline: none; font-size: 14px; min-width: 0; }
.ci-attach-btn { width: 42px; height: 42px; border-radius: 50%; border: none; background: transparent; color: #64748b; cursor: pointer; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 20px; }
.ci-attach-btn:hover { color: #0f172a; background: rgba(0,0,0,0.05); }
.ci-attach-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ci-input-row button[data-action="enviar"] { width: 42px; height: 42px; border-radius: 50%; border: none; background: #25D366; color: #fff; cursor: pointer; flex-shrink: 0; }
.ci-anexo-preview { display: none; padding: 10px 12px; background: #e9edef; border-top: 1px solid #d1d7db; flex-shrink: 0; align-items: center; gap: 12px; }
.ci-anexo-preview.open { display: flex; }
.ci-anexo-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: #fff; flex-shrink: 0; }
.ci-anexo-thumb.file { display: flex; align-items: center; justify-content: center; font-size: 22px; color: #64748b; }
.ci-anexo-info { flex: 1; min-width: 0; }
.ci-anexo-nome { font-size: 13px; font-weight: 700; color: #0f172a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-anexo-tamanho { font-size: 11px; color: #64748b; }
.ci-anexo-remover { border: none; background: none; color: #64748b; font-size: 20px; cursor: pointer; padding: 4px 8px; line-height: 1; }
.ci-bubble-text { white-space: pre-wrap; word-break: break-word; }
.ci-bubble-img { max-width: 240px; max-height: 280px; border-radius: 6px; display: block; margin-bottom: 4px; cursor: pointer; }
.ci-bubble-audio { max-width: 260px; height: 36px; margin-bottom: 4px; }
.ci-bubble-video { max-width: 260px; max-height: 200px; border-radius: 6px; display: block; margin-bottom: 4px; }
.ci-bubble-file { display: inline-flex; align-items: center; gap: 8px; padding: 10px 12px; background: rgba(0,0,0,0.04); border-radius: 8px; color: #0f172a; text-decoration: none; font-weight: 600; font-size: 12px; margin-bottom: 4px; max-width: 100%; }
.ci-bubble-file:hover { background: rgba(0,0,0,0.08); color: #0f172a; }
.ci-bubble.out .ci-bubble-file { background: rgba(0,0,0,0.06); }
.ci-bubble-wrap { display: flex; align-items: flex-end; gap: 4px; max-width: 85%; margin-bottom: 2px; }
.ci-bubble-wrap.out { align-self: flex-end; flex-direction: row-reverse; margin-left: auto; }
.ci-bubble-wrap.in { align-self: flex-start; }
.ci-bubble-wrap .ci-bubble { margin-bottom: 0; max-width: 100%; }
.ci-bubble-actions { position: relative; flex-shrink: 0; opacity: 0; transition: opacity 0.15s; }
.ci-bubble-wrap:hover .ci-bubble-actions, .ci-bubble-wrap.ci-menu-open .ci-bubble-actions { opacity: 1; }
.ci-msg-btn { border: none; background: rgba(0,0,0,0.06); color: #64748b; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }
.ci-msg-btn:hover { background: rgba(0,0,0,0.12); color: #0f172a; }
.ci-msg-menu { display: none; position: absolute; bottom: 100%; right: 0; margin-bottom: 6px; background: #fff; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.15); min-width: 130px; z-index: 30; overflow: hidden; border: 1px solid #e2e8f0; }
.ci-bubble-wrap.in .ci-msg-menu { right: auto; left: 0; }
.ci-msg-menu.open { display: block; }
.ci-msg-menu button { display: block; width: 100%; border: none; background: #fff; text-align: left; padding: 10px 14px; font-size: 13px; font-weight: 600; color: #0f172a; cursor: pointer; }
.ci-msg-menu button:hover { background: #f8fafc; }
.ci-msg-menu button.danger { color: #dc2626; }
.ci-msg-menu button + button { border-top: 1px solid #f1f5f9; }
.ci-editada-tag { font-size: 9px; color: #94a3b8; font-style: italic; font-weight: 500; }
.ci-head-chat-actions { margin-left: auto; flex-shrink: 0; }
.ci-main-head { display: flex; align-items: center; gap: 8px; }
.ci-head-btn.ci-head-danger { background: #fee2e2; color: #dc2626; }
.ci-head-btn.ci-head-danger:hover { background: #fecaca; }
@media (max-width: 1024px) {
    .ci-bubble-actions { opacity: 1; }
}
#ci-file-input { display: none; }
.ci-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: #64748b; font-weight: 600; }
.ci-section-label { font-size: 11px; font-weight: 700; color: #94a3b8; padding: 10px 16px 4px; text-transform: uppercase; flex-shrink: 0; }
.ci-head-actions { display: flex; gap: 6px; align-items: center; }
.ci-head-btn { border: none; background: #2563eb; color: #fff; border-radius: 6px; padding: 5px 9px; font-size: 12px; cursor: pointer; line-height: 1; }
.ci-head-btn.ci-head-aviso { background: #f59e0b; }
.ci-cargo-tag { font-size: 10px; font-weight: 600; color: #64748b; background: #f1f5f9; padding: 1px 6px; border-radius: 4px; margin-left: 4px; }
.ci-item-action { color: #94a3b8; font-size: 14px; flex-shrink: 0; align-self: center; }
.ci-empty-list { padding: 12px 16px; font-size: 12px; color: #94a3b8; text-align: center; }
.ci-picker { display: none; border-bottom: 1px solid #e2e8f0; background: #f8fafc; max-height: 220px; overflow: hidden; flex-shrink: 0; flex-direction: column; }
.ci-picker.open { display: flex; }
.ci-picker-title { padding: 10px 14px; font-size: 12px; font-weight: 700; color: #0f172a; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e2e8f0; flex-shrink: 0; }
.ci-picker-close { border: none; background: none; font-size: 20px; cursor: pointer; color: #64748b; line-height: 1; }
#ci-picker-list { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.ci-btn-contactar { margin-top: 12px; border: none; background: #2563eb; color: #fff; padding: 10px 16px; border-radius: 8px; font-weight: 700; font-size: 13px; cursor: pointer; }
.ci-back-list { cursor: pointer; }
.ci-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #64748b; font-weight: 600; text-align: center; padding: 20px; font-size: 13px; }

/* Mobile comercial */
.ci-quick-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #e2e8f0; background: #f8fafc; flex-shrink: 0; max-height: 132px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.ci-quick-bar.hidden { display: none; }
.ci-quick-btn { border: none; border-radius: 20px; padding: 8px 14px; font-size: 12px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.ci-quick-suporte { background: #0ea5e9; color: #fff; }
.ci-quick-gestor { background: #2563eb; color: #fff; }
.ci-quick-aviso { background: #f59e0b; color: #fff; }
.ci-quick-aviso-com { background: #7c3aed; color: #fff; }
.ci-quick-comercial { background: #16a34a; color: #fff; }
.ci-item-suporte { border-left: 3px solid #0ea5e9; }
.ci-item-gestor { border-left: 3px solid #2563eb; }
.ci-main-head-text { display: flex; flex-direction: column; min-width: 0; }
.ci-subtitulo { font-size: 11px; font-weight: 500; color: #64748b; }

.ci-embed { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.ci-embed .ci-layout { flex: 1; min-height: 0; }

#chat-interno-root,
#chat-interno-comercial,
#chat-interno-tecnico {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ci-mobile { height: 100%; min-height: 0; flex: 1; }
.ci-mobile .ci-layout { height: 100%; min-height: 0; flex: 1; border-radius: 0; border: none; }
.ci-mobile .ci-sidebar { width: 100%; display: none; flex: 1; min-height: 0; }
.ci-mobile .ci-sidebar.show-list { display: flex; }
.ci-mobile .ci-main { display: none; }
.ci-mobile .ci-main.show-chat { display: flex; flex: 1; min-height: 0; }

#tab-chat-interno.active { overflow: hidden; display: flex; flex-direction: column; min-height: 0; flex: 1; }
#tab-chat-interno #chat-interno-comercial { flex: 1; min-height: 0; display: flex; flex-direction: column; }

@media (min-width: 1024px) {
    #tab-chat-interno #chat-interno-comercial:not(.ci-mobile) .ci-layout { min-height: 480px; border-radius: 0; }
    #tab-chat-interno #chat-interno-comercial:not(.ci-mobile) .ci-sidebar { width: 340px; }
}

#tab-chat-tecnico.active { overflow: hidden; display: flex; flex-direction: column; min-height: 0; flex: 1; }
#tab-chat-tecnico #chat-interno-tecnico { flex: 1; min-height: 0; display: flex; flex-direction: column; }

#view-chat-interno.active {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
#view-chat-interno .page-title { flex-shrink: 0; margin-bottom: 12px; }

/* ===== Mobile / tablet: composer do chat interno sempre visível ===== */
@media (max-width: 1024px) {
    #chat-interno-root,
    #chat-interno-comercial,
    #chat-interno-tecnico {
        flex: 1;
        min-height: 0;
        max-height: 100%;
        overflow: hidden;
    }

    .ci-mobile,
    .ci-mobile .ci-layout {
        flex: 1;
        min-height: 0;
        height: auto;
        max-height: 100%;
        overflow: hidden;
    }

    .ci-mobile .ci-main.show-chat {
        display: flex !important;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        height: 100%;
        max-height: 100%;
        overflow: hidden;
        width: 100%;
    }

    .ci-mobile .ci-msgs {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .ci-mobile .ci-anexo-preview {
        flex-shrink: 0;
    }

    .ci-mobile .ci-input-row {
        flex: 0 0 auto;
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        z-index: 20;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
    }

    /* App comercial: reservar espaço para bottom-nav fixo */
    #tab-chat-interno.active.layout-coluna {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    }

    #tab-chat-interno #chat-interno-comercial {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Painel técnico: altura estável em telemóvel/tablet */
    #tab-chat-tecnico.active {
        height: calc(100dvh - 72px);
        max-height: calc(100dvh - 72px);
    }

    #tab-chat-tecnico .tec-chat-workspace {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    #tab-chat-tecnico .tec-chat-stage {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    #tab-chat-tecnico .tec-chat-mount {
        padding: 0;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    #tab-chat-tecnico #chat-interno-tecnico {
        flex: 1;
        min-height: 0;
        max-height: 100%;
    }
}

@media (max-width: 768px) {
    #tab-chat-tecnico .tec-ticker-bar {
        display: none;
    }
}
