/* Chat fullscreen overlay — bright Telegram-style day theme */
#chatFullscreen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  max-width: 480px;
  margin: 0 auto;
  flex-direction: column;
  background: linear-gradient(165deg, #e8f4fc 0%, #d8ecfa 35%, #cfe8ff 55%, #c5e3fd 100%);
  overflow: hidden;
}
#chatFullscreen.active { display: flex; }

#chatFullscreen::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Ccircle cx='18' cy='24' r='3' fill='%232563eb'/%3E%3Ccircle cx='92' cy='18' r='2.5' fill='%230ea5e9'/%3E%3Ccircle cx='70' cy='88' r='2' fill='%2360a5fa'/%3E%3Cpath d='M40 60 Q55 45 70 60 T100 60' stroke='%2393c5fd' stroke-width='1.2' fill='none' opacity='0.7'/%3E%3Cpath d='M10 95 Q30 80 50 95' stroke='%2367e8f9' stroke-width='1' fill='none' opacity='0.6'/%3E%3C/svg%3E");
  background-size: 120px 120px;
  animation: chatBgDrift 42s linear infinite;
  z-index: 0;
}
@keyframes chatBgDrift {
  from { background-position: 0 0; }
  to { background-position: 360px 240px; }
}

/* Chat header */
.chat-fs-header {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(37, 99, 235, 0.12);
  height: 44px;
  gap: 10px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}
.chat-fs-header .hamburger {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: #0f172a;
  font-size: 21px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-fs-header .hamburger:active { background: rgba(37, 99, 235, 0.08); }
.chat-fs-header .title {
  flex: 1;
  font-size: 17px;
  font-weight: 700;
  color: #0f172a;
  cursor: pointer;
}
.chat-fs-header .back-btn {
  font-size: 13px;
  color: #1d4ed8;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(37, 99, 235, 0.35);
  border-radius: 14px;
  padding: 5px 12px;
  cursor: pointer;
}

/* Sidebar overlay */
.chat-sidebar-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.chat-sidebar-overlay.active { opacity: 1; pointer-events: auto; }

/* Sidebar */
.chat-sidebar {
  position: absolute;
  top: 0;
  left: -300px;
  width: 300px;
  height: 100%;
  background: rgba(248, 250, 252, 0.97);
  backdrop-filter: blur(12px);
  z-index: 20;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(37, 99, 235, 0.1);
}
.chat-sidebar.open { left: 0; }
.chat-sidebar-top {
  padding: 17px;
  border-bottom: 1px solid rgba(37, 99, 235, 0.1);
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-sidebar-top h3 {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
}
.chat-sidebar-top .actions { display: flex; gap: 7px; }
.chat-sidebar-top .actions button {
  padding: 6px 11px;
  border-radius: 8px;
  border: none;
  background: rgba(59, 130, 246, 0.18);
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chat-group-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chat-group-item {
  display: flex;
  align-items: center;
  padding: 11px 16px;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.chat-group-item:active { background: rgba(59, 130, 246, 0.1); }
.chat-group-item .avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.chat-group-item .info { flex: 1; min-width: 0; }
.chat-group-item .name {
  font-size: 17px;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.chat-group-item .last-msg {
  font-size: 14px;
  color: #475569;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-group-item .meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.chat-group-item .time { font-size: 12px; color: #64748b; }
.chat-group-item .members-badge {
  font-size: 11px;
  color: #475569;
  background: rgba(226, 232, 240, 0.95);
  padding: 2px 7px;
  border-radius: 8px;
}

/* Skeleton loader */
.chat-skeleton-loader { padding: 12px 16px; }
.chat-skeleton-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.chat-skeleton-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #e2e8f0;
  animation: chatShimmer 1.5s infinite;
  flex-shrink: 0;
}
.chat-skeleton-lines { flex: 1; }
.chat-skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: #e2e8f0;
  animation: chatShimmer 1.5s infinite;
  margin-bottom: 8px;
}
.chat-skeleton-line.long { width: 75%; }
.chat-skeleton-line.short { width: 45%; }
.chat-skeleton-text {
  text-align: center;
  font-size: 14px;
  color: #64748b;
  padding: 12px 0 20px;
  opacity: 0.85;
}
@keyframes chatShimmer { 0%{opacity:0.45} 50%{opacity:0.85} 100%{opacity:0.45} }

/* Messages area */
.chat-fs-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.38);
  background-image:
    radial-gradient(circle at 15% 25%, rgba(147, 197, 253, 0.35) 0%, transparent 42%),
    radial-gradient(circle at 85% 70%, rgba(186, 230, 253, 0.45) 0%, transparent 45%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Ccircle cx='12' cy='20' r='1.2' fill='%2393c5fd' opacity='0.35'/%3E%3Ccircle cx='58' cy='64' r='1' fill='%2367e8f9' opacity='0.4'/%3E%3C/svg%3E");
  background-size: auto, auto, 80px 80px;
}
.chat-msg { max-width: 82%; animation: chatMsgIn 0.2s ease-out; }
@keyframes chatMsgIn { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }
.chat-msg.in { align-self: flex-start; }
.chat-msg.out { align-self: flex-end; }

.chat-msg .sender {
  font-size: 13px;
  font-weight: 700;
  color: #1e40af;
  margin-bottom: 3px;
  padding-left: 10px;
}
.chat-msg.out .sender {
  text-align: right;
  padding-left: 0;
  padding-right: 10px;
  color: #1d4ed8;
}

.chat-msg .bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 17px;
  line-height: 1.45;
  word-break: break-word;
  color: #0f172a;
}
.chat-msg.in .bubble {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-top-left-radius: 5px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.chat-msg.out .bubble {
  background: linear-gradient(145deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
  border-top-right-radius: 5px;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.25);
}
.chat-msg.out .bubble .msg-time { color: rgba(255, 255, 255, 0.88); }
.chat-msg .bubble .msg-time {
  font-size: 12px;
  color: #64748b;
  float: right;
  margin-left: 8px;
  margin-top: 4px;
}

/* Media thumbnails — ~25vw wide per product spec */
.chat-msg .bubble img {
  width: 25vw;
  max-width: 160px;
  min-width: 92px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 10px;
  margin-top: 0;
  cursor: pointer;
  display: block;
  background: #dbeafe;
}

.chat-video-thumb {
  position: relative;
  display: inline-block;
  width: 25vw;
  max-width: 160px;
  min-width: 92px;
  aspect-ratio: 3 / 4;
  vertical-align: bottom;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(180deg, #0b1f3a 0%, #0a1730 100%);
}
.chat-video-thumb video {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 10px;
  background: #0f172a;
  object-fit: cover;
  pointer-events: none;
}
.chat-video-thumb .chat-video-cover {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 10px;
  object-fit: cover;
  background: linear-gradient(180deg, #0b1f3a 0%, #0a1730 100%);
}
.chat-video-play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.55);
  color: #fff;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  padding-left: 3px;
}

.chat-msg .bubble.media-only {
  padding: 2px;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}
.chat-msg.in .bubble.media-only { background: transparent !important; }
.chat-msg.out .bubble.media-only { background: transparent !important; }
.chat-msg .bubble.media-only img,
.chat-msg .bubble.media-only .chat-video-thumb {
  margin-top: 0;
}
.chat-msg.out .bubble.media-only .msg-time {
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

/* Input area */
.chat-fs-input {
  display: flex;
  align-items: flex-end;
  padding: 9px 12px;
  gap: 8px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(37, 99, 235, 0.12);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}
.chat-fs-input .icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  color: #475569;
  font-size: 22px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-fs-input .icon-btn:active { color: #2563eb; }
.chat-fs-input textarea {
  flex: 1;
  background: rgba(241, 245, 249, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 20px;
  padding: 11px 15px;
  color: #0f172a;
  font-size: 17px;
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 38px;
  line-height: 1.45;
}
.chat-fs-input textarea::placeholder { color: #94a3b8; }
.chat-fs-input .send-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: linear-gradient(145deg, #3b82f6, #2563eb);
  color: #fff;
  font-size: 17px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Emoji picker */
.chat-emoji-panel {
  display: none;
  position: absolute;
  bottom: 58px;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(37, 99, 235, 0.1);
  max-height: 220px;
  overflow-y: auto;
  padding: 10px;
  z-index: 30;
}
.chat-emoji-panel.active { display: block; }
.chat-emoji-panel .emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.chat-emoji-panel .emoji-item {
  font-size: 24px;
  text-align: center;
  padding: 7px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
}
.chat-emoji-panel .emoji-item:active { background: rgba(59, 130, 246, 0.15); }

/* Empty state */
.chat-fs-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #475569;
  gap: 9px;
  font-size: 16px;
}
.chat-fs-empty .icon { font-size: 52px; opacity: 0.55; }

/* Toast */
.chat-toast {
  position: absolute;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  color: #f8fafc;
  padding: 11px 21px;
  border-radius: 22px;
  font-size: 14px;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.chat-toast.show { opacity: 1; }

/* Modal */
.chat-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.chat-modal-box {
  background: #ffffff;
  border-radius: 14px;
  padding: 26px;
  width: 320px;
  max-width: 85%;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.15);
}
.chat-modal-box h3 { font-size: 18px; margin-bottom: 5px; color: #0f172a; font-weight: 700; }
.chat-modal-box p { font-size: 14px; color: #475569; margin-bottom: 15px; }
.chat-modal-box input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  font-size: 16px;
  outline: none;
  margin-bottom: 15px;
}
.chat-modal-box input:focus { border-color: #3b82f6; }
.chat-modal-btns { display: flex; gap: 10px; justify-content: flex-end; }
.chat-modal-btns button {
  padding: 9px 19px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  cursor: pointer;
}
.chat-modal-btns .cancel { background: #e2e8f0; color: #475569; }
.chat-modal-btns .primary { background: #2563eb; color: #fff; }

/* Image/Video viewer (fullscreen) */
.chat-img-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.93);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  cursor: default;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.chat-img-viewer-close {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  z-index: 100001;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.chat-img-viewer-close:active { transform: scale(0.96); }

.chat-img-viewer-img {
  max-width: 96%;
  max-height: 88vh;
  border-radius: 6px;
  cursor: default;
}

.chat-img-viewer-video {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
  cursor: default;
  object-fit: contain;
  background: #000;
}
