/* chats.css — «Чаты» веб-приложения (этап 2а): список, тред, композитор,
 * действия, лайтбокс. Только токены kit.css; петли — числа десктопа (точки
 * «печатает…» 0,6 с, скелетон 1,2 с из kit.css). Блоки: ОБЩЕЕ · СПИСОК ·
 * ТРЕД · КОМПОЗИТОР · ДЕЙСТВИЯ. */

/* == ОБЩЕЕ =============================================================== */
/* «Печатает…»: три точки 6 px, цикл 0,6 с, масштаб .67 ↔ 1 (как Telegram и десктоп). */
@keyframes typ-pulse {
  0%, 100% { transform: scale(.67); opacity: .55; }
  50% { transform: scale(1); opacity: 1; }
}
.typ-dots { display: inline-flex; gap: 3px; margin-left: 4px; vertical-align: middle; }
.typ-dots i, .dm-typing-bub i {
  display: block; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: typ-pulse 0.6s ease-in-out infinite;
}
.typ-dots i:nth-child(2), .dm-typing-bub i:nth-child(2) { animation-delay: 0.2s; }
.typ-dots i:nth-child(3), .dm-typing-bub i:nth-child(3) { animation-delay: 0.4s; }
@media (prefers-reduced-motion: reduce) {
  .typ-dots i, .dm-typing-bub i { animation: none; transform: none; opacity: 1; }
}

/* == СПИСОК ============================================================== */
.scr-chats { padding-bottom: 8px; }
.cl-top {
  position: sticky; top: calc(var(--hdr-h) + var(--safe-t)); z-index: 20;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px;
  padding: 8px var(--gutter) 4px; background: var(--bg);
}
.scr-chats.is-archive .cl-top { top: calc(var(--hdr-h) + var(--safe-t) + 52px); }   /* под .sub-head */
.cl-seg {
  position: static; padding: 0; grid-auto-columns: max-content;
  overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain;
}
.cl-seg::-webkit-scrollbar { display: none; }
.cl-seg .seg-b { gap: 6px; padding: 0 14px; }
.cl-seg-n {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent-wash-3); color: var(--panel-fg);
  font-size: 12px; font-weight: 900; line-height: 18px; text-align: center;
}
.cl-shelf {
  display: flex; align-items: center; gap: 12px; min-height: 56px;
  margin: 0 var(--gutter); padding: 0 8px; border-radius: var(--r-4);
  color: var(--ink-mid); font-weight: 800;
  transition: background-color var(--dur-press) linear;
}
.cl-shelf:active { background: var(--accent-wash-2); }
.cl-shelf-ic { display: grid; place-items: center; flex: none; width: 52px; height: 40px; font-size: 22px; }
.cl-shelf-tx { flex: 1; min-width: 0; }
.cl-shelf-n { color: var(--ink-dim); font-size: 13px; }
.cl-shelf.has-unread .cl-shelf-n { color: var(--lav); font-weight: 900; }
.cl-list { display: grid; grid-template-columns: minmax(0, 1fr); }
.cl-row {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 72px;
  padding: 8px var(--gutter); color: var(--panel-fg);
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: pan-y;
  transition: background-color var(--dur-press) linear, translate var(--dur-fast) var(--ease-out);
}
.cl-row:active { background: var(--accent-wash); }
.cl-row.is-swiping { translate: var(--sw, 0px) 0; transition: none; }
.cl-row.is-flip { transition: transform var(--dur-base) var(--ease-out), background-color var(--dur-press) linear; }
.cl-row + .cl-row::before {
  content: ""; position: absolute; top: 0; left: calc(var(--gutter) + 64px); right: 0;
  border-top: 1px solid var(--line);
}
.cl-ava {
  display: grid; place-items: center; flex: none; width: 52px; height: 52px;
  border-radius: 50%; background: var(--accent-wash); overflow: hidden;
}
.cl-emo { font-size: 28px; line-height: 1; }
.cl-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.cl-l1, .cl-l2 { display: flex; align-items: center; gap: 6px; min-width: 0; }
.cl-name {
  flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 16px; font-weight: 900;
}
.cl-fire { flex: none; color: var(--warm-ink); font-size: 12px; font-weight: 900; }
.cl-ic { flex: none; display: inline-grid; color: var(--ink-dim); font-size: 13px; }
.cl-ic .ki { font-size: 15px; }
.cl-time { flex: none; margin-left: auto; padding-left: 6px; color: var(--ink-dim); font-size: 12px; font-weight: 700; }
.cl-prev {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--ink-mid); font-size: 14px;
}
.cl-you { color: var(--panel-fg); font-weight: 800; }
.cl-none { color: var(--ink-dim); font-style: italic; }
.cl-typing { color: var(--lav); font-weight: 800; }
.cl-bdg {
  flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--accent-grad); color: var(--ink-on-accent);
  font-size: 12px; font-weight: 900; line-height: 22px; text-align: center;
}
.cl-bdg.is-muted { background: var(--line-strong); color: var(--panel-fg); }
.cl-bdg.is-dot { min-width: 12px; width: 12px; height: 12px; padding: 0; }
.cl-foot { padding: 0 var(--gutter); }
.cl-foot:empty { display: none; }
@media (prefers-reduced-motion: reduce) {
  .cl-row, .cl-row.is-flip { transition: none; }
}

/* == ТРЕД ================================================================ */
/* Тред — слой во весь видимый экран (visualViewport: --vv-top/--vv-h ставит
 * ui/kbwatch.js): iOS не сжимает раскладку под клавиатуру, слой — сжимается. */
html.in-thread .hdr, html.in-thread .tabbar, html.in-thread .fab { display: none; }
html.in-thread, html.in-thread body { overflow: hidden; overscroll-behavior: none; }
html.in-thread .kt-toast { bottom: calc(80px + var(--kb, 0px)); }
.scr.scr-thread {
  position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); z-index: 30;
  display: flex; flex-direction: column;
  height: var(--vv-h, 100dvh); min-height: 0; max-width: 760px; margin: 0 auto; padding: 0;
  background: var(--bg);
}
.th-head {
  flex: none; display: flex; align-items: center; gap: 2px;
  min-height: calc(56px + var(--safe-t));
  padding: var(--safe-t) calc(4px + var(--safe-r)) 0 calc(4px + var(--safe-l));
  background: var(--bar); border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: saturate(1.4) blur(16px); backdrop-filter: saturate(1.4) blur(16px);
}
.th-who {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: var(--tap);
  padding: 0 4px; border-radius: var(--r-3); color: var(--panel-fg);
  transition: background-color var(--dur-press) linear;
}
a.th-who:active { background: var(--accent-wash-2); }
.th-ava {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px;
  border-radius: 50%; background: var(--accent-wash); overflow: hidden;
}
.th-emo { font-size: 22px; line-height: 1; }
.th-names { min-width: 0; display: grid; }
.th-name { font-size: 16px; line-height: 1.25; }
.th-sub {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--ink-dim); font-size: 12px; font-weight: 700;
}
.th-sub.is-typing { color: var(--lav); }
.th-net {
  flex: none; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-wash-2); color: var(--ink-mid); font-size: 12px; font-weight: 800;
}
.th-pin {
  flex: none; display: flex; align-items: center; gap: 8px; min-height: var(--tap); width: 100%;
  padding: 0 calc(var(--gutter) + var(--safe-r)) 0 calc(var(--gutter) + var(--safe-l));
  border: 0; border-bottom: 1px solid var(--line); background: var(--bg-2); color: var(--ink-soft);
  font: inherit; font-size: 13px; font-weight: 700; text-align: left; cursor: pointer;
}
.th-pin-tx { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.th-scroll {
  position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column;
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; overflow-anchor: none;
  padding: 8px calc(var(--gutter) + var(--safe-r)) 12px calc(var(--gutter) + var(--safe-l));
}
.th-older { flex: none; }
.th-msgs { display: flex; flex-direction: column; margin-top: auto; }
.th-msgs > .es { align-self: center; }
.th-dock { position: relative; flex: none; height: 0; z-index: 2; }
.th-down {
  position: absolute; right: calc(12px + var(--safe-r)); bottom: 12px;
  display: grid; place-items: center; width: var(--tap); height: var(--tap);
  border: 0; border-radius: 50%; background: var(--bg-2); color: var(--lav);
  box-shadow: var(--e2), inset 0 0 0 1px var(--line); cursor: pointer;
  opacity: 0; transform: translateY(8px); pointer-events: none;   /* без scale: тап-цель и спрятанной — 44 px */
  transition: opacity var(--dur-fast) var(--ease-in), transform var(--dur-fast) var(--ease-in);
}
.th-down.is-on {
  opacity: 1; transform: none; pointer-events: auto;
  transition-duration: var(--dur-base); transition-timing-function: var(--ease-pop);
}
.th-down-n { top: -6px; left: auto; right: -4px; }
.th-foot { flex: none; padding-bottom: var(--safe-b); background: var(--bar); border-top: 1px solid var(--line); }
html.kb-open .th-foot { padding-bottom: 0; }
.th-plate {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px;
  min-height: 60px; padding: 8px var(--gutter); text-align: center;
}
.th-plate-tx { margin: 0; color: var(--ink-mid); font-size: 14px; font-weight: 700; }

/* Плашки и строки ленты */
.dm-daysep {
  align-self: center; margin: 12px 0 6px; padding: 3px 12px; border-radius: 999px;
  background: var(--raise-2); box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink-dim); font-size: 12px; font-weight: 900;
}
.dm-unread-line {
  display: flex; align-items: center; gap: 10px; margin: 10px 0 6px;
  color: var(--lav); font-size: 12px; font-weight: 900;
}
.dm-unread-line::before, .dm-unread-line::after { content: ""; flex: 1; border-top: 1px solid var(--accent-wash-3); }
.pk-sys {
  align-self: center; max-width: 86%; margin: 6px 0; padding: 4px 12px; border-radius: 999px;
  background: var(--sink); color: var(--ink-dim); font-size: 12px; font-weight: 800; text-align: center;
}

/* Пузыри (волна F десктопа: свои — справа, хвостик у последнего в серии) */
.chat-msg {
  position: relative; align-self: flex-start; max-width: min(80%, 520px); margin-top: 8px;
  padding: 7px 11px 6px; border-radius: 18px;
  background: var(--raise-2); box-shadow: inset 0 0 0 1px var(--line);
  color: var(--panel-fg); font-size: 15px; line-height: 1.38; overflow-wrap: anywhere;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: pan-y;
  transition: opacity var(--dur-base) var(--ease-out), translate var(--dur-fast) var(--ease-out);
}
.chat-msg.grouped { margin-top: 2px; }
.chat-msg.tail { border-bottom-left-radius: 6px; }
.chat-msg.mine { align-self: flex-end; background: var(--accent-grad); box-shadow: none; color: var(--ink-on-accent); }
.chat-msg.mine.tail { border-bottom-left-radius: 18px; border-bottom-right-radius: 6px; }
.chat-msg.is-swiping { translate: var(--sw, 0px) 0; transition: none; }
.chat-msg.is-stk { padding: 2px 0; background: transparent; box-shadow: none; color: var(--panel-fg); }
.chat-msg.is-stk .dm-meta { color: var(--ink-dim); }
.pk-who { margin-bottom: 2px; color: hsl(var(--nh, 260) var(--nm-s) var(--nm-l)); font-size: 13px; font-weight: 900; }
.dm-fwd { margin-bottom: 2px; opacity: .8; font-size: 12px; font-weight: 800; }
.dm-quote {
  display: grid; width: 100%; min-height: var(--tap); margin: 2px 0 4px; padding: 4px 8px;
  border: 0; border-left: 3px solid currentColor; border-radius: var(--r-1);
  background: color-mix(in srgb, currentColor 10%, transparent); color: inherit;
  font: inherit; font-size: 13px; line-height: 1.3; text-align: left; cursor: pointer;
}
.dm-quote b { font-weight: 900; }
.dm-quote span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
.dm-quote.gone { display: block; min-height: 0; opacity: .7; font-style: italic; cursor: default; }
.dm-text { white-space: pre-wrap; }
.dm-link { color: inherit; text-decoration: underline; }
.dm-img {
  display: block; width: 100%; max-width: 300px; max-height: 360px; margin: 2px 0 4px;
  border-radius: var(--r-3); object-fit: cover; background: var(--sink); cursor: zoom-in;
}
.dm-vid { display: block; max-width: 100%; max-height: 360px; margin: 2px 0 4px; border-radius: var(--r-3); background: var(--sink); }
.dm-circle { display: block; width: 200px; height: 200px; margin: 2px 0 4px; border-radius: 50%; object-fit: cover; background: var(--sink); }
.dm-voice { display: block; width: 240px; max-width: 100%; height: var(--tap); margin: 2px 0; }
.dm-stk { display: block; width: 128px; height: 128px; object-fit: contain; }
.dm-once, .dm-call { font-size: 14px; font-weight: 800; }
.dm-meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 1px;
  color: var(--ink-dim); font-size: 12px;
}
.chat-msg.mine .dm-meta { color: color-mix(in srgb, var(--ink-on-accent) 72%, transparent); }
.dm-meta .ts { font-size: 11px; font-weight: 700; }
.dm-ticks { position: relative; display: inline-block; font-size: 12px; letter-spacing: -2px; }
.dm-ticks.read { color: var(--tick-read); }
.dm-reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.dm-react {
  position: relative; display: inline-flex; align-items: center; gap: 2px; min-height: 30px; padding: 0 9px;
  border: 0; border-radius: 15px; background: color-mix(in srgb, currentColor 12%, transparent);
  color: inherit; font: inherit; font-size: 14px; font-weight: 900; cursor: pointer;
}
.dm-react::before { content: ""; position: absolute; inset: -7px -2px; }   /* поле касания 44 px */
.dm-react.my { box-shadow: inset 0 0 0 2px currentColor; }
.dm-typing-bub {
  align-self: flex-start; display: flex; align-items: center; gap: 4px; margin-top: 8px;
  padding: 12px 14px; border-radius: 18px 18px 18px 6px;
  background: var(--raise-2); box-shadow: inset 0 0 0 1px var(--line); color: var(--lav);
}
.th-msgs > .skeleton { flex: none; }
.sk-bub { align-self: flex-start; width: 60%; height: 38px; margin-top: 8px; border-radius: 18px; }
.sk-bub.mine { align-self: flex-end; }
.sk-bub.short { width: 36%; }

/* Ощущения треда (threaddiff.js): въезд нового, поп новой реакции,
 * кроссфейд галочек, подсветка оригинала цитаты. */
.chat-msg.is-enter { animation: thread-in var(--dur-base) var(--ease-out) both; }
.chat-msg.is-enter-own { animation: thread-own-in var(--dur-base) var(--ease-out) backwards; }
@keyframes thread-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes thread-own-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.dm-react.is-new { animation: react-pop var(--dur-slow) var(--ease-pop); }
@keyframes react-pop { from { transform: scale(.9); } to { transform: none; } }
.dm-ticks.is-swap { animation: tick-in var(--dur-base) var(--ease-out); }
.dm-ticks.is-swap::before {
  content: attr(data-was); position: absolute; inset: 0;
  animation: tick-out var(--dur-base) var(--ease-in) forwards;
}
@keyframes tick-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes tick-out { from { opacity: 1; } to { opacity: 0; } }
.chat-msg.is-hl { animation: msg-hl calc(var(--dur-slow) * 4) var(--ease-out); }
@keyframes msg-hl { from { box-shadow: 0 0 0 3px var(--lav); } to { box-shadow: 0 0 0 3px transparent; } }
@media (prefers-reduced-motion: reduce) {
  .chat-msg.is-enter, .chat-msg.is-enter-own, .dm-react.is-new, .dm-ticks.is-swap,
  .dm-ticks.is-swap::before, .chat-msg.is-hl { animation: none; }
  .dm-ticks.is-swap::before { content: none; }
  .th-down, .th-down.is-on, .chat-msg { transition: none; }
}

/* == КОМПОЗИТОР ========================================================== */
.tbar { display: grid; grid-template-columns: minmax(0, 1fr); padding: 0 calc(var(--gutter) + var(--safe-r)) 0 calc(var(--gutter) + var(--safe-l)); }
.tbar-plate, .tbar-att {
  display: flex; align-items: center; gap: 8px; min-height: 52px; padding-top: 4px;
  border-bottom: 1px solid var(--line);
}
.tbar-plate-ic { flex: none; align-self: stretch; width: 3px; margin: 6px 0; border-radius: 2px; background: var(--lav); }
.tbar-plate-tx { flex: 1; min-width: 0; display: grid; font-size: 13px; line-height: 1.3; }
.tbar-plate-tx b { color: var(--lav); font-weight: 900; }
.tbar-plate-tx span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-mid); }
.tbar-att-img { flex: none; width: 48px; height: 48px; border-radius: var(--r-2); object-fit: cover; background: var(--sink); }
.tbar-att-tx { flex: 1; min-width: 0; color: var(--ink-mid); font-size: 13px; font-weight: 700; }
.tbar-row { display: flex; align-items: flex-end; gap: 4px; padding: 8px 0; }
.tbar-in {
  flex: 1; min-width: 0; min-height: var(--tap); max-height: 152px; padding: 10px 14px; resize: none;
  border: 0; border-radius: 22px; background: var(--raise-2);
  box-shadow: var(--inset-well), inset 0 0 0 1px var(--line);
  color: var(--panel-fg); font-size: 16px; line-height: 22px; outline: none;
}
.tbar-in::placeholder { color: var(--ink-dim); opacity: 1; transition: opacity var(--dur-fast) linear; }
.tbar-in:focus::placeholder { opacity: .5; }
.tbar-in:focus-visible { box-shadow: var(--inset-well), inset 0 0 0 2px var(--lav); }
.tbar-plus { color: var(--ink-mid); }
.tbar-send { color: var(--lav); }
.tbar-send:disabled { color: var(--ink-dim); opacity: .6; }
.tbar-act { display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer; }
.tbar-act .ki { color: var(--lav); font-size: 22px; }
/* Свой пузырь «в полёте» и «не ушло ↻» */
.chat-msg.pending { opacity: .85; }
.chat-msg.pending.failed { opacity: 1; box-shadow: inset 0 0 0 2px var(--danger-ink); }
.dm-state { display: inline-flex; align-items: center; gap: 2px; }
.dm-clock { font-size: 12px; }
.dm-retry, .dm-fail {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 12px;
  border: 0; border-radius: 999px; background: var(--bg-2); color: var(--danger-ink);
  font: inherit; font-size: 13px; font-weight: 900;
}
.dm-retry { cursor: pointer; }
.dm-drop { color: inherit; }
.dm-prog { height: 3px; margin: 0 0 4px; overflow: hidden; border-radius: 2px; background: color-mix(in srgb, currentColor 25%, transparent); }
.dm-prog i {
  display: block; height: 100%; background: currentColor;
  transform: scaleX(0); transform-origin: left center; transition: transform var(--dur-base) linear;
}
.dm-quote.is-local { cursor: default; }
/* Шторка стикеров */
.stk-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; padding-bottom: 6px; }
.stk-b {
  display: grid; place-items: center; aspect-ratio: 1; min-height: var(--tap);
  border: 0; border-radius: var(--r-3); background: var(--raise-2); cursor: pointer;
  transition: background-color var(--dur-press) linear;
}
.stk-b:active { background: var(--accent-wash-3); }
.stk-b img { width: 78%; height: 78%; object-fit: contain; pointer-events: none; }
@media (prefers-reduced-motion: reduce) {
  .tbar-in::placeholder, .dm-prog i { transition: none; }
}

/* == ДЕЙСТВИЯ ============================================================ */
.ms { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.ms-rx { display: flex; justify-content: space-between; gap: 6px; padding: 2px 2px 6px; }
.ms-rx-b {
  display: grid; place-items: center; width: 52px; height: 52px;
  border: 0; border-radius: 50%; background: var(--raise-2); font-size: 26px; cursor: pointer;
  transition: background-color var(--dur-press) linear;
}
.ms-rx-b.on { background: var(--accent-wash-3); box-shadow: inset 0 0 0 2px var(--lav); }
.ms-rx-b:active { background: var(--accent-wash-2); }
/* Лайтбокс фото */
.lbx {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  overflow: hidden; touch-action: none; -webkit-user-select: none; user-select: none;
  animation: sh-fade var(--dur-base) var(--ease-out);
  transition: opacity var(--dur-fast) var(--ease-in);
}
.lbx::before { content: ""; position: absolute; inset: 0; background: var(--scrim-2); opacity: var(--lbx-fade, 1); }
.lbx.is-leaving { opacity: 0; }
.lbx-img {
  position: relative; max-width: 100%; max-height: 100%; object-fit: contain;
  -webkit-user-drag: none; will-change: transform;
}
.lbx-img.is-back { transition: transform var(--dur-base) var(--ease-out); }
.lbx-x {
  position: absolute; z-index: 1; top: calc(8px + var(--safe-t)); right: calc(8px + var(--safe-r));
  background: var(--backdrop); color: var(--ink-on-accent);
}
@media (prefers-reduced-motion: reduce) {
  .lbx { animation: none; }
  .lbx-img.is-back { transition: none; }
}
