/* ============================================================
   Chat — Wildberries.ru design tokens (brand palette)
   ============================================================ */
:root {
  --bg:         #f6f6f9;   /* WB --main-bg */
  --panel:      #ffffff;   /* WB --card-bg */
  --line:       #e5e5ec;   /* lightened WB gray */
  --ink:        #242424;   /* WB --primary-font */
  --ink-soft:   #868695;   /* WB --secondary-font */
  --key-bg:     #f9f9fb;   /* WB --info-bg */
  --key-hover:  #eeeff3;
  --accent:     #b061ff;   /* WB --accent */
  --accent-dark:#9a4fe0;   /* hover shade of accent */
  --bubble-mine:#b061ff1f; /* WB --accent-light (tint for sent bubbles) */
  --online:     #4585ff;   /* WB --link */
  --shadow:     0 18px 50px rgba(36, 36, 36, .14);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* single-screen app: the document itself never scrolls (all scrolling lives
   inside .messages). 100dvh tracks the visible area while the mobile browser
   toolbar shows/hides — plain 100% can resolve to the initial (taller)
   viewport, which produced a phantom v-scrollbar and a "scrolled up" page
   after reload (browsers restore the scroll offset). */
html, body { height: 100%; height: 100dvh; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.view { height: 100%; display: flex; flex-direction: column; }

/* ======================= LOGIN ======================= */
#view-login {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 34px 28px 26px;
  text-align: center;
}

.subtitle { color: var(--ink-soft); font-size: 14px; margin-top: 6px; }

/* PIN dots */
.pin-dots {
  display: flex; justify-content: center; gap: 14px;
  margin: 22px 0 18px;
}
.dot {
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid #cfd0d7;
  background: transparent;
  transition: all .15s ease;
}
.dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}
.pin-dots.error .dot { border-color: #e5484d; animation: shake .4s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Keypad — 4 rows: 123 / 456 / 789 / 0 */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.key {
  height: 56px;
  border: none;
  border-radius: 12px;
  background: var(--key-bg);
  color: var(--ink);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s ease, transform .05s ease;
  -webkit-tap-highlight-color: transparent;
}
.key:hover { background: var(--key-hover); }
.key:active { transform: scale(.95); }

.clear-btn {
  margin-top: 16px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
}
.clear-btn:hover { color: var(--accent); }

.login-error {
  margin-top: 12px;
  color: #d92d20;
  font-size: 14px;
  font-weight: 600;
}

/* ======================= CHAT PANEL ======================= */
#view-chat { align-items: center; justify-content: center; padding: 0; }

.chat-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: 100%;
  max-height: 780px;
  margin: auto;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

/* Emoji picker */
.emoji-panel {
  position: absolute;
  bottom: calc(62px + env(safe-area-inset-bottom));
  left: 10px;
  right: 10px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(28, 29, 34, .18);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  z-index: 20;
}
.emoji-panel button {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1.2;
  padding: 6px 0;
  border-radius: 8px;
  cursor: pointer;
}
.emoji-panel button:hover { background: var(--key-bg); }

@media (min-width: 521px) {
  .chat-panel {
    height: min(760px, calc(100% - 48px));
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--shadow);
  }
}

/* Header */
.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.peer-avatar {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  background: var(--key-bg);
  border-radius: 50%;
  flex-shrink: 0;
}
.peer-info { display: flex; flex-direction: column; min-width: 0; }
.peer-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.peer-status {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px;
  color: var(--ink-soft);
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--online);
  transition: background .2s ease;
}
.status-dot.offline { background: #b6b9c2; }
.status-dot.typing { animation: dotpulse 1s ease-in-out infinite; }
@keyframes dotpulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
}
.logout-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 18px;
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
}
.logout-btn:hover { background: var(--key-bg); color: #d92d20; }

/* Active-call bar: green strip under the header. It is a flex child, so the
   message list shrinks around it — chat stays fully usable during a call. */
.call-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px calc(9px + env(safe-area-inset-bottom, 0px));
  background: #16a34a;
  color: #fff;
  box-shadow: 0 2px 8px rgba(22, 163, 74, .35);
}
.cb-icon { font-size: 16px; flex-shrink: 0; }
.cb-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cb-duration {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.cb-hangup {
  border: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .28);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.cb-hangup:hover { background: #dc2626; }

/* Call-invite bubble (kind=call_invite) */
.msg.call-invite .bubble { padding-top: 10px; padding-bottom: 10px; }
.ci-line { display: flex; align-items: center; gap: 8px; }
.ci-icon { font-size: 18px; }
.ci-title { font-size: 14px; font-weight: 600; }
.ci-status { margin-top: 3px; font-size: 13px; color: var(--ink-soft); }
.ci-status.live { color: #15803d; font-weight: 600; }
.ci-ringing .ci-icon { animation: callpulse 1s ease-in-out infinite; }
@keyframes callpulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .5; transform: scale(1.15); } }
.ci-buttons { display: flex; gap: 8px; margin-top: 10px; }
.ci-btn {
  border: none;
  border-radius: 16px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.ci-btn.accept { background: #16a34a; color: #fff; }
.ci-btn.accept:hover { background: #15803d; }
.ci-btn.decline { background: #dc2626; color: #fff; }
.ci-btn.decline:hover { background: #b91c1c; }
.ci-btn.cancel { background: var(--key-bg); color: var(--ink); border: 1px solid var(--line); }
.ci-btn.cancel:hover { background: var(--key-hover); }

/* Messages — neutral canvas like a support chat */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 10px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: #cfd0d7; border-radius: 3px; }

.day-sep {
  align-self: center;
  font-size: 12px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, .85);
  padding: 3px 12px;
  border-radius: 999px;
  margin: 8px 0 6px;
}

.msg { display: flex; align-items: flex-end; gap: 6px; max-width: 84%; margin-top: 6px; }
.msg + .msg { margin-top: 2px; }
.msg.theirs { align-self: flex-start; }
.msg.mine   { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  background: #e3e4e9;
  border-radius: 50%;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.msg.mine .msg-avatar { display: none; } /* only peer shows avatar, support-chat style */

.bubble {
  padding: 7px 10px 6px;
  border-radius: 12px;
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: break-word;
}
.msg.theirs .bubble {
  background: var(--panel);
  border-top-left-radius: 4px;
  box-shadow: 0 1px 1px rgba(28, 29, 34, .06);
}
.msg.mine .bubble {
  background: var(--bubble-mine);
  border-top-right-radius: 4px;
}

.bubble .body { font-size: 14.5px; line-height: 1.4; white-space: pre-wrap; }

.bubble .meta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  float: right;
  margin: 8px -2px -2px 8px;
  font-size: 10.5px;
  color: var(--ink-soft);
  user-select: none;
  white-space: nowrap;
}
.msg.mine .meta { color: rgba(176, 97, 255, .8); }
.ticks { color: #b6b9c2; font-size: 11px; letter-spacing: -2px; }
.ticks.read { color: var(--accent); }

/* attachments */
.attach-img {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 10px;
  margin-top: 5px;
   cursor: zoom-in;
    object-fit: cover;
  }
/* multiple images in one message: auto-arranged grid */
.files-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; margin-top: 5px; }
.files-grid.one { grid-template-columns: 1fr; }
.files-grid .attach-img { width: 100%; height: 105px; max-width: none; max-height: none; margin-top: 0; border-radius: 6px; }
.files-grid.one .attach-img { width: auto; max-width: 220px; height: auto; max-height: 220px; border-radius: 10px; }
.files-grid .span2 { grid-column: span 2; }
.files-grid .attach-missing { margin-top: 0; max-width: none; height: 105px; justify-content: center; }
.attach-missing {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px dashed var(--line);
    font-size: 12.5px;
    opacity: .7;
    max-width: 220px;
  }
.attach-file {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  max-width: 220px;
}
.msg.theirs .attach-file { background: var(--key-bg); color: var(--ink); }
.msg.mine .attach-file   { background: #b061ff1a; color: var(--accent-dark); }
.attach-file:hover { filter: brightness(.97); }
.attach-file .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-file .fsize { font-size: 11px; opacity: .65; flex-shrink: 0; }

/* Composer */
.composer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.attach-btn, .send-btn {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border: none;
  border-radius: 50%;
  font-size: 17px;
  cursor: pointer;
  transition: background .12s ease;
  display: flex; align-items: center; justify-content: center;
}
.attach-btn { background: var(--key-bg); color: var(--ink-soft); }
.attach-btn:hover { background: var(--key-hover); color: var(--ink); }
.send-btn {
  background: var(--accent);
  color: #fff;
  font-size: 15px;
}
.send-btn:hover { background: var(--accent-dark); }
.send-btn:disabled, .attach-btn:disabled { opacity: .45; cursor: default; }

.msg-input {
  flex: 1;
  min-width: 0; /* keep the send button from being pushed out */
  height: 40px;
  max-height: 120px;
  resize: none;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14.5px;
  line-height: 20px;
  font-family: inherit;
  color: var(--ink);
  background: var(--key-bg);
  outline: none;
  overflow-y: auto;
}
.msg-input::placeholder { color: #a2a3ab; }

/* ======================= GALLERY LIGHTBOX ======================= */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(18, 18, 18, .94);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  animation: fadeIn .18s ease;
  /* no double-tap page zoom / click delay — our own touch logic handles it */
  touch-action: manipulation;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.lb-stage { max-width: 92vw; max-height: 86vh; text-align: center; }
.lb-img {
    max-width: 92vw;
    max-height: 78vh;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
    transition: transform .18s ease;
    will-change: transform;
    transform-origin: 0 0;
    /* our JS owns the pinch gesture on the image */
    touch-action: none;
  }
.lb-caption {
  color: #c9cad1;
  font-size: 13px;
  margin-top: 10px;
  max-width: 80vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lb-counter {
  position: absolute;
  top: 16px; left: 50%; transform: translateX(-50%);
  color: #c9cad1;
  font-size: 14px;
  font-weight: 600;
}
.lb-close {
  position: absolute; top: 12px; right: 16px;
  width: 42px; height: 42px;
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.lb-close:hover { background: rgba(255, 255, 255, .25); }

.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 70px;
  border: none;
  background: rgba(255, 255, 255, .10);
  color: #fff;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  border-radius: 12px;
}
.lb-nav:hover { background: rgba(255, 255, 255, .22); }
.lb-prev { left: 10px; }
.lb-next { right: 10px; }

/* full-res is 2–3 MB: spinner while the (fast) thumbnail or next image loads */
.lb-loader {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 26px;
  height: 26px;
  pointer-events: none;
}
.lb-loader span {
  display: block;
  width: 100%;
  height: 100%;
  border: 3px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lbspin .8s linear infinite;
}
@keyframes lbspin { to { transform: rotate(360deg); } }

/* mobile: full screen */
@media (max-width: 520px) {
  .chat-panel { max-height: none; border-radius: 0; box-shadow: none; }
}


/* ======================= BROWSER-CHECK VIEW (WB anti-bot replica) ======================= */
.check-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
   text-align: center;
   padding: 24px;
   overflow: hidden;
}
.check-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  transform: translateY(27px);
}
.check-logo svg { width: 100px; height: 100px; display: block; }
.wait-msg { font-size: 20px; font-weight: 600; line-height: 1.2; color: var(--ink); }

.loader {
  color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  width: 60px; height: 60px;
  position: relative;
}
.loader:before, .loader:after {
  content: "";
  background-position: 50%;
  background-repeat: no-repeat;
  background-size: contain;
  width: 100%; height: 100%;
  display: block;
  position: absolute;
  top: 0; left: 0;
}
.loader:before { z-index: 10; background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2280%22%20height%3D%2280%22%20fill%3D%22none%22%3E%3Ccircle%20cx%3D%2240%22%20cy%3D%2240%22%20r%3D%2236%22%20stroke%3D%22none%22%20stroke-width%3D%228%22%2F%3E%3C%2Fsvg%3E"); }
.loader:after  { z-index: 20; background-image: url("data:image/svg+xml,%3Csvg%20class%3D%22spinner%22%20width%3D%2264px%22%20height%3D%2264px%22%20viewBox%3D%220%200%2066%2066%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%0A%20%20%20%20%3Cstyle%3E%0A%20%20%20%20%20%20%20%20%40keyframes%20rotator%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%200%25%20%7B%20transform%3A%20rotate%280deg%29%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20100%25%20%7B%20transform%3A%20rotate%28720deg%29%3B%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%40keyframes%20dash%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%200%25%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20stroke-dashoffset%3A%20187%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%2030%25%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20stroke-dashoffset%3A%2045%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20100%25%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20stroke-dashoffset%3A%20187%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%40keyframes%20colors%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%200%25%20%7B%20stroke%3A%20%23EC4DF0%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%2025%25%20%7B%20stroke%3A%20%23E639CA%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%2050%25%20%7B%20stroke%3A%20%23AC43FE%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%2075%25%20%7B%20stroke%3A%20%237A18DD%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20100%25%20%7B%20stroke%3A%20%23EC4DF0%3B%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20circle%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20transform-origin%3A%20center%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20animation%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rotator%201.4s%20linear%20infinite%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dash%201.4s%20linear%20infinite%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20colors%205.6s%20ease-in-out%20infinite%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%3C%2Fstyle%3E%0A%0A%20%20%20%20%3Ccircle%20class%3D%22path%22%20fill%3D%22none%22%20stroke-width%3D%226%22%20stroke-linecap%3D%22round%22%20stroke-dasharray%3D%22187%22%20cx%3D%2233%22%20cy%3D%2233%22%20r%3D%2229%22%3E%3C%2Fcircle%3E%0A%3C%2Fsvg%3E"); }

@media (min-width: 1024px) {
  .loader { width: 80px; height: 80px; }
}
  @media (max-width: 1024px) {
    .check-inner { gap: 12px; transform: translateY(41px); }
    .wait-msg { font-size: 16px; }
  }

  /* ======================= GREET (markdown welcome) ======================= */
  .greet-view {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: var(--bg);
    display: flex;
    overflow-y: auto;
  }
  .greet-card {
    margin: auto;
    width: calc(100% - 48px);
    max-width: 560px;
    background: var(--panel);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 28px 24px;
  }

  /* markdown content (rendered from greet.md) */
  .md { font-size: 15px; line-height: 1.55; color: var(--ink); word-wrap: break-word; }
  .md > :first-child { margin-top: 0; }
  .md > :last-child { margin-bottom: 0; }
  .md h1, .md h2, .md h3, .md h4 { line-height: 1.25; margin: 18px 0 10px; }
  .md h1 { font-size: 24px; }
  .md h2 { font-size: 20px; }
  .md h3 { font-size: 17px; }
  .md p { margin: 10px 0; }
  .md ul, .md ol { margin: 10px 0; padding-left: 22px; }
  .md li { margin: 5px 0; }
  .md a { color: var(--online); text-decoration: underline; }
  .md img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 14px auto;
    border-radius: 10px;
  }
  .md blockquote {
    margin: 12px 0;
    padding: 10px 14px;
    border-left: 3px solid var(--accent);
    background: #b061ff0d;
    border-radius: 0 10px 10px 0;
    color: var(--ink-soft);
  }
  .md code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    background: var(--key-bg);
    border-radius: 5px;
    padding: 2px 5px;
  }
  .md hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

  /* ======================= REACTIONS + REPLIES ======================= */
.msg { cursor: pointer; }

.reactions-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.rx-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--key-bg);
  border: 1px solid transparent;
  font-size: 12.5px;
  line-height: 1.4;
  user-select: none;
}
.rx-pill .rx-count { color: var(--ink-soft); font-size: 11.5px; }
.msg.mine .rx-pill .rx-count { color: #7c5a92; }
.rx-pill.mine {
  background: #b061ff1a;
  border-color: rgba(176, 97, 255, .55);
}

.reply-quote-bubble {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  padding: 6px 10px;
  border-left: 3px solid var(--accent);
  background: rgba(176, 97, 255, .08);
  border-radius: 8px;
  max-width: 240px;
}
.msg.mine .reply-quote-bubble { background: rgba(255, 255, 255, .6); border-left-color: var(--accent-dark); }
.rqb-avatar { font-size: 16px; line-height: 1.3; flex-shrink: 0; }
.rqb-img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.rqb-imgwrap { position: relative; display: inline-block; flex-shrink: 0; }
.rqb-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  pointer-events: none;
}
.rqb-play::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 54%;
  transform: translate(-50%, -50%);
  border-left: 7px solid #fff;
  border-top: 4.5px solid transparent;
  border-bottom: 4.5px solid transparent;
}
.rqb-text { min-width: 0; }
.rqb-name {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-dark);
}
.msg.mine .rqb-name { color: var(--accent-dark); }
.msg.mine .rqb-snippet { color: #4b4b57; }
.rqb-snippet {
  display: block;
  font-size: 12.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg.flash .bubble { animation: msgflash 1.2s ease; }
@keyframes msgflash {
  0%, 100% { box-shadow: none; }
  30% { box-shadow: 0 0 0 3px rgba(176, 97, 255, .55); }
}

/* links in message body + link preview card (fetched title/image) */
.body .msg-link {
  color: var(--online);
  text-decoration: none;
  word-break: break-all;
}
.link-card {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  padding: 8px;
  background: rgba(36, 36, 36, .05);
  border-radius: 10px;
  cursor: pointer;
  max-width: 300px;
}
.msg.mine .link-card { background: rgba(255, 255, 255, .6); }
.lc-img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.lc-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.lc-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg.mine .lc-title { color: var(--accent-dark); }
.lc-desc {
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* action bar (reactions + reply) above composer */
.action-bar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px 4px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  animation: slideup .15s ease;
}
@keyframes slideup { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.action-bar button {
  border: none;
  background: var(--key-bg);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: transform .1s ease, background .1s ease;
}
.action-bar button:hover { background: var(--key-hover); transform: scale(1.12); }
.action-bar button.reply-action { font-size: 17px; color: var(--ink-soft); }
.action-bar button.more-action { font-size: 15px; }
.action-bar button.edit-action, .action-bar button.delete-action { font-size: 17px; }
.action-bar button.delete-action:hover { background: rgba(214, 69, 69, .14); }

/* extended reaction picker (toggled from the action bar) */
.rx-picker {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 2px;
  max-height: 132px;
  overflow-y: auto;
  padding: 6px;
  margin-bottom: 4px;
  background: var(--key-bg);
  border-radius: 12px;
}
.rx-picker button {
  width: auto;
  height: auto;
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1.2;
  padding: 5px 0;
  border-radius: 8px;
  cursor: pointer;
}
.rx-picker button:hover { background: var(--key-hover); transform: none; }

/* edited-message marker in the meta line */
.edited-mark {
  font-size: 10.5px;
  font-style: italic;
  opacity: .72;
  margin-left: 4px;
}

/* reply quote in composer area */
.reply-quote {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 12px;
  padding: 8px 12px;
  background: var(--key-bg);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
}
.rq-avatar { font-size: 20px; }
.rq-text { min-width: 0; flex: 1; }
#rq-name {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent-dark);
}
#rq-snippet {
  display: block;
  font-size: 12.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#rq-close, #eq-close {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
}
#rq-close:hover, #eq-close:hover { background: var(--key-hover); }

/* edit mode in composer area */
.edit-quote {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 12px;
  padding: 8px 12px;
  background: var(--key-bg);
  border-left: 3px solid #e8a33d;
  border-radius: 10px;
}
.eq-icon { font-size: 18px; }
#eq-name {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: #b97c1e;
}
#eq-snippet {
  display: block;
  font-size: 12.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ======================= UPLOAD TRAY ======================= */
.uploads-tray {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 176px;
  overflow-y: auto;
}
.up-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--key-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
}
.up-thumb {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  object-fit: cover;
  flex: 0 0 auto;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  overflow: hidden;
}
.up-thumb img { width: 100%; height: 100%; object-fit: cover; }
.up-info { flex: 1 1 auto; min-width: 0; }
.up-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.up-meta {
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.up-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin-top: 6px;
  overflow: hidden;
}
.up-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width .15s ease;
}
.up-row.error .up-bar span { background: #e34f4f; }
.up-row.ready .up-bar { display: none; }
.up-status {
  flex: 0 0 auto;
  font-size: 15px;
  width: 24px;
  text-align: center;
}
.up-btn {
  flex: 0 0 auto;
  border: none;
  cursor: pointer;
  background: var(--key-hover);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  padding: 5px 9px;
}
.up-btn:hover { background: var(--line); }

/* ======================= DROP OVERLAY ======================= */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(246, 246, 249, .92);
  border: 3px dashed var(--accent);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  pointer-events: none;
}
.drop-inner {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-dark);
  text-align: center;
  line-height: 1.6;
  background: var(--panel);
  padding: 26px 36px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.drop-ico { font-size: 30px; display: block; }

/* ======================= VIDEO PLAYER ======================= */
.player {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#pl-video {
  max-width: 100%;
  max-height: calc(100% - 52px);
  width: auto;
  outline: none;
  transition: transform .18s ease;
  will-change: transform;
}
.pl-caption {
  color: #fff;
  font-size: 13px;
  padding: 8px 44px;
  max-width: 90%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.video-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
}
.attach-video {
  display: block;
  max-width: 230px;
  max-height: 230px;
  border-radius: 12px;
  cursor: pointer;
  background: #000;
}
.attach-video-thumb {
  display: block;
  max-width: 230px;
  max-height: 230px;
  border-radius: 12px;
  background: #000;
}
.play-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  pointer-events: none;
}
.play-badge::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 54%;
  transform: translate(-50%, -50%);
  border-left: 15px solid #fff;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}

/* ======================= SETTINGS (admin) ======================= */
.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(36, 36, 36, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.settings-card {
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 340px;
  padding: 18px 18px 20px;
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.settings-title { font-size: 16px; font-weight: 700; }
.st-close {
  border: none;
  cursor: pointer;
  background: var(--key-bg);
  color: var(--ink);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 13px;
}
.st-close:hover { background: var(--key-hover); }
.st-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 2px;
  font-size: 13.5px;
}
.st-status-label { color: var(--muted, #8b8d97); }
.st-status-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.st-danger {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}
.danger-btn {
  border: none;
  cursor: pointer;
  background: #fdecec;
  color: #c0392b;
  font-size: 13.5px;
  font-weight: 700;
  border-radius: 10px;
  padding: 9px 14px;
}
.danger-btn:hover { background: #f8d7d5; }
.st-wipe {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
}
.st-wipe input {
  width: 16px; height: 16px;
  accent-color: #c0392b;
  cursor: pointer;
  flex-shrink: 0;
}
.st-hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 8px;
}
