/* ============================================
   DON CHUCHO — Asistente turístico Armenia 2026
   ============================================ */

/* ── Tarjeta flotante del botón ─────────────────────────── */
.cafeto-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9000;
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  filter: drop-shadow(0 8px 24px rgba(15, 81, 50, 0.45));
  transition: filter 0.2s, transform 0.2s;
}

.cafeto-btn:hover {
  transform: translateY(-4px);
  filter: drop-shadow(0 14px 32px rgba(15, 81, 50, 0.55));
}

/* Imagen del personaje — sobresale por encima de la tarjeta */
.cafeto-btn-figure {
  position: relative;
  z-index: 2;
  width: 80px;
  flex-shrink: 0;
  margin-bottom: -4px; /* se asienta sobre la tarjeta */
  margin-right: -10px; /* se superpone levemente */
}

.cafeto-btn-figure img {
  width: 80px;
  height: auto;
  display: block;
  object-fit: contain;
  object-position: center top;
  /* sombra suave bajo el personaje */
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.25));
}

/* Tarjeta de texto */
.cafeto-btn-card {
  background: linear-gradient(135deg, #198754 0%, #0f5132 100%);
  border-radius: 16px 16px 16px 4px;
  padding: 0.6rem 1rem 0.6rem 1.2rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  min-width: 148px;
  position: relative;
}

/* Borde dorado */
.cafeto-btn-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid #f1c40f;
  pointer-events: none;
}

.cafeto-btn-name {
  font-size: 0.95rem;
  font-weight: 800;
  color: #f1c40f;
  line-height: 1.1;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.cafeto-btn-role {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.92);
  line-height: 1.2;
  white-space: nowrap;
}

.cafeto-btn-cta {
  margin-top: 0.25rem;
  font-size: 0.68rem;
  font-weight: 700;
  color: #fff;
  background: rgba(241, 196, 15, 0.22);
  border: 1px solid rgba(241, 196, 15, 0.55);
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

/* Badge de notificación */
.cafeto-btn-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  background: #f1c40f;
  border-radius: 50%;
  border: 2px solid #fff;
  animation: cafeto-pulse 2s infinite;
  z-index: 3;
}

@keyframes cafeto-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.3); opacity: 0.75; }
}

/* ── Ventana del chat ────────────────────────────────────── */
.cafeto-window {
  position: fixed;
  bottom: 6rem;
  right: 1.5rem;
  z-index: 9001;
  width: min(370px, calc(100vw - 2rem));
  height: min(530px, calc(100vh - 8rem));
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
  border: 2px solid #198754;
  overflow: hidden;
  transform-origin: bottom right;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s;
}

.cafeto-window[hidden] {
  display: none;
}

.cafeto-window.cafeto-opening {
  animation: cafeto-open 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes cafeto-open {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Header del chat ─────────────────────────────────────── */
.cafeto-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, #198754 0%, #0f5132 100%);
  color: #fff;
  border-bottom: 2px solid #f1c40f;
}

.cafeto-header-avatar {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #f1c40f;
  background: rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cafeto-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.cafeto-header-info {
  flex: 1;
  min-width: 0;
}

.cafeto-header-name {
  font-size: 1rem;
  font-weight: 800;
  margin: 0;
  line-height: 1.2;
  color: #f1c40f;
}

.cafeto-header-role {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.85);
  margin: 0;
  line-height: 1.3;
}

.cafeto-header-status {
  font-size: 0.68rem;
  opacity: 0.85;
  margin: 0.1rem 0 0;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: #fff;
}

.cafeto-header-status::before {
  content: "";
  width: 7px;
  height: 7px;
  background: #69f0ae;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(105, 240, 174, 0.35);
  flex-shrink: 0;
}

.cafeto-close-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.cafeto-close-btn:hover {
  background: rgba(255,255,255,0.3);
}

/* ── Mensajes ────────────────────────────────────────────── */
.cafeto-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: #f8fdf9;
  scroll-behavior: smooth;
}

.cafeto-msg {
  display: flex;
  gap: 0.5rem;
  max-width: 88%;
  animation: cafeto-msg-in 0.2s ease-out;
}

@keyframes cafeto-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cafeto-msg--bot  { align-self: flex-start; }
.cafeto-msg--user { align-self: flex-end; flex-direction: row-reverse; }

.cafeto-msg-avatar {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid #c8e6c9;
  background: #e8f5e9;
  margin-top: 2px;
}

.cafeto-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.cafeto-msg-bubble {
  padding: 0.6rem 0.85rem;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}

.cafeto-msg--bot .cafeto-msg-bubble {
  background: #fff;
  color: #004d40;
  border: 1.5px solid #d8e6df;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.cafeto-msg--user .cafeto-msg-bubble {
  background: linear-gradient(135deg, #198754 0%, #0f5132 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ── Chips de sugerencias ────────────────────────────────── */
.cafeto-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.cafeto-chip {
  background: #e8f5e9;
  border: 1.5px solid #198754;
  color: #0f5132;
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}

.cafeto-chip:hover {
  background: #198754;
  color: #fff;
  transform: translateY(-1px);
}

/* ── Enlace POI ──────────────────────────────────────────── */
.cafeto-poi-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: #198754;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  background: none;
  border: none;
  font-family: inherit;
  font-size: inherit;
  padding: 0;
}

.cafeto-poi-link:hover { color: #0f5132; }

/* ── Typing indicator ────────────────────────────────────── */
.cafeto-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 0.5rem 0.75rem;
}

.cafeto-typing span {
  width: 7px;
  height: 7px;
  background: #198754;
  border-radius: 50%;
  animation: cafeto-typing 1.2s infinite;
}

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

@keyframes cafeto-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* ── Input ───────────────────────────────────────────────── */
.cafeto-input-area {
  flex-shrink: 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border-top: 1.5px solid #d8e6df;
  margin: 0;
}

form.cafeto-input-area {
  border: none;
}

.cafeto-input {
  flex: 1;
  padding: 0.55rem 0.85rem;
  border: 1.5px solid #d8e6df;
  border-radius: 999px;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  background: #f8fdf9;
}

.cafeto-input:focus {
  border-color: #198754;
  background: #fff;
}

.cafeto-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #198754 0%, #0f5132 100%);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 3px 10px rgba(15, 81, 50, 0.35);
}

.cafeto-send-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 5px 14px rgba(15, 81, 50, 0.45);
}

.cafeto-send-btn svg { width: 18px; height: 18px; }

/* ── Chat abierto: bloquear scroll del mapa ─────────────── */
body.cafeto-chat-open {
  overflow: hidden;
  touch-action: none;
}

body.cafeto-chat-open .cafeto-btn--hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.92);
}

/* ── Tablet y móvil ─────────────────────────────────────── */
@media (max-width: 768px) {
  .cafeto-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: none;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    border-left: none;
    border-right: none;
  }

  /* Panel abierto: ocupa el viewport visible (sin cortar abajo) */
  .cafeto-window.cafeto-window--open {
    top: env(safe-area-inset-top, 0px);
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    max-height: none;
    min-height: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.28);
    transform: none;
    animation: none;
  }

  .cafeto-btn {
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.75rem + env(safe-area-inset-right, 0px));
    transition: opacity 0.2s, transform 0.2s;
  }

  .cafeto-messages {
    padding: 0.85rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .cafeto-msg {
    max-width: 92%;
  }

  .cafeto-msg-bubble {
    font-size: 0.9375rem;
    line-height: 1.55;
  }

  .cafeto-chip {
    min-height: 44px;
    padding: 0.45rem 0.9rem;
    font-size: 0.8125rem;
  }

  .cafeto-input-area {
    flex-shrink: 0;
    padding: 0.65rem 0.85rem;
    padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 12px));
    gap: 0.55rem;
    background: #fff;
  }

  .cafeto-input {
    font-size: 16px;
    min-height: 44px;
    padding: 0.65rem 1rem;
  }

  .cafeto-send-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }

  .cafeto-close-btn {
    width: 44px;
    height: 44px;
  }

  .cafeto-header {
    flex-shrink: 0;
    padding: 0.65rem 0.85rem;
  }
}

/* Fallback altura en navegadores sin visualViewport bien soportado */
@supports (height: 100svh) {
  @media (max-width: 768px) {
    .cafeto-window.cafeto-window--open {
      height: calc(100svh - env(safe-area-inset-top, 0px));
    }
  }
}

@media (max-width: 480px) {
  .cafeto-btn-figure { width: 64px; }
  .cafeto-btn-figure img { width: 64px; }
  .cafeto-btn-card {
    min-width: 120px;
    padding: 0.45rem 0.75rem 0.45rem 0.9rem;
  }
  .cafeto-btn-name { font-size: 0.85rem; }
  .cafeto-btn-role { font-size: 0.65rem; }
  .cafeto-btn-cta { font-size: 0.62rem; }
}
