/* ============================================================
   CHAT.CSS — Widget de chat interno (Copiaecola)
   Todos os seletores são prefixados com .cce- pra não colidir.
   ============================================================ */

:root {
  --cce-verde: #1D9E75;
  --cce-verde-dark: #0F6E56;
  --cce-vermelho: #E24B4A;
  --cce-vermelho-dark: #A32D2D;
  --cce-bg-bolhas: #ECE5DD;
  --cce-bolha-out: #ffffff;
  --cce-bolha-in: #DCF8C6;
  --cce-muted: #888780;
  --cce-text: #2C2C2A;
  --cce-border: rgba(0,0,0,0.08);
  --cce-sidebar-largura: 360px;
}

#cce-chat-root .oculto { display: none !important; }

/* ── MODOS DE LAYOUT (sidebar fixa) ─────────────────────────── */
/* Quando sidebar fica fixa, o body precisa abrir espaço pra ela
   e o panel vira coluna full-height ancorada na borda. */
@media (min-width: 768px) {
  body.cce-modo-sidebar-esq { padding-left:  var(--cce-sidebar-largura); }
  body.cce-modo-sidebar-dir { padding-right: var(--cce-sidebar-largura); }

  body.cce-modo-sidebar-esq #cce-chat-panel,
  body.cce-modo-sidebar-dir #cce-chat-panel {
    bottom: 0 !important;
    top: 0 !important;
    width: var(--cce-sidebar-largura) !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    box-shadow: 0 0 16px rgba(0,0,0,0.08) !important;
  }
  body.cce-modo-sidebar-esq #cce-chat-panel {
    left: 0 !important;
    right: auto !important;
  }
  body.cce-modo-sidebar-dir #cce-chat-panel {
    right: 0 !important;
    left: auto !important;
  }

  /* No sidebar não tem FAB */
  body.cce-modo-sidebar-esq #cce-chat-fab,
  body.cce-modo-sidebar-dir #cce-chat-fab { display: none !important; }
}

/* Mobile: sidebar não faz sentido em telas pequenas — força balão */
@media (max-width: 767px) {
  body.cce-modo-sidebar-esq,
  body.cce-modo-sidebar-dir { padding-left: 0 !important; padding-right: 0 !important; }
}

/* ── BOTÕES DE TROCA DE MODO (no header) ────────────────────── */
.cce-modo-controles {
  display: flex;
  gap: 2px;
  margin: 0 4px;
}
.cce-modo-btn {
  font-size: 14px;
  padding: 4px 6px;
  opacity: 0.55;
  border-radius: 4px;
}
.cce-modo-btn:hover { opacity: 0.85; background: rgba(255,255,255,0.12); }
.cce-modo-btn.ativo {
  opacity: 1;
  background: rgba(255,255,255,0.22);
}

/* No mobile, esconde os botões de sidebar (só faz sentido em desktop) */
@media (max-width: 767px) {
  .cce-modo-btn[data-modo="sidebar-esq"],
  .cce-modo-btn[data-modo="sidebar-dir"] { display: none; }
  .cce-modo-controles { display: none; }
}

/* ── BOTÃO FLUTUANTE (FAB) ─────────────────────────────────── */
#cce-chat-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: var(--cce-verde);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 9998;
  transition: transform 0.15s, background 0.15s;
}
#cce-chat-fab:hover { background: var(--cce-verde-dark); transform: scale(1.05); }
#cce-chat-fab:active { transform: scale(0.95); }
#cce-chat-fab.aberto { background: var(--cce-verde-dark); }

.cce-fab-icon { line-height: 1; }
.cce-fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: var(--cce-vermelho);
  color: white;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 2px solid white;
}

/* ── PAINEL ──────────────────────────────────────────────────── */
#cce-chat-panel {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 360px;
  height: min(560px, calc(100vh - 120px));
  background: white;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color: var(--cce-text);
}

@media (max-width: 480px) {
  #cce-chat-panel {
    bottom: 0; right: 0; left: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
  #cce-chat-fab { bottom: 16px; right: 16px; }
}

/* ── HEADER ───────────────────────────────────────────────── */
.cce-chat-header {
  background: var(--cce-verde);
  color: white;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.cce-header-info { flex: 1; min-width: 0; }
.cce-header-titulo { font-size: 15px; font-weight: 600; line-height: 1.2; }
.cce-header-sub { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.cce-icon-btn {
  background: transparent;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  width: 32px; height: 32px;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.cce-icon-btn:hover { background: rgba(255,255,255,0.15); }

/* ── TELAS ────────────────────────────────────────────────── */
.cce-tela {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* TOOLBAR (busca + SOS) */
.cce-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 0.5px solid var(--cce-border);
  flex-shrink: 0;
}
.cce-toolbar input {
  flex: 1;
  background: #F5F5F2;
  border: 0.5px solid var(--cce-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}
.cce-toolbar input:focus {
  border-color: var(--cce-verde);
  box-shadow: 0 0 0 2px rgba(29,158,117,0.15);
}
.cce-btn-sos {
  background: #FCEBEB;
  border: 0.5px solid #F09595;
  color: var(--cce-vermelho-dark);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.cce-btn-sos:hover { background: #F7C1C1; }
.cce-btn-sos:active { transform: scale(0.97); }

/* RESULTADO BUSCA */
.cce-resultado-busca {
  background: white;
  border-bottom: 0.5px solid var(--cce-border);
  max-height: 200px;
  overflow-y: auto;
  flex-shrink: 0;
}
.cce-busca-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}
.cce-busca-item:hover { background: #F5F5F2; }
.cce-busca-vazia {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--cce-muted);
  text-align: center;
}

/* LISTA DE CONVERSAS */
.cce-lista {
  flex: 1;
  overflow-y: auto;
  background: white;
}
.cce-secao {
  padding: 8px 14px;
  background: #F5F5F2;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cce-muted);
  font-weight: 600;
  border-bottom: 0.5px solid var(--cce-border);
}
.cce-item-conversa {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 0.5px solid var(--cce-border);
  cursor: pointer;
  transition: background 0.1s;
}
.cce-item-conversa:hover { background: #F9F9F7; }
.cce-item-meio { flex: 1; min-width: 0; }
.cce-item-linha1 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.cce-item-nome { font-size: 14px; font-weight: 500; color: var(--cce-text); }
.cce-item-hora { font-size: 11px; color: var(--cce-muted); flex-shrink: 0; }
.cce-item-preview {
  font-size: 12px;
  color: var(--cce-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.cce-item-preview strong { color: var(--cce-text); font-weight: 500; }
.cce-badge-nl {
  min-width: 20px; height: 20px;
  border-radius: 10px;
  background: var(--cce-verde);
  color: white;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}

/* AVATAR */
.cce-avatar {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  position: relative; /* pra ancorar a bolinha de presença */
}
.cce-avatar-sm { width: 28px; height: 28px; font-size: 11px; }

/* PRESENÇA — bolinha no canto inferior direito do avatar */
.cce-presenca {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--cce-bg, #fff);
  box-sizing: content-box;
}
.cce-avatar-sm .cce-presenca {
  width: 9px;
  height: 9px;
  bottom: -1px;
  right: -1px;
}
.cce-presenca-online  { background: #22c55e; }
.cce-presenca-ausente { background: #eab308; }
.cce-presenca-offline { background: #94a3b8; }

/* Texto de "última vez online" — só aparece pro admin */
.cce-presenca-detalhe {
  font-size: 11px;
  color: var(--cce-muted, #6b7280);
  font-weight: normal;
  margin-left: 6px;
}

/* MENSAGENS */
.cce-mensagens {
  flex: 1;
  overflow-y: auto;
  background: var(--cce-bg-bolhas);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cce-data-sep {
  text-align: center;
  margin: 8px 0;
}
.cce-data-sep span {
  display: inline-block;
  font-size: 11px;
  background: rgba(255,255,255,0.85);
  color: var(--cce-muted);
  padding: 3px 10px;
  border-radius: 8px;
}

.cce-msg {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  max-width: 100%;
}
.cce-msg.minha { justify-content: flex-end; }
.cce-msg.outra { justify-content: flex-start; }

.cce-bolha {
  background: var(--cce-bolha-out);
  border-radius: 0 8px 8px 8px;
  padding: 6px 10px;
  max-width: 78%;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
}
.cce-msg.minha .cce-bolha {
  background: var(--cce-bolha-in);
  border-radius: 8px 0 8px 8px;
}
.cce-msg.minha .cce-avatar { display: none; }

.cce-bolha-apagada {
  background: rgba(255,255,255,0.7) !important;
  font-style: italic;
  color: var(--cce-muted);
  font-size: 12px;
}

.cce-bolha-autor {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 2px;
}
.cce-bolha-texto { color: var(--cce-text); }
.cce-bolha-meta {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  font-size: 10px;
  color: var(--cce-muted);
  margin-top: 4px;
}
.cce-bolha-status { color: #4FC3F7; }

/* SOS / COMUNICADO inline tags */
.cce-tag-sos {
  background: #FCEBEB;
  color: var(--cce-vermelho-dark);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 4px;
  border-left: 3px solid var(--cce-vermelho);
}
.cce-tag-comunicado {
  background: #FAEEDA;
  color: #854F0B;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 4px;
  border-left: 3px solid #BA7517;
}
.cce-msg.sos .cce-bolha {
  background: #FFF5F5;
  border: 1px solid #F7C1C1;
}
.cce-msg.comunicado .cce-bolha {
  background: #FFFAEF;
  border: 1px solid #F5D7A0;
}

/* COMPOSER */
.cce-composer {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  align-items: flex-end;
  padding: 8px 10px;
  border-top: 0.5px solid var(--cce-border);
  background: white;
}
.cce-composer textarea {
  flex: 1;
  background: #F5F5F2;
  border: 0.5px solid var(--cce-border);
  border-radius: 18px;
  padding: 8px 12px;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 100px;
  font-family: inherit;
  line-height: 1.4;
}
.cce-composer textarea:focus {
  border-color: var(--cce-verde);
  background: white;
}
.cce-btn-enviar {
  width: 36px; height: 36px;
  border-radius: 18px;
  background: var(--cce-verde);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.cce-btn-enviar:hover { background: var(--cce-verde-dark); }
.cce-btn-enviar:active { transform: scale(0.95); }

/* ESTADOS GERAIS */
.cce-loading, .cce-vazio, .cce-erro {
  padding: 24px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--cce-muted);
}
.cce-erro { color: var(--cce-vermelho-dark); }

/* ── MODAL SOS ────────────────────────────────────────────── */
.cce-sos-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.cce-sos-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}
.cce-sos-box {
  position: relative;
  background: white;
  border-radius: 12px;
  padding: 20px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 16px 48px rgba(0,0,0,0.25);
}
.cce-sos-header {
  font-size: 18px;
  font-weight: 600;
  color: var(--cce-vermelho-dark);
  margin-bottom: 8px;
}
.cce-sos-help {
  font-size: 13px;
  color: var(--cce-muted);
  margin: 0 0 12px;
  line-height: 1.5;
}
.cce-sos-help strong { color: var(--cce-text); }
.cce-sos-box textarea {
  width: 100%;
  background: #F5F5F2;
  border: 0.5px solid var(--cce-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  resize: vertical;
  min-height: 80px;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
  box-sizing: border-box;
}
.cce-sos-box textarea:focus {
  border-color: var(--cce-vermelho);
  background: white;
}
.cce-sos-acoes {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}
.cce-btn-secundario {
  background: white;
  border: 0.5px solid var(--cce-border);
  color: var(--cce-text);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.cce-btn-secundario:hover { background: #F5F5F2; }
.cce-btn-perigo {
  background: var(--cce-vermelho);
  border: none;
  color: white;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.cce-btn-perigo:hover { background: var(--cce-vermelho-dark); }
.cce-btn-perigo:disabled { opacity: 0.6; cursor: wait; }

/* ============================================================
   ANEXOS NO CHAT
   ============================================================ */

/* Botão de anexar no composer */
.cce-btn-anexar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--cce-cinza-escuro);
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.cce-btn-anexar:hover { background: var(--cce-fundo-2); }

/* Preview do upload em andamento */
.cce-anexo-preview {
  padding: 10px 12px;
  background: var(--cce-fundo-2);
  border-top: 1px solid var(--cce-borda);
  border-bottom: 1px solid var(--cce-borda);
}
.cce-anexo-preview-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.cce-anexo-preview-icone {
  font-size: 22px;
  flex-shrink: 0;
}
.cce-anexo-preview-meta {
  flex: 1;
  min-width: 0;
}
.cce-anexo-preview-nome {
  font-size: 13px;
  font-weight: 500;
  color: var(--cce-texto);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cce-anexo-preview-tam {
  font-size: 11px;
  color: var(--cce-cinza-escuro);
}
.cce-anexo-preview-barra {
  height: 4px;
  background: var(--cce-borda);
  border-radius: 2px;
  overflow: hidden;
}
.cce-anexo-preview-barra-prog {
  height: 100%;
  background: var(--cce-azul);
  transition: width 0.2s ease;
  width: 0%;
}

/* Anexos dentro da bolha */
.cce-anexo {
  margin: 4px 0;
  border-radius: 8px;
  overflow: hidden;
}

/* Imagem */
.cce-anexo-imagem img {
  display: block;
  max-width: 100%;
  max-height: 280px;
  width: auto;
  height: auto;
  border-radius: 8px;
  cursor: zoom-in;
  background: var(--cce-fundo-2);
  min-width: 120px;
  min-height: 80px;
}

/* Áudio */
.cce-anexo-audio audio {
  width: 100%;
  max-width: 280px;
  display: block;
}

/* Vídeo */
.cce-anexo-video video {
  display: block;
  max-width: 100%;
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: 8px;
  background: #000;
}

/* Documento (PDF, DOC, XLS) */
.cce-anexo-doc {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--cce-fundo-2);
  border-radius: 8px;
  border: 1px solid var(--cce-borda);
  min-width: 220px;
}
.cce-msg.minha .cce-anexo-doc {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.2);
}
.cce-anexo-doc-icone {
  font-size: 28px;
  flex-shrink: 0;
}
.cce-anexo-doc-info {
  flex: 1;
  min-width: 0;
}
.cce-anexo-doc-nome {
  font-size: 13px;
  font-weight: 500;
  color: var(--cce-texto);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.cce-msg.minha .cce-anexo-doc-nome { color: #fff; }
.cce-anexo-doc-meta {
  font-size: 11px;
  color: var(--cce-cinza-escuro);
  margin-top: 2px;
}
.cce-msg.minha .cce-anexo-doc-meta { color: rgba(255,255,255,0.85); }
.cce-anexo-doc-abrir {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--cce-azul);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(37,99,235,0.08);
}
.cce-anexo-doc-abrir:hover { background: rgba(37,99,235,0.15); }
.cce-msg.minha .cce-anexo-doc-abrir {
  color: #fff;
  background: rgba(255,255,255,0.18);
}
.cce-msg.minha .cce-anexo-doc-abrir:hover { background: rgba(255,255,255,0.28); }

/* Meta abaixo de áudio/vídeo */
.cce-anexo-meta {
  font-size: 11px;
  color: var(--cce-cinza-escuro);
  margin-top: 4px;
}
.cce-msg.minha .cce-anexo-meta { color: rgba(255,255,255,0.8); }

/* Lightbox de imagens */
.cce-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  padding: 24px;
  cursor: zoom-out;
}
.cce-lightbox img {
  max-width: 95vw;
  max-height: 90vh;
  width: auto;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 4px 30px rgba(0,0,0,0.5);
  cursor: default;
}
.cce-lightbox-fechar {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 28px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
}
.cce-lightbox-fechar:hover { background: rgba(255,255,255,0.25); }
