/* =========================================================
   ALFA GAMAR Y ASOCIADOS · Asistente
   Archivo: assets/css/chat.css
   Mismo widget que el de RRB, con la identidad negro y oro.
   Usa los tokens de main.css.
========================================================= */

.alfa-chat {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}
.alfa-chat > * { pointer-events: auto; }

/* ---------- Lanzador ---------- */
.alfa-chat-launcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 58px;
  padding: 0 22px 0 12px;
  border: 1px solid rgb(243 220 154 / 0.35);
  border-radius: var(--r-pill);
  background: linear-gradient(160deg, #221c13, #0f0d0a);
  color: var(--text);
  font-weight: 700;
  font-size: 0.98rem;
  box-shadow: 0 18px 40px -14px rgb(201 160 82 / 0.5), 0 8px 24px -10px rgb(0 0 0 / 0.6);
  transition: transform 0.4s var(--ease-out), box-shadow 0.4s var(--ease-out), border-color 0.3s;
}
.alfa-chat-launcher__mark {
  width: 36px; height: 36px; padding: 5px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2c2419, #0b0a08);
  box-shadow: inset 0 0 0 1px rgb(201 160 82 / 0.35);
}
.alfa-chat-launcher:hover { transform: translateY(-2px); border-color: var(--gold); }
.alfa-chat-launcher:active { transform: scale(0.97); }

/* Aro que llama la atención hasta que el visitante abre el chat. */
.alfa-chat-launcher::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: inherit;
  border: 1.5px solid var(--gold);
  opacity: 0;
  animation: alfa-ring 2.8s var(--ease-out) 3s infinite;
}
.alfa-chat.is-known .alfa-chat-launcher::before { animation: none; }
@keyframes alfa-ring {
  0% { opacity: 0.8; transform: scale(1); }
  70%, 100% { opacity: 0; transform: scale(1.22); }
}

.alfa-chat.is-open .alfa-chat-launcher { display: none; }

@media (max-width: 560px) {
  .alfa-chat-launcher { width: 58px; padding: 0; justify-content: center; }
  .alfa-chat-launcher__label { display: none; }
}

/* ---------- Panel ---------- */
.alfa-chat-panel {
  width: min(400px, calc(100vw - 32px));
  height: min(640px, calc(100dvh - 32px));
  display: flex;
  flex-direction: column;
  border-radius: var(--r-card);
  border: 1px solid var(--line-strong);
  background: rgb(23 20 15 / 0.96);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  box-shadow: var(--shadow), 0 0 0 1px rgb(0 0 0 / 0.2);
  overflow: hidden;
  transform-origin: bottom right;
  animation: alfa-pop 0.45s var(--ease-out);
}
.alfa-chat-panel[hidden] { display: none; }
@keyframes alfa-pop {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 560px) {
  .alfa-chat.is-open { inset: 0; right: 0; bottom: 0; }
  .alfa-chat-panel {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

.alfa-chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 16px 18px;
  border-bottom: 1px solid var(--line);
  background: radial-gradient(120% 160% at 0% 0%, rgb(201 160 82 / 0.16), transparent 60%);
}
.alfa-chat-avatar {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2c2419, #0b0a08);
  box-shadow: inset 0 0 0 1px rgb(201 160 82 / 0.4), 0 0 24px -6px rgb(201 160 82 / 0.5);
}
.alfa-chat-avatar svg { width: 100%; height: 100%; }
.alfa-chat-head__txt { flex: 1; min-width: 0; }
.alfa-chat-head h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1.1;
}
.alfa-chat-head p { color: var(--muted); font-size: 0.84rem; }
.alfa-chat-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-2);
  font-size: 1.15rem;
  text-decoration: none;
  transition: border-color 0.3s, color 0.3s;
}
.alfa-chat-icon:hover { border-color: var(--gold); color: var(--gold-hi); }

.alfa-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.alfa-chat-msg {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 0.96rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: alfa-msg 0.4s var(--ease-out);
}
@keyframes alfa-msg { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.alfa-chat-msg.is-bot {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.alfa-chat-msg.is-user {
  align-self: flex-end;
  background: var(--gold-fill);
  color: #1c1508;
  font-weight: 600;
  border-bottom-right-radius: 6px;
}
.alfa-chat-msg a { color: var(--gold-hi); font-weight: 700; }
.alfa-chat-msg.is-user a { color: inherit; }

.alfa-chat-msg.is-typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.alfa-chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  animation: alfa-typing 1.2s infinite ease-in-out;
}
.alfa-chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.alfa-chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes alfa-typing { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

.alfa-chat-ctas { align-self: flex-start; display: flex; flex-wrap: wrap; gap: 8px; }
.alfa-chat-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 18px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--gold-fill);
  color: #1c1508;
  font-weight: 700;
  font-size: 0.92rem;
  transition: transform 0.3s var(--ease-out);
}
.alfa-chat-cta--alt { background: transparent; color: var(--gold-hi); border: 1px solid var(--gold); }
.alfa-chat-cta:hover { transform: translateY(-1px); }
.alfa-chat-cta:active { transform: scale(0.98); }

.alfa-chat-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 18px 12px;
}
.alfa-chat-suggest[hidden] { display: none; }
.alfa-chat-suggest button {
  min-height: 34px;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text-2);
  font-size: 0.86rem;
  transition: border-color 0.3s, color 0.3s, background-color 0.3s;
}
.alfa-chat-suggest button:hover { border-color: var(--gold); color: var(--text); background: var(--gold-soft); }

.alfa-chat-status {
  margin: 0 18px 10px;
  padding: 10px 12px;
  border-radius: var(--r-field);
  background: rgb(224 128 106 / 0.12);
  color: var(--danger);
  font-size: 0.9rem;
}
.alfa-chat-status[hidden] { display: none; }

.alfa-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 12px;
  padding: 8px 8px 8px 14px;
  border-radius: var(--r-field);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  transition: border-color 0.25s, box-shadow 0.25s;
}
.alfa-chat-form:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgb(201 160 82 / 0.22);
}
.alfa-chat-form textarea {
  flex: 1;
  min-height: 36px;
  max-height: 120px;
  padding: 7px 0;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  line-height: 1.45;
  font-size: 1rem;
}
.alfa-chat-form textarea::placeholder { color: var(--muted); }
.alfa-chat-send {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--gold-fill);
  color: #1c1508;
  font-size: 1.1rem;
  transition: transform 0.3s var(--ease-out), opacity 0.3s;
}
.alfa-chat-send:active { transform: scale(0.94); }
.alfa-chat-send:disabled { opacity: 0.5; }

.alfa-chat-note {
  padding: 10px 18px 14px;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: center;
}

/* Con el menú móvil o la ficha de una casa abiertos, el asistente se aparta. */
body.menu-open .alfa-chat,
body.modal-open .alfa-chat:not(.is-open) { display: none; }
