/* Floating chat / call windows (docked bottom-right, like the compose window) */
.chat-window {
  position: fixed;
  bottom: 0;
  right: 24px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 50px);
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 2px 10px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  z-index: 95;
  overflow: hidden;
}
body.theme-light .chat-window { background: #fff; border-color: #cbd5e1; box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.chat-window.hidden { display: none !important; }
.chat-window.minimized { height: 42px !important; }
.chat-window.minimized > :not(.compose-header) { display: none !important; }
body:has(#modal-compose:not(.hidden)) #chat-window { right: 616px; }

.chat-header-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.chat-status { font-size: 11px; opacity: .7; }
.chat-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-view.hidden { display: none; }
.chat-search { padding: 10px; }
.chat-search input, .chat-input input {
  width: 100%; padding: 8px 10px; border: 1px solid rgba(128,128,128,.4);
  border-radius: 8px; background: transparent; color: inherit;
}
.chat-empty-note { padding: 28px 18px; text-align: center; font-size: 13px; opacity: .6; }

/* Avatars */
.chat-avatar {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 32px; height: 32px; border-radius: 50%; color: #fff; font-weight: 600; font-size: 13px; text-transform: uppercase;
}
.chat-avatar.hidden { display: none; }
.chat-avatar-sm { width: 26px; height: 26px; font-size: 11px; }
.chat-avatar-lg { width: 84px; height: 84px; font-size: 32px; }

/* Conversation list */
.chat-conv-list { overflow-y: auto; flex: 1; }
.chat-conv { display: flex; gap: 10px; align-items: center; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid rgba(128,128,128,.15); }
.chat-conv:hover { background: rgba(128,128,128,.15); }
.chat-conv-body { flex: 1; min-width: 0; }
.chat-conv-top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 13px; }
.chat-conv-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-conv-last { font-size: 12px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-presence { position: relative; }
.chat-presence::after { content: ''; position: absolute; right: -1px; bottom: -1px; width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; border: 2px solid #111827; }
body.theme-light .chat-presence::after { border-color: #fff; }
.chat-presence.online::after { background: #22c55e; }
.chat-unread { background: var(--danger, #e74c3c); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; height: 16px; line-height: 16px; }

/* Messages: separate bubbles, sender name on each group */
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 3px; }
.chat-row { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; align-self: flex-start; flex-direction: row; }
.chat-row.me { align-self: flex-end; flex-direction: row-reverse; }
.chat-row.first { margin-top: 10px; }
.chat-avatar-spacer { width: 26px; flex-shrink: 0; }
.chat-bubble-wrap { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.chat-row.me .chat-bubble-wrap { align-items: flex-end; }
.chat-sender { font-size: 11px; font-weight: 600; opacity: .75; margin: 0 6px 2px; }
.chat-msg { padding: 7px 11px; border-radius: 14px 14px 14px 4px; background: rgba(128,128,128,.24); white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.4; }
.chat-row.me .chat-msg { background: var(--primary, #3b82f6); color: #fff; border-radius: 14px 14px 4px 14px; }
.chat-msg-time { font-size: 10px; opacity: .55; margin: 2px 6px 0; }
.chat-input { display: flex; gap: 8px; padding: 8px 10px; border-top: 1px solid rgba(128,128,128,.25); }

/* Call window */
.call-window { right: auto; left: 24px; width: 380px; height: auto; z-index: 96; background: #0b1220; border-color: rgba(255,255,255,.1); }
.call-stage { position: relative; background: radial-gradient(circle at 50% 35%, #1e293b, #0b1220); aspect-ratio: 4 / 3; overflow: hidden; }
#call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; opacity: 0; transition: opacity .25s; }
.call-stage.has-video #call-remote { opacity: 1; }
.call-topbar { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 6px; align-items: center; z-index: 2; }
.call-pill { background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 3px 10px; border-radius: 999px; backdrop-filter: blur(6px); }
.call-pill.hidden { display: none; }
.call-pill-muted { margin-left: auto; opacity: .85; }
.call-avatar-wrap { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #fff; }
.call-stage.has-video .call-avatar-wrap { display: none; }
.call-peer { font-size: 17px; font-weight: 600; }
.call-state { font-size: 13px; opacity: .75; }
.call-stage.ringing .chat-avatar-lg { animation: call-pulse 1.4s ease-out infinite; }
@keyframes call-pulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.35); } 100% { box-shadow: 0 0 0 24px rgba(255,255,255,0); } }
.call-local { position: absolute; right: 10px; bottom: 10px; width: 28%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 2px solid rgba(255,255,255,.55); background: #111; transform: scaleX(-1); z-index: 2; }
.call-local.hidden { display: none; }
.call-controls { display: flex; gap: 14px; justify-content: center; padding: 14px 10px 18px; background: #0b1220; }
.call-btn { width: 48px; height: 48px; border-radius: 50%; border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: #fff; background: rgba(255,255,255,.14); transition: background .15s, transform .1s; }
.call-btn:hover { background: rgba(255,255,255,.25); }
.call-btn:active { transform: scale(.94); }
.call-btn.off { background: #fff; color: #111827; }
.call-btn.danger { background: #ef4444; }
.call-btn.danger:hover { background: #dc2626; }
.call-btn.success { background: #22c55e; }
.call-btn.success:hover { background: #16a34a; }
.call-btn.hidden, .call-btn svg.hidden { display: none; }

/* Draggable handles */
.chat-window .compose-header, .call-stage { cursor: grab; touch-action: none; }
.chat-window.dragging .compose-header, .chat-window.dragging .call-stage { cursor: grabbing; }
.chat-window.dragging { transition: none; user-select: none; }

@media (max-width: 768px) {
  .chat-window { right: 0 !important; left: 0 !important; width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
  .chat-window.minimized { height: 42px !important; }
  .call-window { height: auto; max-height: 100%; }
}
