/* ==========================================================================
   CatalogoCode — Native Storefront Chat (100% Catalog Design System v3 Parity)
   Hereda automáticamente los tokens de los 48 temas curados, 6 temporadas
   y temas legacy sin iframe externo, sin pedir correo y sin branding ajeno.
   ========================================================================== */

.cc-chat {
  --cc-chat-bg: var(--ds-bg-solid, #f8fafc);
  --cc-chat-surface: var(--ds-surface, #ffffff);
  --cc-chat-surface-2: var(--ds-surface-2, #f1f5f9);
  --cc-chat-text: var(--ds-text, #0f172a);
  --cc-chat-muted: var(--ds-text-muted, #64748b);
  --cc-chat-border: var(--ds-border, #e2e8f0);
  --cc-chat-input: var(--ds-input, var(--cc-chat-surface-2));
  --cc-chat-brand: var(--ds-brand, var(--accent, #2563eb));
  --cc-chat-brand-ink: var(--ds-brand-ink, var(--accent-ink, #ffffff));
  --cc-chat-font: var(--ds-font-sans, "Plus Jakarta Sans", system-ui, -apple-system, sans-serif);
  --cc-chat-display: var(--ds-font-display, var(--cc-chat-font));
  font-family: var(--cc-chat-font);
  color: var(--cc-chat-text);
  position: relative;
  z-index: 9100;
}

/* Fallback oscuro para tiendas legacy sin #ds2 */
.store-page--dark:not(.ds2) .cc-chat,
.store-page--oro:not(.ds2) .cc-chat,
.store-page--intimate:not(.ds2) .cc-chat {
  --cc-chat-bg: #0f1117;
  --cc-chat-surface: #171a23;
  --cc-chat-surface-2: #202432;
  --cc-chat-text: #f8fafc;
  --cc-chat-muted: #94a3b8;
  --cc-chat-border: rgba(255, 255, 255, .12);
  --cc-chat-input: #11141c;
}

/* ── Botón flotante lanzador ─────────────────────────────────────────────── */
.cc-chat-launcher {
  position: fixed;
  right: max(18px, env(safe-area-inset-right, 0px));
  bottom: max(22px, env(safe-area-inset-bottom, 0px));
  z-index: 9110;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 58px;
  height: 58px;
  padding: 0 18px;
  border: 1px solid color-mix(in srgb, var(--cc-chat-brand-ink) 18%, transparent);
  border-radius: 999px;
  background: var(--cc-chat-brand);
  color: var(--cc-chat-brand-ink);
  font: 700 14px/1 var(--cc-chat-font);
  cursor: pointer;
  box-shadow:
    0 10px 28px -6px color-mix(in srgb, var(--cc-chat-brand) 52%, rgba(0, 0, 0, .45)),
    0 2px 6px rgba(0, 0, 0, .18);
  transition: transform .18s cubic-bezier(.2, .8, .2, 1), box-shadow .18s ease, opacity .18s ease;
}
.cc-chat-launcher:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow:
    0 14px 34px -6px color-mix(in srgb, var(--cc-chat-brand) 60%, rgba(0, 0, 0, .5)),
    0 4px 10px rgba(0, 0, 0, .2);
}
.cc-chat-launcher:active { transform: scale(.97); }
.cc-chat-launcher:focus-visible {
  outline: 3px solid var(--cc-chat-brand);
  outline-offset: 3px;
}
.cc-chat-launcher__icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}
.cc-chat-launcher__label {
  letter-spacing: -.01em;
  white-space: nowrap;
}
.cc-chat-launcher__dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--cc-chat-brand);
  box-shadow: 0 0 0 2px color-mix(in srgb, #22c55e 28%, transparent);
}

/* Ocultar lanzador cuando el panel está abierto o cuando hay modales/drawers/teclado */
html.is-cc-chat-open .cc-chat-launcher,
body:has(dialog[open]) .cc-chat-launcher,
body:has([data-stories-viewer]:not([hidden])) .cc-chat-launcher,
body:has(.story-viewer:not([hidden]):not(dialog)) .cc-chat-launcher,
body:has(#storiesModal:not([hidden])) .cc-chat-launcher,
body:has(.appt-modal:not([hidden])) .cc-chat-launcher,
body:has(.appt-modal.is-open) .cc-chat-launcher,
body:has(.cart-drawer.is-open) .cc-chat-launcher,
html.cc-kbd-open .cc-chat-launcher,
html.cc-input-focused .cc-chat-launcher {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

/* ── Backdrop + Panel principal ──────────────────────────────────────────── */
.cc-chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9120;
  background: rgba(0, 0, 0, .22);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 1;
  transition: opacity .18s ease;
}
.cc-chat-backdrop[hidden] {
  display: none !important;
}

.cc-chat-panel {
  position: fixed;
  right: max(18px, env(safe-area-inset-right, 0px));
  bottom: max(22px, env(safe-area-inset-bottom, 0px));
  z-index: 9125;
  display: flex;
  flex-direction: column;
  width: min(404px, calc(100vw - 28px));
  height: min(640px, calc(100dvh - 44px));
  max-height: 700px;
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid color-mix(in srgb, var(--cc-chat-brand) 26%, var(--cc-chat-border));
  background: var(--cc-chat-surface);
  color: var(--cc-chat-text);
  box-shadow:
    0 24px 70px -12px rgba(0, 0, 0, .42),
    0 0 0 1px color-mix(in srgb, var(--cc-chat-brand) 10%, transparent);
  animation: ccChatSlideIn .2s cubic-bezier(.2, .8, .2, 1);
}

@keyframes ccChatSlideIn {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Encabezado con identidad real de la tienda ──────────────────────────── */
.cc-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  flex: 0 0 auto;
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--cc-chat-brand) 15%, var(--cc-chat-surface)) 0%,
    var(--cc-chat-surface) 75%
  );
  border-bottom: 1px solid var(--cc-chat-border);
}

.cc-chat-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--cc-chat-brand);
  color: var(--cc-chat-brand-ink);
  font: 800 15px/1 var(--cc-chat-display);
  border: 1.5px solid color-mix(in srgb, var(--cc-chat-brand) 55%, var(--cc-chat-border));
}
.cc-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cc-chat-headmeta {
  min-width: 0;
  flex: 1;
}
.cc-chat-title {
  margin: 0;
  font: 700 15px/1.25 var(--cc-chat-display);
  color: var(--cc-chat-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cc-chat-status {
  margin: 3px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--cc-chat-muted);
}
.cc-chat-status__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px color-mix(in srgb, #22c55e 22%, transparent);
  flex: 0 0 auto;
}

.cc-chat-wa-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, #25d366 45%, var(--cc-chat-border));
  background: color-mix(in srgb, #25d366 15%, var(--cc-chat-surface));
  color: var(--cc-chat-text);
  font: 700 11.5px/1 var(--cc-chat-font);
  text-decoration: none;
  flex: 0 0 auto;
  transition: background .15s ease, transform .15s ease;
}
.cc-chat-wa-btn svg { color: #25d366; flex: 0 0 auto; }
.cc-chat-wa-btn:hover {
  background: color-mix(in srgb, #25d366 24%, var(--cc-chat-surface));
  transform: translateY(-1px);
}

.cc-chat-close {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--cc-chat-border);
  background: var(--cc-chat-surface-2);
  color: var(--cc-chat-text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.cc-chat-close:hover {
  border-color: var(--cc-chat-brand);
  background: color-mix(in srgb, var(--cc-chat-brand) 14%, var(--cc-chat-surface-2));
}

/* ── Barra de cliente identificado (número WhatsApp) ─────────────────────── */
.cc-chat-idbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 14px;
  flex: 0 0 auto;
  background: color-mix(in srgb, var(--cc-chat-brand) 8%, var(--cc-chat-surface-2));
  border-bottom: 1px solid var(--cc-chat-border);
  font-size: 11.5px;
  color: var(--cc-chat-muted);
}
.cc-chat-idbar[hidden] { display: none !important; }
.cc-chat-idbar__who {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cc-chat-idbar__who strong {
  color: var(--cc-chat-text);
  font-weight: 700;
}
.cc-chat-idbar__switch {
  border: 0;
  background: transparent;
  color: var(--cc-chat-brand);
  font: 700 11.5px/1 var(--cc-chat-font);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  flex: 0 0 auto;
}
.cc-chat-idbar__switch:hover {
  background: color-mix(in srgb, var(--cc-chat-brand) 12%, transparent);
}

/* ── Puerta de identificación por WhatsApp (SIN correo electrónico) ──────── */
.cc-chat-gate {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    radial-gradient(90% 45% at 50% 0%, color-mix(in srgb, var(--cc-chat-brand) 10%, transparent), transparent 72%),
    var(--cc-chat-bg);
}
.cc-chat-gate[hidden] { display: none !important; }

.cc-chat-gate__card {
  border-radius: 18px;
  border: 1px solid var(--cc-chat-border);
  background: var(--cc-chat-surface);
  padding: 18px 16px;
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, .2);
}

.cc-chat-gate__badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--cc-chat-brand) 14%, var(--cc-chat-surface-2));
  color: var(--cc-chat-brand);
  font: 700 11px/1 var(--cc-chat-font);
  margin-bottom: 10px;
}

.cc-chat-gate__title {
  margin: 0 0 6px;
  font: 700 17px/1.25 var(--cc-chat-display);
  color: var(--cc-chat-text);
}

.cc-chat-gate__desc {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--cc-chat-muted);
}

.cc-chat-field {
  margin-bottom: 12px;
}
.cc-chat-field label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--cc-chat-text);
}
.cc-chat-field__opt {
  font-weight: 500;
  color: var(--cc-chat-muted);
}

.cc-chat-phone-row {
  display: grid;
  grid-template-columns: 104px 1fr;
  gap: 8px;
}

.cc-chat-select,
.cc-chat-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--cc-chat-border);
  background: var(--cc-chat-input);
  color: var(--cc-chat-text);
  font: 500 14px/1.3 var(--cc-chat-font);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.cc-chat-input::placeholder {
  color: var(--cc-chat-muted);
  opacity: .78;
}
.cc-chat-select:focus,
.cc-chat-input:focus {
  outline: none;
  border-color: var(--cc-chat-brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cc-chat-brand) 22%, transparent);
}

.cc-chat-gate__err {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(239, 68, 68, .12);
  border: 1px solid rgba(239, 68, 68, .35);
  color: #ef4444;
  font-size: 12px;
  font-weight: 600;
}
.cc-chat-gate__err[hidden] { display: none !important; }

.cc-chat-gate__submit {
  width: 100%;
  min-height: 46px;
  margin-top: 4px;
  padding: 11px 16px;
  border: 0;
  border-radius: 13px;
  background: var(--cc-chat-brand);
  color: var(--cc-chat-brand-ink);
  font: 700 14px/1 var(--cc-chat-font);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 22px -6px color-mix(in srgb, var(--cc-chat-brand) 55%, rgba(0, 0, 0, .35));
  transition: filter .15s ease, transform .15s ease;
}
.cc-chat-gate__submit:hover { filter: brightness(1.06); transform: translateY(-1px); }
.cc-chat-gate__submit:disabled { opacity: .6; cursor: wait; transform: none; }

.cc-chat-gate__trust {
  margin: 11px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--cc-chat-muted);
  text-align: center;
}

.cc-chat-gate__wa {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--cc-chat-brand);
  text-decoration: none;
}
.cc-chat-gate__wa:hover { text-decoration: underline; }

/* ── Conversación activa ─────────────────────────────────────────────────── */
.cc-chat-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.cc-chat-stage[hidden] { display: none !important; }

.cc-chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(95% 45% at 50% 0%, color-mix(in srgb, var(--cc-chat-brand) 8%, transparent), transparent 72%),
    var(--cc-chat-bg);
  scrollbar-width: thin;
  scrollbar-color: var(--cc-chat-border) transparent;
}

.cc-chat-msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 88%;
}
.cc-chat-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}

.cc-chat-msg__sender {
  margin: 0 6px 3px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--cc-chat-muted);
}

.cc-chat-bubble {
  padding: 10px 13px;
  border-radius: 16px 16px 16px 4px;
  border: 1px solid var(--cc-chat-border);
  background: var(--cc-chat-surface);
  color: var(--cc-chat-text);
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 14px -6px rgba(0, 0, 0, .14);
}
.cc-chat-msg--user .cc-chat-bubble {
  border-color: transparent;
  border-radius: 16px 16px 4px 16px;
  background: var(--cc-chat-brand);
  color: var(--cc-chat-brand-ink);
  box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--cc-chat-brand) 48%, rgba(0, 0, 0, .35));
}
.cc-chat-bubble strong { font-weight: 700; }
.cc-chat-bubble a {
  color: var(--cc-chat-brand);
  text-decoration: underline;
}
.cc-chat-msg--user .cc-chat-bubble a {
  color: var(--cc-chat-brand-ink);
}

.cc-chat-bubble__img {
  display: block;
  width: 100%;
  max-width: 260px;
  max-height: 220px;
  object-fit: cover;
  border-radius: 11px;
  margin-bottom: 8px;
  border: 1px solid var(--cc-chat-border);
  background: var(--cc-chat-surface-2);
  cursor: zoom-in;
}
.cc-chat-bubble__img:last-child { margin-bottom: 0; }

/* Botones y listas interactivas del bot */
.cc-chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
  max-width: 100%;
}
.cc-chat-action-btn {
  min-height: 36px;
  padding: 7px 12px;
  border-radius: 11px;
  border: 1px solid color-mix(in srgb, var(--cc-chat-brand) 52%, var(--cc-chat-border));
  background: color-mix(in srgb, var(--cc-chat-brand) 10%, var(--cc-chat-surface));
  color: var(--cc-chat-text);
  font: 700 12.5px/1.25 var(--cc-chat-font);
  text-align: left;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .12s ease;
}
.cc-chat-action-btn:hover:not(:disabled) {
  background: var(--cc-chat-brand);
  color: var(--cc-chat-brand-ink);
  transform: translateY(-1px);
}
.cc-chat-action-btn:disabled {
  opacity: .55;
  cursor: default;
}
.cc-chat-action-btn small {
  display: block;
  font-weight: 500;
  font-size: 11px;
  opacity: .8;
  margin-top: 2px;
}

/* Indicador "escribiendo..." */
.cc-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 11px 14px;
  border-radius: 16px 16px 16px 4px;
  border: 1px solid var(--cc-chat-border);
  background: var(--cc-chat-surface);
}
.cc-chat-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cc-chat-brand);
  animation: ccChatPulse .95s infinite alternate;
}
.cc-chat-typing i:nth-child(2) { animation-delay: .18s; }
.cc-chat-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes ccChatPulse {
  from { opacity: .28; transform: translateY(0); }
  to   { opacity: 1; transform: translateY(-3px); }
}

/* Chips sugeridos */
.cc-chat-chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 8px 12px;
  flex: 0 0 auto;
  border-top: 1px solid var(--cc-chat-border);
  background: var(--cc-chat-surface);
  scrollbar-width: none;
}
.cc-chat-chips::-webkit-scrollbar { display: none; }
.cc-chat-chips[hidden] { display: none !important; }
.cc-chat-chip {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--cc-chat-brand) 36%, var(--cc-chat-border));
  background: color-mix(in srgb, var(--cc-chat-brand) 9%, var(--cc-chat-surface-2));
  color: var(--cc-chat-text);
  font: 600 11.5px/1.2 var(--cc-chat-font);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.cc-chat-chip:hover {
  background: var(--cc-chat-brand);
  color: var(--cc-chat-brand-ink);
}

/* Compositor de mensaje */
.cc-chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  flex: 0 0 auto;
  border-top: 1px solid var(--cc-chat-border);
  background: var(--cc-chat-surface);
}
.cc-chat-textarea {
  flex: 1;
  min-height: 44px;
  max-height: 112px;
  resize: none;
  overflow-y: auto;
  padding: 11px 13px;
  border-radius: 14px;
  border: 1px solid var(--cc-chat-border);
  background: var(--cc-chat-input);
  color: var(--cc-chat-text);
  font: 500 14px/1.4 var(--cc-chat-font);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.cc-chat-textarea::placeholder {
  color: var(--cc-chat-muted);
  opacity: .8;
}
.cc-chat-textarea:focus {
  outline: none;
  border-color: var(--cc-chat-brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cc-chat-brand) 22%, transparent);
}

.cc-chat-send {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 13px;
  background: var(--cc-chat-brand);
  color: var(--cc-chat-brand-ink);
  cursor: pointer;
  transition: filter .15s ease, transform .12s ease;
}
.cc-chat-send:hover:not(:disabled) { filter: brightness(1.07); transform: translateY(-1px); }
.cc-chat-send:disabled { opacity: .48; cursor: wait; transform: none; }

.cc-chat-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 14px calc(7px + env(safe-area-inset-bottom, 0px));
  flex: 0 0 auto;
  border-top: 1px solid var(--cc-chat-border);
  background: var(--cc-chat-surface-2);
  font-size: 10.5px;
  color: var(--cc-chat-muted);
}
.cc-chat-foot a {
  color: var(--cc-chat-brand);
  font-weight: 700;
  text-decoration: none;
}
.cc-chat-foot a:hover { text-decoration: underline; }

/* ── Móvil: despeje >= 24px sobre .bottom-nav + pantalla completa al abrir ─ */
@media (max-width: 1024px), (pointer: coarse) {
  .cc-chat-input,
  .cc-chat-select,
  .cc-chat-textarea {
    font-size: 16px;
  }
}

@media (max-width: 767px), (max-height: 520px) and (pointer: coarse) {
  .cc-chat-launcher {
    width: 50px;
    min-width: 50px;
    height: 50px;
    padding: 0;
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  }
  .cc-chat-launcher__label {
    display: none;
  }
  .cc-chat-panel {
    top: var(--cc-vv-top, 0px);
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    max-width: 100%;
    height: var(--cc-vv-height, 100dvh);
    max-height: var(--cc-vv-height, 100dvh);
    border-radius: 0;
    border: 0;
    box-shadow: none;
  }
  html.is-cc-chat-open,
  html.is-cc-chat-open body {
    overflow: hidden !important;
    overscroll-behavior: none !important;
  }
  html.is-cc-chat-open .bottom-nav,
  html.is-cc-chat-open .appt-fab,
  html.is-cc-chat-open .owner-price-bar,
  html.is-cc-chat-open .cookie-banner,
  html.is-cc-chat-open .fomo-pop,
  html.is-cc-chat-open .pwa-install,
  html.is-cc-chat-open .wa-float {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cc-chat-panel,
  .cc-chat-launcher,
  .cc-chat-typing i {
    animation: none !important;
    transition: none !important;
  }
}
