:root {
  color-scheme: light;
  --primary-500: #4CAF50;
  --primary-600: #43A047;
  --primary-700: #2E7D32;
  --primary-200: #A5D6A7;
  --surface: #ffffff;
  --surface-2: #f4fbf5;
  --border: #e2efe4;
  --text: #1f2937;
  --muted: #6b7280;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 24px;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: linear-gradient(180deg, #f8fbf9 0%, #eefaf0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-container {
  width: 100%;
  max-width: 520px;
}

.chat-widget {
  width: 100%;
  height: 75vh;
  max-height: 720px;
  min-height: 540px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}

.chat-widget.abierto {
  display: flex;
}

.chat-header-mini {
  background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-500) 100%);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chat-header-mini .titulo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1rem;
}

.chat-header-mini .titulo .icon {
  width: 18px;
  height: 18px;
  background: #fff;
  opacity: 0.9;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="black" d="M12 12c2.66 0 4.8-2.14 4.8-4.8S14.66 2.4 12 2.4 7.2 4.54 7.2 7.2 9.34 12 12 12zm0 2.4c-3.2 0-9.6 1.6-9.6 4.8V22h19.2v-2.8c0-3.2-6.4-4.8-9.6-4.8z"/></svg>') no-repeat center / contain;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="black" d="M12 12c2.66 0 4.8-2.14 4.8-4.8S14.66 2.4 12 2.4 7.2 4.54 7.2 7.2 9.34 12 12 12zm0 2.4c-3.2 0-9.6 1.6-9.6 4.8V22h19.2v-2.8c0-3.2-6.4-4.8-9.6-4.8z"/></svg>') no-repeat center / contain;
}

.chat-header-mini button.close-btn {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.chat-header-mini button.close-btn:hover {
  transform: scale(1.05);
}

.estado-conexion {
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  font-size: 0.92rem;
  color: var(--muted);
}

.estado-conexion.info {
  background: #eef2ff;
  color: #2d3436;
}

.estado-conexion.progreso {
  background: #fff3cd;
  color: #856404;
}

.estado-conexion.exito {
  background: #ecfdf3;
  color: var(--primary-700);
}

.estado-conexion .icono {
  width: 16px;
  height: 16px;
  display: inline-block;
  background: currentColor;
  mask-size: cover;
  -webkit-mask-size: cover;
}

.estado-conexion .icono.spinner {
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2a10 10 0 1 0 10 10h-2A8 8 0 1 1 12 4V2z"/></svg>') no-repeat center / contain;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2a10 10 0 1 0 10 10h-2A8 8 0 1 1 12 4V2z"/></svg>') no-repeat center / contain;
  animation: spin 1s linear infinite;
}

.estado-conexion .icono.check {
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9 16.2l-3.5-3.5-1.4 1.4L9 19 20.3 7.7l-1.4-1.4z"/></svg>') no-repeat center / contain;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9 16.2l-3.5-3.5-1.4 1.4L9 19 20.3 7.7l-1.4-1.4z"/></svg>') no-repeat center / contain;
}

.estado-conexion.error {
  background: #f8d7da;
  color: #721c24;
}

.loader-overlay {
  position: absolute;
  inset: 0;
  background: rgba(246, 248, 255, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  text-align: center;
  font-weight: 600;
  color: #2d3436;
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 5;
}

.loader-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.loader-spinner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 5px solid rgba(116, 185, 255, 0.25);
  border-top-color: #6c5ce7;
  animation: spin 1s linear infinite;
}

#chat-mensajes {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mensaje {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.mensaje.usuario {
  flex-direction: row-reverse;
}

.mensaje .avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e8f5e9;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.08);
  position: relative;
}

.mensaje.usuario .avatar {
  background: #e3f2fd;
}

.mensaje.profesora .avatar {
  background: #e8f5e9;
}

/* Avatar icons */
.mensaje .avatar::before {
  content: "";
  display: block;
  width: 24px;
  height: 24px;
  background: var(--primary-600);
  mask-size: cover;
  -webkit-mask-size: cover;
}

.mensaje.usuario .avatar::before {
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 12c2.7 0 4.8-2.1 4.8-4.8S14.7 2.4 12 2.4 7.2 4.5 7.2 7.2 9.3 12 12 12zm0 2.4c-3.2 0-9.6 1.6-9.6 4.8V22h19.2v-2.8c0-3.2-6.4-4.8-9.6-4.8z"/></svg>') no-repeat center / contain;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 12c2.7 0 4.8-2.1 4.8-4.8S14.7 2.4 12 2.4 7.2 4.5 7.2 7.2 9.3 12 12 12zm0 2.4c-3.2 0-9.6 1.6-9.6 4.8V22h19.2v-2.8c0-3.2-6.4-4.8-9.6-4.8z"/></svg>') no-repeat center / contain;
}

.mensaje.profesora .avatar::before {
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 3L1 9l11 6 9-4.91V17h2V9L12 3zm-6 8.18V15l6 3 6-3v-3.82L12 14l-6-2.82z"/></svg>') no-repeat center / contain;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 3L1 9l11 6 9-4.91V17h2V9L12 3zm-6 8.18V15l6 3 6-3v-3.82L12 14l-6-2.82z"/></svg>') no-repeat center / contain;
}

.mensaje .contenido {
  max-width: 75%;
  padding: 16px 18px;
  border-radius: 20px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
  border: 2px solid transparent;
  background: #fff;
  line-height: 1.45;
  font-size: 0.95rem;
  color: var(--text);
}

.mensaje .contenido p {
  margin: 0.35rem 0 0;
}

.mensaje .contenido p:first-of-type {
  margin-top: 0.1rem;
}

.mensaje .contenido ul,
.mensaje .contenido ol {
  margin: 0.35rem 0 0;
  padding-left: 1.25rem;
}

.mensaje .contenido li {
  margin-bottom: 0.25rem;
}

.mensaje.usuario .contenido {
  background: #e8f5e9;
  color: var(--text);
  border-color: var(--primary-200);
}

.mensaje.profesora .contenido {
  border-color: var(--primary-200);
}

.mensaje.error .avatar {
  background: #fdecea;
}

.mensaje.error .contenido {
  border-color: #f5c6cb;
  background: #fff5f5;
}

.chat-input-bar {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  background: #fff;
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1;
  min-height: 46px;
  max-height: 110px;
  resize: vertical;
  padding: 10px 12px;
  border: 2px solid var(--primary-200);
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
}

/* focus state */
#chat-input:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.15);
}

#btn-enviar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-500) 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(76, 175, 80, 0.35);
  transition: transform 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#btn-enviar:hover {
  transform: translateY(-1px);
}

/* send icon */
#btn-enviar::before {
  content: "";
  display: block;
  width: 22px;
  height: 22px;
  background: #fff;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M2 21l21-9L2 3v7l15 2-15 2v7z"/></svg>') no-repeat center / contain;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M2 21l21-9L2 3v7l15 2-15 2v7z"/></svg>') no-repeat center / contain;
}

.controles-adicionales {
  padding: 12px 16px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.btn-control {
  background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
  border: none;
  color: #fff;
  border-radius: 18px;
  padding: 9px 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(108, 92, 231, 0.3);
}

.puntos-escribiendo {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.puntos-escribiendo span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary-600);
  animation: latir 1.4s ease-in-out infinite;
}

.puntos-escribiendo span:nth-child(2) {
  animation-delay: 0.25s;
}

.puntos-escribiendo span:nth-child(3) {
  animation-delay: 0.5s;
}

@keyframes latir {

  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }

  30% {
    opacity: 1;
    transform: scale(1.15);
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@media (max-width: 640px) {
  body {
    padding: 12px;
  }

  .chat-widget {
    min-height: 520px;
    height: 80vh;
  }

  .mensaje .contenido {
    max-width: 85%;
  }
}

/* Emphasis in message titles */
.mensaje .contenido strong {
  font-weight: 600;
  color: var(--primary-700);
}