:root {
  --verde: #1f6f4a;
  --verde-claro: #e7f3ec;
  --texto: #1f2a24;
  --fondo: #f6f8f7;
  --gris: #6b7570;
  --borde: #d9e2dc;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
}
.app {
  max-width: 720px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.app-header {
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--borde);
  background: white;
}
.app-header h1 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--verde);
}
.app-header p {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--gris);
}
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 0.95rem;
}
.msg.user {
  white-space: pre-wrap;
}
/* Tipografía del markdown renderizado dentro de mensajes del bot */
.msg.bot p {
  margin: 0 0 10px;
}
.msg.bot p:last-child {
  margin-bottom: 0;
}
.msg.bot h3,
.msg.bot h4,
.msg.bot h5 {
  margin: 14px 0 6px;
  line-height: 1.3;
  color: var(--verde);
}
.msg.bot h3:first-child,
.msg.bot h4:first-child,
.msg.bot h5:first-child {
  margin-top: 0;
}
.msg.bot h3 { font-size: 1.05rem; }
.msg.bot h4 { font-size: 1rem; }
.msg.bot h5 { font-size: 0.95rem; }
.msg.bot ul,
.msg.bot ol {
  margin: 0 0 10px;
  padding-left: 22px;
}
.msg.bot li {
  margin-bottom: 4px;
}
.msg.bot li:last-child {
  margin-bottom: 0;
}
.msg.bot strong {
  color: var(--verde);
  font-weight: 700;
}
.msg.bot code {
  background: var(--verde-claro);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.msg.bot a {
  color: var(--verde);
  text-decoration: underline;
}

/* Tablas — por si el agente igual llega a generar una, que no rompa el layout angosto */
.msg.bot table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 10px;
  font-size: 0.85rem;
  display: block;
  overflow-x: auto;
  white-space: nowrap;
}
.msg.bot table th,
.msg.bot table td {
  border: 1px solid var(--borde);
  padding: 6px 10px;
  text-align: left;
  white-space: normal;
}
.msg.bot table th {
  background: var(--verde-claro);
  color: var(--verde);
  font-weight: 600;
}

.msg.user {
  align-self: flex-end;
  background: var(--verde);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg.bot {
  align-self: flex-start;
  background: white;
  border: 1px solid var(--borde);
  border-bottom-left-radius: 4px;
}
.msg.bot.error {
  background: #fdecec;
  border-color: #f3b6b6;
  color: #8a2c2c;
}

/* ============================
   INDICADOR "TRABAJANDO" — reemplaza el texto plano "Consultando..."
   ============================ */
.msg.bot.pending {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--gris);
  background: var(--verde-claro);
  border-color: var(--borde);
}
.pending-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}
.pending-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--verde);
  opacity: 0.45;
  animation: pending-bounce 1.2s infinite ease-in-out;
}
.pending-dots span:nth-child(1) { animation-delay: 0s; }
.pending-dots span:nth-child(2) { animation-delay: 0.2s; }
.pending-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pending-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}
.pending-label {
  font-size: 0.88rem;
  font-style: italic;
}

.input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--borde);
  background: white;
}
.input-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--borde);
  border-radius: 10px;
  font-size: 0.95rem;
  outline: none;
}
.input-bar input:focus {
  border-color: var(--verde);
}
.input-bar button {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--verde);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
}
.input-bar button:disabled {
  opacity: 0.6;
  cursor: default;
}
.input-bar button:hover:not(:disabled) {
  background: #175a3b;
}
.watermark {
  text-align: center;
  font-size: 0.72rem;
  color: var(--gris);
  padding: 8px 16px 10px;
  background: white;
  border-top: 1px solid var(--borde);
}
.brand-badge {
  position: fixed;
  right: 14px;
  bottom: 14px;
  background: rgba(31, 111, 74, 0.92);
  color: white;
  font-size: 0.75rem;
  padding: 7px 12px;
  border-radius: 999px;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: background 0.15s ease, transform 0.15s ease;
  z-index: 10;
}
.brand-badge:hover {
  background: #175a3b;
  transform: translateY(-1px);
}
@media (max-width: 480px) {
  .brand-badge {
    font-size: 0.68rem;
    padding: 6px 10px;
  }
}