/* ===========================================
   ECOMLISTO CHATBOT - Premium Widget Styles
   =========================================== */

/* ---------- CSS Variables ---------- */
:root {
  --echat-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --echat-primary-solid: #667eea;
  --echat-secondary: #1a1a2e;
  --echat-accent: #00d4ff;
  --echat-bg-light: rgba(255, 255, 255, 0.95);
  --echat-bg-glass: rgba(255, 255, 255, 0.85);
  --echat-text-dark: #1a1a2e;
  --echat-text-light: #ffffff;
  --echat-text-muted: #6b7280;
  --echat-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  --echat-shadow-sm: 0 4px 15px rgba(0, 0, 0, 0.1);
  --echat-radius: 20px;
  --echat-bubble-size: 65px;
  --echat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset for Widget ---------- */
.echat-widget * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ---------- Floating Bubble ---------- */
.echat-bubble {
  position: fixed;
  bottom: 25px;
  right: 25px;
  width: var(--echat-bubble-size);
  height: var(--echat-bubble-size);
  border-radius: 50%;
  background: var(--echat-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--echat-shadow);
  transition: var(--echat-transition);
  z-index: 999998;
  border: none;
  outline: none;
}

.echat-bubble:hover {
  transform: scale(1.1);
  box-shadow: 0 30px 60px -15px rgba(102, 126, 234, 0.5);
}

.echat-bubble:active {
  transform: scale(0.95);
}

/* Pulse animation */
.echat-bubble::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--echat-primary);
  animation: echat-pulse 2s ease-out infinite;
  z-index: -1;
}

@keyframes echat-pulse {
  0% {
    transform: scale(1);
    opacity: 0.5;
  }

  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

/* Bubble icon */
.echat-bubble-icon {
  width: 28px;
  height: 28px;
  fill: var(--echat-text-light);
  transition: var(--echat-transition);
}

/* Bubble image (replaces chat icon when configured) */
.echat-bubble-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  transition: var(--echat-transition);
}

.echat-bubble.active .echat-bubble-img {
  display: none;
}

.echat-bubble-icon.close {
  display: none;
}

.echat-bubble.active .echat-bubble-icon.chat {
  display: none;
}

.echat-bubble.active .echat-bubble-icon.close {
  display: block;
}

.echat-bubble.active::before {
  display: none;
}

/* Notification badge */
.echat-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 22px;
  height: 22px;
  background: #ef4444;
  border-radius: 50%;
  color: white;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  animation: echat-bounce 1s ease infinite;
}

@keyframes echat-bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-3px);
  }
}

/* ---------- Proactive Teaser Bubble ---------- */
.echat-teaser {
  position: fixed;
  bottom: calc(25px + var(--echat-bubble-size) + 14px);
  right: 25px;
  max-width: 220px;
  background: #fff;
  color: var(--echat-text-dark);
  padding: 12px 34px 12px 16px;
  border-radius: 16px;
  box-shadow: var(--echat-shadow-sm);
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  z-index: 999998;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.95);
  transform-origin: bottom right;
  transition: var(--echat-transition);
}

.echat-teaser.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Colita apuntando a la burbuja */
.echat-teaser::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 26px;
  width: 14px;
  height: 14px;
  background: #fff;
  transform: rotate(45deg);
  border-radius: 0 0 3px 0;
}

.echat-teaser-close {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: var(--echat-text-muted);
  cursor: pointer;
  padding: 2px;
  opacity: 0.6;
  transition: var(--echat-transition);
}

.echat-teaser-close:hover {
  opacity: 1;
}

/* ---------- Chat Container ---------- */
.echat-container {
  position: fixed;
  bottom: 100px;
  right: 25px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 550px;
  max-height: calc(100vh - 140px);
  background: var(--echat-bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--echat-radius);
  box-shadow: var(--echat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: var(--echat-transition);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.echat-container.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ---------- Chat Header ---------- */
.echat-header {
  background: var(--echat-primary);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--echat-text-light);
  position: relative;
}

.echat-avatar {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  overflow: hidden;
}

.echat-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.echat-header-info {
  flex: 1;
}

.echat-bot-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 3px;
}

.echat-bot-status {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}

.echat-status-dot {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  animation: echat-blink 2s ease-in-out infinite;
}

@keyframes echat-blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

.echat-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--echat-transition);
}

.echat-close-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: rotate(90deg);
}

.echat-close-btn svg {
  width: 16px;
  height: 16px;
  fill: white;
}

/* ---------- Messages Area ---------- */
.echat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(180deg, rgba(249, 250, 251, 0.8) 0%, rgba(255, 255, 255, 0.9) 100%);
}

/* Custom scrollbar */
.echat-messages::-webkit-scrollbar {
  width: 6px;
}

.echat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.echat-messages::-webkit-scrollbar-thumb {
  background: rgba(102, 126, 234, 0.3);
  border-radius: 10px;
}

.echat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(102, 126, 234, 0.5);
}

/* ---------- Message Bubbles ---------- */
.echat-message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: echat-fadeIn 0.3s ease;
}

@keyframes echat-fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.echat-message.bot {
  align-self: flex-start;
}

.echat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.echat-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}

.echat-avatar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.echat-avatar-name {
  font-size: 10px;
  color: var(--echat-text-muted);
  font-weight: 500;
  max-width: 60px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.echat-message.bot .echat-message-avatar {
  background: var(--echat-primary);
  color: white;
}

.echat-message.user .echat-message-avatar {
  background: var(--echat-secondary);
  color: white;
}

.echat-message-content {
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.echat-message.bot .echat-message-content {
  background: white;
  color: var(--echat-text-dark);
  border-bottom-left-radius: 6px;
  box-shadow: var(--echat-shadow-sm);
}

.echat-message.bot .echat-message-content .echat-link {
  color: var(--echat-primary-solid);
  text-decoration: underline;
  font-weight: 500;
  transition: opacity 0.2s ease;
}

.echat-message.bot .echat-message-content .echat-link:hover {
  opacity: 0.8;
}

.echat-message.user .echat-message-content {
  background: var(--echat-primary);
  color: var(--echat-text-light);
  border-bottom-right-radius: 6px;
}

/* ---------- Typing Indicator ---------- */
.echat-typing {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 20px 15px;
}

.echat-typing-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--echat-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.echat-typing-dots {
  background: white;
  padding: 14px 18px;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  box-shadow: var(--echat-shadow-sm);
  display: flex;
  gap: 5px;
  align-items: center;
}

.echat-typing-dot {
  width: 8px;
  height: 8px;
  background: var(--echat-primary-solid);
  border-radius: 50%;
  animation: echat-typing 1.4s ease-in-out infinite;
}

.echat-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.echat-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes echat-typing {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }

  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* ---------- Input Area ---------- */
.echat-input-area {
  padding: 16px 20px;
  background: white;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  display: flex;
  gap: 12px;
  align-items: center;
}

.echat-input {
  flex: 1;
  padding: 14px 18px;
  border: 2px solid rgba(102, 126, 234, 0.2);
  border-radius: 25px;
  font-size: 14px;
  outline: none;
  transition: var(--echat-transition);
  background: rgba(249, 250, 251, 0.8);
  color: var(--echat-text-dark);
}

.echat-input:focus {
  border-color: var(--echat-primary-solid);
  background: white;
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.echat-input::placeholder {
  color: var(--echat-text-muted);
}

.echat-send-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--echat-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--echat-transition);
  flex-shrink: 0;
}

.echat-send-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.echat-send-btn:active {
  transform: scale(0.95);
}

.echat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.echat-send-btn svg {
  width: 20px;
  height: 20px;
  fill: white;
  margin-left: 2px;
}

/* ---------- Powered By ---------- */
.echat-powered {
  padding: 10px 20px;
  text-align: center;
  font-size: 11px;
  color: var(--echat-text-muted);
  background: rgba(249, 250, 251, 0.9);
}

.echat-powered a {
  color: var(--echat-primary-solid);
  text-decoration: none;
  font-weight: 500;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .echat-bubble {
    bottom: 15px;
    right: 15px;
    width: 58px;
    height: 58px;
  }

  .echat-teaser {
    bottom: calc(15px + 58px + 12px);
    right: 15px;
    max-width: calc(100vw - 90px);
  }

  .echat-container {
    bottom: 85px;
    right: 10px;
    left: 10px;
    width: auto;
    max-width: none;
    height: calc(100vh - 110px);
    max-height: none;
    border-radius: 16px;
  }

  .echat-header {
    padding: 16px;
  }

  .echat-messages {
    padding: 15px;
    gap: 12px;
  }

  .echat-message {
    max-width: 90%;
  }

  .echat-input-area {
    padding: 12px 15px;
  }

  .echat-input {
    padding: 12px 16px;
    font-size: 16px;
    /* Prevents zoom on iOS */
  }
}

/* ---------- Dark Mode Support ---------- */
@media (prefers-color-scheme: dark) {
  .echat-container {
    background: rgba(26, 26, 46, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
  }

  .echat-messages {
    background: linear-gradient(180deg, rgba(26, 26, 46, 0.8) 0%, rgba(26, 26, 46, 0.95) 100%);
  }

  .echat-message.bot .echat-message-content {
    background: rgba(255, 255, 255, 0.1);
    color: var(--echat-text-light);
  }

  .echat-typing-dots {
    background: rgba(255, 255, 255, 0.1);
  }

  .echat-input-area {
    background: rgba(26, 26, 46, 0.95);
    border-top-color: rgba(255, 255, 255, 0.1);
  }

  .echat-input {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(102, 126, 234, 0.3);
    color: var(--echat-text-light);
  }

  .echat-input:focus {
    background: rgba(255, 255, 255, 0.15);
  }

  .echat-powered {
    background: rgba(26, 26, 46, 0.95);
    color: rgba(255, 255, 255, 0.5);
  }

  .echat-teaser {
    background: rgba(26, 26, 46, 0.97);
    color: var(--echat-text-light);
  }

  .echat-teaser::after {
    background: rgba(26, 26, 46, 0.97);
  }
}