:root,
html[data-theme="light"] {
  --canvas: #d9e5ee;
  --chat-bg: #dce7ef;
  --header: #ffffff;
  --composer: #ffffff;
  --bubble: #ffffff;
  --bubble-user: #d9fdd3;
  --text: #111820;
  --muted: #798892;
  --line: rgba(30, 55, 70, .12);
  --tg: #3390ec;
  --tg-soft: rgba(51, 144, 236, .12);
  --shadow: 0 30px 90px rgba(26, 48, 65, .24);
  color-scheme: light;
}

html[data-theme="dark"] {
  --canvas: #07090c;
  --chat-bg: #0e1621;
  --header: #17212b;
  --composer: #17212b;
  --bubble: #182533;
  --bubble-user: #2b5278;
  --text: #f4f5f6;
  --muted: #8494a1;
  --line: rgba(255,255,255,.08);
  --tg: #5da9ef;
  --tg-soft: rgba(93,169,239,.16);
  --shadow: 0 34px 100px rgba(0,0,0,.58);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html,
body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 86px 24px 28px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 12%, var(--tg-soft), transparent 28rem),
    var(--canvas);
}

button,
input { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button { border: 0; cursor: pointer; }

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bot-preview-bar {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 20;
  width: min(calc(100% - 32px), 640px);
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--header) 92%, transparent);
  box-shadow: 0 12px 34px rgba(0,0,0,.12);
  backdrop-filter: blur(18px);
}

.bot-preview-bar a,
.bot-preview-bar button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border-radius: 10px;
  color: var(--tg);
  background: var(--tg-soft);
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
}

.bot-preview-bar span {
  color: var(--muted);
  font-size: 11px;
}

.phone {
  width: min(100%, 390px);
  height: min(844px, calc(100vh - 114px));
  min-height: 650px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border: 10px solid #08090b;
  border-radius: 48px;
  background: var(--chat-bg);
  box-shadow: var(--shadow);
}

.chat-header {
  min-height: 68px;
  display: grid;
  grid-template-columns: 32px 40px 1fr 34px;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  background: var(--header);
}

.back,
.header-menu {
  display: grid;
  place-items: center;
  color: var(--tg);
  background: transparent;
}

.back svg { width: 24px; height: 24px; }
.header-menu svg { width: 22px; height: 22px; }

.bot-avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(145deg, var(--tg), #796bff);
  font-weight: 800;
}

.chat-title {
  min-width: 0;
}

.chat-title strong,
.chat-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-title strong { font-size: 13px; }
.chat-title span { margin-top: 3px; color: var(--muted); font-size: 9.5px; }

.chat {
  overflow: auto;
  padding: 14px 10px 24px;
  background-color: var(--chat-bg);
  background-image:
    radial-gradient(circle at 12px 12px, color-mix(in srgb, var(--muted) 14%, transparent) 1px, transparent 1px);
  background-size: 24px 24px;
  scrollbar-width: none;
}

.chat::-webkit-scrollbar { display: none; }

.date-chip {
  width: max-content;
  margin: 0 auto 12px;
  padding: 5px 9px;
  border-radius: 999px;
  color: #fff;
  background: rgba(75, 100, 118, .58);
  font-size: 9px;
  font-weight: 650;
  backdrop-filter: blur(8px);
}

.message {
  position: relative;
  width: min(84%, 315px);
  margin-bottom: 6px;
  padding: 9px 11px 18px;
  border-radius: 14px 14px 14px 5px;
  color: var(--text);
  background: var(--bubble);
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}

.message.compact { width: max-content; }

.message p {
  margin: 0 0 7px;
  font-size: 12px;
  line-height: 1.42;
}

.message p:last-of-type { margin-bottom: 0; }

.message time {
  position: absolute;
  right: 7px;
  bottom: 4px;
  color: var(--muted);
  font-size: 8px;
}

.user-message {
  margin-left: auto;
  border-radius: 14px 14px 5px 14px;
  background: var(--bubble-user);
}

.menu-grid {
  width: min(90%, 334px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 7px;
}

.menu-button {
  min-height: 62px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  padding: 8px;
  border-radius: 13px;
  color: var(--text);
  background: var(--bubble);
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
  text-decoration: none;
  text-align: center;
}

.menu-button span { font-size: 18px; }
.menu-button strong { font-size: 9.5px; }

.menu-button.primary {
  color: #fff;
  background: var(--tg);
}

.composer {
  display: grid;
  grid-template-columns: 38px 1fr 40px;
  align-items: center;
  gap: 4px;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--composer);
}

.attach,
.send {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: transparent;
}

.attach { color: var(--muted); }
.send { border-radius: 50%; color: #fff; background: var(--tg); }

.attach svg,
.send svg { width: 20px; height: 20px; }

.composer input {
  width: 100%;
  min-height: 38px;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 12px;
}

.composer input::placeholder { color: var(--muted); }

@media (max-width: 560px) {
  body { display: block; padding: 0; background: var(--chat-bg); }
  .bot-preview-bar { display: none; }
  .phone {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .chat-header { padding-top: calc(9px + env(safe-area-inset-top)); }
}
