/**
 * Webchat AtentoBot - Estilos centralizados.
 * Usa variables CSS del sitio (--radius, --accent, etc.) para homogeneizar con el resto.
 */

/* Burbuja flotante */
#atb-bubble {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  min-width: 160px;
  max-width: calc(100vw - 40px);
  height: 56px;
  border-radius: var(--radius-button, 999px);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-soft), 0 4px 12px rgba(var(--accent-rgb, 37, 99, 235), 0.35);
  cursor: pointer;
  z-index: 2147483000;
  font-size: 14px;
  font-weight: 600;
  padding: 0 20px;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  font-family: "Open Sans", "Inter", system-ui, sans-serif;
  box-sizing: border-box;
  animation: atb-pulse 2.5s ease-in-out infinite;
}

@keyframes atb-pulse {
  0%, 100% { box-shadow: var(--shadow-soft), 0 4px 12px rgba(var(--accent-rgb, 37, 99, 235), 0.35); }
  50% { box-shadow: var(--shadow-soft), 0 4px 12px rgba(var(--accent-rgb, 37, 99, 235), 0.35), 0 0 0 6px rgba(var(--accent-rgb, 37, 99, 235), 0.08); }
}

#atb-bubble:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft), 0 8px 24px rgba(var(--accent-rgb, 37, 99, 235), 0.4);
}

#atb-bubble-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#atb-bubble-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

#atb-bubble-text {
  white-space: nowrap;
  color: inherit;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

#atb-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ef4444;
  color: #fff;
  border-radius: var(--radius-badge, 999px);
  font-size: 11px;
  padding: 2px 6px;
  display: none;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}

/* Panel del chat */
#atb-panel {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  width: min(380px, calc(100vw - 2rem));
  height: 520px;
  background: var(--card, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius-card, 20px);
  box-shadow: var(--shadow-soft), 0 12px 40px rgba(0, 0, 0, 0.12);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483000;
  font-family: "Open Sans", "Inter", system-ui, sans-serif;
}

#atb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft, #f8fafc);
  border-radius: var(--radius-card, 20px) var(--radius-card, 20px) 0 0;
}

#atb-head-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

#atb-title {
  font-weight: 700;
  color: var(--text);
  font-size: 15px;
}

#atb-close {
  border: 0;
  background: transparent;
  font-size: 24px;
  cursor: pointer;
  color: var(--muted);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius, 8px);
  transition: background 0.2s ease;
}

#atb-close:hover {
  background: var(--accent-soft, rgba(0, 0, 0, 0.05));
}

#atb-msgs {
  flex: 1;
  overflow: auto;
  background: var(--bg-soft, #fafafa);
  padding: 16px;
}

.atb-m {
  max-width: 78%;
  margin: 8px 0;
  padding: 10px 14px;
  border-radius: var(--radius, 14px);
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.atb-m.me {
  margin-left: auto;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--text);
}

.atb-m.bot {
  margin-right: auto;
  background: var(--card);
  border: 1px solid var(--border);
}

.atb-typing {
  opacity: 0.7;
  font-style: italic;
}

#atb-input {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--card);
  border-radius: 0 0 var(--radius-card, 20px) var(--radius-card, 20px);
}

#atb-text {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 160px;
  border: 1px solid var(--border);
  border-radius: var(--radius, 12px);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

#atb-text:focus {
  border-color: var(--accent);
}

#atb-send {
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-button, 999px);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#atb-send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(var(--accent-rgb, 37, 99, 235), 0.3);
}

#atb-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Móvil: burbuja a la derecha (mismo lado que desktop); tamaño reducido */
@media screen and (max-width: 720px) {
  #atb-bubble {
    right: max(16px, env(safe-area-inset-right));
    min-width: 120px;
    max-width: calc(100vw - 20px);
    height: 50px;
    font-size: 12px;
    padding: 0 14px;
    gap: 6px;
  }
  #atb-bubble-icon {
    width: 16px;
    height: 16px;
  }
  #atb-bubble-text {
    font-size: 11px;
    letter-spacing: 0.05em;
  }
  #atb-panel {
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    width: min(calc(100vw - 2rem), 380px);
    height: min(520px, calc(100vh - 100px));
  }
}

@media screen and (max-width: 480px) {
  #atb-bubble {
    min-width: 100px;
    height: 48px;
    font-size: 11px;
    padding: 0 12px;
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    gap: 5px;
  }
  #atb-bubble-icon {
    width: 14px;
    height: 14px;
  }
  #atb-bubble-text {
    font-size: 10px;
  }
  #atb-panel {
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    width: calc(100vw - 20px);
  }
}
