:root {
  --bg: #0b1220;
  --panel: #0f172a;
  --muted: #94a3b8;
  --text: #e2e8f0;
  --accent: #22c55e;
  --danger: #ef4444;
  --border: #1f2937;
}
* {
  box-sizing: border-box;
}
/* == SCROLL FIX === */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;  /* 💡 SOLO el chat debe tener scroll */
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, Segoe UI, Roboto, Arial;
  height: 100%;
}
/* = HEADER NUEVO LAYOUT = */
header {
  display: grid;
  grid-template-columns: 1fr 300px 110px; /* izq flexible, centro y der ancho fijo */
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #0a1020;
  position: sticky;
  top: 0;
  z-index: 2;
}
header h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  justify-self: start;
}
header .row {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-self: center;
}
header .badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: #334155;
  display: inline-block;
  text-align: center;
  min-width: 110px;
}
header .badge.on {
  background: #065f46;
}
header .badge.off {
  background: var(--danger);
  color: #fff;
}

/* Estado SSE fijo */
.sse-status {
  display: inline-block;
  width: 130px;
  min-width: 130px;
  max-width: 130px;
  height: 22px;
  line-height: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  vertical-align: middle;
  font-size: 11px;
  background: #334155;
  border-radius: 4px;
  color: white;
  transition: background-color 0.3s ease;
}

/* Contenedor toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none; /* Permite click-through salvo botón cerrar */
}

/* Toast individual */
.toast {
  background: rgba(33, 150, 243, 0.9);
  color: white;
  padding: 10px 16px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: Inter, system-ui, Segoe UI, Roboto, Arial;
  pointer-events: auto; /* Habilita interaccion dentro del toast */
  opacity: 0;
  animation: fade-in 0.3s forwards;
}

/* Botón cerrar */
.toast-close {
  background: transparent;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 6px;
  margin-left: 10px;
}

/* Animaciones */
@keyframes fade-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes fade-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(20px); }
}


/* Estado global Bot fijo */
#botGlobal {
  display: inline-block;
  width: 130px;
  min-width: 130px;
  max-width: 130px;
  height: 22px;
  line-height: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  vertical-align: middle;
  padding: 0;
  box-sizing: border-box;
}
/* Badge SSE fijo */
#sseContainer {
  justify-self: end;
  width: 130px;
  display: flex;
  justify-content: flex-end;
}

/* = Layout global = */
.wrap {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 56px); /* altura total menos header */
  overflow: hidden;
}
aside {
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow: auto;
}
.search {
  padding: 10px;
}
.search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
}
.list {
  padding: 6px;
}
.item {
  display: flex;
  gap: 10px;
  padding: 10px 50px 10px 10px; /* espacio para micro-btn */
  border-radius: 12px;
  cursor: pointer;
  align-items: center;
  border: 1px solid transparent;
  position: relative;
}
.item:hover {
  background: #0b1220;
}
.item.active {
  border-color: #334155;
  background: #0b1220;
}
.bubble {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #1e293b;
  display: grid;
  place-items: center;
  font-weight: 600;
}
.meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.meta .num {
  font-weight: 600;
  font-size: 14px;
}
.meta .last {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.tag {
  margin-top: 4px;
  font-size: 11px;
  color: #94a3b8;
  border: 1px solid #334155;
  border-radius: 999px;
  padding: 2px 8px;
}
/* Micro botón lateral */
.micro-btn {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #e2e8f0;
  cursor: pointer;
  transition: all 0.2s;
}
.micro-btn:hover {
  background: #334155;
}
.micro-btn.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.micro-btn.danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}
/* Main chat */
main {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;     /* 💡 previene scroll */
}
.chat {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: linear-gradient(180deg, #0c1425, #0a1020);
  scroll-behavior: smooth;
  padding-left: 40px;
  padding-right: 40px;
}
.msg {
  max-width: 60%;
  padding: 10px 14px;
  border-radius: 12px;
  margin: 8px 0;
  line-height: 1.35;
  font-size: 14px;
  border: 1px solid #293548;
}
/* Mensajes con sangría */
.me {
  margin-left: auto;
  background: #0f1b34;
  margin-right: 80px;
}
.you {
  margin-right: auto;
  background: #101827;
  margin-left: 80px;
}
.sys {
  margin: 14px auto;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
/* Composer */
.composer {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  padding: 10px;
  padding-bottom: 20px;
  border-top: 1px solid var(--border);
  background: #0a1020;
}
.composer input {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
}
.composer button {
  background: #1e293b;
  border: 1px solid #2b3b52;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.composer .danger {
  border-color: #4b1f27;
  color: #fecaca;
  background: #2a0f14;
}
.muted {
  color: var(--muted);
}
.pill {
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid #334155;
  font-size: 12px;
  white-space: nowrap; /* evita salto de línea en botones */
  cursor: pointer;
}

/* Efecto hover para botones pill */
button.pill:hover,
a.pill:hover {
  background-color: var(--accent);
  color: #fff;
  text-decoration: none;
}
a {
  color: #93c5fd;
  text-decoration: none;
}
/* Scrollbar solo en chat */
.chat::-webkit-scrollbar {
  width: 14px; /* más ancho y visible */
}
.chat::-webkit-scrollbar-thumb {
  background: #4b5563; /* color normal */
  border-radius: 7px;
  border: 2px solid #0a1020; /* espacio visual entre thumb y track */
}
/* estado al pasar el ratón */
.chat::-webkit-scrollbar-thumb:hover {
  background: #6b7280; /* color más claro/oscuro para efecto hover */
}
/* Scrollbar para la lista de clientes en aside, igual estilo que chat */
aside::-webkit-scrollbar {
  width: 10px; /* mismo ancho que el del chat */
}
aside::-webkit-scrollbar-thumb {
  background: #4b5563; /* mismo color claro */
  border-radius: 7px;
  border: 2px solid #0a1020; /* borde interior, mismo que chat */
}
aside::-webkit-scrollbar-thumb:hover {
  background: #6b7280; /* aclarado al pasar el mouse igual que chat */
}

.hora-ultimo {
  font-size: 11px;
  color: #94a3b8;
  white-space: nowrap;
  margin-left: 8px;
  flex-shrink: 0;
}

.badge.contador {
  background: #22c55e;
  color: white;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  font-weight: 600;
  text-align: center;
  padding: 0 8px;
  line-height: 22px;
  margin-left: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.estado-btn {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 50%;
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  user-select: none;
  transition: background-color 0.3s ease;
}

.estado-btn.active {
  background-color: #22c55e; /* verde */
}

.estado-btn.suspended {
  background-color: #ef4444; /* rojo */
}
.item {
  padding-right: 50px; /* Reserva espacio para botón */
}
