:root {
  --primary-pink: #ff7eb3;
  --soft-pink: #ffdee9;
  --online-green: #00ff88;
  --glass: rgba(255, 255, 255, 0.82);
  --bubble-me: linear-gradient(135deg, #ff7eb3, #ff758c);
  --bubble-them: #ffffff;
  --text-muted: #888;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Helvetica Neue", sans-serif;
  background: #f5f0f2;
  color: #333;
  -webkit-tap-highlight-color: transparent;
}

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: linear-gradient(180deg, var(--soft-pink) 0%, #f8f4f6 28%, #f0ecee 100%);
  position: relative;
  overflow: hidden;
}

.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 2px 12px rgba(255, 126, 179, 0.12);
  z-index: 10;
}

.btn-back {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #555;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-back:active {
  transform: scale(0.94);
}

.peer-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.peer-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.peer-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #fff;
  box-shadow: 0 4px 10px rgba(255, 126, 179, 0.25);
}

.peer-led {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  background: var(--online-green);
  border: 2px solid #fff;
  border-radius: 50%;
}

.peer-text h1 {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.peer-text p {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.peer-text p.online {
  color: #2ecc71;
}

.btn-more {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #999;
  font-size: 18px;
  letter-spacing: 2px;
  cursor: pointer;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 12px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.time-divider {
  text-align: center;
  font-size: 11px;
  color: #aaa;
  margin: 8px 0 16px;
}

.msg-row {
  display: flex;
  margin-bottom: 14px;
  align-items: flex-end;
  gap: 8px;
}

.msg-row.them {
  flex-direction: row;
}

.msg-row.me {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.msg-row.me .msg-avatar {
  display: none;
}

.msg-bubble-wrap {
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row.me .msg-bubble-wrap {
  align-items: flex-end;
}

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.msg-row.them .bubble {
  background: var(--bubble-them);
  border-bottom-left-radius: 4px;
  color: #333;
}

.msg-row.me .bubble {
  background: var(--bubble-me);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble.bubble-rich {
  padding: 8px;
  min-width: 0;
}

.bubble-media-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  max-width: 240px;
}

.bubble-media-grid.single {
  grid-template-columns: 1fr;
}

.bubble-media {
  display: block;
  width: 100%;
  max-width: 220px;
  max-height: 160px;
  object-fit: cover;
  border-radius: 12px;
  vertical-align: middle;
}

.bubble-media-grid .bubble-media {
  max-width: none;
  max-height: 118px;
  aspect-ratio: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bubble-media:active {
  opacity: 0.92;
}

.img-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(0, 0, 0, 0.92);
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 12px
    max(12px, env(safe-area-inset-bottom));
  animation: lightboxIn 0.22s ease;
}

.img-lightbox.open {
  display: flex;
}

@keyframes lightboxIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.img-lightbox-close {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  z-index: 2;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.img-lightbox-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.img-lightbox-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: pan-x pan-y pinch-zoom;
}

.msg-row.me .bubble-media {
  border: 2px solid rgba(255, 255, 255, 0.35);
}

.bubble-caption {
  margin-top: 8px;
  padding: 2px 6px 4px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
}

.msg-row.me .bubble-caption {
  color: #fff;
}

.msg-row.them .bubble-caption {
  color: #333;
}

.bubble-caption:empty {
  display: none;
}

.bubble-link {
  display: block;
  margin-top: 10px;
  padding: 9px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  line-height: 1.3;
  box-shadow: 0 4px 12px rgba(255, 117, 140, 0.35);
}

.msg-row.them .bubble-link {
  background: linear-gradient(90deg, #ff7eb3, #ff758c);
  color: #fff;
}

.msg-row.me .bubble-link {
  background: rgba(255, 255, 255, 0.95);
  color: #ff5a94;
}

.bubble-link:active {
  opacity: 0.9;
  transform: scale(0.98);
}

.bubble-rich.text-only {
  padding: 10px 14px;
}

.bubble-rich.text-only .bubble-caption {
  margin-top: 0;
}

.msg-row.msg-enter {
  opacity: 0;
  transform: translateY(10px);
}

.msg-row.msg-enter-active {
  animation: msgEnterPop 0.35s ease forwards;
}

@keyframes msgEnterPop {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-time {
  font-size: 10px;
  color: #bbb;
  padding: 0 4px;
}

.typing-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-left: 44px;
}

.typing-indicator.show {
  display: flex;
}

.typing-dots {
  background: #fff;
  padding: 10px 14px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: #ccc;
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-5px);
  }
}

.chat-composer {
  flex-shrink: 0;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255, 255, 255, 0.5);
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer-input-wrap {
  flex: 1;
  background: #fff;
  border-radius: 22px;
  border: 1px solid rgba(255, 126, 179, 0.25);
  padding: 8px 14px;
  min-height: 42px;
  max-height: 120px;
  display: flex;
  align-items: center;
}

.composer-input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  max-height: 96px;
  font-family: inherit;
  color: #333;
}

.composer-input::placeholder {
  color: #bbb;
}

.btn-send {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff7eb3, #ff758c);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 117, 140, 0.45);
  transition: transform 0.15s;
}

.btn-send:disabled {
  opacity: 0.45;
  box-shadow: none;
}

.btn-send:not(:disabled):active {
  transform: scale(0.92);
}

.quick-replies {
  display: flex;
  gap: 8px;
  padding: 0 12px 8px;
  overflow-x: auto;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.quick-replies::-webkit-scrollbar {
  display: none;
}

.quick-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 126, 179, 0.35);
  background: rgba(255, 255, 255, 0.85);
  color: #666;
  cursor: pointer;
}

.quick-chip:active {
  background: #fff0f5;
}
