/* AI Solutions demo: a scripted chat assistant (assets/js/demos/chat.js). The window has a fixed height,
   so new messages scroll inside it and never move the page. */

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-columns: minmax(0, 1fr);
  height: clamp(28rem, 66svh, 34rem);
  background: var(--paper);
  border: var(--border);
  border-radius: calc(var(--radius) * 2);
  box-shadow: var(--shadow);
  font-family: var(--font-sans);
  font-size: var(--step--1);
  overflow: hidden;
}

.chat__head {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-s);
  border-bottom: var(--border);
}

.chat__head img {
  width: 2rem;
  height: 2rem;
}

.chat__name {
  font-weight: 500;
}

.chat__label {
  color: var(--ink-2);
}

.chat__reset {
  min-height: 2.75rem;
  margin-left: auto;
  padding-inline: var(--space-xs);
  color: var(--ink-2);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.chat__reset:hover {
  color: var(--link-hover);
}

.chat__log {
  position: relative; /* message offsets are measured from here */
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-m) var(--space-s);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat__log:focus-visible {
  outline-offset: -2px;
}

/* Messages */

.msg {
  max-width: min(32rem, 88%);
  padding: 0.625rem 0.875rem;
  border-radius: 1rem;
  font-size: var(--step-0);
  line-height: 1.5;
}

.msg--bot {
  align-self: flex-start;
  background: var(--paper-2);
  border-bottom-left-radius: var(--radius);
}

.msg--user {
  align-self: flex-end;
  background: var(--ink);
  color: var(--paper);
  border-bottom-right-radius: var(--radius);
  overflow-wrap: anywhere;
}

.msg > * + * {
  margin-top: var(--space-2xs);
}

.msg :is(ul, ol) {
  padding-left: 1.25rem;
}

.msg strong {
  font-weight: 500;
}

.msg a:hover {
  color: var(--link-hover);
}

.msg--typing {
  display: flex;
  padding-block: 0.625rem;
}

.msg--typing img {
  width: 1.25rem;
  height: 1.25rem;
}

@media (prefers-reduced-motion: no-preference) {
  .msg + .msg {
    animation: card-in var(--dur-fast) var(--ease-out);
  }

  .msg--typing img {
    animation: stamp-pulse 1s var(--ease-out) infinite;
  }

  /* Answers soak in like ink, one paragraph after another. */
  .msg--ink > * {
    animation: ink-in var(--dur-fast) var(--ease-out) both;
  }

  .msg--ink > :nth-child(2) {
    animation-delay: 80ms;
  }

  .msg--ink > :nth-child(3) {
    animation-delay: 160ms;
  }
}

/* Pressed in (180 ms), held, lifted out. */
@keyframes stamp-pulse {
  0% {
    opacity: 0;
    transform: scale(1.15);
  }

  18% {
    opacity: 1;
    transform: scale(0.94);
  }

  30%,
  70% {
    opacity: 1;
    transform: none;
  }

  100% {
    opacity: 0;
    transform: scale(1.06);
  }
}

@keyframes ink-in {
  from {
    opacity: 0;
  }
}

/* Suggested questions and the question box */

.chat__chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs);
  padding: var(--space-2xs) var(--space-s);
}

.chat__chips:empty {
  display: none;
}

.chip {
  min-height: 2.25rem;
  padding: 0.375rem 0.875rem;
  background: var(--paper);
  border: var(--border);
  border-radius: 999px;
  text-align: left;
}

.chip:hover {
  border-color: var(--ink);
}

.chip[aria-disabled="true"] {
  color: var(--ink-2);
  cursor: default;
}

.chat__form {
  display: flex;
  gap: var(--space-2xs);
  padding: var(--space-xs) var(--space-s) var(--space-s);
}

.chat__form input {
  flex: 1;
  min-width: 0;
  min-height: 2.75rem;
  padding-inline: 1rem;
  background: var(--paper);
  border: 1px solid var(--ink-2);
  border-radius: 999px;
  color: var(--ink);
  font: inherit;
  font-size: var(--step-0);
}

.chat__form input::placeholder {
  color: var(--ink-2);
  opacity: 1;
}

.chat__form input:focus-visible {
  outline-offset: 1px;
}

.chat__form input:disabled {
  border-color: var(--line);
}

.chat__send {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: var(--vermilion);
  color: var(--on-accent);
}

.chat__send:hover {
  background: var(--vermilion-press);
}

.chat__send:disabled {
  background: var(--line);
  color: var(--ink-2);
  cursor: default;
}

.chat__send .arrow {
  width: 1.125rem;
  height: 1.125rem;
  color: inherit;
}

.chat__noscript {
  padding: 0 var(--space-s) var(--space-s);
  color: var(--ink-2);
}

@media (min-width: 600px) {
  .chat__head,
  .chat__chips,
  .chat__form {
    padding-inline: var(--space-m);
  }

  .chat__log {
    padding-inline: var(--space-m);
  }
}
