/* ============================================================
   CRM Chat — Telegram Web/Desktop/Mobile uslubi
   Light/dark: var(--...). Backend/realtime TEGilmaydi.
   ============================================================ */

.page-chat {
  --tg-bubble: #3390ec;
  --tg-bubble-2: #54a3ff;
  --tg-pattern: color-mix(in srgb, var(--text) 4%, transparent);
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  overflow: hidden !important;
  height: 100%;
  height: 100dvh;
  max-height: 100%;
  min-height: 0;
}

:root[data-theme="dark"] .page-chat {
  --tg-bubble: #2b84d2;
  --tg-bubble-2: #3d9ae8;
}
/* Avto-dark faqat tizim dark bo'lsa (app.css bilan mos) — aks holda chat
   yorug' rejimda qora bo'lib qolardi. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .page-chat {
    --tg-bubble: #2b84d2;
    --tg-bubble-2: #3d9ae8;
  }
}

.chat-app {
  display: flex;
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.chat-sidebar {
  width: 360px;
  max-width: 42vw;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
  z-index: 2;
}

.chat-side-h {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
  flex-shrink: 0;
}
.chat-side-h h2 {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  letter-spacing: -.02em;
}

.chat-side-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 10px;
  padding: 9px 14px;
  border-radius: 22px;
  background: var(--surface-2);
  border: 1px solid transparent;
  flex-shrink: 0;
  transition: border-color .12s, box-shadow .12s;
}
.chat-side-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.chat-side-search .i { color: var(--text-3); font-size: 16px; }
.chat-side-search input {
  flex: 1;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--text);
  font-size: 14px;
}

.chat-conv-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.chat-conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  min-height: 68px;
  cursor: pointer;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  color: inherit;
  transition: background .12s ease;
}
.chat-conv-item:hover { background: var(--surface-2); }
.chat-conv-item:active { transform: scale(.995); }
.chat-conv-item.active { background: var(--accent-soft); }

.chat-av {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 650;
  font-size: 15px;
  flex-shrink: 0;
  user-select: none;
}
.chat-av .dot-on {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #4caf50;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px color-mix(in srgb, #4caf50 30%, transparent);
}

.chat-conv-meta { flex: 1; min-width: 0; }
.chat-conv-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}
.chat-conv-name {
  font-weight: 650;
  font-size: 15px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-conv-time {
  font-size: 12px;
  color: var(--text-3);
  flex-shrink: 0;
}
.chat-conv-bot {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-conv-prev {
  flex: 1;
  font-size: 13px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-unread {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--tg-bubble);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-muted-ic { color: var(--text-3); font-size: 14px; }

/* ── Thread main ── */
.chat-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  z-index: 1;
}

.chat-empty-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-2);
  padding: 40px;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 40%, color-mix(in srgb, var(--accent) 6%, transparent), transparent 55%),
    var(--bg);
}
.chat-empty-main .i { font-size: 56px; color: var(--text-3); opacity: .55; }
.chat-empty-main strong { color: var(--text); font-size: 17px; font-weight: 650; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 56px;
  z-index: 4;
}
.chat-head-back {
  display: none;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  border-radius: 12px;
  color: var(--text);
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-head-back:hover { background: var(--surface-2); }
.chat-head-back:active { transform: scale(.96); }
.chat-head-info { flex: 1; min-width: 0; }
.chat-head-name {
  font-weight: 650;
  font-size: 15.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-head-sub {
  font-size: 12.5px;
  color: var(--text-2);
  min-height: 16px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-head-sub.typing { color: var(--accent); }
.chat-head-sub.online { color: #4caf50; }
.chat-head-actions { display: flex; gap: 2px; }

.chat-icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: 0;
  background: transparent;
  border-radius: 12px;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s, transform .12s;
}
.chat-icon-btn:hover { background: var(--surface-2); color: var(--text); }
.chat-icon-btn:active { transform: scale(.96); }
.chat-icon-btn.on { color: var(--accent); background: var(--accent-soft); }

/* Typing 3 dots */
.chat-typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  margin-left: 2px;
}
.chat-typing-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  display: block;
  animation: chatDotWave 1.2s ease-in-out infinite;
}
.chat-typing-dots i:nth-child(2) { animation-delay: .15s; }
.chat-typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes chatDotWave {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-3px); opacity: 1; }
}
.chat-bubble-typing {
  padding: 10px 14px !important;
  min-width: 52px;
}
.chat-typing-bubble {
  margin-top: 4px;
  margin-bottom: 2px;
}
.chat-typing-bubble .chat-typing-dots i {
  width: 6px;
  height: 6px;
  background: var(--text-2);
}

/* Messages wallpaper */
.chat-msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 12% 18%, var(--tg-pattern) 1.2px, transparent 1.5px),
    radial-gradient(circle at 72% 42%, var(--tg-pattern) 1px, transparent 1.3px),
    radial-gradient(circle at 38% 78%, var(--tg-pattern) 1.1px, transparent 1.4px),
    linear-gradient(180deg,
      color-mix(in srgb, var(--bg) 88%, #dce3ec) 0%,
      var(--bg) 40%,
      color-mix(in srgb, var(--bg) 90%, #cfd8e6) 100%);
  background-size: 48px 48px, 64px 64px, 56px 56px, 100% 100%;
}
:root[data-theme="dark"] .chat-msgs {
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,.035) 1.2px, transparent 1.5px),
    radial-gradient(circle at 72% 42%, rgba(255,255,255,.028) 1px, transparent 1.3px),
    linear-gradient(180deg, #0f141c 0%, #121820 50%, #0e131a 100%);
  background-size: 48px 48px, 64px 64px, 100% 100%;
}
/* Avto-dark faqat tizim dark rejimida (aks holda yorug'da chat qora bo'lardi) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chat-msgs {
    background-image:
      radial-gradient(circle at 12% 18%, rgba(255,255,255,.035) 1.2px, transparent 1.5px),
      radial-gradient(circle at 72% 42%, rgba(255,255,255,.028) 1px, transparent 1.3px),
      linear-gradient(180deg, #0f141c 0%, #121820 50%, #0e131a 100%);
    background-size: 48px 48px, 64px 64px, 100% 100%;
  }
}

.chat-day {
  align-self: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border: 0;
  padding: 4px 12px;
  border-radius: 999px;
  margin: 10px 0 6px;
  position: sticky;
  top: 6px;
  z-index: 2;
  backdrop-filter: blur(8px);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.chat-row {
  display: flex;
  width: 100%;
  position: relative;
  touch-action: pan-y;
  content-visibility: auto;
  contain-intrinsic-size: 0 48px;
}
.chat-row.mine { justify-content: flex-end; }
.chat-row.theirs { justify-content: flex-start; }
.chat-row.grouped { margin-top: 0; }
.chat-row.grouped .chat-bubble { border-radius: 12px; }
.chat-row.mine.grouped .chat-bubble { border-bottom-right-radius: 12px; }
.chat-row.theirs.grouped .chat-bubble { border-bottom-left-radius: 12px; }
.chat-row.tail .chat-bubble { /* last in group keeps tail corner */ }
.chat-row.mine.tail .chat-bubble { border-bottom-right-radius: 4px; }
.chat-row.theirs.tail .chat-bubble { border-bottom-left-radius: 4px; }
.chat-row.grouped:not(.tail) .chat-meta { display: none; }

.chat-row.enter {
  animation: chatMsgIn .22s cubic-bezier(.2,.8,.2,1) both;
}
.chat-row.mine.enter {
  animation-name: chatMsgInMine;
}
.chat-row.theirs.enter {
  animation-name: chatMsgInTheirs;
}
@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to { opacity: 1; transform: none; }
}
@keyframes chatMsgInMine {
  from { opacity: 0; transform: translate(12px, 8px) scale(.94); }
  to { opacity: 1; transform: none; }
}
@keyframes chatMsgInTheirs {
  from { opacity: 0; transform: translate(-12px, 8px) scale(.94); }
  to { opacity: 1; transform: none; }
}

/* Swipe-to-reply hint */
.chat-swipe-reply {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%) scale(.5);
  opacity: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--tg-bubble);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: opacity .15s ease, transform .18s cubic-bezier(.2,.9,.3,1.2);
  box-shadow: 0 1px 4px rgba(0,0,0,.14);
  will-change: transform, opacity;
}
.chat-row.swiping .chat-swipe-reply {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}
.chat-row.mine .chat-swipe-reply { left: auto; right: 8px; }
.chat-bubble.swiping {
  transition: none !important;
  will-change: transform;
}
.chat-bubble.snap-back {
  transition: transform .28s cubic-bezier(.2,.9,.3,1.15) !important;
}

.chat-bubble {
  max-width: min(72%, 520px);
  padding: 6px 10px 4px;
  border-radius: 12px;
  position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  word-break: break-word;
  transition: transform .12s ease, box-shadow .12s ease;
}
.chat-bubble:active { transform: scale(.985); }

.chat-row.mine .chat-bubble {
  background: linear-gradient(160deg, var(--tg-bubble) 0%, var(--tg-bubble-2) 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-row.theirs .chat-bubble {
  background: var(--surface);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-hover-reply {
  display: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%) scale(.85);
  opacity: 0;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-2);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
  z-index: 2;
  transition: opacity .14s ease, transform .14s cubic-bezier(.2,.9,.3,1.2), background .12s, color .12s;
}
.chat-row.mine .chat-hover-reply { left: -38px; }
.chat-row.theirs .chat-hover-reply { right: -38px; }
@media (hover: hover) and (pointer: fine) {
  .chat-row:hover .chat-hover-reply {
    display: inline-flex;
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }
  .chat-hover-reply:hover { background: var(--accent-soft); color: var(--tg-bubble); }
  .chat-hover-reply:active { transform: translateY(-50%) scale(.9); }
}

.chat-bubble.deleted {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none;
  color: var(--text-3) !important;
  font-style: italic;
  padding: 4px 2px;
}
.chat-reply {
  display: block;
  border-left: 3px solid color-mix(in srgb, currentColor 55%, transparent);
  padding: 3px 8px;
  margin: 0 0 4px;
  border-radius: 0 6px 6px 0;
  background: color-mix(in srgb, currentColor 10%, transparent);
  font-size: 12.5px;
  opacity: .92;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.chat-text {
  font-size: 14.5px;
  line-height: 1.35;
  white-space: pre-wrap;
}
.chat-meta {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  margin-left: 8px;
  float: right;
  font-size: 11px;
  opacity: .72;
  line-height: 1;
  position: relative;
  top: 2px;
}
.chat-row.mine .chat-meta { color: rgba(255,255,255,.85); }
.chat-ticks .i { font-size: 14px; vertical-align: -2px; }
.chat-ticks.read { color: #9ad0ff; }
.chat-ticks.delivered { opacity: .75; }
.chat-row.theirs .chat-ticks.read { color: var(--accent); }
.chat-bubble.err { outline: 1px solid var(--red); }
.chat-retry {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
  margin-left: 6px;
}

.chat-audio {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  max-width: 280px;
}
.chat-audio-play-wrap {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}
.chat-audio-ring {
  position: absolute;
  inset: 0;
  width: 44px;
  height: 44px;
  transform: rotate(-90deg);
  pointer-events: none;
}
.chat-audio-ring-bg {
  fill: none;
  stroke: color-mix(in srgb, currentColor 18%, transparent);
  stroke-width: 2.5;
}
.chat-audio-ring-fg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: stroke-dashoffset .08s linear;
  opacity: .95;
}
.chat-audio-play {
  position: absolute;
  inset: 3px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  background: color-mix(in srgb, currentColor 14%, transparent);
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .12s, background .12s;
  z-index: 1;
}
.chat-audio-play:active { transform: scale(.94); }
.chat-audio-play .i { font-size: 18px; }
.chat-row.mine .chat-audio-play { background: rgba(255,255,255,.18); }
.chat-row.theirs .chat-audio-play { background: color-mix(in srgb, var(--tg-bubble) 16%, transparent); color: var(--tg-bubble); }
.chat-row.theirs .chat-audio-ring-fg { stroke: var(--tg-bubble); }
.chat-audio-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-audio-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
/* Yuklanish/bufer spinner (Telegram uslubi) */
.chat-audio-play.loading .i,
.chat-audio.uploading .chat-audio-play .i { opacity: .25; }
.chat-audio-play.loading::after,
.chat-audio.uploading .chat-audio-play::after {
  content: '';
  position: absolute;
  inset: 5px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: chatSpin .7s linear infinite;
}
@keyframes chatSpin { to { transform: rotate(360deg); } }
.chat-wave {
  flex: 1;
  height: 28px;
  display: flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.chat-wave span {
  flex: 1;
  min-width: 2px;
  border-radius: 2px;
  background: currentColor;
  opacity: .45;
  height: 30%;
  transition: height .12s ease, opacity .12s;
}
.chat-wave span.on { opacity: .95; }
.chat-audio-dur { font-size: 11px; opacity: .8; min-width: 34px; }
.chat-audio-speed {
  border: 0;
  background: color-mix(in srgb, currentColor 12%, transparent);
  color: inherit;
  border-radius: 8px;
  padding: 2px 6px;
  font-size: 11px;
  cursor: pointer;
}
.chat-offline-bar {
  flex-shrink: 0;
  padding: 6px 12px;
  background: color-mix(in srgb, var(--amber) 18%, var(--surface));
  color: var(--text);
  font-size: 12.5px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.chat-offline-bar.online-flash {
  background: color-mix(in srgb, var(--green, #2ecc71) 16%, var(--surface));
}
.chat-ctx {
  position: fixed;
  z-index: 80;
  min-width: 168px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 4px;
  transform-origin: top left;
  animation: chatCtxIn .16s cubic-bezier(.2,.9,.3,1.15) both;
}
@keyframes chatCtxIn {
  from { opacity: 0; transform: scale(.88); }
  to { opacity: 1; transform: scale(1); }
}
.chat-ctx button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  color: var(--text);
  text-align: left;
  min-height: 40px;
  transition: background .1s ease, transform .1s ease;
}
.chat-ctx button:hover { background: var(--surface-2); }
.chat-ctx button:active { transform: scale(.98); }
.chat-ctx button.danger { color: var(--red); }

.chat-composer-wrap {
  flex-shrink: 0;
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  z-index: 5;
}
.chat-reply-bar[hidden] { display: none !important; }
.chat-reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--surface-2);
  border-radius: 12px;
  border-left: 3px solid var(--tg-bubble);
  font-size: 12.5px;
  transform-origin: bottom center;
  animation: chatReplyIn .2s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes chatReplyIn {
  from { opacity: 0; transform: translateY(8px) scaleY(.92); }
  to { opacity: 1; transform: none; }
}
.chat-reply-bar > span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
}
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}
.chat-composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  min-height: 42px;
  padding: 11px 14px;
  border-radius: 22px;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  line-height: 1.35;
  font-size: 14.5px;
  transition: border-color .12s, box-shadow .12s;
  scrollbar-width: none;         /* Firefox */
  -ms-overflow-style: none;      /* IE/Edge */
}
.chat-composer textarea::-webkit-scrollbar { width: 0; height: 0; display: none; }
.chat-composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
/* [hidden] atributi display:flex ni yenga olishi uchun (matn bor bo'lsa mic
   yashirinsin, bo'sh bo'lsa send yashirinsin). */
.chat-send[hidden], .chat-mic[hidden],
.chat-composer [hidden] { display: none !important; }
.chat-send, .chat-mic {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--tg-bubble);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--tg-bubble) 35%, transparent);
  transition: transform .14s cubic-bezier(.2,.9,.3,1.15), background .14s, box-shadow .14s;
  touch-action: none;
}
.chat-send.morph, .chat-mic.morph {
  animation: chatBtnMorph .22s cubic-bezier(.2,.9,.3,1.2) both;
}
@keyframes chatBtnMorph {
  0% { transform: scale(.72) rotate(-8deg); opacity: .6; }
  60% { transform: scale(1.08) rotate(2deg); opacity: 1; }
  100% { transform: none; }
}
.chat-send:hover, .chat-mic:hover { background: var(--tg-bubble-2); }
.chat-send:active, .chat-mic:active { transform: scale(.92); }
.chat-mic.rec {
  background: var(--red);
  animation: chatPulse 1s ease infinite;
  transform: scale(1.06);
}
.chat-mic.locked {
  background: var(--amber);
  animation: none;
  transform: scale(1.04);
}
@keyframes chatPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,72,72,.45); }
  50% { box-shadow: 0 0 0 10px rgba(220,72,72,0); }
}

.chat-rec-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  min-height: 44px;
  will-change: transform;
  transition: transform .08s linear, background .15s ease;
  animation: chatRecIn .18s ease-out both;
  border-radius: 12px;
}
@keyframes chatRecIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.chat-rec-bar .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: chatPulse 1s ease infinite;
  flex-shrink: 0;
}
.chat-rec-wave {
  flex: 1;
  height: 28px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  min-width: 80px;
}
.chat-rec-wave i {
  display: block;
  width: 3px;
  border-radius: 2px;
  background: var(--tg-bubble);
  height: 18%;
  transition: height .08s linear;
}
.chat-rec-hint { font-size: 12.5px; color: var(--text-2); flex: 1; transition: color .12s, transform .12s; white-space: nowrap; }
.chat-rec-bar.cancel {
  background: color-mix(in srgb, var(--red) 10%, transparent);
}
.chat-rec-bar.cancel .chat-rec-hint { color: var(--red); transform: translateX(-4px); }
.chat-rec-bar.lock,
.chat-rec-bar.chat-rec-locked {
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  animation: chatLockPop .22s cubic-bezier(.2,.9,.3,1.2) both;
}
.chat-rec-bar.lock .chat-rec-hint { color: var(--amber); }
@keyframes chatLockPop {
  0% { transform: translateY(6px) scale(.96); }
  100% { transform: none; }
}
.chat-rec-lock-hint {
  position: absolute;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%) scale(.8);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s, transform .12s, color .12s, background .12s;
  z-index: 6;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.chat-rec-lock-hint.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
  color: var(--amber);
  border-color: var(--amber);
}
.chat-rec-trash, .chat-rec-send {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .12s, background .12s;
}
.chat-rec-trash {
  background: color-mix(in srgb, var(--red) 14%, var(--surface));
  color: var(--red);
}
.chat-rec-send {
  background: var(--tg-bubble);
  color: #fff;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--tg-bubble) 35%, transparent);
}
.chat-rec-trash:active, .chat-rec-send:active { transform: scale(.92); }
.chat-composer-wrap { position: relative; }
.chat-rec-timer { font-variant-numeric: tabular-nums; font-size: 13px; min-width: 36px; color: var(--text-2); }
.chat-rec-locked .chat-rec-timer { color: var(--text); font-weight: 600; }

.chat-main-inner {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chat-fab-bottom {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text);
  z-index: 3;
  opacity: 0;
  transform: scale(.72) translateY(8px);
  transition: opacity .2s ease, transform .22s cubic-bezier(.2,.9,.3,1.2);
}
.chat-fab-bottom.show {
  display: inline-flex;
  opacity: 1;
  transform: scale(1) translateY(0);
  animation: chatFabBounce .38s cubic-bezier(.2,.9,.3,1.25);
}
@keyframes chatFabBounce {
  0% { transform: scale(.72) translateY(8px); }
  55% { transform: scale(1.08) translateY(-2px); }
  100% { transform: scale(1) translateY(0); }
}
.chat-fab-bottom:active { transform: scale(.92); }
.chat-fab-bottom .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--tg-bubble);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: chatBadgePop .28s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes chatBadgePop {
  from { transform: scale(.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.chat-blocked-banner {
  padding: 12px 14px;
  background: var(--red-bg);
  color: var(--red);
  font-size: 13px;
  text-align: center;
  border-top: 1px solid var(--border);
}

.chat-new-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  min-height: 56px;
  cursor: pointer;
  border: 0;
  width: 100%;
  background: transparent;
  text-align: left;
  color: inherit;
}
.chat-new-user:hover { background: var(--surface-2); }

.chat-link { color: inherit; text-decoration: underline; word-break: break-all; }
.chat-row.mine .chat-link { color: #e8f0ff; }

.chat-img {
  max-width: 260px;
  max-height: 320px;
  border-radius: 10px;
  cursor: pointer;
  display: block;
}
.chat-file-dl {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: color-mix(in srgb, currentColor 8%, transparent);
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
  font-size: 13px;
}
.chat-file-dl small { opacity: .7; margin-left: auto; }

.chat-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; clear: both; }
.chat-react-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: transform .14s cubic-bezier(.2,.9,.3,1.15);
}
.chat-react-chip:active { transform: scale(1.18); }
.chat-react-chip.mine { border-color: var(--accent); background: var(--accent-soft); }
.chat-react-chip.pop { animation: chatReactPop .28s cubic-bezier(.2,.9,.3,1.2); }
@keyframes chatReactPop {
  0% { transform: scale(.45); opacity: .5; }
  55% { transform: scale(1.22); opacity: 1; }
  100% { transform: scale(1); }
}

.chat-float-heart {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  font-size: 42px;
  line-height: 1;
  transform: translate(-50%, -50%);
  animation: chatFloatHeart .78s cubic-bezier(.2,.7,.2,1) forwards;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.18));
  will-change: transform, opacity;
}
@keyframes chatFloatHeart {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(.35); }
  18% { opacity: 1; transform: translate(-50%, -55%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -140%) scale(1.05); }
}

.chat-react-bar, .chat-emoji-pop {
  position: fixed;
  z-index: 90;
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  transform-origin: bottom center;
  animation: chatReactBarIn .18s cubic-bezier(.2,.9,.3,1.2) both;
}
@keyframes chatReactBarIn {
  from { opacity: 0; transform: translateY(8px) scale(.88); }
  to { opacity: 1; transform: none; }
}
.chat-emoji-pop { flex-wrap: wrap; max-width: 280px; border-radius: 14px; }
.chat-emoji-pop button, .chat-react-bar button {
  border: 0;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  transition: transform .14s cubic-bezier(.2,.9,.3,1.2);
}
.chat-emoji-pop button:hover, .chat-react-bar button:hover {
  background: var(--surface-2);
  transform: scale(1.18) translateY(-2px);
}
.chat-emoji-pop button:active, .chat-react-bar button:active { transform: scale(1.28); }

.chat-unread-divider {
  align-self: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 14px;
  border-radius: 999px;
  margin: 8px 0;
  animation: chatDividerIn .22s ease-out both;
}
@keyframes chatDividerIn {
  from { opacity: 0; transform: scale(.9); }
  to { opacity: 1; transform: none; }
}
.chat-highlight .chat-bubble {
  animation: chatHighlight 1.6s ease;
}
@keyframes chatHighlight {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, #ffe082 0%, transparent); }
  12% { box-shadow: inset 0 0 0 999px color-mix(in srgb, #ffe082 38%, transparent); }
  100% { box-shadow: inset 0 0 0 999px transparent; }
}
.chat-ticks {
  display: inline-flex;
  transition: color .2s ease, opacity .2s ease, transform .18s ease;
}
.chat-ticks.flash { animation: chatTickFlash .28s ease; }
@keyframes chatTickFlash {
  0% { transform: scale(.85); opacity: .5; }
  100% { transform: none; opacity: 1; }
}

.chat-side-label { padding: 6px 14px; font-size: 11px; color: var(--text-3); font-weight: 600; }
.chat-side-empty { padding: 12px 14px; color: var(--text-2); }
.chat-search-hit {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  color: inherit;
}
.chat-search-hit:hover { background: var(--surface-2); }
.chat-block-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.chat-composer-wrap.drag-over {
  outline: 2px dashed var(--accent);
  border-radius: 12px;
}

.top-icon.chat-btn .badge {
  position: absolute;
  top: 0;
  right: 0;
  transform: translate(35%, -35%);
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--tg-bubble);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* Thread open: hide bottom nav on mobile */
body.chat-thread-open .bottom-nav { display: none !important; }
body.chat-thread-open .page { padding-bottom: 0 !important; }

/* Mobile */
@media (max-width: 899px) {
  .page-chat { height: 100%; max-height: calc(100dvh - 0px); }
  .chat-sidebar {
    width: 100%;
    max-width: none;
    border-right: 0;
    position: absolute;
    inset: 0;
    transform: translateX(0);
    transition: transform .22s ease-out, opacity .22s ease-out;
    z-index: 2;
  }
  .chat-main {
    position: absolute;
    inset: 0;
    transform: translateX(100%);
    transition: transform .22s ease-out;
    z-index: 3;
    display: flex !important;
    background: var(--bg);
  }
  .chat-app.thread-open .chat-sidebar {
    transform: translateX(-28%);
    opacity: .55;
    pointer-events: none;
  }
  .chat-app.thread-open .chat-main {
    transform: translateX(0);
  }
  .chat-head-back { display: inline-flex; }
  .chat-bubble { max-width: 85%; }
  .chat-conv-item { min-height: 72px; padding: 12px 16px; }
  .chat-icon-btn { width: 44px; height: 44px; }
  .chat-hover-reply { display: none !important; }
}

@media (min-width: 900px) {
  .chat-sidebar,
  .chat-app.thread-open .chat-sidebar { display: flex; position: relative; transform: none; opacity: 1; pointer-events: auto; }
  .chat-main {
    display: flex !important;
    position: relative;
    transform: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-row.enter,
  .chat-row.mine.enter,
  .chat-row.theirs.enter,
  .chat-fab-bottom,
  .chat-fab-bottom.show,
  .chat-react-chip.pop,
  .chat-ctx,
  .chat-react-bar,
  .chat-emoji-pop,
  .chat-reply-bar,
  .chat-rec-bar,
  .chat-send.morph,
  .chat-mic.morph,
  .chat-float-heart,
  .chat-highlight .chat-bubble,
  .chat-unread-divider,
  .chat-app .chat-sidebar,
  .chat-app .chat-main,
  .chat-pin-bar,
  .chat-lightbox,
  .chat-select-bar,
  .chat-unfurl,
  .chat-lead-card {
    animation: none !important;
    transition: none !important;
  }
  .chat-typing-dots i { animation: none; opacity: .7; }
}

/* —— Features 1–15 —— */
.chat-conv-item.pinned { background: color-mix(in srgb, var(--pri, #2aabee) 6%, transparent); }
.chat-pin-ic { font-size: 11px; margin-right: 4px; opacity: .85; }

.chat-pin-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--surface-2, #f0f2f5);
  border-bottom: 1px solid var(--border, #e4e6eb);
  animation: chatSheetIn .2s cubic-bezier(.2,.8,.2,1);
}
.chat-pin-bar[hidden] { display: none !important; }
.chat-pin-bar-main {
  flex: 1; display: flex; align-items: center; gap: 8px;
  border: 0; background: transparent; cursor: pointer; text-align: left;
  color: var(--text); font: inherit; min-width: 0;
}
.chat-pin-bar-ic { color: var(--pri, #2aabee); flex-shrink: 0; }
.chat-pin-bar-text {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; font-weight: 500;
}
.chat-pin-bar-x {
  border: 0; background: transparent; cursor: pointer; padding: 6px;
  color: var(--text-2); border-radius: 8px;
}
.chat-pin-bar-x:hover { background: var(--surface); }

.chat-fwd {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--pri, #2aabee); font-weight: 600;
  margin-bottom: 4px; opacity: .95;
}
.chat-video {
  max-width: min(280px, 72vw); max-height: 360px; border-radius: 10px;
  background: #000; display: block;
}
.chat-unfurl {
  display: flex; gap: 8px; margin-top: 6px; text-decoration: none; color: inherit;
  border-radius: 10px; overflow: hidden; background: color-mix(in srgb, var(--text) 6%, transparent);
  max-width: 280px; animation: chatSheetIn .18s cubic-bezier(.2,.8,.2,1);
}
.chat-unfurl-img { width: 64px; height: 64px; object-fit: cover; flex-shrink: 0; }
.chat-unfurl-body { padding: 6px 8px; min-width: 0; }
.chat-unfurl-title { font-size: 13px; font-weight: 600; line-height: 1.25; }
.chat-unfurl-desc {
  font-size: 11.5px; color: var(--text-2); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.chat-unfurl-host { font-size: 11px; color: var(--text-3, #8899a6); margin-top: 2px; }

.chat-lead-card {
  display: block; margin-top: 6px; padding: 8px 10px; border-radius: 10px;
  text-decoration: none; color: inherit;
  background: color-mix(in srgb, var(--pri, #2aabee) 10%, transparent);
  border-left: 3px solid var(--pri, #2aabee);
  animation: chatSheetIn .2s cubic-bezier(.2,.8,.2,1);
}
.chat-lead-card-title { font-size: 13px; font-weight: 600; }
.chat-lead-card-stage { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.chat-lead-card-open { font-size: 12px; color: var(--pri, #2aabee); margin-top: 4px; font-weight: 600; }

.chat-lightbox {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center;
  animation: chatSheetIn .2s cubic-bezier(.2,.8,.2,1);
}
.chat-lightbox-img {
  max-width: min(96vw, 1100px); max-height: 88vh; object-fit: contain;
  border-radius: 4px; user-select: none;
}
.chat-lightbox-close {
  position: absolute; top: 12px; right: 14px; width: 44px; height: 44px;
  border: 0; border-radius: 50%; background: rgba(255,255,255,.12); color: #fff;
  font-size: 28px; cursor: pointer; line-height: 1;
}
.chat-lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.12); color: #fff; font-size: 28px; cursor: pointer;
}
.chat-lightbox-nav.prev { left: 12px; }
.chat-lightbox-nav.next { right: 12px; }
.chat-lightbox-cap {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 13px; opacity: .85;
}

.chat-select-bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--surface); border-top: 1px solid var(--border, #e4e6eb);
  animation: chatSheetIn .2s cubic-bezier(.2,.8,.2,1);
}
.chat-select-bar[hidden] { display: none !important; }
.chat-select-count { flex: 1; font-size: 13px; font-weight: 600; }
.chat-row.select-mode { padding-left: 36px; }
.chat-row.selected .chat-bubble {
  outline: 2px solid var(--pri, #2aabee); outline-offset: 1px;
}
.chat-sel-check {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--text-2);
  background: var(--surface); font-size: 12px; line-height: 18px; text-align: center;
  padding: 0; cursor: pointer; color: #fff;
}
.chat-sel-check.on { background: var(--pri, #2aabee); border-color: var(--pri, #2aabee); }
.chat-row { position: relative; }

.chat-global-hit {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; text-align: left; padding: 10px 14px; border: 0; background: transparent;
  cursor: pointer; color: inherit; font: inherit;
}
.chat-global-hit:hover { background: var(--surface-2); }
.chat-global-hit-name { font-size: 13px; font-weight: 600; }
.chat-global-hit-text {
  font-size: 12.5px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.chat-global-hit-time { font-size: 11px; color: var(--text-3, #8899a6); }

.chat-fwd-list { display: flex; flex-direction: column; gap: 4px; max-height: 360px; overflow: auto; }
.chat-fwd-item {
  display: flex; align-items: center; gap: 10px; padding: 8px; border: 0;
  background: transparent; cursor: pointer; border-radius: 10px; font: inherit; color: inherit; text-align: left;
}
.chat-fwd-item:hover { background: var(--surface-2); }

.chat-media-tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.chat-media-tab {
  border: 0; border-radius: 999px; padding: 6px 12px; font-size: 12.5px;
  background: var(--surface-2); cursor: pointer; color: var(--text);
}
.chat-media-tab.on { background: var(--pri, #2aabee); color: #fff; }
.chat-media-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  max-height: 360px; overflow: auto;
}
.chat-media-cell {
  aspect-ratio: 1; border: 0; border-radius: 8px; overflow: hidden;
  background: var(--surface-2); cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  font-size: 22px; color: var(--text);
}
.chat-media-cell img { width: 100%; height: 100%; object-fit: cover; }
.chat-media-cell span { font-size: 10px; margin-top: 4px; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-typing-mic { margin-right: 4px; }

@keyframes chatSheetIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
