/* ── Skeleton loading ─────────────────────────────────────────────────────── */
@keyframes sk-shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position:  400px 0; }
}

.skeleton-messages { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.sk-row { display: flex; align-items: flex-end; gap: 8px; }
.sk-row.sk-mine { flex-direction: row-reverse; }

.sk-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(90deg, #1e293b 25%, #263348 50%, #1e293b 75%);
  background-size: 800px 100%;
  animation: sk-shimmer 1.4s infinite linear;
}

.sk-bubble {
  height: 34px; border-radius: 14px; max-width: 70%;
  background: linear-gradient(90deg, #1e293b 25%, #263348 50%, #1e293b 75%);
  background-size: 800px 100%;
  animation: sk-shimmer 1.4s infinite linear;
}

/* Chat page overrides */
body {
  overflow: hidden !important;
  display: block !important;
  min-height: unset !important;
}

#chat-app {
  position: fixed;
  top: 48px;
  left: 0; right: 0; bottom: 0;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: #0d1a2e;
  border-right: 1px solid rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
}
.sidebar-heading {
  font-size: 14px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: 0.5px;
}
#new-chat-btn {
  background: rgba(59,130,246,0.15);
  border: 1px solid rgba(59,130,246,0.25);
  border-radius: 8px;
  color: #93c5fd;
  font-size: 14px;
  width: 30px; height: 30px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
#new-chat-btn:hover { background: rgba(59,130,246,0.25); }

#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-radius: 8px;
  margin: 2px 8px;
  transition: background 0.1s;
}
.conv-item:hover { background: rgba(255,255,255,0.04); }
.conv-item.active { background: rgba(59,130,246,0.12); }

.conv-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  font-family: 'JetBrains Mono', monospace;
}

.conv-info { flex: 1; min-width: 0; }
.conv-name { font-size: 13px; font-weight: 600; color: #e5e7eb; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 11px; color: #475569; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-preview.unread { color: #94a3b8; font-weight: 600; }
.conv-unread-badge {
  background: #3b82f6;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 8px;
  flex-shrink: 0;
  align-self: center;
}

/* ── Main panel ── */
#main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0f172a;
}

#conv-header {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
#conv-header-left { flex: 1; min-width: 0; }
#msg-search-wrap { flex-shrink: 0; }
#msg-search {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  color: #e5e7eb;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 5px 10px;
  outline: none;
  width: 130px;
  transition: width 0.2s, border-color 0.15s;
}
#msg-search:focus { width: 200px; border-color: rgba(0,245,255,0.3); }
#msg-search::placeholder { color: #334155; }
.msg-group.search-hidden { display: none; }
.msg-search-highlight { background: rgba(250,204,21,0.3); border-radius: 2px; }
#conv-header > div { flex: 1; }
#conv-title { font-size: 15px; font-weight: 700; color: #f1f5f9; }
#conv-subtitle { font-size: 11px; color: #475569; margin-top: 2px; }

#edit-conv-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  color: #64748b;
  font-size: 14px;
  width: 30px; height: 30px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  display: flex; align-items: center; justify-content: center;
}
#edit-conv-btn:hover { background: rgba(255,255,255,0.08); color: #94a3b8; }

#messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── Messages ── */
.msg-group { display: flex; gap: 12px; margin-top: 12px; }
.msg-group.mine { flex-direction: row-reverse; }

.msg-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  align-self: flex-end;
  font-family: 'JetBrains Mono', monospace;
}
.msg-avatar.deleted { background: #1e293b !important; color: #334155; }

.msg-body { max-width: 65%; display: flex; flex-direction: column; gap: 2px; }
.mine .msg-body { align-items: flex-end; }

.msg-meta { display: flex; align-items: baseline; gap: 8px; padding: 0 4px; }
.mine .msg-meta { flex-direction: row-reverse; }
.msg-sender { font-size: 12px; font-weight: 600; color: #94a3b8; }
.msg-sender.deleted { color: #334155; }
.msg-time { font-size: 10px; color: #334155; }

.msg-bubble {
  background: #1e293b;
  border-radius: 16px 16px 16px 4px;
  padding: 8px 14px;
  font-size: 13px;
  color: #e5e7eb;
  line-height: 1.5;
  word-break: break-word;
  cursor: default;
  user-select: text;
}
.msg-bubble a {
  color: #60a5fa;
  text-decoration: underline;
  word-break: break-all;
  cursor: pointer;
  pointer-events: auto;
  -webkit-user-select: text;
  user-select: text;
}
.mine .msg-bubble a { color: #bfdbfe; }
.mine .msg-bubble {
  background: #1d4ed8;
  border-radius: 16px 16px 4px 16px;
  color: #fff;
}
.msg-bubble.deleted {
  background: #131f35;
  color: #334155;
  font-style: italic;
}

/* ── Input bar ── */
#input-bar {
  display: flex;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
}

#msg-input {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  color: #e5e7eb;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 10px 14px;
  outline: none;
}
#msg-input:focus { border-color: rgba(59,130,246,0.4); }

#send-btn {
  background: #1d4ed8;
  border: none;
  border-radius: 10px;
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.15s;
}
#send-btn:hover { background: #2563eb; }

/* Scrollbar */
#messages-area::-webkit-scrollbar,
#conv-list::-webkit-scrollbar { width: 4px; }
#messages-area::-webkit-scrollbar-track,
#conv-list::-webkit-scrollbar-track { background: transparent; }
#messages-area::-webkit-scrollbar-thumb,
#conv-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* ── Date divider ── */
.date-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
  letter-spacing: 1.5px;
  color: #334155;
  padding: 12px 16px 4px;
  text-transform: uppercase;
}
.date-divider::before,
.date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.05);
}

/* ── Typing indicator ── */
#typing-indicator {
  min-height: 20px;
  padding: 0 16px 2px;
  font-size: 11px;
  color: #475569;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
}
.typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}
.typing-dots span {
  width: 4px; height: 4px;
  background: #475569;
  border-radius: 50%;
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-4px); opacity: 1; }
}

/* ── Reply bar (above input) ── */
#reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(59,130,246,0.12);
  border-top: 1px solid rgba(59,130,246,0.25);
  font-size: 12px;
  color: #94a3b8;
}
#reply-bar-inner { flex: 1; display: flex; flex-direction: column; gap: 1px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#reply-bar-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#reply-cancel-btn { background: none; border: none; color: #64748b; cursor: pointer; font-size: 14px; padding: 2px 4px; }
#reply-cancel-btn:hover { color: #e5e7eb; }

/* ── Reply preview inside bubble ── */
.msg-reply-preview {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: rgba(255,255,255,0.06);
  border-left: 3px solid #3b82f6;
  border-radius: 4px;
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 11px;
  max-width: 100%;
  overflow: hidden;
}
.reply-sender { color: #60a5fa; font-weight: 600; }
.reply-text { color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Right-click context menu ── */
#msg-ctx-menu {
  position: fixed;
  z-index: 1000;
  background: #1e293b;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 4px;
  min-width: 140px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  display: none;
}
#msg-ctx-menu.open { display: block; }

.ctx-item {
  padding: 8px 14px;
  font-size: 13px;
  color: #e5e7eb;
  cursor: pointer;
  border-radius: 7px;
  transition: background 0.1s;
  font-family: 'JetBrains Mono', monospace;
}
.ctx-item:hover { background: rgba(255,255,255,0.07); }
.ctx-item.ctx-danger { color: #f87171; }
.ctx-item.ctx-danger:hover { background: rgba(239,68,68,0.12); }
.ctx-sep { height: 1px; background: rgba(255,255,255,0.07); margin: 3px 4px; }

/* ── Emoji picker ── */
#emoji-picker {
  position: fixed;
  z-index: 1001;
  background: #1e293b;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 8px 10px;
  display: none;
  gap: 2px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
#emoji-picker.open { display: flex; }
#emoji-picker span {
  font-size: 22px;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: background 0.1s, transform 0.12s;
  user-select: none;
  line-height: 1;
}
#emoji-picker span:hover {
  background: rgba(255,255,255,0.08);
  transform: scale(1.25);
}

/* ── Reaction badges ── */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.reaction-badge {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
  letter-spacing: 0;
  font-family: inherit;
}
.reaction-badge:hover { background: rgba(255,255,255,0.11); }
.reaction-badge.mine {
  background: rgba(59,130,246,0.2);
  border-color: rgba(59,130,246,0.4);
}

/* ── Edited indicator ── */
.msg-edited {
  font-size: 10px;
  color: #475569;
  margin-left: 5px;
  font-style: italic;
}

/* ── Inline edit mode ── */
.edit-input {
  width: 100%;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  color: inherit;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 5px 8px;
  resize: none;
  outline: none;
  min-height: 60px;
  box-sizing: border-box;
}
.edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.edit-actions button {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: #cbd5e1;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 4px 12px;
  cursor: pointer;
  transition: filter 0.1s;
}
.edit-actions button.save-btn {
  background: rgba(59,130,246,0.2);
  border-color: rgba(59,130,246,0.35);
  color: #93c5fd;
}
.edit-actions button:hover { filter: brightness(1.2); }

/* ── New / edit chat modal overlay ── */
#chat-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#chat-modal {
  background: #131f35;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 20px;
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}

#chat-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#chat-modal-title {
  font-size: 15px;
  font-weight: 700;
  color: #f1f5f9;
}
#chat-modal-close {
  background: none;
  border: none;
  color: #64748b;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
}
#chat-modal-close:hover { color: #e5e7eb; background: rgba(255,255,255,0.06); }

#chat-name-input,
#chat-search-input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  color: #e5e7eb;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 8px 12px;
  outline: none;
  box-sizing: border-box;
}
#chat-name-input:focus,
#chat-search-input:focus { border-color: rgba(59,130,246,0.4); }

/* selected user chips */
#selected-users {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}
.selected-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(59,130,246,0.18);
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 20px;
  padding: 3px 8px 3px 10px;
  font-size: 12px;
  color: #93c5fd;
  font-family: 'JetBrains Mono', monospace;
}
.selected-chip button {
  background: none;
  border: none;
  color: #60a5fa;
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  line-height: 1;
  opacity: 0.7;
}
.selected-chip button:hover { opacity: 1; }

#chat-user-search-wrap {
  position: relative;
}
#chat-search-results {
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 4px);
  background: #131f35;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  z-index: 10;
  overflow: hidden;
  display: none;
  max-height: 220px;
  overflow-y: auto;
}
#chat-search-results.open { display: block; }

.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  color: #e5e7eb;
  transition: background 0.1s;
}
.search-item:hover { background: rgba(59,130,246,0.1); }
.search-item.already-added { opacity: 0.5; pointer-events: none; }
.search-item .si-name { font-weight: 600; }
.search-item .si-email { color: #475569; font-size: 11px; }

#chat-modal-submit {
  background: #1d4ed8;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 10px;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}
#chat-modal-submit:hover { background: #2563eb; }

@media (max-width: 600px) {
  #sidebar { width: 60px; min-width: 60px; }
  .conv-info { display: none; }
  .conv-item { justify-content: center; padding: 10px 0; }
  #chat-modal { width: 100%; max-width: 100%; border-radius: 0; height: 100%; max-height: 100%; }
}
