/* ==========================================================================
   AppBlocks - Widget Flotante de Soporte por WhatsApp
   Capa independiente, accesible, responsive y sin colisión con CTAs ni carrito
   ========================================================================== */

#ab-support-root {
  --ab-wa-green: #25d366;
  --ab-wa-green-hover: #1ebe5d;
  --ab-wa-green-active: #17a34a;
  --ab-wa-green-soft: #ecfdf5;
  --ab-support-offset-y: 0px;

  position: fixed;
  right: 24px;
  bottom: calc(24px + var(--ab-support-offset-y));
  z-index: 900;
  font-family: var(--font-sans, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
  transition: bottom 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

#ab-support-root *,
#ab-support-root *::before,
#ab-support-root *::after {
  box-sizing: border-box;
}

.ab-support-trigger-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  pointer-events: auto;
}

/* Botón flotante circular */
.ab-support-trigger {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 9999px;
  border: 2px solid #ffffff;
  background-color: var(--ab-wa-green);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.08),
    0 10px 24px -4px rgba(15, 23, 42, 0.18),
    0 4px 12px -2px rgba(37, 211, 102, 0.32);
  transition:
    background-color 0.18s ease,
    transform 0.18s cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.ab-support-trigger:hover {
  background-color: var(--ab-wa-green-hover);
  transform: translateY(-2px);
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.1),
    0 14px 28px -4px rgba(15, 23, 42, 0.22),
    0 6px 14px -2px rgba(37, 211, 102, 0.38);
}

.ab-support-trigger:active {
  background-color: var(--ab-wa-green-active);
  transform: translateY(0) scale(0.96);
}

.ab-support-trigger:focus-visible {
  outline: 3px solid var(--brand-blue, #2563eb);
  outline-offset: 3px;
}

.ab-support-trigger svg {
  width: 26px;
  height: 26px;
  display: block;
  flex-shrink: 0;
}

.ab-support-trigger .ab-support-icon-close {
  display: none;
}

.ab-support-trigger[aria-expanded="true"] .ab-support-icon-open {
  display: none;
}

.ab-support-trigger[aria-expanded="true"] .ab-support-icon-close {
  display: block;
}

/* Tooltip discreto solo en escritorio */
.ab-support-tooltip {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) translateX(4px);
  background-color: var(--text-primary, #0f172a);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.18);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
}

.ab-support-tooltip::after {
  content: '';
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-left-color: var(--text-primary, #0f172a);
}

@media (hover: hover) and (pointer: fine) {
  .ab-support-trigger-wrap:hover .ab-support-tooltip,
  .ab-support-trigger:focus-visible + .ab-support-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(0);
  }
}

#ab-support-root.is-open .ab-support-tooltip {
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Panel flotante de soporte */
.ab-support-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: 340px;
  max-width: calc(100vw - 2rem);
  background-color: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 16px;
  box-shadow:
    0 20px 40px -10px rgba(15, 23, 42, 0.16),
    0 8px 18px -6px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.97);
  transform-origin: bottom right;
  transition:
    opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0.2s ease;
}

#ab-support-root.is-open .ab-support-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Encabezado del panel */
.ab-support-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.85rem 1.1rem;
  background-color: var(--bg-surface, #ffffff);
  border-bottom: 1px solid var(--border-subtle, #e2e8f0);
}

.ab-support-header-text {
  min-width: 0;
}

.ab-support-title-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.25rem;
}

.ab-support-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  background-color: var(--ab-wa-green);
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.16);
}

.ab-support-title {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary, #0f172a);
}

.ab-support-subtitle {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.42;
  color: var(--text-muted, #64748b);
}

.ab-support-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted, #64748b);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.ab-support-close:hover {
  background-color: var(--bg-surface-alt, #f1f5f9);
  color: var(--text-primary, #0f172a);
}

.ab-support-close:focus-visible {
  outline: 2px solid var(--brand-blue, #2563eb);
  outline-offset: 2px;
}

.ab-support-close svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* Contexto detectado de Mini App (PDP) */
.ab-support-context-chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 1.1rem;
  background-color: var(--bg-surface-subtle, #f8fafc);
  border-bottom: 1px solid var(--border-subtle, #e2e8f0);
  font-size: 0.75rem;
  color: var(--text-body, #334155);
}

.ab-support-context-chip strong {
  color: var(--text-primary, #0f172a);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Lista de opciones */
.ab-support-options {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.85rem;
  background-color: var(--bg-surface, #ffffff);
}

.ab-support-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.8rem;
  background-color: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 11px;
  text-align: left;
  cursor: pointer;
  color: var(--text-primary, #0f172a);
  font-family: inherit;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease,
    box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.ab-support-option:hover {
  background-color: var(--bg-surface-subtle, #f8fafc);
  border-color: rgba(37, 211, 102, 0.55);
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.05);
  transform: translateY(-1px);
}

.ab-support-option:active {
  transform: translateY(0);
}

.ab-support-option:focus-visible {
  outline: 2px solid var(--brand-blue, #2563eb);
  outline-offset: 2px;
}

.ab-support-option-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background-color: var(--bg-surface-subtle, #f8fafc);
  border: 1px solid var(--border-subtle, #e2e8f0);
  color: var(--text-body, #334155);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ab-support-option:hover .ab-support-option-icon {
  background-color: var(--ab-wa-green-soft);
  border-color: rgba(37, 211, 102, 0.35);
  color: #15803d;
}

.ab-support-option-icon svg {
  width: 17px;
  height: 17px;
  display: block;
}

.ab-support-option-label {
  flex: 1;
  min-width: 0;
  font-size: 0.865rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary, #0f172a);
}

.ab-support-option-arrow {
  width: 15px;
  height: 15px;
  color: var(--text-subtle, #94a3b8);
  flex-shrink: 0;
  transition: transform 0.15s ease, color 0.15s ease;
}

.ab-support-option:hover .ab-support-option-arrow {
  transform: translateX(2px);
  color: #15803d;
}

/* Pie del panel */
.ab-support-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  background-color: var(--bg-surface-subtle, #f8fafc);
  border-top: 1px solid var(--border-subtle, #e2e8f0);
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-muted, #64748b);
}

.ab-support-footer svg {
  width: 14px;
  height: 14px;
  color: var(--ab-wa-green);
  flex-shrink: 0;
}

/* Tablet */
@media (max-width: 1024px) {
  #ab-support-root {
    right: 20px;
    bottom: calc(20px + var(--ab-support-offset-y));
  }
}

/* Móvil con safe-area y prevención de desbordamiento */
@media (max-width: 640px) {
  #ab-support-root {
    right: calc(16px + env(safe-area-inset-right, 0px));
    bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--ab-support-offset-y));
  }

  .ab-support-trigger {
    width: 52px;
    height: 52px;
  }

  .ab-support-trigger svg {
    width: 24px;
    height: 24px;
  }

  .ab-support-tooltip {
    display: none;
  }

  .ab-support-panel {
    width: min(336px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 110px);
    overflow-y: auto;
    bottom: calc(100% + 10px);
    border-radius: 14px;
  }

  .ab-support-header {
    padding: 0.9rem 0.95rem 0.75rem;
  }

  .ab-support-options {
    padding: 0.75rem;
    gap: 0.4rem;
  }

  .ab-support-option {
    padding: 0.68rem 0.75rem;
  }
}

/* Respetar preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  #ab-support-root,
  .ab-support-trigger,
  .ab-support-tooltip,
  .ab-support-panel,
  .ab-support-option,
  .ab-support-option-icon,
  .ab-support-option-arrow {
    transition: none !important;
  }
}
