#shopChat {
  position: fixed;
  inset: auto 1rem 1rem auto;
  width: min(27rem, calc(100% - 2rem));
  max-width: none;
  max-height: calc(100dvh - 2rem);
  margin: 0;
  padding: 1rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--paper);
  color: var(--ink);
}

#shopChat[open] {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#shopChat .shop-chat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

#shopChat [hidden] {
  display: none;
}

#shopChatTitle {
  margin: 0;
  font: 700 clamp(1.25rem, 4.5vw, 1.55rem)/1.2 var(--display, system-ui);
}

#shopChat [data-close-shop-chat] {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.5rem;
}

#shopChatIntake {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0.125rem;
}

#shopChat .shop-chat-intro {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
  background: var(--blue-wash);
  line-height: 1.4;
}

#shopChat .shop-chat-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: #007cc3;
  color: #fff;
  font-weight: 700;
}

#shopChat .shop-chat-intro p {
  margin: 0;
}

#shopChat .shop-chat-assistant {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.5rem;
}

#shopChat .shop-chat-assistant span,
#shopChatIntakeForm label span {
  color: var(--muted);
  font-size: 0.85rem;
}

#shopChatIntakeForm {
  display: grid;
  gap: 0.625rem;
}

#shopChatIntakeForm label {
  margin: 0;
}

#shopChatIntakeForm :is(input, select, textarea) {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0.25rem 0 0;
  padding: 0.5rem;
  border: 1px solid var(--brand-grey);
  border-radius: 0.375rem;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

#shopChatIntakeForm textarea {
  max-height: 8rem;
  resize: vertical;
}

#shopChat .shop-chat-intake-actions:not([hidden]) {
  display: flex;
  flex: none;
  justify-content: flex-end;
}

#shopChatIntakeActions button {
  min-height: 44px;
}

#shopChatHandoff {
  margin: 0;
  padding: 0.625rem 0.75rem;
  border-radius: 0.5rem;
  background: var(--blue-wash);
  font-size: 0.9rem;
  line-height: 1.4;
}

#shopChatMessages {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  min-height: 4.25rem;
  max-height: min(45dvh, 22rem);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}

#shopChat .shop-chat-message {
  align-self: flex-start;
  max-width: 95%;
  padding: 0.55rem 0.75rem;
  border-radius: 0.5rem;
  background: var(--wash);
}

#shopChat .shop-chat-message[data-sender="visitor"] {
  align-self: flex-end;
  background: var(--blue-wash);
}

#shopChat .shop-chat-message[data-sender="alex"] {
  border-inline-start: 2px solid var(--brand-blue, #007cc3);
}

#shopChat .shop-chat-message p {
  margin: 0.375rem 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

#shopChat .shop-chat-byline {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.125rem 0.6rem;
  font-size: 0.85rem;
}

#shopChat .shop-chat-byline :is(time, span),
#shopChatStatus {
  color: var(--muted);
}

#shopChatForm {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

#shopChatForm label {
  align-self: stretch;
  margin: 0;
}

#shopChatForm textarea {
  display: block;
  width: 100%;
  min-height: 4.25rem;
  max-height: 9rem;
  margin-top: 0.375rem;
  padding: 0.625rem;
  border: 1px solid var(--brand-grey);
  border-radius: 0.375rem;
  resize: vertical;
}

#shopChat .shop-chat-compose-actions,
#shopChat .shop-chat-follow-up-actions:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem 0.75rem;
}

#shopChat .shop-chat-compose-actions {
  width: 100%;
  justify-content: flex-end;
}

#shopChat .shop-chat-follow-up-actions {
  margin-inline-end: auto;
}

#shopChatForm button {
  min-height: 44px;
}

#shopChatStatus {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

#shopChatStatus:empty {
  display: none;
}

@media (max-width: 36rem) {
  #shopChat {
    inset-inline: 0;
    bottom: 0;
    width: 100%;
    max-height: calc(100dvh - 1rem);
    padding: 0.875rem 1rem calc(0.875rem + env(safe-area-inset-bottom));
    border-radius: 0.75rem 0.75rem 0 0;
  }
}
