/* ============================================
   Widget de chat — TyL Modelos Replicables
   Usa las variables ya definidas en estilos.css:
   --primary, --accent, --white, --gray-*, --font, --shadow-*
   ============================================ */

#tyl-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full, 50%);
  border: none;
  background: var(--accent, #B92024);
  color: var(--white, #fff);
  font-size: 26px;
  cursor: pointer;
  box-shadow: var(--shadow-lg, 0 8px 40px rgba(0,0,0,0.12));
  z-index: 9998;
  transition: transform var(--transition, 0.3s ease), background var(--transition, 0.3s ease);
}
#tyl-chat-toggle:hover {
  transform: scale(1.06);
  background: var(--accent-hover, #9e1b1f);
}

#tyl-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 350px;
  max-width: calc(100vw - 32px);
  height: 490px;
  max-height: calc(100vh - 140px);
  background: var(--white, #fff);
  border-radius: var(--radius-lg, 16px);
  box-shadow: var(--shadow-xl, 0 16px 48px rgba(0,0,0,0.15));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  font-family: var(--font, 'Montserrat', sans-serif);
  animation: tyl-chat-slide-up 0.2s ease;
}

@keyframes tyl-chat-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tyl-hidden { display: none !important; }

#tyl-chat-header {
  background: var(--primary, #0d233e);
  color: var(--white, #fff);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#tyl-chat-header strong {
  font-weight: 700;
  font-size: 15px;
}
#tyl-chat-status {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 2px;
}
#tyl-chat-close {
  background: transparent;
  border: none;
  color: var(--white, #fff);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

#tyl-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--gray-50, #f8f9fa);
}

.tyl-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: var(--radius-md, 12px);
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.tyl-msg-bot {
  align-self: flex-start;
  background: var(--gray-100, #f1f3f5);
  color: var(--text, #1a1a2e);
  border-bottom-left-radius: 4px;
  text-align: justify;
}
.tyl-msg-user {
  align-self: flex-end;
  background: var(--primary, #0d233e);
  color: var(--white, #fff);
  border-bottom-right-radius: 4px;
}
.tyl-msg-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--accent, #B92024);
  font-weight: 600;
  text-decoration: underline;
}

.tyl-sugerencias {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 2px 6px;
}
.tyl-sugerencia {
  border: 1px solid var(--primary, #0d233e);
  background: var(--white, #fff);
  color: var(--primary, #0d233e);
  border-radius: var(--radius-full, 20px);
  padding: 7px 13px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition, 0.3s ease), color var(--transition, 0.3s ease);
}
.tyl-sugerencia:hover {
  background: var(--primary, #0d233e);
  color: var(--white, #fff);
}

#tyl-chat-typing {
  padding: 4px 18px 10px;
  display: flex;
  gap: 4px;
  background: var(--gray-50, #f8f9fa);
}
#tyl-chat-typing span {
  width: 6px;
  height: 6px;
  background: var(--gray-400, #adb5bd);
  border-radius: 50%;
  animation: tyl-chat-blink 1.2s infinite ease-in-out;
}
#tyl-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
#tyl-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes tyl-chat-blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

#tyl-chat-form {
  display: flex;
  border-top: 1px solid var(--gray-200, #e9ecef);
  padding: 10px;
  gap: 8px;
  background: var(--white, #fff);
}
#tyl-chat-input {
  flex: 1;
  border: 1px solid var(--gray-300, #D9D9D9);
  border-radius: 8px;
  padding: 10px 15px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
}
#tyl-chat-input:focus {
  border-color: var(--primary, #0d233e);
}
#tyl-chat-send {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--accent, #B92024);
  color: var(--white, #fff);
  font-size: 15px;
  cursor: pointer;
  transition: background var(--transition, 0.3s ease);
}
#tyl-chat-send:hover {
  background: var(--accent-hover, #9e1b1f);
}

@media (max-width: 480px) {
  #tyl-chat-window {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 84px;
  }
  #tyl-chat-toggle {
    right: 16px;
    bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #tyl-chat-toggle,
  #tyl-chat-window,
  #tyl-chat-send,
  #tyl-chat-typing span,
  .tyl-msg {
    transition: none !important;
    animation: none !important;
  }
}
