/* ==========================================================================
   Chat (چت)
   ========================================================================== */

.thread-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-3) var(--s-4);
  text-align: start;
  transition: background var(--dur-fast);
}

.thread-row:active { background: var(--surface); }
.thread-row.is-unread { background: var(--gold-softer); }

.thread-row .tr-avatar { position: relative; flex: none; }

.thread-row .tr-thumb {
  position: absolute;
  bottom: -3px;
  inset-inline-start: -6px;
  width: 26px;
  height: 26px;
  border-radius: var(--r-xs);
  overflow: hidden;
  border: 2px solid var(--bg);
  background: var(--surface-3);
}

.thread-row .tr-body { flex: 1; min-width: 0; }

.thread-row .tr-name {
  font-size: var(--fs-md);
  font-weight: 700;
  margin-bottom: 2px;
}

.thread-row .tr-preview {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.thread-row.is-unread .tr-preview { color: var(--text-2); font-weight: 600; }

.thread-row .tr-side {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s-1);
  flex: none;
  font-size: var(--fs-xs);
  color: var(--text-faint);
}

.unread-dot {
  min-width: 19px;
  height: 19px;
  padding-inline: 5px;
  border-radius: var(--r-full);
  background: var(--grad-gold);
  color: var(--on-gold);
  font-size: 10px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.ticks { display: inline-flex; color: var(--text-faint); }
.ticks.is-read { color: var(--gold-2); }

/* ---- Thread view ---- */
/* Fills the view so `.msg-list` owns the scrolling, not the page. */
.chat-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-context {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-4);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  z-index: var(--z-sticky);
}

.chat-context .cc-thumb {
  width: 44px;
  height: 34px;
  border-radius: var(--r-xs);
  overflow: hidden;
  position: relative;
  flex: none;
  background: var(--surface-3);
}

.chat-context .cc-body { flex: 1; min-width: 0; }
.chat-context .cc-label { font-size: 10px; color: var(--text-faint); }
.chat-context .cc-title { font-size: var(--fs-sm); font-weight: 600; }
.chat-context .cc-price { font-size: var(--fs-xs); color: var(--gold-2); font-weight: 700; }

.msg-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  background:
    radial-gradient(700px 340px at 50% 0%, rgba(245, 166, 35, 0.045), transparent 70%),
    var(--bg);
}

.msg-day {
  align-self: center;
  padding: 3px var(--s-3);
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-faint);
  font-size: var(--fs-xs);
  margin-block: var(--s-2);
}

.bubble {
  max-width: 78%;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  line-height: 1.85;
  position: relative;
  animation: bubble-in var(--dur) var(--ease-out) both;
  word-break: break-word;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98) }
  to   { opacity: 1; transform: none }
}

.bubble-in {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-start-start-radius: var(--r-xs);
  color: var(--text);
}

.bubble-out {
  align-self: flex-end;
  background: var(--grad-gold);
  color: var(--on-gold);
  border-start-end-radius: var(--r-xs);
}

.bubble .b-time {
  display: flex;
  align-items: center;
  gap: 3px;
  justify-content: flex-start;
  font-size: 10px;
  opacity: 0.72;
  margin-top: 2px;
}

.bubble.has-image {
  padding: 5px;
  width: min(76%, 270px);
}

.bubble-image {
  width: 100%;
  max-height: 310px;
  object-fit: cover;
  border-radius: calc(var(--r-md) - 3px);
  background: var(--surface-3);
}

.bubble-caption {
  padding: 5px var(--s-2) 0;
  white-space: pre-wrap;
}

.bubble.has-image .b-time { padding-inline: var(--s-2); }

.bubble-out .b-time { justify-content: flex-start; }

.typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: var(--s-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  border-start-start-radius: var(--r-xs);
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typing 1s infinite;
}

.typing i:nth-child(2) { animation-delay: 0.15s }
.typing i:nth-child(3) { animation-delay: 0.3s }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0) }
  30%           { opacity: 1;   transform: translateY(-3px) }
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  padding-bottom: calc(var(--s-2) + var(--safe-b));
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  flex: none;
}

.composer-wrap {
  flex: none;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}

.composer-wrap .composer { border-top: 0; }

.composer-safety-message {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  margin: var(--s-2) var(--s-3) 0;
  padding: var(--s-3);
  border: 1px solid rgba(225, 76, 76, 0.28);
  border-radius: var(--r-md);
  color: var(--danger);
  background: var(--danger-soft);
}

.composer-safety-message > svg {
  margin-top: 2px;
  flex: none;
}

.composer-safety-message > span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.composer-safety-message strong {
  font-size: var(--fs-xs);
}

.composer-safety-message small {
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.7;
}

.composer.is-blocked textarea {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.composer.moderation-shake {
  animation: moderation-shake 260ms ease-out;
}

@keyframes moderation-shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-5px); }
  65% { transform: translateX(4px); }
}

/* The composer is text-only; `.bubble.has-image` above stays so threads saved
   before attachments were removed still render. */

.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 110px;
  min-height: 42px;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: var(--fs-sm);
  line-height: 1.7;
  resize: none;
}

.composer textarea:focus { border-color: var(--gold-1); }

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--r-full);
  background: var(--grad-gold);
  color: var(--on-gold);
  display: grid;
  place-items: center;
  flex: none;
  transition: transform var(--dur-fast), opacity var(--dur-fast);
}

.send-btn:active { transform: scale(0.9); }
.send-btn:disabled { opacity: 0.4; }
