/* Chatbot Widget Styles */

:root {
  --chatbot-primary-color: #0073aa;
  --chatbot-secondary-color: #005177;
  --chatbot-text-color: #333;
  --chatbot-bg-color: #ffffff;
  --chatbot-user-msg-bg: #0073aa;
  --chatbot-bot-msg-bg: #f1f1f1;
}

.chatbot-widget {
  position: fixed;
  bottom: 95px;
  right: 20px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.chatbot-widget * {
  box-sizing: border-box;
}

/* Toggle Button */
.chatbot-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--chatbot-primary-color);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  position: relative;
}

.chatbot-toggle:hover {
  background: var(--chatbot-secondary-color);
  transform: scale(1.05);
}

.chatbot-icon {
  font-size: 28px;
  line-height: 1;
}

.chatbot-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #dc3232;
  color: #fff;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
}

/* Chat Container */
.chatbot-container {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--chatbot-bg-color);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: chatbot-slideUp 0.3s ease;
}

.chatbot-container.active {
  display: flex;
}

@keyframes chatbot-slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
.chatbot-header {
  background: var(--chatbot-primary-color);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  z-index: 10;
}

/* Formulario Pre-chat */
.chatbot-prechat-form {
  flex: 1;
  padding: 0.85rem;
  background: #f9f9f9;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
}

.chatbot-prechat-content {
  width: 100%;
  max-width: 100%;
  background: #ffffff;
  padding: 1rem;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  position: relative;
  z-index: 1;
  overflow: visible;
}

.chatbot-prechat-title {
  margin: 0 0 8px 0;
  font-size: 22px;
  font-weight: 700;
  color: #2c3e50;
  text-align: center;
}

.chatbot-prechat-description {
  margin: 0 0 24px 0;
  font-size: 14px;
  color: #666;
  text-align: center;
  line-height: 1.5;
}

.chatbot-form-group {
  margin-bottom: 18px;
  position: relative;
  z-index: auto;
}

.chatbot-form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
  color: #34495e;
}

.chatbot-form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #e1e8ed;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
  background: #fff;
}

.chatbot-form-group input:focus {
  outline: none;
  border-color: #e74c3c;
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.1);
}

.chatbot-form-group input::placeholder {
  color: #95a5a6;
}

/* Selector de país con banderas */
.chatbot-phone-container {
  display: flex;
  gap: 8px;
}

.chatbot-country-selector {
  position: relative;
  flex-shrink: 0;
  z-index: 100;
}

.chatbot-country-button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 10px;
  border: 2px solid #e1e8ed;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  font-family: inherit;
  min-width: 100px;
}

.chatbot-country-button:hover {
  border-color: #e74c3c;
}

.chatbot-country-button .chatbot-flag {
  font-size: 20px;
  line-height: 1;
}

.chatbot-country-button .chatbot-country-code {
  font-weight: 600;
  color: #2c3e50;
}

.chatbot-dropdown-arrow {
  font-size: 10px;
  color: #95a5a6;
  margin-left: auto;
}

.chatbot-country-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 280px;
  max-height: 300px;
  background: #fff;
  border: 2px solid #e1e8ed;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chatbot-country-search {
  width: 100%;
  padding: 12px;
  border: none;
  border-bottom: 2px solid #e1e8ed;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.chatbot-country-search:focus {
  border-bottom-color: #e74c3c;
}

.chatbot-country-list {
  max-height: 240px;
  overflow-y: auto;
}

.chatbot-country-list::-webkit-scrollbar {
  width: 6px;
}

.chatbot-country-list::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.chatbot-country-list::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.chatbot-country-list::-webkit-scrollbar-thumb:hover {
  background: #999;
}

.chatbot-country-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.chatbot-country-item:hover {
  background: #f8f9fa;
}

.chatbot-country-item .chatbot-flag {
  font-size: 20px;
  flex-shrink: 0;
}

.chatbot-country-item .chatbot-country-name {
  flex: 1;
  font-size: 14px;
  color: #2c3e50;
}

.chatbot-country-item .chatbot-country-code {
  font-size: 13px;
  color: #7f8c8d;
  font-weight: 600;
}

.chatbot-phone-container input[type="tel"] {
  flex: 1;
  width: auto;
}

.chatbot-prechat-content form {
  overflow: visible;
  position: relative;
}

.chatbot-btn-start {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 12px rgba(231, 76, 60, 0.25);
  margin-top: 8px;
}

.chatbot-btn-start:hover {
  background: linear-gradient(135deg, #c0392b 0%, #a93226 100%);
  box-shadow: 0 6px 16px rgba(231, 76, 60, 0.35);
  transform: translateY(-1px);
}

.chatbot-btn-start:active {
  transform: translateY(0);
}

.chatbot-btn-start:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.chatbot-title {
  font-size: 16px;
  font-weight: 600;
}

.chatbot-minimize {
  background: none;
  border: none;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.chatbot-minimize:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Messages Container */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f9f9f9;
  width: 100%;
}

.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* Message Bubble */
.chatbot-message {
  display: flex;
  width: 100%;
  margin-bottom: 8px;
  animation: chatbot-fadeIn 0.3s ease;
  clear: both;
}

@keyframes chatbot-fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot-message-content {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chatbot-message-bot {
  flex-direction: column;
  align-items: flex-start;
}

/* Formateo de mensajes del bot */
.chatbot-message-content p {
  margin: 0 0 8px 0;
}

.chatbot-message-content p:last-child {
  margin-bottom: 0;
}

.chatbot-list-item {
  display: flex;
  align-items: flex-start;
  margin: 6px 0;
  line-height: 1.4;
}

.chatbot-list-number,
.chatbot-bullet {
  font-weight: 600;
  margin-right: 8px;
  flex-shrink: 0;
  color: var(--chatbot-primary-color);
}

.chatbot-list-text {
  flex: 1;
  word-wrap: break-word;
}

.chatbot-message-bot .chatbot-list-number,
.chatbot-message-bot .chatbot-bullet {
  color: var(--chatbot-primary-color);
}

.chatbot-section-title {
  font-weight: 700;
  margin: 12px 0 8px 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--chatbot-primary-color);
}

.chatbot-message-bot .chatbot-section-title {
  color: var(--chatbot-primary-color);
}

.chatbot-price {
  color: #e74c3c;
  font-weight: 700;
  font-size: 16px;
}

/* Enlaces mejorados */
.chatbot-message-content a {
  color: var(--chatbot-primary-color);
  text-decoration: none;
  word-break: break-word;
  transition: all 0.2s;
  font-weight: 500;
  border-bottom: 1px solid transparent;
}

.chatbot-message-content a:hover {
  border-bottom: 1px solid var(--chatbot-primary-color);
}

.chatbot-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
  border: 1px solid #d1d8e0;
  border-radius: 6px;
  font-size: 13px;
  margin: 4px 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.chatbot-link:hover {
  background: linear-gradient(135deg, #e8ecf1 0%, #dfe4ea 100%);
  border-color: var(--chatbot-primary-color);
  text-decoration: none;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.chatbot-link-icon {
  font-size: 16px;
  filter: grayscale(0.3);
}

/* Enlaces de productos */
.chatbot-product-link {
  margin: 12px 0;
  padding: 14px;
  background: linear-gradient(135deg, #ffffff 0%, #fef5f5 100%);
  border: 2px solid #e74c3c;
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(231, 76, 60, 0.15);
  transition: all 0.3s;
}

.chatbot-product-link:hover {
  box-shadow: 0 5px 15px rgba(231, 76, 60, 0.25);
  transform: translateY(-2px);
  border-color: #c0392b;
}

.chatbot-link-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800 !important;
  font-size: 15px;
  color: #e74c3c;
  text-decoration: none !important;
  margin-bottom: 10px;
  padding: 4px 0;
  line-height: 1;
}

.chatbot-link-primary:hover {
  color: #c0392b;
  opacity: 1;
}

.chatbot-link-primary .chatbot-link-icon {
  display: none;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

.chatbot-product-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.chatbot-product-actions a {
  text-decoration: none !important;
  color: white !important;
}

.chatbot-btn {
  padding: 8px 16px;
  font-size: 13px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 600;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  min-width: 120px;
}

.chatbot-btn:hover {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

.chatbot-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chatbot-btn-view {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  color: #fff;
}

.chatbot-btn-view:hover {
  background: linear-gradient(135deg, #c0392b 0%, #a93226 100%);
}

.chatbot-btn-view::before {
  content: "👁️";
  font-size: 14px;
  margin-right: -2px;
}

.chatbot-btn-cart {
  background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
  color: #fff;
}

.chatbot-btn-cart:hover {
  background: linear-gradient(135deg, #229954 0%, #1e8449 100%);
}

.chatbot-btn-cart::before {
  content: "🛒";
  font-size: 14px;
  margin-right: -2px;
}

.chatbot-btn-cart:disabled {
  background: #cccccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.chatbot-btn-cart:disabled:hover {
  transform: none;
  box-shadow: none;
}

.chatbot-btn-success {
  background: linear-gradient(135deg, #2e7d32 0%, #1b5e20 100%) !important;
}

.chatbot-btn-success::before {
  content: "✓";
}

.chatbot-btn-error {
  background: #d32f2f !important;
}

.chatbot-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: chatbot-spin 0.6s linear infinite;
}

@keyframes chatbot-spin {
  to {
    transform: rotate(360deg);
  }
}

.chatbot-message-user .chatbot-message-content a {
  color: #fff !important;
  text-decoration: underline;
}

.chatbot-message-content strong {
  font-weight: 600;
}

.chatbot-message-content em {
  font-style: italic;
}

.chatbot-message-bot .chatbot-message-content {
  background: var(--chatbot-bot-msg-bg);
  color: var(--chatbot-text-color);
  border-bottom-left-radius: 4px;
}

.chatbot-message-user {
  justify-content: flex-end;
}

.chatbot-message-user .chatbot-message-content {
  background: var(--chatbot-user-msg-bg);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Feedback Buttons */
.chatbot-feedback {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  margin-left: 4px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.chatbot-message-bot:hover .chatbot-feedback {
  opacity: 1;
}

.chatbot-message-user .chatbot-feedback {
  display: none;
}

.chatbot-feedback-btn {
  background: transparent;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}

.chatbot-feedback-btn:hover {
  background: #f5f5f5;
  transform: scale(1.1);
}

.chatbot-feedback-btn.active {
  border-color: var(--chatbot-primary-color);
  background: var(--chatbot-primary-color);
  transform: scale(1.15);
}

.chatbot-feedback-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.chatbot-feedback-btn.active.saved {
  animation: feedback-pulse 0.3s ease;
}

@keyframes feedback-pulse {
  0%,
  100% {
    transform: scale(1.15);
  }
  50% {
    transform: scale(1.3);
  }
}

/* Typing Indicator */
.chatbot-typing {
  display: none;
  padding: 10px 16px;
  background: transparent;
  align-items: flex-start;
  gap: 4px;
  margin: 0;
  padding-left: 20px;
  padding-bottom: 8px;
}

.chatbot-typing span {
  width: 8px;
  height: 8px;
  background: var(--chatbot-primary-color);
  border-radius: 50%;
  animation: chatbot-typing 1.4s infinite;
  opacity: 0.6;
}

.chatbot-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.chatbot-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes chatbot-typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Input Container */
.chatbot-input-container {
  padding: 16px;
  background: var(--chatbot-bg-color);
  border-top: 1px solid #e5e5e5;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chatbot-input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  resize: none;
  max-height: 100px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.chatbot-input:focus {
  outline: none;
  border-color: var(--chatbot-primary-color);
}

.chatbot-input::placeholder {
  color: #999;
}

.chatbot-send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--chatbot-primary-color);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.chatbot-send:hover {
  background: var(--chatbot-secondary-color);
  transform: scale(1.05);
}

.chatbot-send:active {
  transform: scale(0.95);
}

.chatbot-send:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

/* Spinner para estados de carga */
.chatbot-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: chatbot-spin 0.6s linear infinite;
}

@keyframes chatbot-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Mobile Styles */
.chatbot-widget.mobile .chatbot-container {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
}

.chatbot-widget.mobile .chatbot-toggle {
  bottom: 20px;
  right: 20px;
}

/* Responsive */
@media (max-width: 480px) {
  .chatbot-container {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }

  .chatbot-widget {
    bottom: 0;
    right: 0;
  }

  .chatbot-toggle {
    bottom: 20px;
    right: 20px;
  }
}

/* Dark Mode Support (optional) */
@media (prefers-color-scheme: dark) {
  :root {
    --chatbot-text-color: #e5e5e5;
    --chatbot-bg-color: #1e1e1e;
    --chatbot-bot-msg-bg: #2d2d2d;
  }

  .chatbot-messages {
    background: #1a1a1a;
  }

  .chatbot-input {
    background: #2d2d2d;
    color: #e5e5e5;
    border-color: #3d3d3d;
  }

  .chatbot-input-container {
    background: #1e1e1e;
    border-top-color: #3d3d3d;
  }
}

/* Custom Scrollbar for Webkit Browsers */
.chatbot-messages {
  scrollbar-width: thin;
  scrollbar-color: #ccc transparent;
}

/* Message Links */
.chatbot-message-content a {
  color: inherit;
  text-decoration: underline;
}

.chatbot-message-bot .chatbot-message-content a {
  color: var(--chatbot-primary-color);
}

.chatbot-message-user .chatbot-message-content a {
  color: #fff;
}

/* Error Message */
.chatbot-message-error .chatbot-message-content {
  background: #fee;
  color: #c00;
  border: 1px solid #fcc;
}

/* System Message */
.chatbot-message-system .chatbot-message-content {
  background: #fffbcc;
  color: #666;
  border: 1px solid #ffeb99;
  font-size: 13px;
  text-align: center;
}
