:root {
  --lr-green: #2f6b3c;
  --lr-green-dark: #244f2d;
  --lr-green-light: #e8f1ea;
  --bg: #f4f6f5;
  --bubble-bot: #ffffff;
  --bubble-user: #2f6b3c;
  --text: #1c2620;
  --text-muted: #6b7a70;
  --border: #e2e8e4;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
}

/* Contenedor principal: ocupa toda la pantalla en móvil,
   se centra como tarjeta en desktop */
.chat {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  background: var(--bg);
}

@media (min-width: 520px) {
  body {
    align-items: center;
    padding: 24px;
  }
  .chat {
    height: min(720px, 90dvh);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    border: 1px solid var(--border);
  }
}

/* Header */
.chat__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--lr-green);
  color: #fff;
  flex-shrink: 0;
}

.chat__avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.5px;
}

.chat__title {
  font-size: 16px;
  font-weight: 600;
}

.chat__subtitle {
  font-size: 12.5px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.chat__status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #7ee2a0;
  box-shadow: 0 0 0 0 rgba(126, 226, 160, 0.7);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(126, 226, 160, 0.6); }
  70% { box-shadow: 0 0 0 6px rgba(126, 226, 160, 0); }
  100% { box-shadow: 0 0 0 0 rgba(126, 226, 160, 0); }
}

/* Lista de mensajes */
.chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: appear 0.25s ease;
}

@keyframes appear {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg--bot {
  align-self: flex-start;
  background: var(--bubble-bot);
  color: var(--text);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow);
}

.msg--user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.msg__time {
  display: block;
  font-size: 10.5px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}

/* Indicador "escribiendo…" */
.typing {
  align-self: flex-start;
  background: var(--bubble-bot);
  border-radius: var(--radius);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  gap: 4px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.4s infinite both;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* Formulario de entrada */
.chat__form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.chat__input {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 22px;
  padding: 11px 16px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.chat__input:focus {
  border-color: var(--lr-green);
  background: #fff;
}

.chat__send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--lr-green);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.chat__send:hover { background: var(--lr-green-dark); }
.chat__send:active { transform: scale(0.92); }
.chat__send:disabled {
  background: #b9c5bd;
  cursor: not-allowed;
}

.chat__send svg {
  margin-left: -2px;
}
