/* ── Shared Chat Panel ── */

.chat-toggle {
  position: fixed; bottom: 24px; right: 24px; z-index: 7001;
  width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid rgba(56,189,248,0.4);
  background: rgba(15,23,42,0.95); color: var(--accent);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: border-color 0.15s, box-shadow 0.15s, opacity 0.2s;
}
.chat-toggle:hover { border-color: var(--accent); box-shadow: 0 4px 24px rgba(56,189,248,0.2); }
.chat-toggle.hidden { opacity: 0; pointer-events: none; }
.chat-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: #f87171; color: #fff;
  font-size: 10px; font-weight: 700; line-height: 18px;
  text-align: center; display: none;
  align-items: center; justify-content: center;
  border: 2px solid rgba(15,23,42,0.95);
  animation: chat-pulse 2s infinite;
  font-family: system-ui, -apple-system, sans-serif;
}
@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248,113,113,0.5); }
  50% { box-shadow: 0 0 0 5px rgba(248,113,113,0); }
}
/* Sidebar unread badge */
.sidebar-chat-badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: #f87171; color: #fff;
  font-size: 10px; font-weight: 700; line-height: 20px;
  text-align: center; display: none;
  align-items: center; justify-content: center;
  margin: 0 auto 4px;
  animation: chat-pulse 2s infinite;
  font-family: system-ui, -apple-system, sans-serif;
}
.sidebar:hover .sidebar-chat-badge {
  margin: 0 0 4px 12px;
}
[data-theme="light"] .chat-badge,
[data-theme="light"] .sidebar-chat-badge {
  border-color: rgba(241,245,249,0.95);
}

.chat-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px;
  background: rgba(15,23,42,0.98); border-left: 1px solid rgba(148,163,184,0.15);
  z-index: 7000; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.25s ease;
  backdrop-filter: blur(12px);
}
.chat-panel.open { transform: translateX(0); }
.chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid rgba(148,163,184,0.12);
  flex-shrink: 0;
}
.chat-header h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text); }
.chat-close {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(148,163,184,0.3);
  background: none; color: var(--muted); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.chat-close:hover { border-color: var(--danger); color: var(--danger); }
.chat-channel-bar {
  display: flex; flex-direction: column; gap: 6px; padding: 10px 16px;
  border-bottom: 1px solid rgba(148,163,184,0.08); flex-shrink: 0;
}
.chat-channel-bar select {
  width: 100%; padding: 6px 8px; border-radius: 6px;
  border: 1px solid rgba(148,163,184,0.2); background: rgba(2,6,23,0.8);
  color: var(--text); font-size: 12px; font-family: inherit;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.chat-msg {
  display: flex; gap: 8px; align-items: flex-start;
}
.chat-msg.own { flex-direction: row-reverse; }
.chat-bubble-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  font-size: 10px; font-weight: 700; display: flex;
  align-items: center; justify-content: center;
  text-transform: uppercase; flex-shrink: 0; border: 1.5px solid;
}
.chat-msg-body {
  max-width: 260px; min-width: 0;
}
.chat-msg-meta {
  font-size: 10px; color: var(--muted); margin-bottom: 2px;
  display: flex; align-items: center; gap: 6px;
}
.chat-msg.own .chat-msg-meta { flex-direction: row-reverse; }
.chat-msg-text {
  padding: 8px 12px; border-radius: 12px;
  font-size: 13px; line-height: 1.5; word-break: break-word;
  background: rgba(30,41,59,0.8); color: var(--text);
  border: 1px solid rgba(148,163,184,0.08);
  position: relative;
}
.chat-msg.own .chat-msg-text {
  background: rgba(56,189,248,0.12); border-color: rgba(56,189,248,0.2);
}
.chat-msg-text.deleted {
  font-style: italic; color: var(--muted); background: transparent;
  border: 1px dashed rgba(148,163,184,0.2);
}
.chat-msg-delete {
  display: none; position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid rgba(148,163,184,0.3); background: rgba(15,23,42,0.95);
  color: var(--muted); font-size: 11px; cursor: pointer;
  align-items: center; justify-content: center;
}
.chat-msg-text:hover .chat-msg-delete { display: flex; }
.chat-msg-delete:hover { border-color: var(--danger); color: var(--danger); }
.chat-input-bar {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid rgba(148,163,184,0.12); flex-shrink: 0;
}
.chat-input-bar input {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  border: 1px solid rgba(148,163,184,0.2); background: rgba(2,6,23,0.8);
  color: var(--text); font-size: 13px; font-family: inherit;
}
.chat-input-bar input:focus { border-color: var(--accent); outline: none; }
.chat-input-bar button {
  padding: 8px 16px; border-radius: 8px; border: none;
  background: var(--accent); color: #0f172a; font-size: 12px;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  cursor: pointer;
}
.chat-input-bar button:hover { opacity: 0.9; }
.chat-empty { text-align: center; padding: 40px 16px; font-size: 12px; color: var(--muted); }

/* Typing indicator */
.chat-typing {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 16px 8px; flex-shrink: 0;
  font-size: 11px; color: var(--muted);
}
.chat-typing-dots {
  display: flex; align-items: center; gap: 3px;
}
.chat-typing-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--muted);
  animation: chat-typing-bounce 1.4s infinite ease-in-out both;
}
.chat-typing-dots span:nth-child(1) { animation-delay: 0s; }
.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}
.chat-typing-text {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Toast notification */
.chat-toast {
  position: fixed; top: 16px; right: 16px; z-index: 7002;
  max-width: 340px; padding: 10px 14px; border-radius: 10px;
  background: rgba(15,23,42,0.96); border: 1px solid rgba(56,189,248,0.3);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  display: flex; align-items: center; gap: 10px;
  animation: chat-toast-in 0.3s ease;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.chat-toast.out { animation: chat-toast-out 0.3s ease forwards; }
@keyframes chat-toast-in { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes chat-toast-out { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-20px); opacity: 0; } }
.chat-toast-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  font-size: 10px; font-weight: 700; display: flex;
  align-items: center; justify-content: center;
  text-transform: uppercase; flex-shrink: 0; border: 1.5px solid;
}
.chat-toast-body { min-width: 0; }
.chat-toast-name { font-size: 11px; font-weight: 600; color: var(--text); }
.chat-toast-text { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }

/* ── Light mode ── */
[data-theme="light"] .chat-toggle {
  background: rgba(255,255,255,0.95);
  border-color: rgba(56,189,248,0.35);
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}
[data-theme="light"] .chat-toggle:hover {
  box-shadow: 0 4px 24px rgba(56,189,248,0.15);
}
[data-theme="light"] .chat-panel {
  background: rgba(255,255,255,0.98);
  border-left-color: rgba(148,163,184,0.2);
}
[data-theme="light"] .chat-header {
  border-bottom-color: rgba(148,163,184,0.15);
}
[data-theme="light"] .chat-channel-bar {
  border-bottom-color: rgba(148,163,184,0.12);
}
[data-theme="light"] .chat-channel-bar select {
  background: #f8fafc;
  border-color: rgba(148,163,184,0.25);
}
[data-theme="light"] .chat-msg-text {
  background: #f1f5f9;
  border-color: rgba(148,163,184,0.15);
  color: #1e293b;
}
[data-theme="light"] .chat-msg.own .chat-msg-text {
  background: rgba(56,189,248,0.1);
  border-color: rgba(56,189,248,0.25);
}
[data-theme="light"] .chat-msg-text.deleted {
  background: transparent;
  border-color: rgba(148,163,184,0.25);
}
[data-theme="light"] .chat-msg-delete {
  background: #fff;
  border-color: rgba(148,163,184,0.3);
}
[data-theme="light"] .chat-input-bar {
  border-top-color: rgba(148,163,184,0.15);
}
[data-theme="light"] .chat-input-bar input {
  background: #f8fafc;
  border-color: rgba(148,163,184,0.25);
  color: #1e293b;
}
[data-theme="light"] .chat-input-bar button {
  color: #fff;
}
[data-theme="light"] .chat-close {
  border-color: rgba(148,163,184,0.3);
  color: #64748b;
}
[data-theme="light"] .chat-toast {
  background: rgba(255,255,255,0.97);
  border-color: rgba(56,189,248,0.3);
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
[data-theme="light"] .chat-toast-name {
  color: #1e293b;
}
[data-theme="light"] .chat-toast-text {
  color: #64748b;
}
[data-theme="light"] .chat-typing-dots span {
  background: #94a3b8;
}

@media (max-width: 768px) {
  .chat-panel { width: 100%; }
  .chat-toast { right: 8px; left: 8px; max-width: none; }
}
