/* ReiSource messenger-style expanded chat
   Load AFTER /styles.css.
*/

/* Compact intake state stays as a normal side drawer. */
.chat-drawer {
  width: min(440px, calc(100vw - 24px));
  transition:
    width 0.35s ease,
    height 0.35s ease,
    max-height 0.35s ease,
    transform 0.35s ease;
}

/* Once the conversation starts, use the full viewport height. */
.chat-drawer.chat-drawer--active {
  top: 0;
  right: 0;
  bottom: 0;
  width: min(760px, 100vw);
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header and status stay fixed while the message history scrolls. */
.chat-drawer--active .chat-header,
.chat-drawer--active .availability {
  flex: 0 0 auto;
}

.chat-drawer--active #chatConversation {
  flex: 1;
  min-height: 0;
  display: flex !important;
  flex-direction: column;
  overflow: hidden;
}

/* Messenger-like conversation area. */
.chat-drawer--active .chat-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Existing /script.js renders:
   .chat-message.user
   .chat-message.assistant
*/
.chat-thread .chat-message {
  position: relative;
  width: fit-content;
  max-width: min(78%, 560px);
  padding: 12px 15px;
  margin: 0;
  border: 0;
  font-size: 0.96rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.chat-thread .chat-message p {
  margin: 0;
}

.chat-thread .chat-message.user {
  align-self: flex-end;
  margin-left: auto;
  background: #111;
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

.chat-thread .chat-message.assistant {
  align-self: flex-start;
  margin-right: auto;
  background: #ecece7;
  color: #111;
  border-radius: 18px 18px 18px 4px;
}

/* Small bubble tails, kept deliberately subtle. */
.chat-thread .chat-message.user::after {
  content: "";
  position: absolute;
  right: -4px;
  bottom: 0;
  width: 10px;
  height: 10px;
  background: #111;
  clip-path: polygon(0 0, 100% 100%, 0 100%);
}

.chat-thread .chat-message.assistant::after {
  content: "";
  position: absolute;
  left: -4px;
  bottom: 0;
  width: 10px;
  height: 10px;
  background: #ecece7;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

/* Thinking state behaves like an assistant bubble. */
.chat-thread .chat-message.assistant.thinking {
  opacity: 0.7;
  font-style: italic;
}

/* Any service link stays visually attached to the AI bubble. */
.chat-thread .chat-service-link {
  display: inline-block;
  margin-top: 9px;
  color: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Composer stays pinned at the bottom, like a messenger app. */
.chat-drawer--active .agent-chat-form {
  flex: 0 0 auto;
  margin: 0;
  padding: 16px 20px 20px;
  background: #fff;
  border-top: 1px solid rgba(17, 17, 17, 0.14);
}

.chat-drawer--active .agent-chat-form > label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chat-drawer--active #chatInput {
  min-height: 66px;
  max-height: 150px;
  resize: vertical;
  border-radius: 18px;
  padding: 14px 16px;
}

.chat-drawer--active .chat-actions {
  margin-top: 10px;
}

/* Handoff card can sit between thread and composer without taking over. */
.chat-drawer--active .handoff-panel {
  flex: 0 0 auto;
  margin: 0 20px 14px;
  padding: 14px 16px;
  border: 1px solid rgba(17, 17, 17, 0.16);
  background: #f7f7f2;
}

/* Email validation feedback. */
#chatEmail[aria-invalid="true"] {
  border-color: #b42318;
  outline-color: #b42318;
}

.field-error {
  min-height: 1.1em;
  margin: 6px 0 0;
  color: #b42318;
  font-size: 0.78rem;
  line-height: 1.3;
}

.field-error:empty {
  display: none;
}

/* Active conversation becomes full screen on smaller devices too. */
@media (max-width: 700px) {
  .chat-drawer.chat-drawer--active {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
  }

  .chat-drawer--active .chat-thread {
    padding-left: 14px;
    padding-right: 14px;
  }

  .chat-thread .chat-message {
    max-width: 86%;
  }
}
