/* Pre-sales chat widget — Mensajo landing / FAQ.
 * Tokens come from tokens.css (loaded via styles.css). Inline fallbacks are
 * kept as defense against load-order edge cases; values match tokens.css. */

.presales-fab {
  position: fixed;
  right: max(var(--s-6, 16px), env(safe-area-inset-right));
  bottom: max(var(--s-6, 16px), env(safe-area-inset-bottom));
  z-index: 900;
  max-width: min(280px, calc(100vw - 32px));
  min-height: var(--s-12, 44px);
  padding: var(--s-4, 12px) var(--s-6, 16px);
  border: 1px solid var(--line, #d8d4cb);
  border-radius: var(--r-pill, 100px);
  background: var(--surface, #fff);
  color: var(--ink, #141516);
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-semibold, 600);
  font-size: var(--text-xs, 14px);
  line-height: var(--lh-snug, 1.2);
  box-shadow: var(--shadow-lift, 0 8px 20px -10px rgba(0, 0, 0, 0.1));
  cursor: pointer;
}

.presales-fab[hidden] {
  display: none !important;
}

.presales-panel {
  position: fixed;
  inset: 0;
  z-index: 901;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  pointer-events: none;
}

.presales-panel[hidden] {
  display: none !important;
}

/* Scrim — mobile-only backdrop. Tap-outside dismisses the panel. */
.presales-scrim {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(20, 21, 22, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--d-base, 220ms) var(--ease-out, cubic-bezier(0.2, 0.7, 0.2, 1));
}

.presales-scrim[hidden] {
  display: none !important;
}

.presales-scrim.presales-scrim--open {
  opacity: 1;
  pointer-events: auto;
}

.presales-panel-inner {
  pointer-events: auto;
  width: 100%;
  max-width: 420px;
  /* dvh shrinks with the iOS soft keyboard; vh is the fallback for older browsers. */
  max-height: min(85vh, 640px);
  max-height: min(85dvh, 640px);
  margin: 0 0 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--surface, #fff);
  border: 1px solid var(--line, #d8d4cb);
  border-radius: var(--r-3xl, 18px) var(--r-3xl, 18px) 0 0;
  box-shadow: var(--shadow-modal, 0 30px 60px -20px rgba(0, 0, 0, 0.3));
  overflow: hidden;
  transform: translateY(100%);
  transition: transform var(--d-base, 220ms) var(--ease-out, cubic-bezier(0.2, 0.7, 0.2, 1));
  will-change: transform;
}

.presales-panel.presales-panel--open .presales-panel-inner {
  transform: translateY(0);
}

/* While the user is dragging the grabber we drive the transform from JS
 * and want the response to be immediate; the snap-back transition is
 * re-enabled by removing this class. */
.presales-panel-inner.is-dragging {
  transition: none;
}

body.presales-panel-open {
  overflow: hidden;
}

/* Grabber handle — mobile-only swipe affordance at the top of the sheet. */
.presales-grabber {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: var(--s-2, 8px) 0 var(--s-1, 4px);
  background: transparent;
  border: 0;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.presales-grabber:active {
  cursor: grabbing;
}

.presales-grabber::before {
  content: "";
  display: block;
  width: 36px;
  height: 4px;
  border-radius: var(--r-pill, 100px);
  background: var(--line, #d8d4cb);
}

.presales-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4, 12px);
  padding: var(--s-5, 14px) var(--s-6, 16px);
  border-bottom: 1px solid var(--line, #d8d4cb);
}

.presales-title {
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-semibold, 600);
  font-size: var(--text-sm, 15px);
  line-height: var(--lh-snug, 1.2);
  color: var(--ink, #141516);
}

.presales-sub {
  margin-top: var(--s-1, 4px);
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-regular, 400);
  font-size: var(--text-xs, 14px);
  line-height: var(--lh-base, 1.4);
  color: var(--ink-3, #65615a);
}

.presales-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--s-12, 44px);
  min-height: var(--s-12, 44px);
  padding: 0 var(--s-2, 8px);
  border: 0;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-3, #65615a);
}

.presales-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2, 8px);
  padding: var(--s-3, 10px) var(--s-4, 12px);
  border-bottom: 1px solid var(--line, #d8d4cb);
}

.presales-chip {
  min-height: var(--s-12, 44px);
  padding: var(--s-2, 8px) var(--s-5, 14px);
  border-radius: var(--r-pill, 100px);
  border: 1px solid var(--line, #d8d4cb);
  background: var(--accent-soft, #e7f5ec);
  color: var(--accent-text, #141516);
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-medium, 500);
  font-size: var(--text-xs, 14px);
  line-height: var(--lh-snug, 1.2);
  cursor: pointer;
}

.presales-stream {
  flex: 1 1 auto;
  min-height: 180px;
  max-height: 42vh;
  overflow-y: auto;
  padding: var(--s-4, 12px);
  display: flex;
  flex-direction: column;
  gap: var(--s-2, 8px);
  background: var(--paper, #f7f4ef);
}

.presales-msg {
  display: flex;
}

.presales-msg--user {
  justify-content: flex-end;
}

.presales-msg--bot {
  justify-content: flex-start;
  align-items: flex-end;
  gap: var(--s-2, 8px);
}

.presales-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--r-circle, 50%);
  background: var(--accent-soft, #e7f5ec);
  color: var(--ink, #141516);
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-semibold, 600);
  font-size: var(--text-xs, 14px);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.presales-bubble {
  max-width: 88%;
  padding: var(--s-3, 10px) var(--s-4, 12px);
  border-radius: var(--r-2xl, 14px);
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-regular, 400);
  font-size: var(--text-xs, 14px);
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.presales-msg--user .presales-bubble {
  background: var(--bub-out, #e3f3e8);
  color: var(--ink, #141516);
}

.presales-msg--bot .presales-bubble {
  background: var(--bub-in, #fff);
  border: 1px solid var(--line, #d8d4cb);
  color: var(--ink, #141516);
}

.presales-meta {
  margin-top: var(--s-1, 4px);
  font-size: var(--text-xs, 14px);
  opacity: 0.65;
  text-align: right;
}

.presales-bubble--typing .presales-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 3px;
  border-radius: var(--r-circle, 50%);
  background: var(--ink-3, #65615a);
  animation: presales-bounce 1.2s infinite ease-in-out;
}

.presales-bubble--typing .presales-dot:nth-child(2) {
  animation-delay: 0.15s;
}
.presales-bubble--typing .presales-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes presales-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

/* Inline retry chip — only shown after a connection failure. */
.presales-retry-row {
  padding-left: calc(32px + var(--s-2, 8px));
}

.presales-retry {
  min-height: var(--s-12, 44px);
  padding: var(--s-2, 8px) var(--s-5, 14px);
  border-radius: var(--r-pill, 100px);
  border: 1px solid var(--line-2, #c9c4ba);
  background: var(--surface, #fff);
  color: var(--ink, #141516);
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-medium, 500);
  font-size: var(--text-xs, 14px);
  cursor: pointer;
}

.presales-form {
  display: flex;
  gap: var(--s-2, 8px);
  padding: var(--s-3, 10px) var(--s-4, 12px);
  border-top: 1px solid var(--line, #d8d4cb);
  background: var(--surface, #fff);
}

.presales-input {
  flex: 1;
  min-height: var(--s-12, 44px);
  padding: var(--s-3, 10px) var(--s-5, 14px);
  border-radius: var(--r-pill, 100px);
  border: 1px solid var(--line, #d8d4cb);
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-regular, 400);
  font-size: var(--text-base, 16px);
}

.presales-send {
  min-height: var(--s-12, 44px);
  padding: 0 var(--s-6, 16px);
  border: 0;
  border-radius: var(--r-pill, 100px);
  background: var(--accent, #2fa95d);
  color: var(--accent-text, #141516);
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-semibold, 600);
  font-size: var(--text-xs, 14px);
  cursor: pointer;
}

.presales-send:disabled,
.presales-input:disabled {
  opacity: 0.55;
}

.presales-cta {
  margin: var(--s-2, 8px) var(--s-4, 12px) var(--s-2, 8px);
  min-height: var(--s-12, 44px);
  border: 1px solid var(--line-2, #c9c4ba);
  border-radius: var(--r-pill, 100px);
  background: transparent;
  color: var(--ink, #141516);
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-medium, 500);
  font-size: var(--text-xs, 14px);
  cursor: pointer;
}

.presales-foot {
  margin: 0 var(--s-4, 12px) var(--s-4, 12px);
  font-family: var(--font-sans, Inter, "Helvetica Neue", Arial, sans-serif);
  font-weight: var(--w-regular, 400);
  font-size: var(--text-xs, 14px);
  line-height: var(--lh-base, 1.4);
  color: var(--ink-3, #65615a);
  text-align: center;
}

.presales-foot a {
  color: inherit;
}

@media (max-width: 480px) {
  /* Reclaim vertical space on small phones: the subtitle duplicates info
   * conveyed by the FAB label + greeting bubble, so hide it here. */
  .presales-sub {
    display: none;
  }

  /* Collapse chip row to a single horizontal-scroll lane so two rows of
   * chips don't eat the stream's vertical budget. */
  .presales-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-right: var(--s-4, 12px);
  }

  .presales-chips::-webkit-scrollbar {
    display: none;
  }

  .presales-chip {
    flex-shrink: 0;
  }

  /* CTA + footer compete with the conversation stream on first paint.
   * Hold them back until the user has received a real reply, then reveal. */
  .presales-cta,
  .presales-foot {
    display: none;
  }

  .presales-panel.after-first-reply .presales-cta,
  .presales-panel.after-first-reply .presales-foot {
    display: block;
  }
}

@media (min-width: 768px) {
  .presales-panel {
    inset: auto var(--s-6, 16px) var(--s-6, 16px) auto;
    left: auto;
    top: auto;
    width: 420px;
  }

  .presales-panel-inner {
    border-radius: var(--r-3xl, 18px);
    max-height: min(70vh, 560px);
    max-height: min(70dvh, 560px);
    /* On desktop the panel is a floating card, not a sheet — no slide-up animation. */
    transform: none;
    transition: opacity var(--d-fast, 180ms) var(--ease-out, cubic-bezier(0.2, 0.7, 0.2, 1));
  }

  .presales-panel.presales-panel--open .presales-panel-inner {
    transform: none;
  }

  /* Scrim is mobile-only; desktop keeps the floating-card behavior. */
  .presales-scrim {
    display: none !important;
  }

  /* Grabber is mobile-only. */
  .presales-grabber {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .presales-bubble--typing .presales-dot {
    animation: none;
  }

  .presales-panel-inner,
  .presales-scrim {
    transition: none;
  }
}
