/* ============================ 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;
}

/* ---- Formulario de proyecto generado por la IA ---- */
.chat-lead {
  margin: 4px 0 10px;
  padding: 14px;
  border: 1px solid #d9e3dc;
  border-left: 3px solid var(--green);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 6px 20px rgba(24, 48, 32, .07);
  animation: chat-lead-in .32s ease both;
}
@keyframes chat-lead-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.chat-lead-title {
  margin: 0 0 2px;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
}
.chat-lead-sub {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--ink-faint);
}
.chat-lead.is-sent { border-left-color: #3e7b46; background: #fbfdfb; }

.lead-form { display: grid; gap: 9px; }
.lead-form label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: .01em;
}
.lead-form input,
.lead-form select,
.lead-form textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #cfd9d1;
  border-radius: 9px;
  background: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.lead-form input:focus,
.lead-form select:focus,
.lead-form textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(62, 123, 70, .14);
}
.lead-form textarea { resize: vertical; min-height: 64px; }
.lead-hp {
  position: absolute !important;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.lead-submit {
  margin-top: 4px;
  padding: 11px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease;
}
.lead-submit:hover:not(:disabled) { background: var(--green-dark); }
.lead-submit:disabled { opacity: .6; cursor: default; }
.lead-status { margin: 0; font-size: 12.5px; color: var(--ink-faint); }
.lead-status.is-error { color: #b4453c; }
.lead-done {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eaf3ec;
  color: #2a5630;
  font-size: 13px;
  line-height: 1.5;
}
.lead-quote {
  margin: 12px 0 0;
  padding: 14px 16px;
  border: 1px solid #cfe0d3;
  border-radius: 12px;
  background: #fff;
  text-align: center;
}
.lead-quote-cap {
  margin: 0 0 4px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #6b7a6f;
}
.lead-quote-code {
  margin: 0 0 8px;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: .08em;
  color: #1d2b20;
}
.lead-quote-hint {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: #4b5a4f;
}

@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; }
}
