:root {
  --chat-bg: #070b08;
  --chat-surface: #101712;
  --chat-border: #263229;
  --chat-text: #f4f8f5;
  --chat-muted: #a5b2aa;
  --chat-green: #55e879;
  --chat-error: #ffb4ab;
}

.boton-chat {
  position: fixed;
  right: 1.25rem;
  bottom: 5.5rem;
  z-index: 1001;
  display: grid;
  width: 3.75rem;
  height: 3.75rem;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: var(--chat-green);
  color: #031007;
  box-shadow: 0 0.75rem 2.25rem rgba(0, 0, 0, 0.42);
  cursor: pointer;
  transition: transform 180ms ease, background-color 180ms ease;
}

.boton-chat:hover { transform: translateY(-2px); background: #6ff18e; }
.boton-chat:active { transform: translateY(0); }
.boton-chat svg { width: 1.65rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }

.ventana-chat {
  position: fixed;
  right: 1.25rem;
  bottom: 10rem;
  z-index: 1000;
  display: flex;
  width: min(23rem, calc(100vw - 2rem));
  height: min(32rem, calc(100dvh - 12rem));
  min-height: 22rem;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--chat-border);
  border-radius: 1.15rem;
  background: var(--chat-bg);
  color: var(--chat-text);
  box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.55);
  animation: chat-entrada 180ms ease-out both;
}

.ventana-chat[hidden] { display: none !important; }

.chat-header {
  display: flex;
  min-height: 4.5rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 0.9rem 0.8rem 1rem;
  border-bottom: 1px solid var(--chat-border);
  background: #050806;
}

.chat-header > div { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 0.55rem; }
.chat-header strong { font-size: 0.95rem; line-height: 1.2; }
.chat-header small { grid-column: 2; margin-top: 0.12rem; color: var(--chat-muted); font-size: 0.72rem; }
.chat-estado { grid-row: 1 / 3; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--chat-green); box-shadow: 0 0 0 0.22rem rgba(85, 232, 121, 0.12); }

.chat-cerrar {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--chat-muted);
  font: inherit;
  cursor: pointer;
}

.chat-cerrar:hover { background: var(--chat-surface); color: var(--chat-text); }

.chat-mensajes {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.65rem;
  overflow-y: auto;
  padding: 1rem;
  overscroll-behavior: contain;
}

.chat-mensaje {
  max-width: 86%;
  padding: 0.68rem 0.82rem;
  border-radius: 0.9rem;
  font-size: 0.88rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.chat-mensaje.model { align-self: flex-start; border: 1px solid var(--chat-border); border-bottom-left-radius: 0.25rem; background: var(--chat-surface); color: var(--chat-text); }
.chat-mensaje.user { align-self: flex-end; border-bottom-right-radius: 0.25rem; background: var(--chat-green); color: #031007; }
.chat-mensaje.escribiendo { color: var(--chat-muted); font-style: italic; }
.chat-mensaje.error { color: var(--chat-error); }

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--chat-border);
  background: #050806;
}

.chat-form input {
  min-width: 0;
  min-height: 2.75rem;
  padding: 0 0.8rem;
  border: 1px solid var(--chat-border);
  border-radius: 0.7rem;
  outline: none;
  background: var(--chat-surface);
  color: var(--chat-text);
  font: inherit;
  font-size: 0.86rem;
}

.chat-form input::placeholder { color: var(--chat-muted); }
.chat-form input:focus { border-color: var(--chat-green); box-shadow: 0 0 0 3px rgba(85, 232, 121, 0.16); }

.chat-form button {
  min-height: 2.75rem;
  padding: 0 0.9rem;
  border: 0;
  border-radius: 0.7rem;
  background: var(--chat-green);
  color: #031007;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.chat-form button:disabled, .chat-form input:disabled { cursor: wait; opacity: 0.62; }
.boton-chat:focus-visible, .chat-cerrar:focus-visible, .chat-form button:focus-visible { outline: 3px solid #ffffff; outline-offset: 3px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@keyframes chat-entrada {
  from { opacity: 0; transform: translateY(0.6rem) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 34rem) {
  .boton-chat { right: 1rem; bottom: 5.25rem; }
  .ventana-chat { right: 1rem; bottom: 9.5rem; width: calc(100vw - 2rem); height: min(30rem, calc(100dvh - 11rem)); }
}

@media (prefers-reduced-motion: reduce) {
  .boton-chat, .ventana-chat { animation: none; transition: none; }
}
