/* Cofbot no painel admin — FAB + modal alinhados ao tema admin (Inter, cinzas, accent #dc2626) */

#medcof-admin-cofbot-root {
  position: fixed;
  z-index: 99990;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  display: flex;
  flex-direction: column-reverse;
  gap: 12px;
  pointer-events: none;
}
#medcof-admin-cofbot-root.medcof-admin-cofbot-root--br,
#medcof-admin-cofbot-root.medcof-admin-cofbot-root--tr {
  align-items: flex-end;
}
#medcof-admin-cofbot-root.medcof-admin-cofbot-root--bl,
#medcof-admin-cofbot-root.medcof-admin-cofbot-root--tl {
  align-items: flex-start;
}

#medcof-admin-cofbot-root.medcof-admin-cofbot-root--br {
  right: 18px;
  bottom: 18px;
  top: auto;
  left: auto;
}
#medcof-admin-cofbot-root.medcof-admin-cofbot-root--bl {
  left: 18px;
  bottom: 18px;
  top: auto;
  right: auto;
}
#medcof-admin-cofbot-root.medcof-admin-cofbot-root--tr {
  right: 18px;
  top: 18px;
  bottom: auto;
  left: auto;
}
#medcof-admin-cofbot-root.medcof-admin-cofbot-root--tl {
  left: 18px;
  top: 18px;
  bottom: auto;
  right: auto;
}

#medcof-admin-cofbot-root > .medcof-admin-cofbot-fab-cluster,
#medcof-admin-cofbot-root > .medcof-coord-chat-panel {
  pointer-events: auto;
}

/* ── Cluster FAB + setas (como referência visual) ── */
.medcof-admin-cofbot-fab-cluster {
  position: relative;
  width: 120px;
  height: 120px;
  flex-shrink: 0;
}

.medcof-admin-cofbot-fab-cluster .medcof-coord-chat-fab {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 4px 3px;
  overflow: visible;
  transition: transform 0.15s ease, box-shadow 0.2s;
  flex-shrink: 0;
  z-index: 2;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

/* Modo escuro (admin): círculo claro neutro (contraste com fundo escuro do painel) — sombra vem da animação pulse */
html[data-theme="dark"] #medcof-admin-cofbot-root .medcof-coord-chat-fab {
  background: linear-gradient(160deg, #f8fafc 0%, #e8ecf1 45%, #d4dce6 100%);
}
html[data-theme="dark"] #medcof-admin-cofbot-root .medcof-coord-chat-fab::before,
html[data-theme="dark"] #medcof-admin-cofbot-root .medcof-coord-chat-fab::after {
  display: none;
}

/* Painel admin em tema claro: mesmo FAB claro (Cofbot sempre formato claro) */
html[data-theme="light"] #medcof-admin-cofbot-root .medcof-coord-chat-fab {
  background: linear-gradient(160deg, #f8fafc 0%, #e8ecf1 45%, #d4dce6 100%);
}
html[data-theme="light"] #medcof-admin-cofbot-root .medcof-coord-chat-fab::before,
html[data-theme="light"] #medcof-admin-cofbot-root .medcof-coord-chat-fab::after {
  display: none;
}

@keyframes medcof-admin-cofbot-fab-pulse {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(1);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22), 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 0 0 0 rgba(220, 38, 38, 0.28);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.08);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.65) inset, 0 0 0 14px rgba(220, 38, 38, 0);
  }
}

#medcof-admin-cofbot-root .medcof-coord-chat-fab {
  animation: medcof-admin-cofbot-fab-pulse 2.1s ease-in-out infinite;
}

#medcof-admin-cofbot-root .medcof-coord-chat-fab:hover {
  transform: translate(-50%, -50%) scale(1.06);
  animation: none;
}

.medcof-admin-cofbot-nudge {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.1);
  transition: transform 0.12s ease;
}
html[data-theme="dark"] .medcof-admin-cofbot-nudge {
  background: linear-gradient(145deg, #f1f5f9 0%, #e2e8f0 100%);
  color: #64748b;
}
html[data-theme="light"] .medcof-admin-cofbot-nudge {
  background: linear-gradient(145deg, #f1f5f9 0%, #e2e8f0 100%);
  color: #64748b;
}
.medcof-admin-cofbot-nudge:hover {
  transform: scale(1.08);
}
.medcof-admin-cofbot-nudge--tl {
  left: 0;
  top: 0;
}
.medcof-admin-cofbot-nudge--tr {
  right: 0;
  top: 0;
}
.medcof-admin-cofbot-nudge--bl {
  left: 0;
  bottom: 0;
}
.medcof-admin-cofbot-nudge-ico {
  width: 15px;
  height: 15px;
  display: block;
  pointer-events: none;
}
.medcof-admin-cofbot-nudge--tl .medcof-admin-cofbot-nudge-ico {
  transform: rotate(-45deg);
}
.medcof-admin-cofbot-nudge--tr .medcof-admin-cofbot-nudge-ico {
  transform: rotate(45deg);
}
.medcof-admin-cofbot-nudge--bl .medcof-admin-cofbot-nudge-ico {
  transform: rotate(-135deg);
}

.medcof-coord-chat-fab-icon {
  display: block;
  width: auto;
  height: 58px;
  max-width: 100%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.14));
}
@media (prefers-reduced-motion: reduce) {
  .medcof-coord-chat-fab-icon {
    animation: none;
  }
  #medcof-admin-cofbot-root .medcof-coord-chat-fab {
    animation: none !important;
  }
}

.medcof-coord-chat-panel[hidden] {
  display: none !important;
}

/* ── Painel aberto: mesmo chrome do Cofbot do painel do coordenador ── */
#medcof-admin-cofbot-root .medcof-coord-chat-panel {
  position: relative;
  width: min(100vw - 36px, 480px);
  /* Altura explícita: o layout em coluna reparte espaço entre sugestões e chat; só max-height deixa o painel “baixo” e esmaga o histórico */
  height: min(720px, calc(100vh - 156px));
  height: min(720px, calc(100dvh - 156px));
  max-height: min(720px, calc(100dvh - 156px));
  display: flex;
  flex-direction: column;
  border-radius: 32px;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.14);
  overflow: hidden;
  border: 1px solid rgba(220, 38, 38, 0.42);
  background: #ffffff;
}

#medcof-admin-cofbot-root .medcof-coord-chat-panel.medcof-admin-cofbot-panel--fullscreen {
  position: fixed !important;
  left: 12px !important;
  right: 12px !important;
  top: 12px !important;
  bottom: 12px !important;
  width: auto !important;
  height: auto !important;
  max-height: none !important;
  z-index: 999999;
  border-radius: 24px;
}

.medcof-admin-cofbot-resize-grip {
  position: absolute;
  right: 10px;
  bottom: 8px;
  width: 18px;
  height: 18px;
  opacity: 0.45;
  pointer-events: none;
  color: #64748b;
  background: linear-gradient(
    135deg,
    transparent 0%,
    transparent 40%,
    currentColor 40%,
    currentColor 45%,
    transparent 45%,
    transparent 55%,
    currentColor 55%,
    currentColor 60%,
    transparent 60%
  );
  background-size: 18px 18px;
}

.medcof-admin-cofbot-head {
  align-items: center !important;
}
.medcof-admin-cofbot-head-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.medcof-admin-cofbot-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: linear-gradient(180deg, #fef2f2 0%, #ffffff 100%);
  border: 2px solid rgba(220, 38, 38, 0.25);
}
.medcof-admin-cofbot-avatar img {
  width: 36px;
  height: auto;
  object-fit: contain;
  display: block;
}

.medcof-admin-cofbot-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.medcof-admin-cofbot-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  color: #dc2626;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  transition: transform 0.12s ease, background 0.15s, border-color 0.15s;
}
.medcof-admin-cofbot-icon-btn:hover {
  background: #fef2f2;
  border-color: rgba(220, 38, 38, 0.35);
  transform: scale(1.04);
}

#medcof-admin-cofbot-root .medcof-coord-chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  border-bottom: 1px solid #e2e8f0;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
}

#medcof-admin-cofbot-root .medcof-coord-chat-title {
  color: #0f172a;
  font-weight: 800;
  font-size: 0.95rem;
  margin: 0;
}

#medcof-admin-cofbot-root .medcof-coord-chat-sub {
  color: #64748b;
  font-size: 0.72rem;
  line-height: 1.4;
  margin-top: 2px;
  max-width: 280px;
}

#medcof-admin-cofbot-root .medcof-coord-chat-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
  padding: 6px 8px;
  margin: -4px -4px -4px 0;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
  border-radius: 8px;
}
#medcof-admin-cofbot-root .medcof-coord-chat-close:hover {
  color: #0f172a;
  background: rgba(15, 23, 42, 0.06);
}

.medcof-admin-cofbot-ies-wrap {
  padding: 0 14px 10px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}
.medcof-admin-cofbot-ies-wrap label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  color: #64748b;
}
.medcof-admin-cofbot-ies-optional {
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85em;
  color: #94a3b8;
}
.medcof-admin-cofbot-ies-wrap select {
  width: 100%;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.92rem;
  font-family: inherit;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
}

.medcof-admin-cofbot-actions-lead {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}
.medcof-admin-cofbot-actions-lead[hidden] {
  display: none !important;
}

.medcof-coord-chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 6px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}

/* Sugestões não podem roubar altura do histórico: teto + scroll */
#medcof-admin-cofbot-root .medcof-coord-chat-suggestions {
  flex: 0 1 auto;
  max-height: min(200px, 30vh);
  max-height: min(200px, 30dvh);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.medcof-coord-chat-insight {
  font-size: 0.78rem;
  line-height: 1.45;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(220, 38, 38, 0.2);
  color: #334155;
  background: #ffffff;
}
.medcof-coord-chat-insight::before {
  content: "Insight · ";
  font-weight: 800;
  color: #dc2626;
}

.medcof-coord-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
/* Até 3 perguntas longas: uma por linha, mais legível */
#medcof-admin-cofbot-root .medcof-coord-chat-chips {
  flex-direction: column;
  flex-wrap: nowrap;
}
#medcof-admin-cofbot-root .medcof-coord-chat-chip {
  width: 100%;
  max-width: none;
  box-sizing: border-box;
}
.medcof-coord-chat-chip {
  font-size: 0.74rem;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  text-align: left;
  line-height: 1.35;
  max-width: 100%;
  border: 1px solid rgba(220, 38, 38, 0.35);
  background: #ffffff;
  color: #b91c1c;
  transition: background 0.15s;
}
.medcof-coord-chat-chip:hover {
  background: rgba(220, 38, 38, 0.08);
}

.medcof-coord-chat-messages {
  flex: 1;
  min-height: 180px;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
/* Área de mensagens ocupa o que sobra e pode encolher (evita cortar o formulário no max-height do painel) */
#medcof-admin-cofbot-root .medcof-coord-chat-messages {
  min-height: 0;
  flex: 1 1 0;
  -webkit-overflow-scrolling: touch;
  background: #fff;
}

.medcof-coord-chat-msg {
  font-size: 0.9rem;
  line-height: 1.45;
  padding: 10px 12px;
  border-radius: 14px;
  max-width: 92%;
  white-space: pre-wrap;
  word-break: break-word;
}
#medcof-admin-cofbot-root .medcof-coord-chat-msg {
  font-size: 0.86rem;
  line-height: 1.5;
  max-width: 92%;
  padding: 10px 12px;
}
#medcof-admin-cofbot-root .medcof-coord-chat-msg--user {
  align-self: flex-end;
  background: rgba(220, 38, 38, 0.1);
  color: #0f172a;
  border: 1px solid rgba(220, 38, 38, 0.28);
}
#medcof-admin-cofbot-root .medcof-coord-chat-msg--assistant {
  align-self: flex-start;
  background: #f1f5f9;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  box-shadow: none;
}
.medcof-coord-chat-msg--assistant strong {
  font-weight: 700;
}
.medcof-coord-chat-insight strong {
  font-weight: 700;
}
.medcof-coord-chat-loading {
  opacity: 0.85;
  font-style: italic;
  color: #64748b;
  font-size: 0.86rem;
}

.medcof-coord-chat-error {
  font-size: 0.78rem;
  color: #dc2626;
  padding: 0 14px 8px;
  line-height: 1.35;
}

.medcof-coord-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px 18px;
  border-top: 1px solid transparent;
}
/* Campo e botão sempre visíveis: não encolhem dentro do painel com altura máxima */
#medcof-admin-cofbot-root .medcof-coord-chat-form {
  flex-shrink: 0;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
}

.medcof-coord-chat-input {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-family: inherit;
  border: 1px solid transparent;
}
#medcof-admin-cofbot-root textarea.medcof-admin-cofbot-input {
  border-radius: 12px;
  min-height: 40px;
  max-height: 120px;
  resize: vertical;
  line-height: 1.4;
  padding: 0.45rem 0.65rem;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
}
#medcof-admin-cofbot-root textarea.medcof-admin-cofbot-input::placeholder {
  color: #94a3b8;
}

.medcof-coord-chat-send {
  border: none;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-weight: 700;
  font-size: 0.78rem;
  line-height: 1.2;
  cursor: pointer;
  background: #dc2626;
  color: #fff;
  font-family: inherit;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
  flex-shrink: 0;
  align-self: flex-end;
  min-height: 2rem;
}
.medcof-coord-chat-send:hover {
  background: #b91c1c;
}
.medcof-coord-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  #medcof-admin-cofbot-root.medcof-admin-cofbot-root--br {
    right: 12px;
    bottom: 12px;
  }
  #medcof-admin-cofbot-root.medcof-admin-cofbot-root--bl {
    left: 12px;
    bottom: 12px;
  }
  #medcof-admin-cofbot-root.medcof-admin-cofbot-root--tr {
    right: 12px;
    top: 12px;
  }
  #medcof-admin-cofbot-root.medcof-admin-cofbot-root--tl {
    left: 12px;
    top: 12px;
  }
  #medcof-admin-cofbot-root .medcof-coord-chat-panel {
    width: calc(100vw - 24px);
  }
}
