body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f0f2f5;
}

#app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
#sidebar {
  width: 30%;
  background: #fff;
  border-right: 1px solid #ddd;
  display: flex;
  flex-direction: column;
}

#sidebar h2 {
  margin: 0;
  padding: 15px;
  background: #075e54;
  color: white;
}

#chatList {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#chatList li {
  padding: 15px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
}

#chatList li:hover {
  background: #f5f5f5;
}

/* Cada chat-item ocupa UNA FILA COMPLETA */
.chat-item {
  display: block;
  width: 100%;
  text-align: left;
}

/* Botón activo */
.chat-item.active-chat {
  background: #d0ebff !important;
  border-left: 4px solid #0b7dda;
}

/* WA ID */
.chat-waid {
  font-weight: bold;
  font-size: 14px;
}

/* preview debajo */
.chat-preview {
  font-size: 11px;
  opacity: 0.7;
}

/* Chat area */
#chatArea {
  flex: 1;
  display: flex;
  flex-direction: column;
}

#chatHeader {
  padding: 15px;
  background: #075e54;
  color: white;
  font-weight: bold;
}

#messages {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
  background: #e5ddd5;
}

.message {
  margin: 5px 0;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 70%;
  min-width: 34px;
  clear: both;
}

.message.self {
  background: #dcf8c6;
  float: right;
}

.message.other {
  background: #fff;
  float: left;
}

#inputArea {
  display: flex;
  padding: 10px;
  background: #f0f0f0;
}

#messageInput {
  flex: 1;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

#sendBtn {
  padding: 8px 16px;
  margin-left: 5px;
  background: #075e54;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

#sendBtn:disabled {
  background: #999;
  cursor: not-allowed;
}

.status-box {
  margin-top: 10px;
  margin-bottom: 15px;
  padding: 6px 10px;
  font-size: 14px;
  border-radius: 5px;
  font-weight: 500;
}

/* Estados */
.status-ok {
  background: #e7ffe7;
  color: #0a7d00;
  border: 1px solid #8bcf8b;
}

.status-warn {
  background: #fff7d6;
  color: #a67c00;
  border: 1px solid #e8d28b;
}

.status-error {
  background: #ffe6e6;
  color: #b10000;
  border: 1px solid #d38b8b;
}

/* --- TEMA OSCURO BÁSICO (temporal) --- */
body.dark {
  background: #111;
  color: #eee;
}

body.dark #sidebar {
  background: #1e1e1e;
}

body.dark #chatArea {
  background: #121212;
}

body.dark #messages {
  background: #1a1a1a;
}

body.dark .message.other {
  background: #333;
  color: #eee;
}

body.dark .message.self {
  background: #004d40;
  color: white;
}

/* ======== SWITCH TIPO PALANCA ======== */

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 0;
  font-size: 14px;
  user-select: none;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}

/* ocultar checkbox real */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* track */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #bbb;
  border-radius: 34px;
  transition: 0.3s;
}

/* knob */
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: 0.3s;
}

/* activado */
.switch input:checked + .slider {
  background-color: #4cd964; /* verde estilo iOS */
}

.switch input:checked + .slider:before {
  transform: translateX(22px);
}

/* Botón activo (fondo + borde) */
.chat-item-active {
  background: #d0ebff !important; /* celeste suave */
  border-left: 4px solid #0b7dda;
}

/* El número (wa_id) resaltado en el activo */
.chat-item-active .chat-waid {
  font-weight: bold;
  color: #0b7dda;
}

/* Preview estándar de todos los chats */
.chat-preview {
  font-size: 11px;
  opacity: 0.7;
}

.chat-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-info {
  display: flex;
  flex-direction: column;
}

.chat-waid {
  font-size: 14px;
}

.chat-preview {
  font-size: 11px;
  opacity: 0.7;
}

.chat-item.nuevo {
  background: #fff3cd !important; /* amarillo suave */
  border-left: 4px solid #d29600 !important;
}

.chat-item.nuevo .chat-preview {
  font-weight: bold;
  opacity: 1;
}

.hora {
  font-size: 11px;
  opacity: 0.6;
  margin-right: 6px;
}

.message {
  position: relative;
  padding-bottom: 22px;
}

/* posición de la hora abajo a la derecha */
.message .hora {
  position: absolute;
  bottom: 4px;
  right: 2px;
  font-size: 10px;
  opacity: 0.6;
}

/* los tildes irán al lado de la hora */
.message .estado {
  position: absolute;
  bottom: 4px;
  right: 38px;
  font-size: 10px;
}

.date-separator {
  text-align: center;
  margin: 10px 0;
  font-size: 12px;
  opacity: 0.7;
  padding: 4px 0;
}

.chat-operator-mark {
  color: #4caf50;
  font-weight: bold;
  margin-left: 4px;
}

/* ================================
   PESTAÑAS
==================================*/

.chat-tabs {
  display: flex;
  gap: 6px;
  margin: 0 10px 10px 10px;
}

.chat-tabs .tab {
  flex: 1;
  padding: 6px 0;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #fafafa;
  font-size: 13px;
  cursor: pointer;
  transition:
    background 0.2s,
    border-color 0.2s;
}

.chat-tabs .tab:hover {
  background: #e9e9e9;
}

.chat-tabs .tab.active {
  background: #075e54;
  color: white;
  border-color: #075e54;
}

/* Modo oscuro */
body.dark .chat-tabs .tab {
  background: #2b2b2b;
  border-color: #555;
  color: #ccc;
}

body.dark .chat-tabs .tab.active {
  background: #0b7dda;
  border-color: #0b7dda;
  color: #fff;
}

/* ================================
   ESTADOS DE CHAT EN LA LISTA
==================================*/

/* Chat no atendido (sin asignación) */
.chat-item.no-asignado {
  background: #fffbe6;
  border-left: 4px solid #e6c200;
}

/* Chat asignado a otro operador */
.chat-item.asignado-otro {
  background: #f2f2f2;
  border-left: 4px solid #888;
}

/* Chat asignado a mí (operador actual) */
.chat-item.asignado-mi {
  background: #d0ebff;
  border-left: 4px solid #0b7dda;
}

/* Chat finalizado */
.chat-item.finalizado {
  opacity: 0.5;
  background: #eee !important;
  border-left: 4px solid #555 !important;
}

/* Nuevo mensaje */
.chat-item.nuevo {
  background: #fff3cd !important;
  border-left: 4px solid #d29600 !important;
}

/* ================================
   BOTONES ASIGNAR / FINALIZAR
==================================*/

.header-buttons {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.header-buttons button {
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 13px;
  border: none;
  cursor: pointer;
}

.btn-asignar {
  background: #4caf50;
  color: white;
}

.btn-finalizar {
  background: #d9534f;
  color: white;
}

.btn-asignar:hover {
  background: #45a049;
}

.btn-finalizar:hover {
  background: #c9302c;
}

/* Modo oscuro */
body.dark .btn-asignar {
  background: #358a3e;
}

body.dark .btn-finalizar {
  background: #b73430;
}
