/* Chat / messages thread */
[hidden] { display: none !important; }
body:has(.chat-page) .site-footer { display: none; }
.chat-page {
  display: flex; flex-direction: column;
  height: calc(100vh - 72px - 64px); height: calc(100dvh - 72px - 64px);
  min-height: 420px; max-width: 900px; margin: 0 auto;
  background: #ffffff; border-left: 1px solid #e4e7ec; border-right: 1px solid #e4e7ec;
}
.chat-page button { font-family: inherit; cursor: pointer; }
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: #ffffff; border-bottom: 1px solid #101828; flex-shrink: 0;
}
.chat-back { font-size: 32px; line-height: 1; color: #101828; text-decoration: none; padding: 0 6px 4px; }
.chat-avatar-wrap { position: relative; flex-shrink: 0; }
.chat-avatar {
  width: 42px; height: 42px; border-radius: 50%; overflow: hidden;
  background: #0b5fff; color: #ffffff; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-presence {
  position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px;
  border-radius: 50%; background: #98a2b3; border: 2px solid #ffffff;
}
.chat-presence.online { background: #12b76a; }
.chat-head-info { min-width: 0; }
.chat-head-name { font-size: 16px; font-weight: 700; color: #101828; }
.chat-head-status { font-size: 12px; color: #475467; }
.chat-listing-bar {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  padding: 8px 14px; background: #f2f4f7; border-bottom: 1px solid #e4e7ec;
  text-decoration: none; color: #101828;
}
.chat-listing-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; border: 1px solid #101828; }
.chat-listing-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-listing-cta { font-size: 13px; font-weight: 600; color: #0b5fff; white-space: nowrap; }
.chat-messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 8px; background: #f9fafb;
}
.chat-msg { display: flex; flex-direction: column; max-width: 80%; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.theirs { align-self: flex-start; align-items: flex-start; }
.chat-bubble {
  padding: 9px 13px; border-radius: 16px; font-size: 15px; line-height: 1.4;
  word-break: break-word; white-space: pre-wrap;
}
.mine .chat-bubble { background: #0b5fff; color: #ffffff; border-bottom-right-radius: 4px; }
.theirs .chat-bubble { background: #ffffff; color: #101828; border: 1px solid #101828; border-bottom-left-radius: 4px; }
.chat-bubble-deleted { font-style: italic; opacity: 0.7; }
.chat-bubble-media { padding: 4px; }
.chat-bubble-media img { display: block; max-width: min(240px, 100%); max-height: 300px; border-radius: 12px; }
.chat-bubble-audio { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.voice-play {
  width: 34px; height: 34px; border-radius: 50%; border: 0; padding: 0; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.25); color: inherit;
}
.theirs .voice-play { background: #f2f4f7; color: #101828; border: 1px solid #101828; }
.voice-play svg { width: 18px; height: 18px; }
.voice-wave { display: flex; align-items: center; gap: 2px; height: 26px; flex: 1; }
.voice-wave span { width: 3px; height: 40%; background: currentColor; opacity: 0.65; border-radius: 2px; }
.voice-wave span:nth-child(3n) { height: 85%; }
.voice-wave span:nth-child(3n+1) { height: 55%; }
.voice-wave span:nth-child(5n) { height: 100%; }
.voice-dur { font-size: 12px; font-variant-numeric: tabular-nums; }
.chat-meta { font-size: 11px; color: #667085; margin-top: 3px; padding: 0 4px; }
.chat-typing { padding: 4px 16px; font-size: 12px; color: #475467; font-style: italic; flex-shrink: 0; }
.chat-quick-replies {
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 14px; flex-shrink: 0;
  background: #ffffff; border-top: 1px solid #e4e7ec; scrollbar-width: none;
}
.chat-quick-replies::-webkit-scrollbar { display: none; }
.qr-chip {
  flex: 0 0 auto; padding: 7px 14px; font-size: 13px; font-weight: 600; white-space: nowrap;
  background: #ffffff; color: #101828; border: 1px solid #101828; border-radius: 999px;
}
.qr-chip:active { background: #f2f4f7; }
.chat-composer {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
  padding: 10px 12px; background: #ffffff; border-top: 1px solid #101828;
}
.chat-input {
  flex: 1; min-width: 0; height: 44px; padding: 0 14px; font-size: 16px; font-family: inherit;
  border: 1px solid #101828; border-radius: 999px; background: #ffffff; color: #101828; outline: none;
}
.chat-input:focus { border-color: #0b5fff; box-shadow: 0 0 0 2px rgba(11,95,255,0.15); }
.chat-attach, .chat-mic {
  width: 44px; height: 44px; border-radius: 50%; padding: 0; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: #ffffff; color: #101828; border: 1px solid #101828;
}
.chat-send {
  width: 44px; height: 44px; border-radius: 50%; padding: 0; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: #0b5fff; color: #ffffff; border: 1px solid #0b5fff;
}
.chat-recording {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  padding: 10px 14px; background: #fef3f2; border-top: 1px solid #fda29b; font-size: 14px;
}
.chat-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #d92d20; animation: crx-pulse 1s infinite; }
@keyframes crx-pulse { 50% { opacity: 0.3; } }
.chat-rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.chat-rec-hint { flex: 1; color: #475467; font-size: 13px; }
.chat-rec-cancel { width: 34px; height: 34px; border-radius: 50%; background: #ffffff; border: 1px solid #101828; }
.chat-uploading { padding: 8px 14px; font-size: 13px; background: #f2f4f7; color: #475467; text-align: center; flex-shrink: 0; }

/* Inbox / conversation list */
.messages-page { max-width: 720px; margin: 0 auto; padding: 16px 14px 24px; }
.messages-title { font-size: 24px; font-weight: 700; color: #101828; margin: 4px 0 14px; }
.messages-empty {
  text-align: center; padding: 40px 20px; background: #ffffff;
  border: 1px solid #101828; border-radius: 16px;
}
.messages-empty-icon { font-size: 40px; margin-bottom: 8px; }
.messages-empty-head { font-size: 17px; font-weight: 700; color: #101828; margin: 0 0 6px; }
.messages-empty-sub { font-size: 14px; color: #475467; margin: 0; }
.conv-list { display: flex; flex-direction: column; gap: 10px; }
.conv-row {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: #ffffff; border: 1px solid #101828; border-radius: 14px;
  text-decoration: none; color: #101828;
}
.conv-row:hover, .conv-row:focus-visible { border-color: #0b5fff; }
.conv-avatar-wrap { position: relative; flex-shrink: 0; }
.conv-avatar {
  width: 48px; height: 48px; border-radius: 50%; overflow: hidden;
  background: #0b5fff; color: #ffffff; font-weight: 700; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.conv-avatar img { width: 100%; height: 100%; object-fit: cover; }
.conv-online {
  position: absolute; right: 0; bottom: 0; width: 13px; height: 13px;
  border-radius: 50%; background: #12b76a; border: 2px solid #ffffff;
}
.conv-body { flex: 1; min-width: 0; }
.conv-top, .conv-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conv-name { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: #667085; white-space: nowrap; flex-shrink: 0; }
.conv-preview {
  font-size: 14px; color: #475467; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; min-width: 0; flex: 1;
}
.conv-unread {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; flex-shrink: 0;
  background: #0b5fff; color: #ffffff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.conv-listing {
  display: block; margin-top: 3px; font-size: 12px; font-weight: 600; color: #0b5fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 640px) { .messages-page { padding-bottom: 90px; } }

/* Image messages: no bubble border/background, just the photo */
.chat-bubble.chat-bubble-media,
.mine .chat-bubble.chat-bubble-media,
.theirs .chat-bubble.chat-bubble-media {
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
}
.chat-bubble-media img {
  border: 1px solid #101828;
  border-radius: 14px;
  background: #ffffff;
}

/* Delete-message popup (opened by long-press or right-click on your own message) */
.chat-msg-menu {
  position: fixed;
  z-index: 10002;
  min-width: 160px;
  padding: 6px;
  background: #ffffff;
  border: 1px solid #101828;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.2);
}
.chat-msg-menu-del {
  display: block;
  width: 100%;
  padding: 11px 14px;
  text-align: left;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #d92d20;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.chat-msg-menu-del:hover,
.chat-msg-menu-del:active { background: #fef3f2; }
.chat-msg.mine .chat-bubble,
.chat-msg.mine .chat-bubble img { -webkit-touch-callout: none; }

/* Delete-message popup (opened by long-press or right-click on your own message) */
.chat-msg-menu {
  position: fixed;
  z-index: 10002;
  min-width: 160px;
  padding: 6px;
  background: #ffffff;
  border: 1px solid #101828;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.2);
}
.chat-msg-menu-del {
  display: block;
  width: 100%;
  padding: 11px 14px;
  text-align: left;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #d92d20;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.chat-msg-menu-del:hover,
.chat-msg-menu-del:active { background: #fef3f2; }
.chat-msg.mine .chat-bubble,
.chat-msg.mine .chat-bubble img { -webkit-touch-callout: none; }

/* Photos hug the correct side instead of stretching */
.chat-bubble.chat-bubble-media { width: fit-content !important; max-width: 100%; }
.mine .chat-bubble.chat-bubble-media { margin-left: auto; }
.theirs .chat-bubble.chat-bubble-media { margin-right: auto; }

/* Photos: fixed width so the message box hugs the photo and aligns right/left */
.chat-bubble-media img {
  width: min(260px, 70vw) !important;
  max-width: none !important;
  height: auto !important;
  max-height: 340px;
  object-fit: cover;
}
.chat-msg.mine { margin-left: auto; }
.chat-msg.theirs { margin-right: auto; }
.chat-msg:has(.chat-bubble-media) { width: fit-content; }

/* Full-screen photo viewer (tap a chat photo to open, tap anywhere to close) */
.chat-bubble-media img { cursor: zoom-in; }
.chat-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10003;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.94);
  cursor: zoom-out;
}
.chat-lightbox.open { display: flex; }
.chat-lightbox img {
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 0;
}
.chat-lightbox::after {
  content: "\00d7";
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 14px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  line-height: 1;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
}
