/* ── Messages Tab ─────────────────────────────────────────────────────────── */

.tab-messages-layer {
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

/* ── Header ── */
.msg-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: var(--st-btn, 95px);
  padding: 60px 10px;
  padding-top: var(--st-logo, 54px);
  background: #fff;
  flex-shrink: 0;
  border-bottom: 0px solid #efefef;
}

.msg-header-title {
  position: absolute;
  top: calc(var(--st-logo, 54px) + 15px);
  left: 0;
  right: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: #111;
  letter-spacing: -0.2px;
  pointer-events: none;
}

.msg-header-edit {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: #111;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}

.msg-header-edit svg {
  width: 24px;
  height: 24px;
}

.msg-header-edit:active { opacity: 0.5; }

/* ── Notifications bell ── */
.msg-header-bell {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: #111;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
  z-index: 1;
}

.msg-header-bell svg {
  width: 25px;
  height: 25px;
}

.msg-header-bell:active { opacity: 0.5; }

.msg-bell-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  box-sizing: border-box;
  background: #ff3b30;
  color: #fff;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  border: 2px solid #fff;
}

/* ── Pin-notifications inbox (bottom-sheet) ── */
.pin-notif-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: none;
  align-items: flex-start;
  justify-content: flex-end;
  padding: calc(var(--st-btn, 95px) + 4px) 10px 0;
  background: rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.pin-notif-overlay.open {
  display: flex;
  opacity: 1;
}

html.ios-pwa-edge .pin-notif-overlay {
  top: var(--ios-pwa-status-offset);
  --device-safe-top: 0px;
}

/* Выпадающее меню из кнопки-колокольчика: 80% ширины всегда, до 70% высоты */
.pin-notif-sheet {
  width: 80%;
  max-width: 560px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  padding: 8px 0 12px;
  /* Раскрытие «из колокольчика»: растём из правого верхнего угла */
  transform-origin: top right;
  transform: scale(0.05);
  opacity: 0;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.2s ease;
}

/* Содержимое плавно проявляется чуть позже, когда меню уже почти раскрылось */
.pin-notif-sheet > * {
  opacity: 0;
  transition: opacity 0.18s ease 0.12s;
}

.pin-notif-overlay.open .pin-notif-sheet {
  transform: scale(1);
  opacity: 1;
}

.pin-notif-overlay.open .pin-notif-sheet > * {
  opacity: 1;
}

.pin-notif-grip {
  display: none;
}

.pin-notif-head {
  padding: 6px 20px 12px;
  flex-shrink: 0;
}

.pin-notif-title {
  font-size: 18px;
  font-weight: 700;
  color: #111;
  letter-spacing: -0.2px;
}

.pin-notif-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 10px 4px;
}

.pin-notif-empty {
  text-align: center;
  color: #999;
  font-size: 14px;
  padding: 32px 16px;
}

.pin-notif-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.pin-notif-row:active { background: #f2f2f2; }

.pin-notif-av {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: #e6e6e6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 18px;
}

.pin-notif-av img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pin-notif-body {
  flex: 1;
  min-width: 0;
}

.pin-notif-name {
  font-size: 15px;
  font-weight: 700;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pin-notif-sub {
  font-size: 13px;
  color: #777;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pin-notif-thumb {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: cover;
  background: #eee;
}

.pin-notif-count {
  flex-shrink: 0;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  box-sizing: border-box;
  background: #111;
  color: #fff;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}

/* ── DM rows inside the bell inbox ── */
.pin-notif-row-dm {
  border-bottom: 0.5px solid #f0f0f0;
}

.pin-notif-dm-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
}

/* ── Search + button row ── */
.msg-search-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  margin: 10px 16px 12px;
  flex-shrink: 0;
}

/* ── Search bar ── */
.msg-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f0f0f0;
  border-radius: 12px;
  padding: 9px 12px;
  flex: 1;
  min-width: 0;
}

.msg-search-bar svg {
  width: 16px;
  height: 16px;
  color: #999;
  flex-shrink: 0;
}

.msg-search-bar span {
  font-size: 15px;
  color: #999;
}

/* ── Conversations list ── */
.msg-conversations-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.msg-convo-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.msg-convo-row:active { background: #f5f5f5; }

.msg-convo-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: #ccc;
  position: relative;
}

.msg-convo-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msg-convo-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-convo-name {
  font-size: 15px;
  font-weight: 600;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-convo-preview {
  font-size: 14px;
  color: #999;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-convo-name.msg-unread {
  font-weight: 700;
  color: #000;
}

.msg-convo-preview.msg-unread {
  color: #111;
  font-weight: 700;
}

.msg-convo-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.msg-convo-time {
  font-size: 12px;
  color: #999;
  white-space: nowrap;
}

.msg-convo-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3897f0;
}

.msg-convo-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ff3040;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  border-radius: 10px;
}

.msg-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 32px;
  color: #bbb;
  text-align: center;
}

.msg-empty svg {
  width: 56px;
  height: 56px;
  stroke: #ddd;
}

.msg-empty-title {
  font-size: 18px;
  font-weight: 600;
  color: #222;
}

.msg-empty-hint {
  font-size: 14px;
  color: #999;
  line-height: 1.5;
}

/* ══ New Chat Panel ══════════════════════════════════════════════════════════ */
.msg-new-chat-panel {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 710;
  background: #fff;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
}

.msg-new-chat-panel.msg-new-chat-open {
  transform: translateX(0);
}

.msg-new-chat-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: calc(var(--topbar-safe-h, 0px) + 60px);
  padding: var(--topbar-safe-h, 0px) 10px 0;
  border-bottom: 0px solid #efefef;
  background: #fff;
  flex-shrink: 0;
}

/* Кнопка «Назад» — позиция под защитным блоком */
.msg-new-chat-header .msg-chat-back {
  top: calc(var(--topbar-safe-h, 0px) + 5px);
}

.msg-new-chat-title {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--topbar-safe-h, 0px);
  line-height: 60px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: #111;
  letter-spacing: -0.2px;
  pointer-events: none;
}

.msg-new-chat-search-wrap {
  padding: 10px 14px 6px;
  flex-shrink: 0;
}

.msg-new-chat-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f0f0f0;
  border-radius: 12px;
  padding: 9px 12px;
}

.msg-new-chat-search svg {
  width: 16px;
  height: 16px;
  color: #999;
  flex-shrink: 0;
}

.msg-new-chat-search input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  color: #111;
  outline: none;
  min-width: 0;
}

.msg-new-chat-search input::placeholder { color: #aaa; }

.msg-new-chat-section-label {
  padding: 8px 16px 4px;
  font-size: 12px;
  font-weight: 600;
  color: #999;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.msg-new-chat-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.msg-new-chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.msg-new-chat-row:active { background: #f5f5f5; }

.msg-new-chat-av {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: #ccc;
}

.msg-new-chat-av img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msg-new-chat-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-new-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 32px;
  color: #bbb;
  text-align: center;
}

.msg-new-chat-empty svg {
  width: 48px;
  height: 48px;
  stroke: #ddd;
}

.msg-new-chat-empty-title {
  font-size: 16px;
  font-weight: 600;
  color: #222;
}

.msg-new-chat-empty-hint {
  font-size: 13px;
  color: #999;
  line-height: 1.5;
}

/* ── Chat panel (slides from right) ── */
#msg-chat-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 700;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
}

#msg-chat-panel.msg-chat-open {
  transform: translateX(0);
}

/* Messages list — fills full height, compose floats on top */
#dm-messages.cp-messages {
  background: transparent;
  padding-top: calc(var(--full-panel-safe-top, 0px) + 74px); /* room for absolute header */
  padding-bottom: 80px; /* fallback; JS ResizeObserver overrides dynamically */
  /* Override the base -webkit-overflow-scrolling:touch from .cp-messages.
     That legacy value forces a GPU compositing layer in WebKit, creating a
     new stacking context that traps child z-indices — preventing the pressed
     bubble (z-997) from rising above the blur overlay (z-995).
     Modern iOS (16+, as required by Telegram) handles momentum scrolling
     natively without this property. */
  -webkit-overflow-scrolling: auto;
}

/* Compose floats over the message list */
#dm-compose {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  transition: bottom 0.22s ease;
}

/* Скрываем аватарку собеседника внутри переписки */
#dm-messages .cp-avatar {
  display: none;
}


/* Увеличенный отступ при смене автора (own→other или other→own) */
#dm-messages .cp-msg-own + .cp-msg-other,
#dm-messages .cp-msg-other + .cp-msg-own {
  margin-top: 4px;
}


/* ── DM compose: Telegram glass style ── */
#dm-compose.cp-compose {
  border-top: none;
  background: transparent;
  padding-bottom: 0;
}

#dm-compose .cp-compose-row {
  background: linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgb(248, 238, 239,0.85) 100%);
  border-top: none;
  padding-top: 0;
}

#dm-compose.kb-open .cp-compose-row {
  padding-bottom: 10px;
}

html[data-android="1"][data-env="tg"] #dm-compose .cp-compose-row,
html[data-android="1"][data-env="web"] #dm-compose .cp-compose-row,
html[data-android="1"][data-env="tg"] #dm-compose.kb-open .cp-compose-row,
html[data-android="1"][data-env="web"] #dm-compose.kb-open .cp-compose-row {
  padding-bottom: 60px;
}

#dm-compose .cp-attach-btn {
  background: rgba(255, 255, 255, 0.60);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.14);
  color: #555;
}

#dm-compose .cp-input-wrap {
  background: rgba(255, 255, 255, 0.60);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.14);
  flex-direction: column;
  align-items: stretch;
  padding: 4px 0;
  min-height: 44px;
}
#dm-compose .cp-input-row {
  padding: 4px 8px 0 14px;
}

#dm-compose .cp-send-btn {
  background: rgba(64, 167, 227, 0.88);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.18);
}

/* ── Chat header (same pattern as .ch-header in channels) ── */
.msg-chat-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--full-panel-safe-top, 0px)) 12px 10px;
  background: transparent;
  z-index: 10;
  min-height: 54px;
}

/* gradient blur backdrop — fades out downward, content scrolls through */
.msg-chat-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(242,239,242,0.85) 0%, rgba(242,239,242,0) 100%);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  -webkit-mask-image: linear-gradient(to bottom, black 35%, transparent 100%);
  mask-image: linear-gradient(to bottom, black 35%, transparent 100%);
  pointer-events: none;
  z-index: -1;
}

html.ios-pwa-edge #msg-chat-panel.msg-chat-open .msg-chat-header::before {
  background: linear-gradient(to bottom, rgba(0,0,0,0.20) 0%, rgba(242,239,242,0.90) 40%, rgba(242,239,242,0) 100%);
}

/* back button — round frosted glass circle (same as .ch-header-btn) */
.msg-chat-back {
  width: 44px;
  height: 44px;
  border: none;
  cursor: pointer;
  padding: 0;
  color: #1a1a1a;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  background: rgba(255,255,255,0.60);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  box-shadow: 0 1px 8px rgba(0,0,0,0.14);
  transition: background 0.15s;
}

.msg-chat-back svg {
  width: 22px;
  height: 22px;
  stroke: #1a1a1a;
  stroke-width: 2.5;
}

.msg-chat-back:active {
  background: rgba(255,255,255,0.85);
}

/* center pill — identical to .ch-header-center in channel-chat.css */
.msg-chat-header-center {
  flex: 1;
  min-width: 0;
  text-align: center;
  max-width: 50%;
  margin: 0 auto;
  background: rgba(255,255,255,0.60);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  box-shadow: 0 1px 8px rgba(0,0,0,0.14);
  border-radius: 999px;
  height: 44px;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.msg-chat-header-center:active {
  background: rgba(255,255,255,0.85);
}

/* name inside pill — identical to .ch-title */
.msg-chat-header-name {
  font-size: 18px;
  font-weight: 700;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 2;
  width: 100%;
}

/* right-side avatar — identical to .ch-header-avatar */
.msg-chat-header-av {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  font-weight: 700;
  color: #fff;
  background: #bbb;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 0 0 2.5px rgba(255,255,255,0.60), 0 1px 8px rgba(0,0,0,0.14);
  cursor: pointer;
}

.msg-chat-header-av img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Chat messages ── */
.msg-chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #fff;
}

.msg-chat-loading {
  text-align: center;
  color: #999;
  padding: 32px 16px;
  font-size: 14px;
}

/* Bubble rows — same pattern as comments */
.msg-bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 85%;
}

.msg-bubble-row.msg-own {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-bubble-row.msg-other {
  align-self: flex-start;
}

.msg-bubble-av {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #ccc;
}

.msg-bubble-av img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msg-bubble {
  padding: 9px 13px;
  border-radius: 18px;
  max-width: 100%;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}

.msg-own .msg-bubble {
  background: #3897f0;
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

.msg-other .msg-bubble {
  background: #f0f0f0;
  color: #111;
  border-radius: 18px 18px 18px 4px;
}

.msg-bubble-text {
  font-size: 15px;
  line-height: 1.45;
}

.msg-bubble-time {
  font-size: 10px;
  margin-top: 3px;
  text-align: right;
  opacity: 0.65;
}

.msg-own .msg-bubble-time { color: #fff; }
.msg-other .msg-bubble-time { color: #888; }

/* Date separator */
.msg-date-sep {
  text-align: center;
  font-size: 12px;
  color: #bbb;
  margin: 8px 0 4px;
  font-weight: 500;
}

/* ── Chat compose bar ── */
.msg-chat-compose {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #efefef;
  background: #fff;
  flex-shrink: 0;
}

.msg-chat-input-wrap {
  flex: 1;
  background: #f0f0f0;
  border-radius: 22px;
  padding: 10px 14px;
  min-height: 40px;
  max-height: 120px;
  overflow-y: auto;
  font-size: 15px;
  color: #111;
  outline: none;
  line-height: 1.4;
  -webkit-overflow-scrolling: touch;
}

.msg-chat-input-wrap:empty::before {
  content: attr(data-placeholder);
  color: #aaa;
  pointer-events: none;
}

.msg-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #3897f0;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.msg-chat-send:disabled {
  background: #ddd;
  cursor: default;
}

.msg-chat-send:not(:disabled):active {
  transform: scale(0.92);
}

.msg-chat-send svg {
  width: 18px;
  height: 18px;
}

/* ── Read-receipt checkmarks (own messages) ── */
.cp-ticks {
  display: inline-flex;
  align-items: center;
  margin-left: 3px;
  color: #8a9099;
  vertical-align: middle;
  line-height: 0;
}
.cp-ticks svg {
  display: block;
}
.cp-ticks-read {
  color: #34b7f1;
}

/* Time row now holds [time] + [ticks] — keep them on one baseline. */
.cp-media-caption .cp-time,
.cp-footer-row .cp-time {
  align-items: center;
}

/* Over media (dark time pill): unread ticks are light, read ticks cyan. */
.cp-media-time-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.cp-media-time-pill .cp-ticks {
  margin-left: 1px;
  color: rgba(255, 255, 255, 0.85);
}
.cp-media-time-pill .cp-ticks-read {
  color: #5fd0ff;
}

/* ── New-message in-app banner (notify.js) ─────────────────────────────── */
.notify-banner {
  position: fixed;
  top: calc(var(--app-safe-btn-top) + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(calc(-100% - 130px));
  width: min(440px, calc(100vw - 20px));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px;
  background: #ffffff;
  color: #111;
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
  z-index: 100000;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
  -webkit-tap-highlight-color: transparent;
}
.notify-banner.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.notify-banner-dragging {
  transition: none !important;
}
.notify-banner-av {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  background: #c9c9c9;
}
.notify-banner-av img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.notify-banner-body {
  flex: 1 1 auto;
  min-width: 0;
}
.notify-banner-name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notify-banner-text {
  font-size: 13px;
  color: #555;
  line-height: 1.3;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notify-banner-text img.emoji {
  height: 1em;
  width: 1em;
  vertical-align: -0.1em;
}
@media (prefers-color-scheme: dark) {
  .notify-banner {
    background: #2a2a2e;
    color: #f2f2f2;
  }
  .notify-banner-text {
    color: #b8b8bd;
  }
}

/* ── Pin attachment bar (compose area) ─────────────────────────────────────── */
.dm-pin-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #f4f4f8;
  border-top: 1px solid #e8e8ec;
}
.dm-pin-bar-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: #ddd;
}
.dm-pin-bar-body {
  flex: 1;
  min-width: 0;
}
.dm-pin-bar-label {
  font-size: 11px;
  font-weight: 600;
  color: #5568ff;
  margin-bottom: 2px;
}
.dm-pin-bar-title {
  font-size: 13px;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Shared pin card (inside bubble) ────────────────────────────────────────── */
.dm-pin-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.dm-pin-card:active {
  background: rgba(0,0,0,0.05);
}
.cp-msg-own .dm-pin-card {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.35);
}
.cp-msg-own .dm-pin-card:active {
  background: rgba(255,255,255,0.15);
}
.dm-pin-card-thumb {
  width: 44px;
  height: 44px;
  border-radius: 7px;
  object-fit: cover;
  flex-shrink: 0;
  background: #e0e0e0;
}
.dm-pin-card-info {
  flex: 1;
  min-width: 0;
}
.dm-pin-card-label {
  font-size: 11px;
  font-weight: 600;
  color: #5568ff;
  margin-bottom: 2px;
}
.cp-msg-own .dm-pin-card-label {
  color: rgba(255,255,255,0.85);
}
.dm-pin-card-title {
  font-size: 13px;
  color: #222;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.cp-msg-own .dm-pin-card-title {
  color: rgba(255,255,255,0.95);
}

/* ── Linkified URLs inside message bubbles ───────────────────────────────────── */
.cp-text a,
.cp-media-caption .cp-text a {
  color: #0583c7;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
.cp-msg-own .cp-text a,
.cp-msg-own .cp-media-caption .cp-text a {
  color: #4a28a0;
}
.cp-text a:active,
.cp-media-caption .cp-text a:active {
  opacity: 0.65;
}

/* ── OG link preview card in message bubbles ────────────────────────────────── */
.dm-og-card {
  margin: 6px 0 2px;
  border-radius: 10px;
  overflow: hidden;
  background: #f0f2f5;
  cursor: pointer;
  border-left: 3px solid #0583c7;
  max-width: 260px;
  -webkit-tap-highlight-color: transparent;
}
.dm-og-loading {
  min-height: 48px;
  background: #f0f2f5;
  border-left-color: #ccc;
}
.dm-og-img {
  width: 100%;
  max-height: 140px;
  object-fit: cover;
  display: block;
}
.dm-og-body {
  padding: 8px 10px 8px 9px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.dm-og-title {
  font-size: 13px;
  font-weight: 600;
  color: #111;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.dm-og-desc {
  font-size: 12px;
  color: #555;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.dm-og-domain {
  font-size: 11px;
  color: #0583c7;
  margin-top: 1px;
}
.dm-og-card:active { opacity: 0.8; }

/* Own-message (dark bubble) variants */
.cp-msg-own .dm-og-card {
  background: rgba(255,255,255,0.15);
  border-left-color: rgba(255,255,255,0.65);
}
.cp-msg-own .dm-og-title  { color: #fff; }
.cp-msg-own .dm-og-desc   { color: rgba(255,255,255,0.78); }
.cp-msg-own .dm-og-domain { color: rgba(255,255,255,0.55); }

/* ── Internal channel link preview card ─────────────────────────────────────── */
.dm-ch-preview {
  margin: 6px 10px 10px 10px;
  max-width: 300px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dm-ch-preview-loading {
  height: 90px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.06);
  overflow: hidden;
  position: relative;
}
.dm-ch-preview-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  background-size: 200% 100%;
  animation: skShimmer 1.4s ease-in-out infinite;
}
.dm-ch-preview-inner {
  background: #ffedef;
  border: 1px solid rgba(0, 0, 0, 0.09);
  border-radius: 12px;
  padding: 10px 12px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-left: 3px solid #e60023;
}
.cp-msg-own .dm-ch-preview-inner {
  background: rgba(254, 128, 147, 0.18);
  border-color: rgb(254, 128, 147, 0.18);
  border-left-color: rgb(230, 0, 35, 1);
}
.dm-ch-preview-toprow {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.dm-ch-preview-title {
  flex: 1;
  font-size: 14px;
  font-weight: 700;
  color: #000000;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.cp-msg-own .dm-ch-preview-title {
  color: #000000;
}
.dm-ch-preview-av {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: #ddd;
}
.dm-ch-preview-desc {
  font-size: 12px;
  color: #555;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.cp-msg-own .dm-ch-preview-desc {
  color: rgb(0, 0, 0, 0.85);
}
.dm-ch-preview-divider {
  height: 1px;
  background: rgb(180, 180, 180, 0.5);
  margin: 2px 0;
}
.cp-msg-own .dm-ch-preview-divider {
  background: rgb(180, 180, 180, 0.5);
}
.dm-ch-preview-btn {
  display: block;
  width: 100%;
  padding: 4px 0 2px;
  font-size: 15px;
  font-weight: 600;
  color: #000;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.01em;
}
.cp-msg-own .dm-ch-preview-btn {
  color: #e60023;
}
.dm-ch-preview-btn:active {
  opacity: 0.55;
}
.dm-ch-preview:active .dm-ch-preview-inner {
  background: rgba(255, 255, 255, 0.65);
}
.cp-msg-own .dm-ch-preview:active .dm-ch-preview-inner {
  background: rgba(255, 255, 255, 0.10);
}

/* ── DM video lazy-load: poster + play button ────────────────────────────── */
.cp-media-wrap-video {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  background: #111;
}
.cp-vid-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  cursor: pointer;
  -webkit-touch-callout: none;
}
.cp-vid-poster-blur {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(14px);
  transform: scale(1.1);
  pointer-events: none;
  transition: opacity 0.25s;
}
.cp-vid-poster-full {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s;
  /* Override the generic .cp-vid-poster img rule from comments.css */
  filter: none !important;
  transform: none !important;
}
.cp-vid-poster-full.cp-vid-poster-full-loaded {
  opacity: 1;
}
.cp-lqip-spinner {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.cp-lqip-spinner svg {
  animation: cp-spin 1.1s linear infinite;
  filter: drop-shadow(0 0 3px rgba(0,0,0,0.5));
}
@keyframes cp-spin {
  to { transform: rotate(360deg); }
}
.cp-vid-upload-spinner {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(0,0,0,0.18);
  border-radius: 10px;
}
.cp-vid-upload-spinner svg {
  animation: cp-spin 1.1s linear infinite;
  filter: drop-shadow(0 0 4px rgba(0,0,0,0.5));
}
.cp-vid-play-btn {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
}
.cp-vid-play-btn svg {
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.35));
  transition: transform 0.15s ease;
}
.cp-vid-play-btn:active svg {
  transform: scale(0.88);
}
.cp-media-main-vid {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* ── DM chat skeleton ─────────────────────────────────────────────────────── */
.dm-skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 4px 8px;
}
.dm-skel-msg {
  pointer-events: none;
}
.dm-skel-bubble {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px 14px;
  border-radius: 16px 16px 16px 4px;
  max-width: 72%;
  background: #e9e9e9;
  background-image: linear-gradient(100deg, #e9e9e9 30%, #f3f3f3 50%, #e9e9e9 70%);
  background-size: 220% 100%;
  animation: dm-skel-shimmer 1.3s ease-in-out infinite;
}
.cp-msg-own .dm-skel-bubble {
  border-radius: 16px 16px 4px 16px;
  background: #fce8de;
  background-image: linear-gradient(100deg, #fce8de 30%, #fef1eb 50%, #fce8de 70%);
  background-size: 220% 100%;
}
.dm-skel-line {
  height: 11px;
  border-radius: 6px;
  background: rgba(0,0,0,0.09);
  width: 100%;
}
.dm-skel-line-short {
  width: 55%;
}
.dm-skel-media {
  width: 180px;
  max-width: 58vw;
  height: 150px;
  border-radius: 10px;
  background: rgba(0,0,0,0.08);
}
@keyframes dm-skel-shimmer {
  0%   { background-position: 220% 0; }
  100% { background-position: -220% 0; }
}
@media (prefers-color-scheme: dark) {
  .dm-skel-bubble {
    background: #2a2a2a;
    background-image: linear-gradient(100deg, #2a2a2a 30%, #353535 50%, #2a2a2a 70%);
    background-size: 220% 100%;
  }
  .cp-msg-own .dm-skel-bubble {
    background: #3a2820;
    background-image: linear-gradient(100deg, #3a2820 30%, #4a3228 50%, #3a2820 70%);
    background-size: 220% 100%;
  }
  .dm-skel-line { background: rgba(255,255,255,0.08); }
  .dm-skel-media { background: rgba(255,255,255,0.06); }
}

/* ── Share menu button (index.html global overlay) ──────────────────────────── */
.pc-share-menu-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 22px;
  border: none;
  background: none;
  font-size: 16px;
  font-family: inherit;
  color: #111;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.pc-share-menu-btn:active {
  background: #f2f2f2;
}
.pc-share-menu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #f0f0f5;
  color: #333;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════
   DM media chip strip (above compose row, expands upward)
   ═══════════════════════════════════════════════════════ */
.dm-media-row {
  display: flex;
  align-items: center;
  padding: 5px 8px 4px 10px;
  gap: 6px;
  border-bottom: 1px solid #e0e8f5;
}
.dm-media-track {
  display: flex;
  gap: 5px;
  align-items: center;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  min-width: 0;
}
.dm-media-track::-webkit-scrollbar { display: none; }
.dm-media-item {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 7px;
  overflow: hidden;
  background: #e0e8f5;
}
.dm-media-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.dm-media-video {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #222;
  color: #fff;
}
.dm-media-video .dm-media-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.dm-media-video-icon {
  position: relative;
  z-index: 1;
  font-size: 13px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
  pointer-events: none;
}
.dm-media-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  font-size: 11px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  z-index: 2;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.dm-media-remove:active { opacity: 0.7; }
.dm-media-file-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 4px 6px;
  font-size: 10px;
  line-height: 1.2;
  color: var(--text-secondary, #888);
  word-break: break-all;
  text-align: center;
}

/* ── Tappable reply quote ── */
.dm-reply-quote-tappable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dm-reply-quote-tappable:active {
  opacity: 0.65;
}
.ch-reply-quote-tappable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ch-reply-quote-tappable:active {
  opacity: 0.65;
}

/* ── Jump-to-message highlight flash ── */
@keyframes cp-msg-jump-flash {
  0%   { background: rgba(255, 200, 50, 0.35); }
  100% { background: transparent; }
}
.cp-msg-jump-highlight {
  border-radius: 8px;
  animation: cp-msg-jump-flash 1.4s ease-out forwards;
}
