/* ===== RESET Y ESTILOS BASE ===== */
:root {
  --primary-color: #075e54;
  --secondary-color: #128c7e;
  --accent-color: #25d366;
  --chat-bg-color: #e5ddd5;
  --incoming-msg: #ffffff;
  --outgoing-msg: #dcf8c6;
  --text-color: #333;
  --text-light: #777;
  --border-color: #e1e1e1;
  --error-color: #d32f2f;
  --success-color: #388e3c;
  --warning-color: #ffa000;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Segoe UI', 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.5;
  color: var(--text-color);
  background-color: #f0f2f5;
  height: 100vh;
  overflow: hidden;
}

/* ===== ESTRUCTURA PRINCIPAL ===== */
.chat-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  background-color: white;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
  position: relative;
}

.app-header {
  background-color: var(--primary-color);
  color: white;
  padding: 0.8rem 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 100%;
  margin: 0 auto;
}

.app-title {
  font-size: 1.3rem;
  font-weight: 500;
}

.connection-status {
  display: flex;
  align-items: center;
  font-size: 0.85rem;
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #bbb;
  margin-right: 6px;
}

.status-indicator.connected {
  background-color: var(--accent-color);
}

.status-indicator.disconnected {
  background-color: var(--error-color);
}

.app-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== PANEL DE CONTACTOS ===== */
.contacts-panel {
  width: 350px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
  background-color: #f7f7f7;
  overflow: hidden;
}

.search-container {
  position: relative;
  padding: 0.8rem;
  background-color: #f0f2f5;
  border-bottom: 1px solid var(--border-color);
}

.search-container input {
  width: 100%;
  padding: 0.6rem 1rem 0.6rem 2.2rem;
  border: none;
  border-radius: 18px;
  background-color: white;
  font-size: 0.9rem;
  outline: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.search-icon {
  position: absolute;
  left: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 0.9rem;
}

.contacts-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #ccc transparent;
}

.contacts-list::-webkit-scrollbar {
  width: 6px;
}

.contacts-list::-webkit-scrollbar-thumb {
  background-color: #ccc;
  border-radius: 3px;
}

.contact-button {
  width: 100%;
  padding: 0.9rem 1rem;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--border-color);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background-color 0.2s;
  font-size: 0.95rem;
}

.contact-button:hover {
  background-color: #f0f0f0;
}

.contact-button.active {
  background-color: #e1f5e0;
  font-weight: 500;
}

.contact-button .contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #ddd;
  margin-right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  font-weight: bold;
  overflow: hidden;
}

.contact-button .contact-info {
  flex: 1;
  min-width: 0;
}

.contact-button .contact-name {
  font-weight: 500;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-button .contact-phone {
  font-size: 0.8rem;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.loading-contacts,
.empty-contacts {
  padding: 2rem;
  text-align: center;
  color: var(--text-light);
  font-size: 0.9rem;
}

/* ===== PANEL DE CHAT ===== */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--chat-bg-color);
  /* background-image: url('whatsapp-bg.png');  Eliminado para evitar 404 */
  background-size: contain;
  position: relative;
}

.chat-header {
  padding: 0.8rem 1rem;
  background-color: #f0f2f5;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
}

.chat-header h2 {
  font-size: 1.1rem;
  font-weight: 500;
}

.messages-container {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}

.empty-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-light);
  text-align: center;
  padding: 2rem;
}

.message {
  max-width: 70%;
  margin-bottom: 0.8rem;
  padding: 0.6rem 0.8rem;
  border-radius: 7.5px;
  position: relative;
  word-wrap: break-word;
  font-size: 0.95rem;
  line-height: 1.4;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.1);
}

.message.incoming {
  background-color: var(--incoming-msg);
  align-self: flex-start;
  border-top-left-radius: 0;
  margin-right: auto;
}

.message.outgoing {
  background-color: var(--outgoing-msg);
  align-self: flex-end;
  border-top-right-radius: 0;
  margin-left: auto;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-light);
  float: right;
  margin-left: 8px;
  margin-top: 4px;
}

.message-status {
  font-size: 0.7rem;
  margin-left: 4px;
}

.message-status.read {
  color: #4fc3f7;
}

/* ===== FORMULARIO DE MENSAJE ===== */
.message-form {
  padding: 0.6rem;
  background-color: #f0f2f5;
  border-top: 1px solid var(--border-color);
}

.input-container {
  display: flex;
  background-color: white;
  border-radius: 20px;
  padding: 0.3rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message-input {
  flex: 1;
  border: none;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  outline: none;
  background: transparent;
}

.send-button {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s;
  margin-left: 0.3rem;
}

.send-button:hover {
  background-color: var(--secondary-color);
}

.send-button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

.send-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.button-text {
  display: none;
}

/* ===== NOTIFICACIONES Y ESTADOS ===== */
.notification-area {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  max-width: 300px;
}

.notification {
  padding: 0.8rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: 4px;
  color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  animation: slideIn 0.3s ease-out;
  display: flex;
  align-items: center;
}

.notification.error {
  background-color: var(--error-color);
}

.notification.success {
  background-color: var(--success-color);
}

.notification.warning {
  background-color: var(--warning-color);
}

.notification-icon {
  margin-right: 8px;
  font-size: 1.2rem;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ===== ESTADOS DE CARGA ===== */
.loading {
  position: relative;
  overflow: hidden;
}

.loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
  .contacts-panel {
    width: 100%;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .contacts-panel.visible {
    transform: translateX(0);
  }

  .chat-panel {
    width: 100%;
  }

  .message {
    max-width: 85%;
  }

  .button-text {
    display: inline;
    font-size: 0.9rem;
  }

  .send-icon {
    display: none;
  }

  .send-button {
    width: auto;
    padding: 0 1rem;
    border-radius: 20px;
    margin-left: 0.5rem;
  }
}

@media (max-width: 480px) {
  .app-title {
    font-size: 1.1rem;
  }

  .message {
    max-width: 90%;
    padding: 0.5rem 0.7rem;
    font-size: 0.9rem;
  }

  .message-input {
    padding: 0.5rem;
    font-size: 0.9rem;
  }
}
