/* ═══════════════════ CHATS LIST SCREEN ═══════════════════ */
#screen-chats {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100dvh;
  display: none;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  background: #F3F4F6;
  z-index: 9;
}

#screen-chats.active {
  display: flex !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

#screen-chats .m-scroll {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow-y: auto;
  box-sizing: border-box;
  margin-top: 8px;
  margin-bottom: 80px;
  background: #FFFFFF;
}

/* ═══════════════════ CHAT SCREEN ═══════════════════ */
#screen-chat {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  background: #FFFFFF;
  height: 100%;
  overflow: hidden;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px;
  background: #FFFFFF;
  border-bottom: 4px solid #F3F4F6;
  flex-shrink: 0;
  z-index: 10;
}
body.platform-ios .chat-header,
body.platform-android .chat-header {
  padding-top: max(
    calc(env(safe-area-inset-top, 0px) * 1.4 + 24px),
    calc(var(--tg-content-safe-area-inset-top, 0px) * 1.4 + 24px)
  );
}
.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #E5E5EA;
  flex-shrink: 0;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}
.chat-header-text {
  flex: 1;
  min-width: 0;
}
.chat-seller-name {
  font-family: 'Onest', sans-serif;
  font-size: 17px;
  font-weight: 600;
  color: #1C1C1E;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-online {
  font-family: 'Onest', sans-serif;
  font-size: 12px;
  color: #34C759;
  margin-top: 1px;
}
.chat-menu-btn {
  background: none;
  border: none;
  padding: 4px 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

/* Ad preview card */
.chat-ad-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 16px 0;
  padding: 8px 12px;
  background: #EAE8FF;
  border-radius: 12px;
  flex-shrink: 0;
}
.chat-ad-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #FFFFFF;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}
.chat-ad-info {
  flex: 1;
  min-width: 0;
}
.chat-ad-title {
  font-family: 'Onest', sans-serif;
  font-size: 13px;
  color: #1C1C1E;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}
.chat-ad-price {
  font-family: 'Onest', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: #1C1C1E;
  margin-top: 2px;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-messages > *:first-child {
  margin-top: auto;
}
.chat-messages::-webkit-scrollbar { display: none; }

/* Chats list populated state */
.chats-list {
  display: flex;
  flex-direction: column;
  gap: 0; /* Chat items are 72px tall with internal padding, creating their own spacing */
  width: 100%;
}

.chat-item {
  position: relative;
  width: 100%;
  height: 72px; 
}

/* Delete Button (underneath) */
.chat-item-delete-btn {
  position: absolute;
  top: 0;
  right: 12px;
  width: 72px;
  height: 72px;
  background-color: #FF383C;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-family: 'Onest', sans-serif;
  font-size: 14px;
  font-weight: 500;
  z-index: 1;
}

/* Chat content (what gets swiped) */
.chat-item-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #FFFFFF;
  padding: 0 12px;
  box-sizing: border-box;
  z-index: 2;
  transition: transform 0.2s ease-out, background-color 0.2s ease-out;
  border-radius: 12px;
}
.chat-item.swiping .chat-item-content {
  transition: none; /* Disable transition during drag */
}
.chat-item.swiped-left .chat-item-content {
  transform: translateX(-92px); /* 72px button + 12px right + 8px gap = 92px */
}

/* Swipe states */
.chat-item.swiping .chat-item-content,
.chat-item.swiped-left .chat-item-content {
  background-color: rgba(99, 92, 251, 0.12); /* 12% opacity purple from Figma */
}

.chat-item-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: #E3E3E3;
  flex-shrink: 0;
  object-fit: cover;
}

.chat-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}

.chat-name {
  font-family: 'Onest', sans-serif;
  font-size: 14px;
  font-weight: 500;
  line-height: 18px;
  color: #000000;
}

.chat-msg {
  font-family: 'Onest', sans-serif;
  font-size: 12px;
  font-weight: 400;
  line-height: 15px;
  color: #000000;
}

.chat-time {
  font-family: 'Onest', sans-serif;
  font-size: 12px;
  font-weight: 400;
  line-height: 15px;
  color: #8E8E93;
  align-self: flex-start;
  margin-top: 13.5px; /* Offset from top to match 121.5 y-coord vs 116 y-coord avatar top. Center of text block */
}

/* Empty state */
.chats-empty {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  box-sizing: border-box;
  text-align: center;
}

.chats-empty-title {
  font-family: 'Onest', sans-serif;
  font-size: 28px;
  font-weight: 600;
  color: #000000;
  margin-bottom: 12px;
  line-height: 1.25;
  letter-spacing: -1.12px;
  text-align: center;
}

.chats-empty-subtitle {
  font-family: 'Onest', sans-serif;
  font-size: 14px;
  font-weight: 500;
  color: #9CA3AF;
  line-height: 1.275;
  letter-spacing: -0.28px;
  max-width: 290px;
  margin: 0 auto;
  text-align: center;
}

/* Message bubbles */
.chat-msg {
  display: flex;
  max-width: 80%;
  margin-bottom: 2px;
}
.chat-msg--sent {
  align-self: flex-end;
}
.chat-msg--received {
  align-self: flex-start;
}
.chat-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-family: 'Onest', sans-serif;
  font-size: 15px;
  line-height: 1.4;
  position: relative;
  z-index: 0;
  word-wrap: break-word;
}

/* Sent Style */
.chat-msg--sent .chat-bubble {
  background: #635CFB;
  color: #FFFFFF;
  border-radius: 18px 18px 0 18px;
}
.chat-msg--sent .chat-bubble::before {
  content: "";
  position: absolute;
  bottom: 0;
  right: -8px;
  height: 20px;
  width: 20px;
  background: #635CFB;
  border-bottom-left-radius: 16px;
  z-index: -1;
}
.chat-msg--sent .chat-bubble::after {
  content: "";
  position: absolute;
  bottom: 0;
  right: -10px;
  height: 20px;
  width: 10px;
  background: #FFFFFF;
  border-bottom-left-radius: 10px;
  z-index: -1;
}

/* Received Style */
.chat-msg--received .chat-bubble {
  background: #F2F2F7;
  color: #1C1C1E;
  border-radius: 18px 18px 18px 0;
}
.chat-msg--received .chat-bubble::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: -8px;
  height: 20px;
  width: 20px;
  background: #F2F2F7;
  border-bottom-right-radius: 16px;
  z-index: -1;
}
.chat-msg--received .chat-bubble::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: -10px;
  height: 20px;
  width: 10px;
  background: #FFFFFF;
  border-bottom-right-radius: 10px;
  z-index: -1;
}



/* Input bar */
/* ── Фото в сообщениях ── */
.chat-bubble--photo {
  padding: 4px;
  position: relative;
}
.chat-bubble-img {
  display: block;
  width: 220px;
  height: 220px;
  border-radius: 12px;
  object-fit: cover;
  cursor: pointer;
  background: #F2F2F7; /* плейсхолдер, пока фото грузится */
}
.chat-bubble-img--sending {
  opacity: 0.6;
}
.chat-bubble--photo .chat-bubble-time {
  position: absolute;
  right: 10px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  padding: 1px 6px;
  border-radius: 8px;
}
#chat-photo-viewer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.92);
  align-items: center;
  justify-content: center;
}
#chat-photo-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  background: #FFFFFF;
  flex-shrink: 0;
}
.chat-input-wrapper {
  display: flex;
  align-items: center;
  flex: 1;
  background: #FFFFFF;
  border: 1px solid #E5E5EA;
  border-radius: 16px;
  height: 48px;
  padding: 0 16px;
  box-sizing: border-box;
}
.chat-attach-btn {
  background: none;
  border: none;
  padding: 0;
  margin-right: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0;
  height: 100%;
  font-family: 'Onest', sans-serif;
  font-size: 15px;
  color: #000000;           /* набираемый текст — чёрный */
  caret-color: #635CFB;     /* мигающая каретка — фирменный фиолетовый */
  outline: none;
  -webkit-appearance: none;
}
.chat-input::placeholder { color: #8E8E93; }
.chat-send-btn {
  background: none;
  border: 1px solid #E5E5EA;
  border-radius: 16px;
  width: 48px;
  height: 48px;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  transition: transform 0.15s;
}
.chat-send-btn svg {
  pointer-events: none;
}
.chat-send-btn:active { transform: scale(0.9); }
