html,
body {
  height: 100%;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  font-family: sans-serif;
  background: #f7f7f7;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

#new-session {
  margin-bottom: 1rem;
}

.session {
  background: #fff;
  border: 1px solid #ccc;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border-radius: 6px;
  box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.05);
  position: relative;
}

.session h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.controls {
  margin-top: 8px;
  margin-bottom: 12px;
  padding-top: 4px;
}

.controls button {
  margin-right: 0.5rem;
}

canvas {
  display: block;
  margin: 0.5rem 0;
}

.ready {
  color: green;
}

.waiting {
  color: orange;
}

.disconnected {
  color: red;
}

label {
  display: block;
  margin-top: 0.5rem;
  font-weight: bold;
}

input,
select,
textarea {
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.3rem;
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  overflow-y: auto; /* Permite rolagem do modal inteiro */
  padding: 20px 0; /* Espaçamento superior e inferior */
}

.modal-content {
  background-color: #fefefe;
  margin: 0 auto; /* Centraliza horizontalmente */
  padding: 20px;
  border: 1px solid #888;
  width: 90%; /* Responsivo */
  max-width: 600px;
  min-height: auto;
  max-height: calc(100vh - 40px); /* Altura máxima baseada na viewport */
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  overflow-y: auto; /* Rolagem interna quando necessário */
  position: relative;
  box-sizing: border-box;
}

.close, .modal-close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
  padding: 5px;
  border-radius: 50%;
  transition: all 0.3s ease;
  width: 35px;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close:hover, .modal-close:hover {
  color: #fff;
  background-color: #f44336;
  transform: scale(1.1);
}

.status-details {
  margin: 20px 0;
}

.connection-details {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 6px;
  margin-top: 15px;
}

.connection-details h5 {
  color: #333;
  margin: 10px 0;
  border-bottom: 1px solid #ddd;
  padding-bottom: 5px;
}

.connection-details ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.connection-details li {
  margin: 5px 0;
  padding: 5px;
  background: #fff;
  border-radius: 4px;
}

.modal-actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-reconnect,
.btn-disconnect {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

.btn-reconnect {
  background: #4caf50;
  color: white;
}

.btn-disconnect {
  background: #f44336;
  color: white;
}

.btn-reconnect:hover {
  background: #45a049;
}

.btn-disconnect:hover {
  background: #da190b;
}

/* Novo layout com flex para mostrar QR e histórico lado a lado */
.session-content {
  display: flex;
  margin-top: 10px;
  gap: 15px;
}

.qr-container {
  flex: 0 0 auto;
}

.historico-lateral {
  flex: 1;
  height: auto;
  max-height: 400px; /* Aumentar altura máxima */
  min-height: 200px;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 15px;
  background-color: #f5f5f5;
  width: 100%; /* Usar largura total */
  margin-right: 15px;
}

.historico-lateral::after {
  content: "";
  display: block;
  min-height: 220px;
  width: 1px;
}

.historico-lateral::-webkit-scrollbar {
  width: 8px;
}

.historico-lateral::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.historico-lateral::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

.historico-lateral::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

.msg {
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 10px;
  max-width: 80%;
  position: relative;
  clear: both;
  display: flex;
  flex-direction: column;
  word-wrap: break-word;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.user {
  background-color: #fff; /* Mensagens do cliente (recebidas) */
  border-radius: 0px 10px 10px 10px;
  float: left;
  margin-right: auto;
  margin-left: 0;
}

.user::after {
  content: "";
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-top: 8px solid #fff;
  border-right: 8px solid transparent;
}

.assistant, .system {
  background-color: #dcf8c6; /* Mensagens do bot/agente (enviadas) */
  border-radius: 10px 0px 10px 10px;
  float: right;
  margin-left: auto;
  margin-right: 0;
}

.assistant::after, .system::after {
  content: "";
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border-top: 8px solid #dcf8c6;
  border-left: 8px solid transparent;
}

.msg-content {
  margin-bottom: 4px;
}

.msg-time {
  font-size: 0.7em;
  color: #888;
  text-align: right;
  margin-top: 4px;
}

/* Ocultar mensagens de grupo em sessões individuais */
.msg[class*="g.us"] {
  display: none;
}

/* Exibir um histórico com aparência mais limpa */
.historico {
  background-color: #f5f5f5;
  padding: 15px;
  border-radius: 8px;
  margin-top: 10px;
  overflow-y: auto;
  max-height: 400px;
}

.mensagem {
  position: relative;
  clear: both;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
  max-width: 80%;
  word-wrap: break-word;
}

.mensagem.user {
  background-color: #dcf8c6;
  border-radius: 10px 0px 10px 10px;
  float: right;
  margin-left: auto;
  margin-right: 0;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.mensagem.user::after {
  content: "";
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-top: 8px solid #dcf8c6;
  border-right: 8px solid transparent;
}

.mensagem.assistant, .mensagem.system {
  background-color: #ffffff;
  border-radius: 0px 10px 10px 10px;
  float: left;
  margin-right: auto;
  margin-left: 0;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.mensagem.assistant::after, .mensagem.system::after {
  content: "";
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border-top: 8px solid #ffffff;
  border-left: 8px solid transparent;
}

.mensagem .content {
  margin-bottom: 4px;
}

.mensagem .time {
  font-size: 0.7em;
  color: #888;
  text-align: right;
  margin-top: 4px;
}

/* Esconder mensagens de grupo */
.mensagem .content:contains("@g.us"), 
.msg-content:contains("@g.us") {
  display: none;
}

/* Estilos para o modo passivo */
.passive-mode {
  display: inline-block;
  margin-left: 8px;
  font-size: 1.1em;
  cursor: help;
}

.passive-warning {
  background-color: #fff3e0;
  border: 1px solid #ffcc80;
  border-radius: 4px;
  padding: 10px;
  margin-top: 10px;
  font-size: 0.9em;
  color: #e65100;
}

/* Estilos para o seletor de números */
.numero-selector {
  margin-bottom: 10px;
  display: flex;
  gap: 5px;
}

.numero-selector select {
  flex: 1;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  background-color: #f8f8f8;
}

.numero-selector button {
  background: #9c27b0;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0 15px;
  cursor: pointer;
}

.numero-selector button:hover {
  background: #7b1fa2;
}

.modal-status {
  display: block !important;
}

/* Estilos para o painel de informações */
.info-panel {
  background: #fff;
  padding: 15px;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.info-panel h3 {
  margin: 0 0 10px 0;
}

.info-panel p {
  margin: 5px 0;
  font-size: 0.9em;
}

.info-button {
  width: 100%;
  padding: 8px;
  margin: 5px 0;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #f8f9fa;
  cursor: pointer;
}

.info-button:hover {
  background: #e9ecef;
}

.session-header {
  border-bottom: 1px solid #eee;
  padding-bottom: 8px;
}

/* Estilos para as abas de autenticação */
.auth-option-tabs {
  display: flex;
  border-bottom: 1px solid #ddd;
  margin-bottom: 15px;
}

.auth-tab {
  flex: 1;
  padding: 8px 12px;
  background: #f5f5f5;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: normal;
  color: #666;
}

.auth-tab.active {
  border-bottom: 2px solid #25D366;
  background: #fff;
  font-weight: bold;
  color: #25D366;
}

.auth-tab-content {
  display: none;
}

.auth-tab-content.active-tab {
  display: block;
}

.auth-button:hover {
  background: #1FB355;
}

/* Estilo para o código de pareamento */
#pairing-code-container {
  text-align: center;
}

/* Otimização para exibição mobile */
/* Estilos para informações da sessão */
.session-display-name {
  background: linear-gradient(135deg, #2196F3, #1976D2);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.9em;
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  box-shadow: 0 2px 4px rgba(33, 150, 243, 0.3);
  display: inline-block;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-info-button {
  background: linear-gradient(135deg, #2196F3, #1976D2) !important;
  border: none !important;
  transition: all 0.3s ease !important;
}

.session-info-button:hover {
  background: linear-gradient(135deg, #1976D2, #1565C0) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(33, 150, 243, 0.4);
}

/* Melhorias no modal de informações */
#session-info-modal .modal-content {
  max-width: 800px;
  width: 90%;
  margin: 2% auto;
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  border: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  max-height: 90vh;
  overflow-y: auto;
}

#session-info-modal h3 {
  background: linear-gradient(135deg, #2196F3, #1976D2);
  color: white;
  margin: -20px -20px 25px -20px;
  padding: 18px 20px;
  border-radius: 8px 8px 0 0;
  text-align: center;
  font-size: 1.3em;
}

#session-info-modal .modal-content {
  padding: 25px !important;
}

#session-info-modal label {
  color: #333;
  font-weight: 600;
  margin-bottom: 5px;
}

#session-info-modal input,
#session-info-modal textarea {
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  padding: 10px 14px;
  transition: border-color 0.3s ease;
  font-size: 14px;
  box-sizing: border-box;
}

#session-info-modal input:focus,
#session-info-modal textarea:focus {
  border-color: #2196F3;
  outline: none;
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

#session-display-name {
  background: linear-gradient(135deg, #e3f2fd, #bbdefb);
  border: 2px solid #2196F3 !important;
  font-weight: bold !important;
  color: #1976D2 !important;
}

/* Responsividade melhorada para todos os modais */
@media (max-width: 768px) {
  .session-content {
    flex-direction: column;
  }
  
  .qr-container {
    margin-right: 0;
    margin-bottom: 15px;
  }
  
  .modal {
    padding: 10px 0; /* Menos padding em telas pequenas */
  }

  .modal-content {
    width: 95% !important;
    margin: 0 auto !important;
    padding: 15px !important;
    max-height: calc(100vh - 20px) !important; /* Mais espaço em telas pequenas */
  }
  
  #session-info-modal .modal-content {
    margin: 0 auto;
    width: 95%;
    max-width: none;
    max-height: 95vh;
  }
  
  #session-info-modal .grid,
  #session-info-modal div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Ajustes específicos para textarea em telas pequenas */
  textarea {
    min-height: 120px !important;
    max-height: 200px !important;
    resize: vertical;
  }

  /* Ajustes para inputs e selects */
  input, select {
    font-size: 16px; /* Evita zoom no iOS */
  }
}

@media (max-width: 480px) {
  .modal-content {
    width: 98% !important;
    padding: 10px !important;
    margin: 0 auto !important;
  }

  /* Textarea ainda menor em telas muito pequenas */
  textarea {
    min-height: 100px !important;
    max-height: 150px !important;
  }

  /* Botões menores em telas pequenas */
  button {
    padding: 8px 12px;
    font-size: 14px;
  }
}

@media (min-width: 769px) and (max-width: 1200px) {
  .modal-content {
    width: 85% !important;
  }

  #session-info-modal .modal-content {
    width: 85%;
    margin: 1% auto;
  }
}

@media (min-width: 1400px) {
  .modal-content {
    max-width: 700px !important;
  }

  #session-info-modal .modal-content {
    max-width: 900px;
  }
}

/* Melhorias na rolagem dos modais */
.modal-content::-webkit-scrollbar {
  width: 8px;
}

.modal-content::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Animação suave para abertura dos modais */
.modal {
  animation: fadeIn 0.3s ease-out;
}

.modal-content {
  animation: slideIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { 
    transform: translateY(-50px);
    opacity: 0;
  }
  to { 
    transform: translateY(0);
    opacity: 1;
  }
}

/* Estilos para melhorar a legibilidade em modais */
.modal h3 {
  margin-top: 0;
  margin-bottom: 20px;
  color: #333;
  border-bottom: 2px solid #eee;
  padding-bottom: 10px;
}

.modal label {
  color: #555;
  font-weight: 600;
  margin-bottom: 5px;
  margin-top: 15px;
}

.modal textarea {
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
  line-height: 1.4;
}

.modal input, .modal select, .modal textarea {
  border: 2px solid #ddd;
  border-radius: 6px;
  padding: 10px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.modal input:focus, .modal select:focus, .modal textarea:focus {
  border-color: #2196F3;
  outline: none;
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

/* Melhorias para botões em modais */
.modal button {
  transition: all 0.3s ease;
  border-radius: 6px;
  font-weight: 500;
}

.modal button:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}