/* ============================ Asistente (chat IA) ============================ */
.chat {
  position: fixed;
  right: clamp(14px, 2.4vw, 28px);
  bottom: clamp(14px, 2.4vw, 28px);
  z-index: 70;
  font-family: var(--font);
}

/* ---- Burbuja circular flotante (te sigue en todo el scroll) ---- */
.chat-launcher {
  position: relative;
  width: 60px;
  height: 60px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
  color: #fff;
  border: 1px solid var(--green);
  border-radius: 50%;
  box-shadow: 0 10px 28px rgba(35, 76, 43, .32);
  transition: background .2s ease, border-color .2s ease, transform .2s ease, box-shadow .2s ease;
  cursor: pointer;
}
.chat-launcher:hover { background: var(--green-dark); border-color: var(--green-dark); transform: translateY(-2px); box-shadow: 0 14px 34px rgba(35, 76, 43, .38); }
.chat-launcher:active { transform: translateY(0); }
.chat-launcher:focus-visible { outline: 2px solid var(--green-dark); outline-offset: 3px; }

.chat-launcher-icon { transition: transform .25s ease, opacity .2s ease; }
.chat-icon-close { display: none; }
.chat-launcher.is-open .chat-icon-bubble { display: none; }
.chat-launcher.is-open .chat-icon-close { display: block; }

.chat-launcher-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #9fe0a7;
  border: 2px solid #fbfdfb;
  animation: jb-pulse 2.4s ease-out infinite;
}
@keyframes jb-pulse {
  0% { box-shadow: 0 0 0 0 rgba(159, 224, 167, .55); }
  70% { box-shadow: 0 0 0 9px rgba(159, 224, 167, 0); }
  100% { box-shadow: 0 0 0 0 rgba(159, 224, 167, 0); }
}

/* ---- Globo de bienvenida flotante (teaser) ---- */
.chat-teaser {
  position: absolute;
  right: 74px;
  bottom: 8px;
  max-width: 260px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 38px 14px 16px;
  box-shadow: 0 14px 34px rgba(35, 76, 43, .22);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  cursor: pointer;
  animation: jb-teaser-in .25s ease;
}
.chat-teaser[hidden] { display: none; }
@keyframes jb-teaser-in {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: translateX(0); }
}
.chat-teaser-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: 0;
  font-size: 18px;
  line-height: 1;
  color: var(--ink-faint);
  padding: 2px 6px;
}
.chat-teaser-text { margin: 0; }

/* ---- Ventana del chat ---- */
.chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  width: min(380px, calc(100vw - 28px));
  height: min(560px, calc(100vh - 140px));
  display: flex;
  flex-direction: column;
  background: #fbfdfb;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(35, 76, 43, .25);
  overflow: hidden;
}
.chat-panel[hidden] { display: none; }

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f3f7f2);
}
.chat-head-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-avatar {
  width: 40px;
  height: 40px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  border: 1px solid var(--green-soft);
}
.chat-kicker {
  margin: 0 0 2px;
  color: var(--green);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
}
.chat-title { font-size: 17px; font-weight: 600; }
.chat-status {
  margin: 2px 0 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-soft);
}
.chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #68b66e;
}
.chat-head-actions { display: flex; gap: 4px; }
.chat-reset,
.chat-close {
  background: none;
  border: 0;
  font-size: 20px;
  line-height: 1;
  color: var(--ink-soft);
  padding: 4px 8px;
  border-radius: 8px;
}
.chat-reset:hover,
.chat-close:hover { background: var(--paper-alt); color: var(--green-dark); }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #fbfdfb, #f3f7f2);
}
.chat-msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-msg.is-assistant {
  align-self: flex-start;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.chat-msg.is-user {
  align-self: flex-end;
  background: var(--green);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.chat-msg.is-error { border-color: #d89c46; }
.chat-msg.is-typing { color: var(--ink-faint); letter-spacing: .2em; }

/* ---- Chips de inicio rapido ---- */
.chat-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.chat-starter {
  background: #fff;
  border: 1px solid var(--green-soft);
  color: var(--green-dark);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.chat-starter:hover { background: var(--paper-alt); border-color: var(--green); }

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}
#chat-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
  background: #fbfdfb;
}
.chat-send {
  background: var(--green);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 11px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.chat-send:hover { background: var(--green-dark); }
.chat-send:disabled,
#chat-input:disabled { opacity: .6; }

.chat-note {
  margin: 0;
  padding: 8px 16px 12px;
  font-size: 11.5px;
  color: var(--ink-faint);
  background: #fff;
}

@media (max-width: 560px) {
  .chat-launcher { width: 54px; height: 54px; }
  .chat-teaser { right: 66px; max-width: 220px; font-size: 13px; }
  .chat-panel { height: min(78vh, 600px); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-launcher { transition: none; }
  .chat-launcher-badge { animation: none; }
  .chat-teaser { animation: none; }
}
