:root {
  --chat-bg:        #111213;
  --chat-card:      #1a1c1e;
  --chat-item:      #1e2122;
  --chat-teal:      #00897b;
  --chat-teal-lt:   #26a69a;
  --chat-gold:      #f5c518;
  --chat-text:      #e8eaea;
  --chat-muted:     #7a8a8a;
  --chat-border:    #242829;
  --chat-success:   #00c853;
  --chat-danger:    #e53935;
  --chat-in-bg:     #20262a;
  --chat-in-border: #2c343a;
  --chat-radius:    16px;
  --chat-tr:        .22s cubic-bezier(.4,0,.2,1);
}

.chat-fab {
  position: fixed;
  right: 18px;
  bottom: 96px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-teal), var(--chat-teal-lt));
  border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(0,137,123,.45);
  z-index: 500;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .25s ease;
  animation: fabPop .4s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes fabPop { from{transform:scale(0);opacity:0} to{transform:scale(1);opacity:1} }
.chat-fab:hover { transform: scale(1.08) translateY(-2px); box-shadow: 0 10px 30px rgba(0,137,123,.55); }
.chat-fab:active { transform: scale(.94); }

.chat-fab-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--chat-danger); color: #fff;
  font-size: .6rem; font-weight: 900;
  min-width: 20px; height: 20px;
  padding: 0 4px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--chat-bg);
  animation: badgePop .3s cubic-bezier(.34,1.56,.64,1) both;
  line-height: 1;
}
@keyframes badgePop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.chat-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(6px);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease; z-index: 1000;
}
.chat-modal-overlay.open { opacity: 1; pointer-events: all; }

.chat-modal {
  width: 100%; max-width: 480px;
  height: 88vh; max-height: 700px;
  background: var(--chat-card);
  border-radius: 24px 24px 0 0;
  border: 1px solid var(--chat-border); border-bottom: none;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .4s cubic-bezier(.34,1.2,.64,1);
  overflow: hidden;
}
.chat-modal-overlay.open .chat-modal { transform: translateY(0); }

.chat-header {
  padding: 16px 18px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(135deg, #0d4a43, #0a2e29);
  border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
}
.chat-header-left { display: flex; align-items: center; gap: 12px; }
.chat-avatar-online { position: relative; flex-shrink: 0; }
.chat-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-teal), var(--chat-teal-lt));
  display: flex; align-items: center; justify-content: center;
  font-family: 'Rajdhani', sans-serif;
  font-size: .85rem; font-weight: 700; color: #fff; letter-spacing: 1px;
}
.chat-online-dot {
  position: absolute; bottom: 1px; right: 1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--chat-success); border: 2px solid #0d4a43;
  animation: onlinePulse 2s infinite;
}
@keyframes onlinePulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.chat-header-title { font-family:'Rajdhani',sans-serif; font-size:1rem; font-weight:700; color:#fff; margin-bottom:2px; }
.chat-header-status { font-size:.67rem; font-weight:700; color:var(--chat-success); letter-spacing:.5px; }
.chat-close-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15);
  color: rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background var(--chat-tr);
}
.chat-close-btn:hover { background: rgba(255,255,255,.2); color: #fff; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 14px;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--chat-bg); scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #2a3030; border-radius: 2px; }

.chat-date-divider {
  text-align: center; font-size: .62rem; font-weight: 800;
  letter-spacing: 2px; text-transform: uppercase;
  color: var(--chat-muted); padding: 8px 0; position: relative;
}
.chat-date-divider::before, .chat-date-divider::after {
  content: ''; position: absolute; top: 50%;
  width: calc(50% - 40px); height: 1px; background: var(--chat-border);
}
.chat-date-divider::before { left: 0; }
.chat-date-divider::after  { right: 0; }

.chat-welcome {
  display: flex; gap: 10px; align-items: flex-start;
  background: rgba(0,137,123,.08);
  border: 1px solid rgba(0,137,123,.2);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
}
.chat-welcome-icon { font-size: 1.2rem; flex-shrink: 0; }
.chat-welcome-text { font-size: .78rem; color: rgba(0,200,160,.8); line-height: 1.6; font-weight: 600; }

.chat-msg {
  display: flex; gap: 8px; max-width: 88%;
  animation: msgPop .25s cubic-bezier(.34,1.56,.64,1) both;
  position: relative;
}
@keyframes msgPop { from{opacity:0;transform:translateY(8px) scale(.96)} to{opacity:1;transform:translateY(0) scale(1)} }

.chat-msg.incoming { align-self: flex-start; flex-direction: row; }
.chat-msg.outgoing { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .6rem; font-weight: 900; color: #fff;
  flex-shrink: 0; margin-top: 2px; letter-spacing: .5px;
}
.chat-msg.incoming .msg-avatar { background: linear-gradient(135deg, var(--chat-teal), var(--chat-teal-lt)); }
.chat-msg.outgoing .msg-avatar { background: linear-gradient(135deg, #4a4a4a, #2c2c2c); }

.msg-bubble-wrap { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.msg-meta { display: flex; align-items: center; gap: 6px; padding: 0 4px; }
.chat-msg.outgoing .msg-meta { flex-direction: row-reverse; }
.msg-sender { font-size: .65rem; font-weight: 800; color: var(--chat-teal-lt); letter-spacing: .3px; }
.chat-msg.outgoing .msg-sender { color: var(--chat-muted); }
.msg-time { font-size: .58rem; color: var(--chat-muted); letter-spacing: .3px; }

.msg-bubble {
  padding: 10px 13px; border-radius: 18px; font-size: .82rem;
  line-height: 1.55; word-break: break-word; position: relative; cursor: pointer;
}
.chat-msg.incoming .msg-bubble {
  background: var(--chat-in-bg); border: 1px solid var(--chat-in-border);
  color: var(--chat-text); border-bottom-left-radius: 4px;
}
.chat-msg.outgoing .msg-bubble {
  background: linear-gradient(135deg, var(--chat-teal), var(--chat-teal-lt));
  color: #fff; border-bottom-right-radius: 4px;
}
.msg-bubble:active { filter: brightness(1.08); }

.msg-image { max-width: 100%; width: 220px; border-radius: 12px; display: block; cursor: pointer; transition: opacity var(--chat-tr); }
.msg-image:hover { opacity: .9; }
.msg-img-wrap { padding: 6px 6px 2px; }

.msg-video { max-width: 100%; width: 240px; border-radius: 12px; display: block; background: #000; }
.msg-video-wrap { padding: 6px 6px 2px; }

.msg-audio-wrap { padding: 4px 4px 2px; min-width: 200px; }
.msg-audio-wrap audio { width: 100%; height: 38px; border-radius: 20px; }
.chat-msg.incoming .msg-audio-wrap audio { filter: invert(.9) hue-rotate(180deg); }
.chat-msg.outgoing .msg-audio-wrap audio { filter: invert(1) hue-rotate(180deg) brightness(1.3); }

.msg-ticks { text-align: right; font-size: .62rem; color: rgba(255,255,255,.6); margin-top: 2px; padding-right: 2px; }

.msg-reply-quote {
  display: flex; gap: 8px; align-items: stretch;
  background: rgba(0,0,0,.15); border-radius: 10px;
  padding: 6px 10px; margin: 2px 2px 8px; cursor: pointer;
}
.chat-msg.incoming .msg-reply-quote { background: rgba(0,137,123,.08); }
.chat-msg.outgoing .msg-reply-quote { background: rgba(255,255,255,.15); }
.msg-reply-bar { width: 3px; border-radius: 2px; background: var(--chat-teal-lt); flex-shrink: 0; }
.chat-msg.outgoing .msg-reply-bar { background: rgba(255,255,255,.6); }
.msg-reply-info { min-width: 0; padding: 1px 0; }
.msg-reply-sender { font-size: .68rem; font-weight: 800; color: var(--chat-teal-lt); margin-bottom: 1px; }
.chat-msg.outgoing .msg-reply-sender { color: rgba(255,255,255,.85); }
.msg-reply-text {
  font-size: .72rem; color: var(--chat-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.chat-msg.outgoing .msg-reply-text { color: rgba(255,255,255,.7); }

.msg-actions {
  position: absolute; top: -2px; display: flex; gap: 4px;
  opacity: 0; transition: opacity var(--chat-tr); pointer-events: none;
}
.chat-msg.incoming .msg-actions { right: -34px; }
.chat-msg.outgoing .msg-actions { left: -34px; }
.chat-msg:hover .msg-actions { opacity: 1; pointer-events: all; }
.msg-action-btn {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--chat-item); border: 1px solid var(--chat-border); color: var(--chat-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background var(--chat-tr), color var(--chat-tr);
}
.msg-action-btn:hover { background: var(--chat-teal); color: #fff; border-color: var(--chat-teal); }
.msg-action-btn svg { width: 13px; height: 13px; }

.chat-typing { display: flex; align-items: center; gap: 8px; padding: 8px 14px; flex-shrink: 0; }
.typing-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-teal), var(--chat-teal-lt));
  display: flex; align-items: center; justify-content: center;
  font-size: .55rem; font-weight: 900; color: #fff; flex-shrink: 0;
}
.typing-dots { display: flex; gap: 4px; background: var(--chat-in-bg); border: 1px solid var(--chat-border); border-radius: 14px; padding: 8px 12px; }
.typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--chat-muted); animation: typingBounce 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce { 0%,60%,100%{transform:translateY(0);opacity:.5} 30%{transform:translateY(-5px);opacity:1} }
.typing-label { font-size: .65rem; color: var(--chat-muted); font-weight: 600; }

.reply-bar {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  background: var(--chat-item); border-top: 1px solid var(--chat-border); flex-shrink: 0;
}
.reply-bar-line { width: 3px; height: 30px; background: var(--chat-teal); border-radius: 2px; flex-shrink: 0; }
.reply-bar-content { flex: 1; min-width: 0; }
.reply-bar-sender { font-size: .7rem; font-weight: 800; color: var(--chat-teal-lt); margin-bottom: 2px; }
.reply-bar-text { font-size: .74rem; color: var(--chat-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar-close { width: 26px; height: 26px; border-radius: 50%; background: transparent; border: none; color: var(--chat-muted); cursor: pointer; font-size: .8rem; flex-shrink: 0; }
.reply-bar-close:hover { color: var(--chat-danger); }

.chat-img-preview, .chat-video-preview {
  padding: 8px 14px 4px; position: relative;
  display: flex; align-items: center; gap: 10px;
  background: var(--chat-item); border-top: 1px solid var(--chat-border); flex-shrink: 0;
}
.chat-img-preview img { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; border: 1px solid var(--chat-border); }
.chat-video-preview video { width: 64px; height: 52px; border-radius: 10px; object-fit: cover; border: 1px solid var(--chat-border); background:#000; }
.preview-remove-btn {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--chat-muted); border: none; color: #fff; font-size: .7rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.preview-filename { font-size: .7rem; color: var(--chat-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }

.audio-record-bar {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px;
  background: rgba(229,57,53,.08); border-top: 1px solid rgba(229,57,53,.25); flex-shrink: 0;
}
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--chat-danger); animation: recBlink 1s infinite; flex-shrink: 0; }
@keyframes recBlink { 0%,100%{opacity:1} 50%{opacity:.3} }
.rec-time { font-family: 'Rajdhani', sans-serif; font-size: 1rem; font-weight: 700; color: var(--chat-danger); letter-spacing: 1px; }
.rec-label { flex: 1; font-size: .75rem; color: rgba(229,57,53,.8); font-weight: 700; }
.rec-cancel-btn, .rec-stop-btn {
  border: none; border-radius: 10px; padding: 7px 12px;
  font-family: 'Nunito', sans-serif; font-size: .7rem; font-weight: 800; cursor: pointer; transition: opacity var(--chat-tr);
}
.rec-cancel-btn { background: var(--chat-item); color: var(--chat-muted); }
.rec-stop-btn   { background: var(--chat-danger); color: #fff; }
.rec-cancel-btn:hover, .rec-stop-btn:hover { opacity: .85; }

.audio-preview-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--chat-item); border-top: 1px solid var(--chat-border); flex-shrink: 0;
}
.audio-preview-bar audio { flex: 1; height: 36px; }

.chat-input-area {
  padding: 10px 12px; display: flex; align-items: flex-end; gap: 8px;
  background: var(--chat-card); border-top: 1px solid var(--chat-border);
  flex-shrink: 0; position: relative;
}
.attach-wrap { position: relative; flex-shrink: 0; }
.chat-attach-btn {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--chat-item); border: 1px solid var(--chat-border); color: var(--chat-muted);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background var(--chat-tr), color var(--chat-tr), border-color var(--chat-tr), transform var(--chat-tr);
}
.chat-attach-btn:hover { background: #1e2f2e; border-color: var(--chat-teal); color: var(--chat-teal-lt); }
.chat-attach-btn.active { transform: rotate(45deg); background: var(--chat-teal); color: #fff; border-color: var(--chat-teal); }

.attach-menu {
  position: absolute; bottom: 50px; left: 0;
  background: var(--chat-card); border: 1px solid var(--chat-border);
  border-radius: 14px; padding: 8px; display: none; flex-direction: column; gap: 4px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5); z-index: 10; min-width: 140px;
  animation: menuPop .2s cubic-bezier(.34,1.56,.64,1) both;
}
.attach-menu.open { display: flex; }
@keyframes menuPop { from{opacity:0;transform:translateY(8px) scale(.95)} to{opacity:1;transform:translateY(0) scale(1)} }
.attach-option { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer; transition: background var(--chat-tr); }
.attach-option:hover { background: var(--chat-item); }
.attach-opt-icon { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: .95rem; flex-shrink: 0; }
.attach-opt-icon.img-bg { background: rgba(33,150,243,.12); }
.attach-opt-icon.vid-bg { background: rgba(156,39,176,.12); }
.attach-opt-icon.aud-bg { background: rgba(229,57,53,.12); }
.attach-opt-label { font-size: .8rem; font-weight: 700; color: var(--chat-text); }

.chat-input-wrap { flex: 1; }
.chat-textarea {
  width: 100%; background: var(--chat-item); border: 1.5px solid var(--chat-border);
  border-radius: 20px; padding: 10px 16px; color: var(--chat-text);
  font-family: 'Nunito', sans-serif; font-size: .88rem;
  resize: none; outline: none; max-height: 120px; overflow-y: auto; line-height: 1.4;
  transition: border-color var(--chat-tr), box-shadow var(--chat-tr);
}
.chat-textarea:focus { border-color: var(--chat-teal); box-shadow: 0 0 0 3px rgba(0,137,123,.1); }
.chat-textarea::placeholder { color: #3a4040; }

.chat-send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-teal), var(--chat-teal-lt));
  border: none; color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
  box-shadow: 0 3px 12px rgba(0,137,123,.4);
  transition: transform var(--chat-tr), box-shadow var(--chat-tr);
}
.chat-send-btn:hover { transform: scale(1.08); box-shadow: 0 5px 18px rgba(0,137,123,.55); }
.chat-send-btn:active { transform: scale(.94); }

.chat-loading { display: flex; justify-content: center; padding: 20px; }
.chat-spinner { width: 24px; height: 24px; border: 2.5px solid var(--chat-border); border-top-color: var(--chat-teal); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

.chat-error {
  text-align: center; font-size: .75rem; color: #ef9a9a;
  background: rgba(229,57,53,.08); border: 1px solid rgba(229,57,53,.2);
  border-radius: 10px; padding: 10px 14px; margin: 8px 0;
}

.img-lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.9);
  z-index: 2000; display: flex; align-items: center; justify-content: center;
  cursor: pointer; animation: fadeIn .2s ease;
}
.img-lightbox img, .img-lightbox video { max-width: 94vw; max-height: 90vh; border-radius: 12px; object-fit: contain; }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }