/* Customer chat widget — storefront only. Matches the terracotta design tokens
   from public.css (falls back to literals if loaded standalone). */
.ad-chat {
  --ac: var(--accent, #B94A3D);
  --ac2: var(--accent-2, #C15B4E);
  --line: var(--line, #E6E2DB);
  --ink: var(--ink, #262421);
  --muted: var(--muted, #6B6459);
  position: fixed;
  right: 20px;
  bottom: 20px;
  /* Above page content, but below the storefront mobile nav drawer (40) and its
     backdrop (39) so an open menu cleanly covers the widget. */
  z-index: 38;
  font-family: 'Assistant', system-ui, sans-serif;
}

/* Floating button */
.ad-chat__fab {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--ac);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  display: grid;
  place-items: center;
  transition: transform .15s ease, background .15s ease;
}
.ad-chat__fab { position: relative; }
.ad-chat__fab:hover { background: var(--ac2); transform: translateY(-2px); }
.ad-chat__fab .msym { font-size: 28px; }

/* Unread-reply badge on the launcher */
.ad-chat__badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #E5484D;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
  animation: adChatPop .18s ease;
}
@keyframes adChatPop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Panel */
.ad-chat__panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .24);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ad-chat__panel[hidden] { display: none; }

.ad-chat__head {
  background: var(--ac);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ad-chat__title { display: block; font-size: 1.02rem; }
.ad-chat__hours { display: block; font-size: .72rem; opacity: .85; }
.ad-chat__close { background: none; border: none; color: #fff; cursor: pointer; display: grid; place-items: center; }

.ad-chat__body {
  flex: 1;
  min-height: 0; /* allow the thread to shrink so the contact form always fits */
  overflow-y: auto;
  padding: 14px;
  background: var(--hero, #FBF4F1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ad-chat__msg {
  max-width: 80%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: .9rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ad-chat__msg--agent { align-self: flex-start; background: #fff; border: 1px solid var(--line); color: var(--ink); }
.ad-chat__msg--customer { align-self: flex-end; background: var(--ac); color: #fff; }

/* "Escribiendo…" — an agent bubble whose content is three pulsing dots. Always
   the last child of the thread (addBubble inserts messages before it). */
.ad-chat__typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 80%;
  padding: 9px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted, #6b6b6b);
  font-size: .82rem;
}
.ad-chat__typing[hidden] { display: none; }
.ad-chat__dots { display: inline-flex; gap: 4px; }
.ad-chat__dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .35;
  animation: ad-chat-dot 1.1s infinite ease-in-out;
}
.ad-chat__dots i:nth-child(2) { animation-delay: .18s; }
.ad-chat__dots i:nth-child(3) { animation-delay: .36s; }
@keyframes ad-chat-dot {
  0%, 60%, 100% { opacity: .35; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  .ad-chat__dots i { animation: none; opacity: .6; }
}

/* Quick-start buttons */
.ad-chat__quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.ad-chat__chip {
  border: 1px solid var(--ac);
  background: #fff;
  color: var(--ac);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: .82rem;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.ad-chat__chip:hover { background: var(--ac); color: #fff; }

/* Contact form (Shopify-style, shown after the first message) */
.ad-chat__contact { padding: 12px 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; overflow-y: auto; background: #fff; }
.ad-chat__contact[hidden] { display: none; }
.ad-chat__contact-head strong { display: block; font-size: .96rem; color: var(--ink); }
.ad-chat__contact-head p { font-size: .8rem; color: var(--muted); margin: 2px 0 4px; }
.ad-chat__row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ad-chat__contact > label { font-size: .78rem; color: var(--ink); display: flex; flex-direction: column; gap: 3px; }
.ad-chat__row2 > label { font-size: .78rem; color: var(--ink); display: flex; flex-direction: column; gap: 3px; }
.ad-chat__contact input[type="text"],
.ad-chat__contact input[type="email"],
.ad-chat__contact input[type="tel"] {
  border: 1px solid var(--field-border, #D9D3C9);
  border-radius: 6px;
  padding: 7px 9px;
  font: inherit;
}
.ad-chat__check { display: flex; align-items: flex-start; gap: 7px; font-size: .8rem; color: var(--ink); line-height: 1.35; cursor: pointer; }
.ad-chat__check input { margin-top: 2px; flex: 0 0 auto; }
.ad-chat__contact-actions { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.ad-chat__contact-skip { background: none; border: none; color: var(--muted); font-size: .8rem; cursor: pointer; text-decoration: underline; }

/* Composer */
.ad-chat__composer { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); background: #fff; }
.ad-chat__composer[hidden] { display: none; }
.ad-chat__composer input {
  flex: 1;
  border: 1px solid var(--field-border, #D9D3C9);
  border-radius: 999px;
  padding: 9px 14px;
  font: inherit;
}
.ad-chat__composer input:focus { outline: 2px solid var(--ac2); outline-offset: 1px; }
.ad-chat__send {
  border: none;
  background: var(--ac);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.ad-chat__send:hover { background: var(--ac2); }

/* WhatsApp continue */
.ad-chat__foot { padding: 0 10px 10px; background: #fff; }
.ad-chat__foot[hidden] { display: none; }
.ad-chat__wa {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px;
  border-radius: 8px;
  background: #25D366;
  color: #fff;
  font-size: .88rem;
  font-weight: 600;
  text-decoration: none;
}
.ad-chat__wa:hover { filter: brightness(.96); }

/* Error banner */
.ad-chat__error { margin: 0 12px; padding: 8px 10px; background: #FBEAE8; color: #8A3A32; border-radius: 6px; font-size: .82rem; }
.ad-chat__error[hidden] { display: none; }

.ad-chat__typing { align-self: flex-start; color: var(--muted); font-size: .8rem; font-style: italic; }

@media (max-width: 480px) {
  .ad-chat { right: 12px; bottom: 12px; }
  .ad-chat__panel { width: calc(100vw - 24px); height: calc(100vh - 90px); bottom: 68px; }
}
