/* ══════════════════════════════════════════════
   BibiBook Chat — Facebook 2010 style
   ══════════════════════════════════════════════ */

/* ── Chat bar (bottom) ──────────────────────── */
#chat-bar {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  height: 28px;
  background: linear-gradient(to bottom, #3e5a94, #2d4373);
  border-top: 1px solid #1e3060;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 8px;
  gap: 2px;
  box-shadow: 0 -1px 4px rgba(0,0,0,0.3);
  overflow: hidden;
}

#chat-bar-label {
  margin-right: auto;
  color: #c8d4f0;
  font-size: 11px;
  font-weight: bold;
  font-family: 'Lucida Grande', Arial, sans-serif;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: default;
  user-select: none;
}

#chat-bar-label::before {
  display: none;
}

/* ── Online user pills in bar ───────────────── */
.chat-bar-user {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 11px;
  color: #d8e4f8;
  font-family: 'Lucida Grande', Arial, sans-serif;
  transition: background 0.15s;
  position: relative;
  white-space: nowrap;
}
.chat-bar-user:hover {
  background: rgba(255,255,255,0.12);
}
.chat-bar-user .chat-bar-avatar {
  width: 18px; height: 18px;
  border-radius: 3px;
  background: #4a6fa5;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  overflow: hidden;
  flex-shrink: 0;
}
.chat-bar-user .chat-bar-avatar img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.chat-bar-user .online-dot {
  width: 7px; height: 7px;
  background: #6abf69;
  border-radius: 50%;
  border: 1px solid #2d4373;
  position: absolute;
  bottom: 2px; right: 4px;
}

/* ── Chat window ────────────────────────────── */
.chat-window {
  position: fixed;
  bottom: 28px;
  width: 320px;
  background: #fff;
  border: 1px solid #b0b8cc;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  box-shadow: -1px -2px 6px rgba(0,0,0,0.2);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  font-family: 'Lucida Grande', Arial, sans-serif;
  font-size: 11px;
}

.chat-window-header {
  background: linear-gradient(to bottom, #3e5a94, #2d4373);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px 4px 0 0;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  min-height: 26px;
}
.chat-window-header .chat-win-name {
  flex: 1;
  font-size: 11px;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-window-header .chat-win-avatar {
  width: 16px; height: 16px;
  border-radius: 2px;
  background: #4a6fa5;
  overflow: hidden;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px;
}
.chat-window-header .chat-win-avatar img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.chat-win-close {
  background: none;
  border: none;
  color: #c8d4f0;
  font-size: 13px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
}
.chat-win-close:hover { color: #fff; }

.chat-window-body {
  height: 300px;
  overflow-y: auto;
  padding: 6px 8px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}
.chat-window-body::-webkit-scrollbar { width: 4px; }
.chat-window-body::-webkit-scrollbar-thumb { background: #c4cfe0; border-radius: 2px; }

/* messages */
.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  max-width: 100%;
}
.chat-msg.mine {
  flex-direction: row-reverse;
}
.chat-msg-avatar {
  width: 20px; height: 20px;
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
  background: #4a6fa5;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
}
.chat-msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.chat-msg-name {
  font-size: 9px;
  font-weight: bold;
  color: #3b5998;
  margin-bottom: 1px;
}
.chat-msg.mine .chat-msg-name {
  color: #8b9dc3;
  text-align: right;
}
.chat-msg-bubble {
  background: #e8edf5;
  border-radius: 10px 10px 10px 2px;
  padding: 4px 8px;
  font-size: 11px;
  color: #1c2a3a;
  max-width: 230px;
  word-wrap: break-word;
  line-height: 1.4;
}
.chat-msg.mine .chat-msg-bubble {
  background: #3b5998;
  color: #fff;
  border-radius: 10px 10px 2px 10px;
}

.chat-msg-time {
  font-size: 9px;
  color: #aaa;
  text-align: center;
  margin: 2px 0;
}

.chat-msg-ts {
  font-size: 8px;
  color: #aaa;
  margin-top: 1px;
}
.chat-msg.mine .chat-msg-ts {
  text-align: right;
}

.chat-window-input {
  border-top: 1px solid #dce4f0;
  display: flex;
  align-items: center;
  padding: 4px 6px;
  background: #f5f7fa;
  border-radius: 0 0 0 0;
  gap: 4px;
}
.chat-window-input input {
  flex: 1;
  border: 1px solid #c4cfe0;
  border-radius: 10px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: inherit;
  outline: none;
  background: #fff;
}
.chat-window-input input:focus {
  border-color: #3b5998;
}
.chat-window-input button {
  background: none;
  border: none;
  color: #3b5998;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  flex-shrink: 0;
}
.chat-window-input button:hover { color: #1a3a6b; }

/* minimized state */
.chat-window.minimized .chat-window-body,
.chat-window.minimized .chat-window-input {
  display: none;
}

/* unread badge */
.chat-bar-user .unread-badge {
  background: #e00;
  color: #fff;
  border-radius: 8px;
  font-size: 9px;
  padding: 0 4px;
  min-width: 14px;
  text-align: center;
  line-height: 14px;
  height: 14px;
  display: none;
}
.chat-bar-user.has-unread .unread-badge { display: inline-block; }

/* ── Username prompt modal ──────────────────── */
#chat-name-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9100;
  align-items: center;
  justify-content: center;
}
#chat-name-modal.open { display: flex; }
#chat-name-box {
  background: #fff;
  border: 1px solid #b0b8cc;
  border-radius: 5px;
  padding: 20px 24px;
  width: 280px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  font-family: 'Lucida Grande', Arial, sans-serif;
}
#chat-name-box h3 {
  margin: 0 0 6px;
  font-size: 14px;
  color: #1c2a3a;
}
#chat-name-box p {
  font-size: 11px;
  color: #666;
  margin: 0 0 12px;
}
#chat-name-input {
  width: 100%;
  border: 1px solid #c4cfe0;
  border-radius: 3px;
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
  margin-bottom: 10px;
}
#chat-name-input:focus { border-color: #3b5998; }
#chat-name-btn {
  width: 100%;
  background: linear-gradient(to bottom, #5b74a8, #3b5998);
  color: #fff;
  border: 1px solid #2d4373;
  border-radius: 3px;
  padding: 6px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
}
#chat-name-btn:hover { background: linear-gradient(to bottom, #6a84b8, #4a6aa8); }

/* ── System message ─────────────────────────── */
.chat-system-msg {
  text-align: center;
  font-size: 10px;
  color: #aaa;
  font-style: italic;
  padding: 2px 0;
}
