/*
 * Conversation demo enhancement.
 * Imported after refresh.css: all rules stay within the hero conversation stage.
 */

.stage .chat {
  /* Make room for the compact control bar without making the homepage stage taller. */
  height: 536px;
  scroll-behavior: auto;
}

/* The previous demo applied the same pop-in to every chat fragment. The engine owns
   insertion timing now; rows and intentional states below provide the only motion. */
.chat .bubble,
.chat .typing,
.chat .sender {
  animation: none;
}

.chat .row.is-current .av {
  box-shadow: 0 0 0 2px rgba(5, 165, 216, .22), 0 0 0 4px rgba(5, 165, 216, .08);
}

.chat .typing {
  width: fit-content;
  min-height: 43px;
  gap: 9px;
  padding: 10px 14px;
  color: #547083;
  background: #e8f6fa;
  border: 1px solid rgba(4, 122, 160, .12);
  box-shadow: 0 1px 2px rgba(15, 24, 39, .025);
}

.chat .typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 14px;
}

.chat .typing .typing-dots i {
  width: 5px;
  height: 5px;
  margin: 0;
  background: #0788ae;
  opacity: .42;
  animation: none;
}

.chat .typing-label {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .005em;
  white-space: nowrap;
}

/* A reply replaces its typing state with a brief, quiet upward settle. */
.chat .bubble.is-revealing {
  will-change: opacity, transform;
}

.chat .design img.is-revealing {
  will-change: opacity, transform;
}

.chat .chip.ok.on {
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}

/* Compact native controls live immediately below #showcase inside the stage. */
.stage .demo-controls {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: calc(100% - 16px);
  max-width: 684px;
  min-height: 40px;
  margin: -8px auto 0;
  padding: 2px 0 6px;
  color: #506879;
  font-size: 12px;
  line-height: 1.2;
  border-top: 1px solid rgba(4, 122, 160, .12);
}

.stage .demo-meta,
.stage .demo-actions {
  display: flex;
  align-items: center;
  min-width: 0;
}

.stage .demo-meta {
  gap: 7px;
  flex: 1 1 auto;
}

.stage .demo-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: #0d9ac2;
  box-shadow: 0 0 0 3px rgba(5, 165, 216, .11);
}

.stage .demo-status {
  overflow: hidden;
  color: #526c7d;
  font-weight: 600;
  letter-spacing: .002em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage .demo-actions {
  flex: 0 0 auto;
  gap: 4px;
}

.stage .demo-toggle,
.stage .demo-replay {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 36px;
  min-height: 36px;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: #386174;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .005em;
  cursor: pointer;
  white-space: nowrap;
}

.stage .demo-toggle:hover,
.stage .demo-replay:hover {
  border-color: rgba(4, 122, 160, .15);
  background: rgba(225, 243, 249, .74);
  color: #046f91;
}

.stage .demo-toggle:active,
.stage .demo-replay:active {
  background: rgba(205, 238, 247, .9);
}

.stage .demo-toggle svg,
.stage .demo-replay svg {
  width: 14px;
  height: 14px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stage .demo-toggle:focus-visible,
.stage .demo-replay:focus-visible {
  outline: 2px solid #047aa0;
  outline-offset: 2px;
}

/* The engine may expose either a local control state or a stage state. */
.stage .demo-controls.is-paused .demo-dot,
.stage.is-demo-paused .demo-dot,
.stage[data-demo-state="paused"] .demo-dot {
  background: #6f8795;
  box-shadow: 0 0 0 3px rgba(82, 108, 125, .10);
}

.stage .demo-progress {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(4, 122, 160, .13);
}

.stage .demo-progress-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: #0999c1;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 100ms linear;
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes conversation-row-seed {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }

  @keyframes conversation-reply-reveal {
    from { opacity: 0; transform: translateY(3px); }
    to { opacity: 1; transform: translateY(0); }
  }

  @keyframes conversation-typing-wave {
    0%, 100% { opacity: .34; transform: translateY(0); }
    45% { opacity: .9; transform: translateY(-2px); }
  }

  @keyframes conversation-flyer-reveal {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
  }

  @keyframes conversation-approval {
    0% { box-shadow: 0 0 0 0 rgba(5, 165, 216, .30); }
    55% { box-shadow: 0 0 0 5px rgba(5, 165, 216, 0); }
    100% { box-shadow: 0 0 0 0 rgba(5, 165, 216, 0); }
  }

  .chat .row.is-seeded {
    animation: conversation-row-seed 420ms cubic-bezier(.22, .72, .27, 1) var(--seed-delay, 0ms) both;
    will-change: opacity, transform;
  }

  .chat .bubble.is-revealing {
    animation: conversation-reply-reveal 260ms cubic-bezier(.22, .72, .27, 1) both;
  }

  .chat .typing .typing-dots i {
    animation: conversation-typing-wave 900ms ease-in-out infinite;
  }

  .chat .typing .typing-dots i:nth-child(2) { animation-delay: 120ms; }
  .chat .typing .typing-dots i:nth-child(3) { animation-delay: 240ms; }

  .chat .design img.is-revealing {
    animation: conversation-flyer-reveal 360ms cubic-bezier(.22, .72, .27, 1) both;
  }

  .chat .chip.ok.on {
    animation: conversation-approval 400ms ease-out 1;
  }
}

@media (max-width: 899px) {
  .stage .chat { height: 508px; }
}

@media (max-width: 600px) {
  .stage .chat { height: 518px; }

  .stage .demo-controls {
    width: calc(100% - 4px);
    margin-top: -7px;
  }
}

@media (max-width: 390px) {
  .stage .demo-controls {
    gap: 6px;
    font-size: 11px;
  }

  .stage .demo-meta { gap: 6px; }

  .stage .demo-status { font-size: 11px; }

  .stage .demo-actions { gap: 2px; }

  .stage .demo-toggle,
  .stage .demo-replay {
    gap: 4px;
    min-width: 36px;
    min-height: 36px;
    padding: 6px;
    font-size: 10.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage .chat,
  .stage .chat .row,
  .stage .chat .bubble,
  .stage .chat .typing,
  .stage .chat .typing-dots i,
  .stage .chat .design img,
  .stage .chat .chip.ok.on,
  .stage .demo-toggle,
  .stage .demo-replay,
  .stage .demo-progress-fill {
    animation: none !important;
    transition: none !important;
  }

  .stage .chat { scroll-behavior: auto; }
}

/* Playback integration: the controller owns following and height changes. */
.stage .chat { overflow-anchor: none; }
.chat .row.is-morphing { overflow: hidden; overflow: clip; }
.chat.is-paused *, .chat.is-paused *::before, .chat.is-paused *::after { animation-play-state: paused !important; }
.chat .row.me .typing { color: #eafaff; background: #047aa0; border-color: #047aa0; border-radius: 18px 18px 5px 18px; }
.chat .row.me .typing .typing-dots i { background: #dbf7ff; }

.chat[data-playback="static"] *, .chat[data-playback="static"] *::before, .chat[data-playback="static"] *::after { animation: none !important; transition: none !important; }
