:root {
  --bg: #d7e9bd;
  --pat: rgba(112, 148, 94, 0.18);
  --out: #e7ffd0;
  --in: #ffffff;
  --txt: #1f1f1f;
  --checks: #5cb6f6;
  --muted: #87928a;
  --header-bg: rgba(255, 255, 255, 0.96);
  --header-line: rgba(0, 0, 0, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--txt);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 20px 20px, var(--pat) 0 2px, transparent 3px),
    radial-gradient(circle at 90px 40px, var(--pat) 0 2px, transparent 3px),
    radial-gradient(circle at 150px 120px, var(--pat) 0 2px, transparent 3px),
    radial-gradient(circle at 250px 80px, var(--pat) 0 2px, transparent 3px),
    radial-gradient(circle at 350px 160px, var(--pat) 0 2px, transparent 3px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.06));
  background-size: 180px 180px, 210px 210px, 240px 240px, 260px 260px, 280px 280px, cover;
  overflow: hidden;
}

button { font: inherit; }

.chat-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-top {
  flex: none;
  height: 72px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-line);
  backdrop-filter: blur(10px);
}

.head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: radial-gradient(circle at 42% 40%, #1b4f72 0 12%, #081321 28%, #122e4b 47%, #000 62%, #16344f 76%, #6eb4d7 100%);
  position: relative;
  overflow: hidden;
  flex: none;
}

.avatar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(0, 0, 0, 0.75) 0 24%, transparent 35%);
}

.title-wrap { min-width: 0; }
.title-wrap h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.title-wrap p {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 0 18px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}

.flow {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 0 clamp(10px, 2vw, 18px) 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bot-card-row,
.row {
  display: flex;
  width: 100%;
  content-visibility: auto;
  contain-intrinsic-size: 280px;
}

.bot-card-row { justify-content: center; margin-top: 2px; }
.row.out { justify-content: flex-end; }
.row.in { justify-content: flex-start; }

.day {
  align-self: center;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(122, 177, 122, 0.78);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  margin: 4px 0 10px;
}

.bot-card {
  width: min(420px, 100%);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  background: #fff;
}

.bot-card-image,
.media-button {
  display: block;
  width: min(var(--media-w, 100%), 100%);
  max-width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
  contain: layout paint style;
}

.bot-card-image,
.media-frame {
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(255,255,255,.35), rgba(0,0,0,.04));
}

.bot-card-image img,
.media-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .18s ease;
}

.bot-card-image img.is-loaded,
.media-button img.is-loaded {
  opacity: 1;
}

.bot-card-body {
  padding: 10px 12px 12px;
  background: #fff;
}
.bot-card-body h3 { margin: 0 0 8px; font-size: 13px; font-weight: 700; }
.bot-card-body p { margin: 0; font-size: 12px; line-height: 1.45; white-space: pre-wrap; }

.bubble {
  position: relative;
  max-width: min(560px, 92%);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.bubble.text-only {
  padding: 10px 12px 11px;
  white-space: pre-wrap;
  line-height: 1.38;
  font-size: 14px;
}
.bubble.with-media,
.bubble.single-media,
.bubble.album {
  padding: 6px;
}
.row.out .bubble { background: var(--out); border-top-right-radius: 4px; }
.row.in .bubble { background: var(--in); border-top-left-radius: 4px; }

.row.out .bubble::before,
.row.in .bubble::before {
  content: "";
  position: absolute;
  top: 0;
  width: 10px;
  height: 12px;
  background: inherit;
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}
.row.out .bubble::before { right: -8px; }
.row.in .bubble::before { left: -8px; transform: scaleX(-1); }

.text-content { white-space: pre-wrap; word-break: break-word; }
.caption-text {
  padding: 8px 6px 0;
  font-size: 14px;
  line-height: 1.38;
  white-space: pre-wrap;
}

.single-media .media-button,
.with-media .media-button {
  aspect-ratio: var(--media-ratio, auto);
}

.album-grid {
  display: grid;
  gap: 2px;
  overflow: hidden;
  border-radius: 12px;
  width: min(var(--album-w, 100%), 100%);
  max-width: 100%;
}
.album-grid button { width: 100%; height: 100%; }
.album-3-grid {
  grid-template-columns: 2fr 1fr;
  grid-template-rows: 1fr 1fr;
  aspect-ratio: 294 / 418;
}
.album-3-grid button:first-child { grid-row: 1 / span 2; }
.album-2-grid {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr;
  aspect-ratio: 418 / 304;
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: 12px;
  color: #7d8b86;
  white-space: nowrap;
}
.row.out .meta-row { color: #87a38d; }
.meta-row.overlay {
  position: absolute;
  right: 10px;
  bottom: 9px;
  margin-top: 0;
  padding: 2px 6px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.78);
}
.row.out .meta-row.overlay { background: rgba(231, 255, 208, 0.86); }
.status { color: var(--checks); letter-spacing: -1px; }
.edited { color: #8d9893; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.74);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 99;
}
.lightbox.open { display: flex; }
.lb-card {
  width: min(1180px, 100%);
  max-height: 92vh;
  overflow: hidden;
  border-radius: 16px;
  background: rgba(14, 18, 24, 0.98);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}
.lb-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  color: #f3f6fb;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.lb-head button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
.lb-body {
  padding: 16px;
  overflow: auto;
  background: #0f141b;
}
.lb-body img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: calc(92vh - 150px);
  margin: 0 auto;
  border-radius: 12px;
  background: #fff;
}
.lb-body p {
  margin: 12px 4px 0;
  color: #f5f8ff;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

@media (max-width: 768px) {
  .chat-top { height: 64px; padding: 0 12px; }
  .avatar { width: 38px; height: 38px; }
  .title-wrap h1 { font-size: 16px; }
  .title-wrap p { font-size: 12px; }
  .flow { padding-inline: 10px; }
  .bubble { max-width: 92%; }
  .bubble.text-only,
  .caption-text { font-size: 13px; }
  .meta-row { font-size: 11px; }
}

@media (max-width: 480px) {
  .flow { padding-inline: 8px; }
  .bot-card { border-radius: 14px; }
  .lb-body { padding: 12px; }
}
