/*--------------------------------------------------------------
# CHAT WIDGET - SISTEMA DE ATENDIMENTO AO CLIENTE
--------------------------------------------------------------*/

:root {
  --chat-primary: #64748b;
  --chat-primary-dark: #475569;
  --chat-secondary: #94a3b8;
  --chat-dark: #0f172a;
  --chat-surface: #1e293b;
  --chat-border: rgba(100, 116, 139, 0.3);
  --chat-text: #f1f5f9;
  --chat-text-muted: #94a3b8;
  --chat-danger: #ef4444;
  --chat-success: #10b981;
}

/*--------------------------------------------------------------
# BOTÃO FLUTUANTE
--------------------------------------------------------------*/
.chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9000; /* BEM MENOR QUE SIDEBAR (10000) */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.chat-toggle {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #64748b, #475569);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(100, 116, 139, 0.4), 0 0 0 0 rgba(100, 116, 139, 0.4);
  transition: all 0.3s ease;
  position: relative;
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 8px 24px rgba(100, 116, 139, 0.4), 0 0 0 0 rgba(100, 116, 139, 0.4);
  }
  50% {
    box-shadow: 0 8px 24px rgba(100, 116, 139, 0.4), 0 0 0 10px rgba(100, 116, 139, 0);
  }
  100% {
    box-shadow: 0 8px 24px rgba(100, 116, 139, 0.4), 0 0 0 0 rgba(100, 116, 139, 0.4);
  }
}

.chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 32px rgba(100, 116, 139, 0.5);
  animation: none;
}

.chat-icon,
.chat-close-icon {
  font-size: 28px;
  transition: all 0.3s ease;
}

.chat-close-icon {
  position: absolute;
  opacity: 0;
  transform: rotate(90deg) scale(0.8);
}

.chat-widget.open .chat-icon {
  opacity: 0;
  transform: rotate(-90deg) scale(0.8);
}

.chat-widget.open .chat-close-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 24px;
  height: 24px;
  background: #ef4444;
  color: white;
  border-radius: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  padding: 0 6px;
  border: 3px solid white;
  animation: badgePulse 2s infinite;
}

.chat-badge.show {
  display: flex;
}

@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/*--------------------------------------------------------------
# JANELA DO CHAT
--------------------------------------------------------------*/
.chat-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 120px);
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.98), rgba(15, 23, 42, 0.98));
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.chat-widget.open .chat-window {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/*--------------------------------------------------------------
# HEADER
--------------------------------------------------------------*/
.chat-header {
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.chat-header-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.chat-header-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.1));
}

.chat-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-header-avatar i {
  font-size: 24px;
  color: white;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-title {
  font-size: 16px;
  font-weight: 700;
  color: white;
  margin: 0 0 4px 0;
}

.chat-header-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--chat-success);
  border-radius: 50%;
  animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.chat-minimize {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.chat-minimize:hover {
  background: rgba(255, 255, 255, 0.25);
}

.chat-minimize i {
  font-size: 20px;
}

/*--------------------------------------------------------------
# BOAS-VINDAS
--------------------------------------------------------------*/
.chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  text-align: center;
}

.chat-welcome-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, rgba(100, 116, 139, 0.2), rgba(71, 85, 105, 0.2));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  position: relative;
}

.chat-welcome-icon i {
  font-size: 40px;
  color: var(--chat-primary);
}

/* Avatar com inicial do nome */
.chat-welcome-avatar {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 700;
  color: white;
  position: absolute;
  top: 0;
  left: 0;
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.3);
}

.chat-welcome-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--chat-text);
  margin: 0 0 8px 0;
  line-height: 1.3;
}

.chat-welcome-text {
  font-size: 14px;
  color: var(--chat-text-muted);
  margin: 0 0 8px 0;
  line-height: 1.5;
}

.chat-welcome-horario {
  font-size: 12px;
  color: var(--chat-success);
  margin: 0 0 24px 0;
  padding: 8px 16px;
  background: rgba(16, 185, 129, 0.1);
  border-radius: 20px;
  border: 1px solid rgba(16, 185, 129, 0.2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chat-welcome-horario i {
  font-size: 14px;
}

.chat-welcome-form {
  width: 100%;
  max-width: 300px;
}

.chat-form-group {
  margin-bottom: 16px;
  text-align: left;
}

.chat-form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--chat-text);
  margin-bottom: 6px;
}

.chat-form-group input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  color: var(--chat-text);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.3s ease;
}

.chat-form-group input::placeholder {
  color: #64748b;
}

.chat-form-group input:focus {
  outline: none;
  border-color: var(--chat-primary);
  background: rgba(15, 23, 42, 0.8);
  box-shadow: 0 0 0 3px rgba(100, 116, 139, 0.2);
}

.chat-btn-primary {
  width: 100%;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
  border: none;
  border-radius: 10px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(100, 116, 139, 0.3);
}

.chat-btn-primary:hover {
  background: linear-gradient(135deg, var(--chat-primary-dark), #334155);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(100, 116, 139, 0.4);
}

/* Estilo para botão de usuário logado */
.chat-welcome-logged {
  width: 100%;
  max-width: 300px;
  margin-top: 0;
}

.chat-welcome-logged .chat-btn-primary {
  width: 100%;
}

/* Opções de voltar ao chat */
.chat-welcome-options {
  width: 100%;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-option-btn {
  width: 100%;
  padding: 14px 24px;
  background: rgba(100, 116, 139, 0.15);
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  color: var(--chat-text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.chat-option-btn:hover {
  background: rgba(100, 116, 139, 0.25);
  border-color: var(--chat-primary);
  transform: translateY(-2px);
}

.chat-option-btn.primary {
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
  border: none;
  color: white;
  box-shadow: 0 4px 12px rgba(100, 116, 139, 0.3);
}

.chat-option-btn.primary:hover {
  background: linear-gradient(135deg, var(--chat-primary-dark), #334155);
  box-shadow: 0 6px 16px rgba(100, 116, 139, 0.4);
}

/*--------------------------------------------------------------
# MENSAGENS
--------------------------------------------------------------*/
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: rgba(15, 23, 42, 0.3);
  display: flex;
  flex-direction: column;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.5);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.5);
  border-radius: 3px;
}

.chat-messages-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-message {
  display: flex;
  gap: 10px;
  animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message.sent {
  flex-direction: row-reverse;
}

.chat-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.chat-message.sent .chat-message-avatar {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.chat-message-content {
  flex: 1;
  max-width: 75%;
}

.chat-message-bubble {
  background: rgba(100, 116, 139, 0.2);
  border: 1px solid rgba(100, 116, 139, 0.3);
  padding: 12px 16px;
  border-radius: 16px;
  border-top-left-radius: 4px;
  color: var(--chat-text);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-message.sent .chat-message-bubble {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.25), rgba(37, 99, 235, 0.25));
  border-color: rgba(59, 130, 246, 0.4);
  border-top-left-radius: 16px;
  border-top-right-radius: 4px;
}

.chat-message-time {
  font-size: 11px;
  color: var(--chat-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.chat-message.sent .chat-message-time {
  text-align: right;
}

/*--------------------------------------------------------------
# INPUT
--------------------------------------------------------------*/
.chat-input {
  border-top: 1px solid var(--chat-border);
  padding: 16px;
  background: rgba(15, 23, 42, 0.8);
  flex-shrink: 0;
}

.chat-input-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 8px;
}

.chat-input-form textarea {
  flex: 1;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  color: var(--chat-text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  transition: all 0.3s ease;
}

.chat-input-form textarea::placeholder {
  color: #64748b;
}

.chat-input-form textarea:focus {
  outline: none;
  border-color: var(--chat-primary);
  background: rgba(15, 23, 42, 0.8);
  box-shadow: 0 0 0 3px rgba(100, 116, 139, 0.2);
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
  border: none;
  border-radius: 12px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(100, 116, 139, 0.3);
}

.chat-send-btn:hover {
  background: linear-gradient(135deg, var(--chat-primary-dark), #334155);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(100, 116, 139, 0.4);
}

.chat-send-btn i {
  font-size: 18px;
}

.chat-powered {
  text-align: center;
  font-size: 11px;
  color: var(--chat-text-muted);
  margin-top: 4px;
}

/*--------------------------------------------------------------
# BOTÕES DE AÇÃO
--------------------------------------------------------------*/
.chat-actions-bar {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  background: rgba(15, 23, 42, 0.5);
  border-top: 1px solid var(--chat-border);
}

.chat-action-btn {
  flex: 1;
  padding: 10px 16px;
  background: rgba(100, 116, 139, 0.15);
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  color: var(--chat-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.3s ease;
}

.chat-action-btn:hover {
  background: rgba(100, 116, 139, 0.25);
  border-color: var(--chat-primary);
}

.chat-action-btn.danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #ef4444;
}

.chat-action-btn.danger:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
}

/*--------------------------------------------------------------
# MODAL DE CONFIRMAÇÃO
--------------------------------------------------------------*/
.chat-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9500; /* ABAIXO DO SIDEBAR */
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

/* Quando mostrar o modal */
.chat-modal-overlay.show {
  display: flex !important;
  opacity: 1;
  pointer-events: all;
}

.chat-modal {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.98), rgba(15, 23, 42, 0.98));
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  padding: 32px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  z-index: 9501;
  pointer-events: all;
}

.chat-modal-overlay.show .chat-modal {
  transform: scale(1);
}

.chat-modal-header {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(220, 38, 38, 0.2));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  border: 3px solid rgba(239, 68, 68, 0.3);
}

.chat-modal-header i {
  font-size: 36px;
  color: var(--chat-danger);
}

.chat-modal-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--chat-text);
  margin: 0 0 12px 0;
}

.chat-modal-text {
  font-size: 15px;
  color: var(--chat-text-muted);
  margin: 0 0 28px 0;
  line-height: 1.6;
}

.chat-modal-buttons {
  display: flex;
  gap: 12px;
}

.chat-modal-btn {
  flex: 1;
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  pointer-events: all;
  position: relative;
  z-index: 9502;
}

.chat-modal-btn.cancel {
  background: rgba(100, 116, 139, 0.2);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
}

.chat-modal-btn.cancel:hover {
  background: rgba(100, 116, 139, 0.3);
  border-color: var(--chat-primary);
  transform: translateY(-2px);
}

.chat-modal-btn.confirm {
  background: linear-gradient(135deg, var(--chat-danger), #dc2626);
  color: white;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.chat-modal-btn.confirm:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.5);
}

/*--------------------------------------------------------------
# RESPONSIVE - MOBILE
--------------------------------------------------------------*/
@media (max-width: 480px) {
  /* Botão flutuante mantém posição igual ao desktop */
  .chat-toggle {
    width: 56px;
    height: 56px;
  }
  
  .chat-icon,
  .chat-close-icon {
    font-size: 24px;
  }
  
  /* Chat ocupa 100% da tela quando aberto (fullscreen) */
  .chat-window {
    position: fixed !important;
    width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    z-index: 10000 !important; /* MOBILE FULLSCREEN - MAIOR QUE SIDEBAR */
  }
  
  /* Widget também precisa de z-index alto quando aberto */
  .chat-widget.open {
    z-index: 10000 !important;
  }
  
  /* Ajustar espaçamento interno no mobile */
  .chat-welcome {
    padding: 32px 24px;
  }
  
  .chat-messages {
    padding: 16px;
  }
  
  .chat-input {
    padding: 12px 16px;
  }
  
  /* Modal também responsivo no mobile */
  .chat-modal {
    width: calc(100% - 40px);
    padding: 24px;
  }
  
  /* ===== OCULTAR BARRA DE AÇÕES INFERIOR NO MOBILE ===== */
  .chat-actions-bar {
    display: none !important;
  }
  
  /* ===== BOTÕES NO HEADER MOBILE - MELHORADO ===== */
  .chat-header-actions {
    display: flex !important;
    gap: 10px;
    align-items: center;
    margin-right: 10px;
  }
  
  .chat-header-action-btn {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
  }
  
  .chat-header-action-btn:hover,
  .chat-header-action-btn:active {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
  }
  
  .chat-header-action-btn.danger {
    background: rgba(239, 68, 68, 0.25);
  }
  
  .chat-header-action-btn.danger:hover,
  .chat-header-action-btn.danger:active {
    background: rgba(239, 68, 68, 0.35);
    transform: scale(1.05);
  }
  
  .chat-header-action-btn i {
    font-size: 18px;
  }
  
  /* ===== AJUSTAR POSICIONAMENTO DO AVATAR NO HEADER ===== */
  .chat-header-content {
    padding-left: 4px;
  }
  
  .chat-header-avatar {
    margin-right: 10px;
  }
}

/* ===== TRAVAR SCROLL DO BODY QUANDO CHAT ABERTO NO MOBILE ===== */
@media (max-width: 480px) {
  body.chat-open-mobile {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100vh !important;
  }
}

/* ===== OCULTAR BOTÕES DO HEADER NO DESKTOP ===== */
@media (min-width: 481px) {
  .chat-header-actions {
    display: none !important;
  }
}

/* Mensagem de Sistema */
.chat-message-system {
    display: flex;
    justify-content: center;
    margin: 12px 0;
    animation: messageSlideIn 0.3s ease;
}

.chat-message-system-text {
    background: rgba(100, 116, 139, 0.15);
    border: 1px solid rgba(100, 116, 139, 0.25);
    padding: 8px 16px;
    border-radius: 20px;
    color: var(--chat-text-muted);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-message-system-text i {
    font-size: 14px;
}

/* Avatar do Bot */
.chat-message-avatar.bot-avatar {
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
    font-size: 18px;
}

/* Avatar do Atendente */
.chat-message-avatar.admin-avatar {
    background: linear-gradient(135deg, #10b981, #059669);
}