/* Importing Google Fonts - Lexend */
@import url("https://fonts.googleapis.com/css2?family=Lexend:wght@300;400;500;600;700&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Lexend", sans-serif;
}

:root {
  --page: #f5f6fb;
  --surface: #ffffff;
  --text: #191b2a;
  --muted: #6c7089;
  --border: #e6e8f1;
  --brand: #6d5dfc;
  --brand-2: #b05cff;
  --bubble-them: #f1f2f8;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

body {
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[hidden] {
  display: none !important;
}

/* ---------- Demo page ---------- */
.demo {
  max-width: 1000px;
  margin: 0 auto;
  padding: 90px 24px;
}

.eyebrow {
  color: var(--brand);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.demo h1 {
  margin: 14px 0;
  font-size: clamp(2.2rem, 5.5vw, 3.8rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.demo h1 span {
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.demo p {
  max-width: 560px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.demo-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 44px;
}

.demo-cards div {
  height: 200px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
}

/* =========================================================
   Widget
   ========================================================= */
.chat-root {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
}

/* ---------- Launcher ---------- */
.launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: 0 16px 34px -12px rgba(109, 93, 252, 0.8);
  cursor: pointer;
  transition: transform 0.3s var(--ease);
}

.launcher:hover {
  transform: scale(1.06);
}

.launcher:focus-visible,
.head-btn:focus-visible,
.c-btn:focus-visible,
.send:focus-visible,
.chip:focus-visible {
  outline: 3px solid rgba(109, 93, 252, 0.45);
  outline-offset: 2px;
}

.launcher svg {
  position: absolute;
  width: 28px;
  height: 28px;
  transition: transform 0.35s var(--ease), opacity 0.25s;
}

.i-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.launcher[aria-expanded="true"] .i-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.launcher[aria-expanded="true"] .i-close {
  opacity: 1;
  transform: none;
}

.unread {
  position: absolute;
  top: -2px;
  right: -2px;
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 3px solid var(--page);
  border-radius: 999px;
  background: #ef4444;
  font-size: 0.72rem;
  font-weight: 700;
  animation: popIn 0.4s var(--ease);
}

@keyframes popIn {
  from {
    transform: scale(0);
  }
}

/* ---------- Greeting bubble ---------- */
.greeting {
  position: relative;
  max-width: 290px;
  animation: rise 0.45s var(--ease);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
}

.greeting-body {
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 18px 18px 4px 18px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 18px 40px -20px rgba(25, 27, 42, 0.4);
  cursor: pointer;
}

.greeting-body b {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.g-av {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f59e0b;
  color: #fff;
  font-weight: 700;
}

.greeting-close {
  position: absolute;
  top: -10px;
  left: -10px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.65rem;
  cursor: pointer;
}

/* ---------- Chat window ---------- */
/* Positioned above the launcher so a closed chat takes no space */
.chat {
  position: absolute;
  right: 0;
  bottom: 76px;
  display: flex;
  flex-direction: column;
  width: 380px;
  height: min(620px, calc(100vh - 120px));
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 40px 90px -30px rgba(25, 27, 42, 0.45);
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.92);
  transition: opacity 0.25s, transform 0.4s var(--ease), visibility 0.25s;
}

.chat.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px 16px 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
}

.team {
  display: flex;
}

.team span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-right: -10px;
  border: 2px solid #8d6dfd;
  border-radius: 50%;
  background: var(--c);
  font-size: 0.8rem;
  font-weight: 700;
}

.head-text {
  flex: 1;
  min-width: 0;
  margin-left: 14px;
  overflow: hidden;
}

.head-text b {
  display: block;
  overflow: hidden;
  font-size: 0.98rem;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.head-text small {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.74rem;
  font-weight: 300;
  white-space: nowrap;
}

.online {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.3);
}

.head-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
}

.head-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.head-btn svg {
  width: 18px;
  height: 18px;
}

.head-btn[aria-pressed="false"] .wave {
  display: none;
}

.more {
  position: relative;
}

.more-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 5;
  width: 210px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 18px 40px -16px rgba(25, 27, 42, 0.4);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.18s, transform 0.2s var(--ease), visibility 0.18s;
}

.more.is-open .more-menu {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.more-menu button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--text);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.more-menu button:hover {
  background: var(--bubble-them);
}

/* ---------- Messages ---------- */
.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 16px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.day {
  align-self: center;
  margin: 4px 0 10px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bubble-them);
  color: var(--muted);
  font-size: 0.7rem;
}

.system {
  align-self: center;
  margin: 8px 0;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: center;
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 86%;
  animation: msgIn 0.3s var(--ease);
}

.no-anim .msg {
  animation: none;
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.msg.them {
  align-self: flex-start;
}

.msg.me {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.m-av {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c, var(--brand));
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}

.msg.grouped .m-av {
  visibility: hidden;
}

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.9rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.them .bubble {
  border-bottom-left-radius: 6px;
  background: var(--bubble-them);
}

.me .bubble {
  border-bottom-right-radius: 6px;
  background: linear-gradient(135deg, var(--brand), #8a5cff);
  color: #fff;
}

.bubble img {
  display: block;
  max-width: 200px;
  max-height: 200px;
  margin: -4px -8px;
  border-radius: 12px;
}

.meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 2px 4px 8px;
  color: #a2a5b9;
  font-size: 0.68rem;
}

.meta.me {
  align-self: flex-end;
}

.meta.them {
  margin-left: 40px;
}

.ticks {
  letter-spacing: -3px;
  color: #a2a5b9;
}

.ticks.read {
  color: var(--brand);
}

/* Bot card (e.g. pricing) */
.card {
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.card b {
  display: block;
}

.card .price {
  margin: 2px 0 8px;
  color: var(--brand);
  font-weight: 600;
}

.card a {
  display: block;
  padding: 8px;
  border-radius: 10px;
  background: var(--text);
  color: #fff;
  font-size: 0.82rem;
  text-align: center;
  text-decoration: none;
}

/* Quick replies */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 10px 36px;
}

.chip {
  padding: 7px 12px;
  border: 1.5px solid var(--brand);
  border-radius: 999px;
  background: var(--surface);
  color: var(--brand);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.chip:hover {
  background: var(--brand);
  color: #fff;
}

/* Typing indicator */
.typing .bubble {
  display: flex;
  gap: 4px;
  padding: 14px 16px;
}

.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9a9db3;
  animation: blink 1.2s infinite;
}

.typing i:nth-child(2) {
  animation-delay: 0.15s;
}

.typing i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ---------- Emoji panel ---------- */
.emoji-panel {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  margin: 0 12px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 12px 30px -18px rgba(25, 27, 42, 0.4);
  animation: msgIn 0.2s var(--ease);
}

.emoji-panel button {
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 1.25rem;
  cursor: pointer;
}

.emoji-panel button:hover {
  background: var(--bubble-them);
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  margin: 10px 12px 4px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fafbfe;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(109, 93, 252, 0.12);
}

.c-btn {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.c-btn:hover {
  background: var(--bubble-them);
  color: var(--text);
}

.c-btn svg,
.send svg {
  width: 20px;
  height: 20px;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 110px;
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.4;
  resize: none;
  outline: none;
}

.send {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s;
}

.send:disabled {
  opacity: 0.35;
  cursor: default;
}

.send:not(:disabled):active {
  transform: scale(0.9);
}

.powered {
  padding: 6px 0 10px;
  color: #a2a5b9;
  font-size: 0.68rem;
  text-align: center;
}

.powered a {
  color: inherit;
}

/* ---------- Phones: full-screen chat ---------- */
@media (max-width: 520px) {
  .chat-root {
    right: 16px;
    bottom: 16px;
  }

  .chat {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    border-radius: 0;
    transform-origin: bottom center;
  }

  .chat-root:has(.chat.is-open) .launcher {
    display: none;
  }

  .demo-cards {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
