/*
 * ST-UDIO | Service: LP Chat
 * Modal chat that grows out of the composer: backdrop, panel, bubbles, typing dots, chips, WhatsApp handoff.
 */

/* --- Overlay ------------------------------------------------------ */
.lp_chat {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.lp_chat[hidden] {
  display: none;
}

.lp_chat-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--_theme---main--text) 28%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity .5s var(--ease-out);
}

.lp_chat.is--open .lp_chat-backdrop {
  opacity: 1;
}

.lp_chat-panel {
  position: fixed;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--_theme---main--border);
  border-radius: var(--_primitives---radius--2xl);
  background: var(--_theme---main--background);
  box-shadow: 0 24px 48px -28px color-mix(in srgb, var(--_theme---main--text) 25%, transparent);
}

/* Lock on html, not body, so the sticky nav keeps sticking; the gutter stops a sideways shift */
.lp-chat-lock {
  overflow: hidden;
  scrollbar-gutter: stable;
}

/* Closing: chrome fades out fast, the empty panel morphs onto the composer. */
.lp_chat.is--closing .lp_chat-head,
.lp_chat.is--closing .lp_chat-log,
.lp_chat.is--closing .lp_chat-dock {
  opacity: 0;
  transition: opacity .15s ease-out;
}

.lp_chat.is--closing .lp_chat-panel {
  border-color: transparent;
  box-shadow: none;
  transition: border-color .3s ease, box-shadow .3s ease;
}

/* --- Head --------------------------------------------------------- */
.lp_chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--_layout---gap--md);
  padding: var(--_layout---gap--sm) var(--_layout---gap--md);
  border-bottom: 1px solid var(--_theme---main--border);
}

.lp_chat-head,
.lp_chat-log {
  opacity: 0;
  transition: opacity .35s var(--ease-out);
}

.lp_chat.is--ready .lp_chat-head,
.lp_chat.is--ready .lp_chat-log {
  opacity: 1;
}

.lp_chat-who {
  display: flex;
  align-items: center;
  gap: var(--_layout---gap--sm);
  min-width: 0;
}

.lp_chat-who-text {
  min-width: 0;
}

.lp_chat-name {
  margin: 0;
  font-size: var(--_typography---text--sm);
  font-weight: 500;
  line-height: 1.3;
  color: var(--_theme---main--text);
}

.lp_chat-note {
  margin: 0;
  font-size: var(--_typography---text--xs);
  line-height: 1.35;
  color: var(--_theme---main--text-muted);
}

.lp_chat-tools {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--_layout---gap--sm);
}

.lp_chat-reset {
  padding: 0;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: var(--_typography---text--xs);
  color: var(--_theme---main--text);
  text-decoration: underline;
  text-underline-offset: .2em;
  cursor: pointer;
}

.lp_chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--_theme---main--border);
  border-radius: var(--_primitives---radius--full);
  background: transparent;
  color: var(--_theme---main--text);
  cursor: pointer;
  transition: background-color .25s ease, transform .3s var(--ease-bounce);
}

.lp_chat-close:hover {
  background: var(--_theme---main--card);
  transform: rotate(90deg);
}

/* --- Log ---------------------------------------------------------- */
.lp_chat-log {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: var(--_layout---gap--sm);
  min-height: 0;
  overflow-y: auto;
  padding: var(--_layout---gap--md);
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--_theme---main--border) transparent;
}

.lp_chat-dock {
  flex: none;
  padding: 0 var(--_layout---gap--sm) var(--_layout---gap--sm);
}

.lp_chat-dock [data-lp-composer] {
  width: 100%;
  max-width: none;
}

/* --- Messages ----------------------------------------------------- */
.lp_chat-msg {
  display: flex;
  align-items: flex-end;
  gap: var(--_layout---gap--xs);
  animation: lp-chat-in .45s var(--ease-out) both;
}

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

.lp_chat-avatar {
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: var(--_primitives---radius--full);
  background: var(--_theme---main--card) no-repeat;
  background-position: var(--lp-chat-avatar-position, center);
  background-size: var(--lp-chat-avatar-size, cover);
}

.lp_chat-head .lp_chat-avatar {
  width: 2.5rem;
  height: 2.5rem;
}

.lp_chat-bubble {
  max-width: min(85%, 34rem);
  margin: 0;
  padding: .7em 1em;
  border: 1px solid var(--_theme---main--border);
  border-radius: var(--_primitives---radius--xl) var(--_primitives---radius--xl) var(--_primitives---radius--xl) var(--_primitives---radius--sm);
  background: var(--_theme---main--card);
  color: var(--_theme---main--text);
  font-size: var(--_typography---text--sm);
  line-height: 1.45;
}

.lp_chat-msg.is--user .lp_chat-bubble {
  border-color: transparent;
  border-radius: var(--_primitives---radius--xl) var(--_primitives---radius--xl) var(--_primitives---radius--sm) var(--_primitives---radius--xl);
  background: var(--_theme---main--foreground);
  color: var(--_theme---main--text-foreground);
}

/* Typing dots */
.lp_chat-bubble.is--typing {
  display: inline-flex;
  gap: .3em;
  padding-top: 1em;
  padding-bottom: 1em;
}

.lp_chat-bubble.is--typing span {
  width: .4em;
  height: .4em;
  border-radius: 50%;
  background: currentColor;
  opacity: .3;
  animation: lp-chat-dot 1s infinite;
}

.lp_chat-bubble.is--typing span:nth-child(2) { animation-delay: .15s; }
.lp_chat-bubble.is--typing span:nth-child(3) { animation-delay: .3s; }

/* --- Chips -------------------------------------------------------- */
.lp_chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--_layout---gap--xs);
  padding-left: calc(2rem + var(--_layout---gap--xs));
}

.lp_chat-chip {
  padding: .55em 1em;
  border: 1px solid var(--_theme---main--border);
  border-radius: var(--_primitives---radius--full);
  background: transparent;
  color: var(--_theme---main--text);
  font: inherit;
  font-size: var(--_typography---text--sm);
  line-height: 1.2;
  cursor: pointer;
  animation: lp-chat-in .4s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 50ms);
  transition: background-color .25s ease, color .25s ease, border-color .25s ease, transform .3s var(--ease-bounce);
}

.lp_chat-chip:hover {
  border-color: var(--_theme---main--text);
}

.lp_chat-chip:active {
  transform: scale(.96);
}

.lp_chat-chip.is--active {
  border-color: var(--_theme---main--foreground);
  background: var(--_theme---main--foreground);
  color: var(--_theme---main--text-foreground);
}

.lp_chat-chip.is--submit {
  border-color: var(--_theme---button--primary-bg);
  background: var(--_theme---button--primary-bg);
  color: var(--_theme---button--primary-text);
}

.lp_chat-chip:focus-visible,
.lp_chat-reset:focus-visible,
.lp_chat-close:focus-visible,
.lp_chat-mail:focus-visible {
  outline: 2px solid var(--_theme---main--primary);
  outline-offset: 2px;
}

/* --- Handoff ------------------------------------------------------ */
.lp_chat-cta {
  display: flex;
  flex-direction: column;
  gap: var(--_layout---gap--xs);
  padding-left: calc(2rem + var(--_layout---gap--xs));
  animation: lp-chat-in .5s var(--ease-out) both;
}

.lp_chat-preview-label {
  margin: 0;
  font-size: var(--_typography---text--xs);
  color: var(--_theme---main--text-muted);
}

.lp_chat-preview {
  margin: 0;
  padding-left: var(--_layout---gap--sm);
  border-left: 2px solid var(--_theme---main--border);
  font-size: var(--_typography---text--xs);
  line-height: 1.5;
  color: var(--_theme---main--text-muted);
  white-space: pre-line;
}

.lp_chat-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--_layout---gap--sm) var(--_layout---gap--md);
  padding-top: var(--_layout---gap--xs);
}

.lp_chat-mail {
  font-size: var(--_typography---text--sm);
  color: var(--_theme---main--text);
  text-decoration: underline;
  text-underline-offset: .2em;
}

/* --- Mobile ------------------------------------------------------- */
@media screen and (max-width: 479px) {
  .lp_chat-head {
    padding: var(--_layout---gap--xs) var(--_layout---gap--sm);
  }

  .lp_chat-note {
    display: none;
  }

  .lp_chat-log {
    padding: var(--_layout---gap--sm);
  }

  .lp_chat-dock {
    padding: 0 var(--_layout---gap--xs) var(--_layout---gap--xs);
  }
}

/* --- Touch: keyboard and cookie badge ----------------------------- */
/* Keyboard room: spacer at the document end while the page composer has focus on a phone */
.lp_chat-room {
  display: block;
  pointer-events: none;
  overflow-anchor: none;
}

/* Cookie badge covers the composer on phones: hidden while the chat is open or typing, touch only; the 16px input stops the iOS zoom */
@media (hover: none) and (pointer: coarse) {
  .lp-chat-lock #cookiescript_badge,
  .lp-chat-typing #cookiescript_badge {
    display: none !important;
  }
}

/* --- Motion ------------------------------------------------------- */
@keyframes lp-chat-in {
  from { opacity: 0; transform: translateY(.75rem); }
}

@keyframes lp-chat-dot {
  0%, 60%, 100% { opacity: .3; transform: none; }
  30% { opacity: 1; transform: translateY(-.2em); }
}

@media (prefers-reduced-motion: reduce) {
  .lp_chat,
  .lp_chat * {
    animation: none !important;
    transition-duration: .001ms !important;
  }
}
