/* ========================================================
   MAKY CHAT & ASISTENTE EVA 3D — CENTRO MÉDICO MAKARE
   ======================================================== */

#maky-widget {
  --maky-teal: #073e42;
  --maky-green: #0c5152;
  --maky-gold: #c6a76b;
  --maky-paper: #fffaf4;
  --maky-ink: #26332d;
  position: fixed;
  right: 14px;
  bottom: calc(var(--maky-dock-bottom, 14px) + env(safe-area-inset-bottom, 0px));
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  color: var(--maky-ink);
}

/* El mismo robot 3D de MAKY se muestra en todas las páginas. */

/* ==================== BURBUJA DE SALUDO FLOTANTE (TEASER) ==================== */
#maky-floating-teaser {
  position: relative;
  width: 250px;
  background: #ffffff;
  border: 1px solid var(--maky-gold);
  box-shadow: 0 14px 30px rgba(7, 62, 66, 0.16), 0 3px 8px rgba(0, 0, 0, 0.05);
  border-radius: 16px;
  padding: 11px 13px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  z-index: 999998;
  opacity: 0;
  transform: translateY(12px) scale(0.94);
  transition: opacity 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
}

#maky-floating-teaser::after {
  content: "";
  position: absolute;
  bottom: -6px;
  right: 28px;
  width: 11px;
  height: 11px;
  background: #ffffff;
  border-right: 1px solid var(--maky-gold);
  border-bottom: 1px solid var(--maky-gold);
  transform: rotate(45deg);
}

#maky-floating-teaser.maky-teaser-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

#maky-floating-teaser.maky-teaser-hidden {
  display: none !important;
}

.maky-teaser-text {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--maky-ink);
  flex: 1;
}

.maky-teaser-text strong {
  color: var(--maky-teal);
}

#maky-teaser-close {
  background: none;
  border: none;
  color: #999;
  font-size: 17px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

#maky-teaser-close:hover {
  color: var(--maky-teal);
}

/* ==================== BOTÓN DISPARADOR: MAKI 3D ==================== */
#maky-trigger {
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  outline: none;
  animation: makyEnterBounce 0.9s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
  transition: transform 0.3s ease;
}

@keyframes makyEnterBounce {
  0% {
    opacity: 0;
    transform: translateY(30px) scale(0.7);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.maky-3d-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Imagen del Robot 3D */
.maky-3d-img {
  width: 70px;
  height: auto;
  display: block;
  filter: drop-shadow(0 14px 22px rgba(7, 62, 66, 0.32));
  animation: makiFloat3D 3.5s ease-in-out infinite;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
}

/* Sombra suave e interactiva en el piso */
.maky-3d-shadow {
  width: 60px;
  height: 9px;
  background: radial-gradient(ellipse at center, rgba(7, 62, 66, 0.4) 0%, rgba(7, 62, 66, 0) 72%);
  border-radius: 50%;
  margin-top: -1px;
  animation: makiShadow3D 3.5s ease-in-out infinite;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Efecto hover */
#maky-trigger:hover .maky-3d-img {
  transform: scale(1.1) rotate(-3deg);
}

/* Levitación */
@keyframes makiFloat3D {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-5px) rotate(1.5deg); }
  50% { transform: translateY(-9px) rotate(-1deg); }
  75% { transform: translateY(-4px) rotate(-2deg); }
}

@keyframes makiShadow3D {
  0%, 100% { transform: scale(1); opacity: 0.4; }
  50% { transform: scale(0.72); opacity: 0.15; }
}

/* Etiqueta de nombre MAKY */
.maky-badge-label {
  margin-top: 4px;
  background: #ffffff;
  border: 1.5px solid var(--maky-gold);
  box-shadow: 0 4px 10px rgba(7, 62, 66, 0.12);
  border-radius: 14px;
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--maky-teal);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.3s ease, transform 0.2s ease, border-color 0.2s ease;
}

#maky-trigger:hover .maky-badge-label {
  transform: translateY(-2px);
  border-color: var(--maky-teal);
}

.maky-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 6px #38bdf8;
  display: inline-block;
}

/* ==================== COMPORTAMIENTO INTELIGENTE AL HACER SCROLL ==================== */
/* Cuando el usuario baja a leer, MAKY se compacta un 35% y oculta la etiqueta */
#maky-trigger.maky-scrolled .maky-3d-img {
  width: 58px;
  opacity: 0.88;
}

#maky-trigger.maky-scrolled .maky-3d-shadow {
  width: 40px;
}

#maky-trigger.maky-scrolled .maky-badge-label {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
}

/* Si pasa el ratón sobre ella mientras lee, vuelve a expandirse */
#maky-trigger.maky-scrolled:hover .maky-3d-img {
  width: 70px;
  opacity: 1;
}

#maky-trigger.maky-scrolled:hover .maky-badge-label {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-2px);
}

/* ==================== VENTANA DEL CHAT ==================== */
#maky-chat-window {
  display: flex;
  width: 360px;
  max-width: calc(100vw - 28px);
  height: 520px;
  max-height: min(72vh, calc(100dvh - 120px));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #d9c9ad;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 20px 50px rgba(7, 62, 66, 0.28);
  transform-origin: bottom right;
  visibility:visible;
  transition:opacity .32s cubic-bezier(.2,.75,.25,1),transform .42s cubic-bezier(.2,.75,.25,1),visibility 0s linear 0s;
}

#maky-chat-window.maky-closed {
  display:flex!important;
  visibility:hidden;
  opacity:0;
  transform:translateY(20px) scale(.965);
  pointer-events:none;
  transition:opacity .28s ease,transform .36s cubic-bezier(.2,.75,.25,1),visibility 0s linear .36s;
}

/* Encabezado */
.maky-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(125deg, var(--maky-teal), var(--maky-green));
  color: #fffaf4;
  border-bottom: 2px solid var(--maky-gold);
}

.maky-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.maky-header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ffffff;
  border: 1.5px solid var(--maky-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.mini-eva-eye {
  width: 3.5px;
  height: 6px;
  background: var(--maky-teal);
  border-radius: 50%;
  margin: 0 2px;
}

.maky-header-info h3 {
  margin: 0;
  font-size: 14.5px;
  letter-spacing: 0.08em;
}

.maky-header-info p {
  margin: 2px 0 0;
  font-size: 10px;
  opacity: 0.88;
}

#maky-toggle-calendar-btn {
  background: rgba(198, 167, 107, 0.25);
  border: 1px solid var(--maky-gold);
  color: #fffaf4;
  padding: 5px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

#maky-toggle-calendar-btn:hover {
  background: var(--maky-gold);
  color: var(--maky-teal);
}

.maky-close-btn {
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: white;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: opacity 0.2s;
}

.maky-close-btn:hover {
  opacity: 0.75;
}

/* Cuerpo de mensajes */
.maky-chat-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 11px;
  overflow-y: auto;
  padding: 15px;
  background: #f8f5ef;
}

.maky-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.maky-msg.bot {
  align-self: flex-start;
  border: 1px solid #e8dfd2;
  border-bottom-left-radius: 4px;
  background: #fff;
  color: var(--maky-ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.maky-msg.user {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: var(--maky-teal);
  color: #fff;
  box-shadow: 0 2px 6px rgba(7, 62, 66, 0.2);
}

.maky-msg.loading {
  color: #6b716b;
  background: #eee9df;
  font-style: italic;
}

/* Botones de acción rápida */
.maky-quick-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
}

.maky-pill-btn {
  padding: 9px 13px;
  border: 1px solid var(--maky-gold);
  border-radius: 20px;
  background: #ffffff;
  color: var(--maky-teal);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s, border-color 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.maky-pill-btn:hover {
  transform: translateX(3px);
  background: #f4ead8;
  border-color: var(--maky-teal);
}

/* Panel de Agenda */
#maky-calendar-panel {
  background: #ffffff;
  border-top: 1px solid #e9e1d5;
  border-bottom: 1px solid #e9e1d5;
  padding: 12px 14px;
  max-height: 240px;
  overflow-y: auto;
}

#maky-calendar-panel input,
#maky-calendar-panel select {
  font-family: inherit;
  border: 1px solid #d8d1c7;
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 12px;
  color: var(--maky-ink);
  outline: none;
  background: #fff;
}

#maky-calendar-panel input:focus,
#maky-calendar-panel select:focus {
  border-color: var(--maky-gold);
  box-shadow: 0 0 0 2px #c6a76b2a;
}

#maky-btn-buscar-horas,
#maky-btn-crear-prereserva {
  background: var(--maky-teal);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

#maky-btn-buscar-horas:hover,
#maky-btn-crear-prereserva:hover {
  background: var(--maky-green);
}

/* Footer del Chat */
.maky-chat-footer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e9e1d5;
  background: #fff;
}

#maky-user-input {
  min-width: 0;
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #d8d1c7;
  border-radius: 10px;
  color: var(--maky-ink);
  font: 13px Arial, sans-serif;
  outline: none;
}

#maky-user-input:focus {
  border-color: var(--maky-gold);
  box-shadow: 0 0 0 3px #c6a76b2a;
}

#maky-send-btn {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: var(--maky-teal);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

#maky-send-btn:hover {
  transform: translateY(-1px);
  background: var(--maky-green);
}

#maky-send-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* Adaptabilidad Móvil */
@media (max-width: 600px) {
  #maky-widget {
    bottom: calc(var(--maky-dock-bottom, 12px) + env(safe-area-inset-bottom, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
  }
  .maky-3d-img {
    width: 58px;
  }
  .maky-3d-shadow {
    width: 50px;
    height: 7px;
  }
  #maky-trigger.maky-scrolled .maky-3d-img {
    width: 48px;
  }
  #maky-trigger.maky-scrolled .maky-3d-shadow {
    width: 36px;
  }
  #maky-chat-window {
    width: calc(100vw - 24px);
    height: min(510px, calc(100dvh - 105px));
    max-height: calc(100dvh - 105px);
  }
  #maky-floating-teaser {
    display: none !important; /* Despejado en móvil */
  }
}

/* En agenda, MAKY se integra abierto al panel principal y no flota en la esquina. */
.booking-page .maky-embedded-widget{position:static;inset:auto;z-index:auto;width:100%;display:block;margin-top:18px}
.booking-page #maky-chat-window{position:static;width:100%;max-width:none;height:min(620px,72vh);max-height:none;border-radius:18px;box-shadow:0 16px 42px rgba(7,62,66,.18);transform:none;opacity:1;pointer-events:auto}
.booking-page #maky-chat-window.maky-closed{display:flex!important}
.booking-page .maky-chat-header{padding:15px 20px}
.booking-page .maky-chat-header h3{font-size:16px}
.booking-page .maky-chat-header p{font-size:11px}
.booking-page .maky-chat-body{padding:20px;gap:13px}
.booking-page .maky-msg{font-size:14px}
.booking-page .maky-chat-footer{padding:14px}
.booking-page .maky-chat-footer input{min-height:46px;font-size:14px}
.booking-page .maky-chat-footer button{width:46px;height:46px}
.booking-page .maky-close-btn{display:none}
@media(max-width:760px){.booking-page .maky-embedded-widget{width:100%;margin-top:12px}.booking-page #maky-chat-window{height:min(610px,70vh);min-height:470px;border-radius:14px}.booking-page .maky-chat-body{padding:13px}.booking-page .maky-msg{max-width:95%;font-size:13px}}

@media(prefers-reduced-motion:reduce){
  #maky-chat-window,#maky-chat-window.maky-closed{transition:none!important;transform:none!important}
  #maky-trigger,.maky-3d-img,.maky-3d-shadow,#maky-floating-teaser{animation:none!important;transition:none!important}
}

/* El selector por ID debe vencer al estilo global del widget flotante en Agenda. */
body.booking-page #maky-widget.maky-embedded-widget{position:static;inset:auto;z-index:auto;display:block;width:100%;margin:18px auto 0;align-items:stretch}
@media(max-width:760px){body.booking-page #maky-widget.maky-embedded-widget{width:100%;margin-top:12px}}

/* El widget deja pasar clics al contenido y el chat cerrado no conserva un panel vacío. */
#maky-widget{pointer-events:none}
#maky-widget>#maky-trigger,#maky-widget>#maky-floating-teaser,#maky-widget>#maky-chat-window{pointer-events:auto}
#maky-chat-window.maky-closed{display:none!important;visibility:hidden;opacity:0;pointer-events:none}
body.menu-open #maky-widget{visibility:hidden!important;pointer-events:none!important}
body.menu-open #maky-widget *{pointer-events:none!important}

/* Mantener el personaje original y compacto en las páginas generales. */
#maky-trigger .maky-3d-img{width:52px!important}
#maky-trigger:hover .maky-3d-img,#maky-trigger.maky-scrolled:hover .maky-3d-img{width:58px!important}
#maky-trigger.maky-scrolled .maky-3d-img{width:46px!important}
@media(max-width:600px){
  #maky-trigger .maky-3d-img{width:44px!important}
  #maky-trigger:hover .maky-3d-img,#maky-trigger.maky-scrolled .maky-3d-img{width:40px!important}
  #maky-trigger.maky-scrolled:hover .maky-3d-img{width:46px!important}
  .maky-chat-body{gap:8px;padding:12px}
  .maky-quick-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px}
  .maky-pill-btn{min-height:40px;padding:8px;font-size:11px;text-align:center}
}
