.messaging-container {
  display: flex;
  width: 100%;
  height: 86vh;
  background-color: #ffffff;
  border: 1px solid #dde7f1;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  font-family: system-ui, -apple-system, sans-serif;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

.chat-sidebar {
  width: 340px;
  min-width: 340px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #dde7f1;
  background-color: #ffffff;
}

.sidebar-chat-header {
  padding: 16px;
  border-bottom: 1px solid #dde7f1;
}

.sidebar-chat-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #56687a;
  margin: 0 0 12px 0;
}

.chat-search-box {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.chat-search-box input {
  flex: 1;
  padding: 8px 12px;
  background-color: #e7e2dc;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #56687a;
  outline: none;
  transition: all 0.2s ease;
}

.chat-search-box input:focus {
  background-color: #ffffff;
  border-color: #788fa5;
}

.btn-filter-chats {
  background: none;
  border: 1px solid #c0d1e2;
  border-radius: 4px;
  padding: 8px;
  cursor: pointer;
  color: #788fa5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-filter-chats:hover {
  background-color: #dde7f1;
  color: #56687a;
}

.chat-quick-filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.chat-quick-filters::-webkit-scrollbar {
  display: none;
}

.filter-tag {
  background-color: #e7e2dc;
  border: none;
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #56687a;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-tag:hover {
  background-color: #c0d1e2;
}

.filter-tag.active {
  background-color: #56687a;
  color: #ffffff;
}

.chat-threads-list {
  flex: 1;
  overflow-y: auto;
}

.thread-item {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #f0f2f5;
  cursor: pointer;
  position: relative;
  transition: background-color 0.2s;
}

.thread-item:hover {
  background-color: #f8fafc;
}

.thread-item.active {
  background-color: #edf4fc;
  border-left: 4px solid #56687a;
}

.thread-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  position: relative;
  margin: 0;
  flex-shrink: 0;
  background-color: #e7e2dc;
}

.thread-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.status-indicator {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #ffffff;
}

.status-indicator.online {
  background-color: #137333;
}

.status-indicator.offline {
  background-color: #9db3c8;
}

.thread-info {
  flex: 1;
  min-width: 0;
}

.thread-top-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.thread-entity-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #333333;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-time {
  font-size: 0.75rem;
  color: #788fa5;
}

.thread-project-context {
  font-size: 0.8rem;
  color: #56687a;
  margin: 0 0 2px 0;
}

.thread-last-message {
  font-size: 0.8rem;
  color: #788fa5;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  background-color: #137333;
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  position: absolute;
  right: 16px;
  bottom: 14px;
}

.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #fafbfc;
}

.chat-window-header {
  padding: 14px 20px;
  background-color: #ffffff;
  border-bottom: 1px solid #dde7f1;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header-entity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-avatar {
  width: 40px;
  height: 40px;
  margin: 0;
}

.header-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  object-fit: cover;
}

.chat-title-name {
  font-size: 1rem;
  font-weight: 700;
  color: #333333;
  margin: 0 0 2px 0;
}

.chat-subtitle {
  font-size: 0.8rem;
  color: #788fa5;
  margin: 0;
}

.badge-project {
  background-color: #dde7f1;
  color: #56687a;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

.btn-header-action {
  background-color: #e6f4ea;
  border: 1px solid #137333;
  color: #137333;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-header-action:hover {
  background-color: #d2ebd9;
}

.btn-header-action-more {
  background: none;
  border: none;
  color: #788fa5;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 8px;
}

.chat-messages-log {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-log-divider {
  text-align: center;
  margin: 10px 0;
  position: relative;
}

.chat-log-divider span {
  background-color: #fafbfc;
  padding: 0 12px;
  font-size: 0.75rem;
  color: #788fa5;
  font-weight: 600;
  position: relative;
  z-index: 1;
}

.chat-log-divider::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  height: 1px;
  background-color: #dde7f1;
  z-index: 0;
}

.message-row {
  display: flex;
  gap: 10px;
  max-width: 75%;
}

.message-row.incoming {
  align-self: flex-start;
}

.message-row.outgoing {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  margin: 0;
  flex-shrink: 0;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.message-bubble-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.incoming .message-bubble {
  background-color: #ffffff;
  color: #333333;
  border: 1px solid #dde7f1;
  border-top-left-radius: 0;
}

.outgoing .message-bubble {
  background-color: #56687a;
  color: #ffffff;
  border-top-right-radius: 0;
}

.message-bubble p {
  margin: 0;
}

.message-time {
  font-size: 0.7rem;
  color: #788fa5;
  align-self: flex-end;
  margin-top: 2px;
}

.outgoing .message-time {
  align-self: flex-start;
}

.message-attachment-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: #ffffff;
  border: 1px solid #c0d1e2;
  border-radius: 6px;
  padding: 10px;
  margin-top: 6px;
  width: 280px;
}

.attachment-icon {
  font-size: 1.5rem;
}

.attachment-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.attachment-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #56687a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-meta {
  font-size: 0.75rem;
  color: #788fa5;
}

.btn-download-attachment {
  text-decoration: none;
  font-size: 1.1rem;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.btn-download-attachment:hover {
  background-color: #f0f4f8;
}

.chat-input-area {
  background-color: #ffffff;
  border-top: 1px solid #dde7f1;
  padding: 12px 16px;
}

.chat-input-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}

.btn-input-tool {
  background: none;
  border: none;
  color: #788fa5;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-input-tool:hover {
  background-color: #f0f2f5;
  color: #56687a;
}

.chat-input-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background-color: #f8fafc;
  border: 1px solid #c0d1e2;
  border-radius: 20px;
  padding: 6px 12px 6px 16px;
}

.chat-input-form textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  padding: 4px 0;
  font-size: 0.9rem;
  color: #333333;
  resize: none;
  font-family: inherit;
  max-height: 100px;
}

.btn-send-message {
  background-color: #56687a;
  color: #ffffff;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.2s;
}

.btn-send-message:hover {
  background-color: #788fa5;
}

.chat-threads-list::-webkit-scrollbar,
.chat-messages-log::-webkit-scrollbar {
  width: 6px;
}

.chat-threads-list::-webkit-scrollbar-thumb,
.chat-messages-log::-webkit-scrollbar-thumb {
  background-color: #c0d1e2;
  border-radius: 4px;
}


/* Estilo por defecto del botón de volver (Oculto en escritorio) */
.btn-mobile-back {
  display: none;
  background: none;
  border: none;
  color: #56687a;
  cursor: pointer;
  margin-right: 8px;
  padding: 4px;
}

/* ==========================================================================
   RESPONSIVE DESIGN: MÓVILES Y TABLETS (Menos de 768px)
   ========================================================================== */
@media (max-width: 768px) {

  .messaging-container {
    height: 100vh;
    max-height: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .chat-sidebar {
    width: 100%;
    min-width: 100%;
    border-right: none;
  }

  .chat-window {
    display: none;
    width: 100%;
  }

  .messaging-container.chat-active .chat-sidebar {
    display: none;
  }

  .messaging-container.chat-active .chat-window {
    display: flex;
  }

  .btn-mobile-back {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .chat-window-header {
    padding: 10px 12px;
  }

  .chat-header-actions {
    gap: 4px;
  }

  .btn-header-action span {
    display: none;
  }

  .message-row {
    max-width: 90%;
  }

  .message-attachment-card {
    width: 100%;
    box-sizing: border-box;
  }

  .chat-input-area {
    padding: 10px;
  }

  .btn-input-tool {
    font-size: 0;
  }

  .btn-input-tool::first-letter {
    font-size: 1.2rem;
  }
}