:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-synthesis: none;
  --header: #163d35;
  --header-text: #ffffff;
  --chat-background: #e8eeeb;
  --incoming: #ffffff;
  --outgoing: #d9f8c5;
  --text: #17201d;
  --muted: #64716c;
  --border: #d6dfdc;
  --action: #157a66;
  --focus: #5bb8ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--chat-background);
  color: var(--text);
}

button,
[contenteditable="true"] {
  font: inherit;
}

.demo-app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--chat-background);
}

.conversation-header {
  min-height: 66px;
  display: grid;
  grid-template-columns: 40px 42px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left));
  background: var(--header);
  color: var(--header-text);
  box-shadow: 0 2px 8px rgb(13 43 37 / 20%);
  z-index: 2;
}

.back-button,
.reset-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.back-button {
  text-decoration: none;
}

.back-button:hover,
.reset-button:hover {
  background: rgb(255 255 255 / 12%);
}

.back-button svg,
.reset-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #f1b61c;
  color: #26332f;
  font-size: 13px;
  font-weight: 800;
}

.conversation-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.conversation-copy strong,
.conversation-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-copy strong {
  font-size: 16px;
}

.conversation-copy span {
  color: rgb(255 255 255 / 72%);
  font-size: 12px;
}

.reset-button {
  position: relative;
}

.reset-button::after {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: max-content;
  max-width: 180px;
  padding: 6px 8px;
  border-radius: 5px;
  background: #101513;
  color: #fff;
  content: attr(data-tooltip);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-3px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.reset-button:hover::after,
.reset-button:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.message-list {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px max(18px, calc((100% - 860px) / 2)) 24px;
  background-color: var(--chat-background);
  background-image:
    linear-gradient(45deg, rgb(62 109 94 / 3%) 25%, transparent 25%),
    linear-gradient(-45deg, rgb(62 109 94 / 3%) 25%, transparent 25%);
  background-position: 0 0, 12px 12px;
  background-size: 24px 24px;
  scrollbar-gutter: stable;
}

.date-divider {
  display: flex;
  justify-content: center;
  margin: 2px 0 16px;
}

.date-divider span {
  padding: 5px 10px;
  border-radius: 8px;
  background: #f8fbfa;
  color: var(--muted);
  font-size: 12px;
  box-shadow: 0 1px 2px rgb(20 47 39 / 9%);
}

.message-in,
.message-out {
  width: 100%;
  display: flex;
  margin: 5px 0;
}

.message-in {
  justify-content: flex-start;
}

.message-out {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(76%, 620px);
  padding: 9px 11px 7px;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgb(20 47 39 / 12%);
}

.message-in .message-bubble {
  background: var(--incoming);
  border-top-left-radius: 3px;
}

.message-out .message-bubble {
  background: var(--outgoing);
  border-top-right-radius: 3px;
}

.message-text {
  min-width: 0;
  font-size: 15px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-meta {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 3px;
  color: #6d7a75;
  font-size: 10px;
  line-height: 1;
}

.message-out .status {
  color: #188bd0;
  font-weight: 800;
}

.composer-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 10px max(14px, calc((100% - 900px) / 2)) max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: #f7f9f8;
}

.message-composer {
  min-height: 44px;
  max-height: 132px;
  overflow-y: auto;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: #fff;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.message-composer:empty::before {
  color: #87918d;
  content: attr(data-placeholder);
  pointer-events: none;
}

.message-composer:focus {
  border-color: #4d9b8c;
  box-shadow: 0 0 0 3px rgb(77 155 140 / 18%);
}

.send-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--action);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.send-button:hover {
  background: #106a58;
}

.send-button:active {
  background: #0d594b;
}

.send-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.back-button:focus-visible,
.reset-button:focus-visible,
.send-button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (max-width: 520px) {
  .conversation-header {
    grid-template-columns: 36px 38px minmax(0, 1fr) 36px;
    gap: 8px;
  }

  .back-button,
  .reset-button {
    width: 36px;
    height: 36px;
  }

  .avatar {
    width: 38px;
    height: 38px;
  }

  .message-list {
    padding-inline: 10px;
  }

  .message-bubble {
    max-width: 86%;
  }

  .send-button {
    width: 44px;
    padding: 0;
  }

  .send-button span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reset-button::after {
    transition: none;
  }
}
