/* ═══════════════════ 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;
  /* Буква-заглушка (span) должна стоять по центру кружка, а не в углу */
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.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;
  font-weight: 500;
  line-height: 18px;
  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; }

/* Empty state */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #8E8E93;
  text-align: center;
  padding: 40px 20px;
}
.chat-empty-icon {
  font-size: 48px;
  opacity: 0.5;
}
.chat-empty-text {
  font-family: 'Onest', sans-serif;
  font-size: 15px;
  color: #8E8E93;
}

/* 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-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); }

/* ─── Global Loader ─── */
.global-loader {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.global-loader.active {
  opacity: 1;
  visibility: visible;
}
.dot-flashing {
  display: flex;
  gap: 6px;
}
.dot-flashing div {
  width: 12px; height: 12px;
  background-color: #635CFB;
  border-radius: 50%;
  animation: dotFlashing 0.6s infinite alternate;
}
.dot-flashing div:nth-child(2) { animation-delay: 0.2s; }
.dot-flashing div:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotFlashing {
  0% { background-color: #635CFB; opacity: 1; transform: scale(1); }
  100% { background-color: #EAE8FF; opacity: 0.3; transform: scale(0.8); }
}

/* ── Favorites Panel ───────────────────────────────────────────────────────── */
.favorites-panel {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  background: #F3F4F6;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 50;
}

/* Избранное Header */
.fav-header {
  background: #FFFFFF;
  flex-shrink: 0;
  z-index: 10;
  position: sticky;
  top: 0;
}
.fav-header-inner {
  display: flex;
  height: 48px;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  margin-top: var(--app-title-margin, 0px);
}
.fav-title {
  font-family: 'Onest', sans-serif;
  font-weight: 600;
  font-size: 16px;
  color: #000;
  flex: 1;
  text-align: center;
}
.fav-header-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* Content Container */
.fav-content-wrap {
  flex: 1;
  padding: 12px 0 88px 0; /* 12px top, 88px bottom for tab bar */
  background: #FFFFFF;
  border-radius: 8px 8px 0 0;
  margin: 4px 0 0 0;
}

/* Пустое избранное — дизайн Figma 4042-69.
   column, чтобы .favs-empty (flex:1) занял всю высоту и отцентрировался;
   на сетке карточек не сказывается (grid не сжимаем — flex-shrink:0) */
#favorites-panel .fav-content-wrap {
  display: flex;
  flex-direction: column;
}
#favorites-panel #favorites-grid { flex-shrink: 0; }
.favs-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* увеличенный нижний отступ смещает центрируемый блок выше середины */
  padding: 20px 12px 120px 12px;
  text-align: center;
}
.favs-empty-img {
  width: 232px;
  height: 232px;
  /* у картинки снизу прозрачное поле (~34px) — отрицательным отступом
     подтягиваем текст ближе к рисунку, чтобы блок не «провисал» */
  margin-bottom: -8px;
}
.favs-empty-title {
  font-family: 'Onest', sans-serif;
  font-weight: 700;
  font-size: 24px;
  line-height: 31px;
  color: #000;
  margin-bottom: 12px;
}
.favs-empty-desc {
  font-family: 'Onest', sans-serif;
  font-weight: 400;
  font-size: 14px;
  line-height: 18px;
  color: #8E8E93;
  max-width: 302px;
}

/* Badges */
.ad-badge {
  position: absolute;
  display: flex;
  align-items: center;
  color: #fff;
  z-index: 2;
}
.ad-badge-red {
  top: 8px;
  left: 8px;
  background: #FF383C;
  gap: 4px;
  padding: 2px 8px 2px 4px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 400;
}
.ad-badge-red svg {
  width: 18px;
  height: 18px;
}
.ad-badge-green {
  top: 0;
  left: 0;
  background: #34C759;
  padding: 3px 6px;
  border-radius: 16px 0 8px 0;
  font-size: 10px;
  font-weight: 500;
}

/* Hide Scrollbar */
.favorites-panel::-webkit-scrollbar {
  display: none;
}
.favorites-panel {
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
}

/* Heart Icon Overlay */
.ad-heart-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  cursor: pointer;
  backdrop-filter: none;
  box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.08);
}
.ad-heart-btn svg {
  width: 16px;
  height: 16px;
  fill: #FFFFFF;
}



