/* ── FAB 채팅 버튼 (전역 — 모든 페이지에서 표시) ── */
#chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-primary, #1264a3);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
  z-index: 900;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}
#chat-fab:hover {
  background: var(--primary-color, #0d4f87);
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
}
#chat-fab:active { transform: translateY(0); }

/* 버튼이 #chat-fab 전체 영역을 덮어야 클릭 누락 방지 */
#chat-fab .chat-fab-btn {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
  font-size: inherit;
  padding: 0;
}

#chat-fab .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #e01e5a;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid #fff;
  line-height: 1;
  pointer-events: none;
}

#chat-fab-popup {
  position: fixed;
  bottom: 84px;
  right: 24px;
  width: 400px;
  height: 500px;
  background: var(--bg-primary, #fff);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border-color, #e8eaed);
  z-index: 899;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform-origin: bottom right;
  transform: scale(0.92);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
#chat-fab-popup.open {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}

#chat-fab-popup .fab-popup-header {
  padding: 0.75rem 1rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color, #e8eaed);
  flex-shrink: 0;
}

#chat-fab-popup .fab-popup-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color, #e2e8f0) transparent;
}
#chat-fab-popup .fab-popup-list::-webkit-scrollbar { width: 4px; }
#chat-fab-popup .fab-popup-list::-webkit-scrollbar-thumb {
  background: var(--border-color, #e2e8f0);
  border-radius: 4px;
}

#chat-fab-popup .fab-room-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background 0.1s;
  color: var(--text-color, #374151);
  font-size: 0.875rem;
}
#chat-fab-popup .fab-room-item:hover { background: var(--bg-secondary, #f3f4f6); }
#chat-fab-popup .fab-room-item .fab-room-badge {
  margin-inline-start: auto;
  background: #e01e5a;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  flex-shrink: 0;
}

/* ── Toast 알림 (전역 — 모든 페이지에서 표시) ─────── */
#chat-toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 9999;
  pointer-events: none;
}

.chat-toast {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border-color, #e8eaed);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.14);
  min-width: 260px;
  max-width: 340px;
  pointer-events: auto;
  animation: chat-toast-in 0.22s ease forwards;
  position: relative;
  overflow: hidden;
}
.chat-toast.removing {
  animation: chat-toast-out 0.2s ease forwards;
}

@keyframes chat-toast-in {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes chat-toast-out {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(110%); opacity: 0; }
}

.chat-toast-avatar {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--bg-secondary, #f3f4f6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
}
.chat-toast-avatar img { width: 32px; height: 32px; object-fit: cover; }

.chat-toast-body { flex: 1; min-width: 0; }

.chat-toast-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary, #1a1d21);
  margin-block-end: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-toast-room {
  font-size: 0.72rem;
  color: var(--text-secondary, #6b7280);
  margin-block-end: 2px;
}
.chat-toast-msg {
  font-size: 0.82rem;
  color: var(--text-color, #374151);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary, #6b7280);
  font-size: 0.8rem;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  align-self: flex-start;
  margin-block-start: 2px;
  transition: color 0.1s;
}
.chat-toast-close:hover { color: var(--text-primary, #1a1d21); }

/* 진행 바 (자동 소멸 타이머) */
.chat-toast::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--color-primary, #1264a3);
  border-radius: 0 0 0 10px;
  animation: chat-toast-progress var(--toast-duration, 4s) linear forwards;
}
@keyframes chat-toast-progress {
  from { width: 100%; }
  to   { width: 0%; }
}


.fab-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color, #e8eaed);
  flex-shrink: 0;
}

.fab-popup-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.fab-view {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color, #e2e8f0) transparent;
}
.fab-view::-webkit-scrollbar { width: 4px; }
.fab-view::-webkit-scrollbar-thumb { background: var(--border-color, #e2e8f0); border-radius: 4px; }

/* 방 목록 뷰 */
.fab-rooms-view .fab-room-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 0.875rem;
  color: var(--text-color, #374151);
  border-bottom: 1px solid var(--border-color, #f0f0f0);
}
.fab-rooms-view .fab-room-item:hover { background: var(--bg-secondary, #f3f4f6); }
.fab-room-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fab-room-badge {
  background: #e01e5a;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  flex-shrink: 0;
}
.fab-open-full {
  color: var(--text-secondary, #9ca3af);
  font-size: 0.75rem;
  flex-shrink: 0;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.1s;
}
.fab-open-full:hover { color: var(--color-primary, #1264a3); }

/* 방 타입 아이콘 */
.fab-room-type-icon {
  font-size: 0.7rem;
  color: var(--text-secondary, #9ca3af);
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}

/* 헤더 팝업 버튼 */
.fab-header-popup-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary, #6b7280);
  font-size: 0.8rem;
  padding: 3px 6px;
  border-radius: 5px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
}
.fab-header-popup-btn:hover {
  background: var(--bg-secondary, #f3f4f6);
  color: var(--text-primary, #1a1d21);
}

/* 미니채팅 뷰 헤더 */
.fab-chat-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-color, #e8eaed);
  flex-shrink: 0;
  background: var(--bg-primary, #fff);
}
.fab-header-identity {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.fab-header-type-icon {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-primary, #1a1d21);
  line-height: 1;
  flex-shrink: 0;
}
.fab-header-type-icon.group {
  font-size: 0.78rem;
  color: var(--text-secondary, #6b7280);
}
.fab-chat-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary, #1a1d21);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fab-back-btn,
.fab-popup-win-btn,
.fab-open-chat-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary, #6b7280);
  font-size: 0.85rem;
  padding: 4px 6px;
  border-radius: 5px;
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
  line-height: 1;
}
.fab-back-btn:hover,
.fab-popup-win-btn:hover,
.fab-open-chat-btn:hover {
  background: var(--bg-secondary, #f3f4f6);
  color: var(--text-primary, #1a1d21);
}

.fab-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color, #e2e8f0) transparent;
  min-height: 0;
}
.fab-messages::-webkit-scrollbar { width: 4px; }
.fab-messages::-webkit-scrollbar-thumb { background: var(--border-color, #e2e8f0); border-radius: 4px; }

.fab-msg {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  max-width: 85%;
}
.fab-msg-mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.fab-msg-sender {
  font-size: 0.7rem;
  color: var(--text-secondary, #6b7280);
  margin-bottom: 2px;
  padding-left: 2px;
}
.fab-msg-bubble {
  background: var(--bg-secondary, #f3f4f6);
  color: var(--text-primary, #1a1d21);
  padding: 8px 12px;
  border-radius: 18px;
  font-size: 0.875rem;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 100%;
}
.fab-msg:not(.fab-msg-mine) .fab-msg-bubble { border-top-left-radius: 4px; }
.fab-msg-mine .fab-msg-bubble { border-top-right-radius: 4px; }
.fab-msg-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  align-self: flex-start;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
  margin-top: 1px;
}
.fab-msg-avatar img {
  width: 24px;
  height: 24px;
  object-fit: cover;
  display: block;
}
/* continued 상대방 메시지: 아바타 없음 → 아바타(24px) + gap(6px) 만큼 들여쓰기 */
.fab-msg.continued:not(.fab-msg-mine) { padding-left: 30px; }
.fab-msg:not(.continued) { margin-top: 6px; }
.fab-msg.continued { margin-top: 1px; }
.fab-msg-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.fab-msg-time {
  font-size: 0.65rem;
  color: var(--text-secondary, #9ca3af);
  padding: 0 4px;
  flex-shrink: 0;
  align-self: flex-end;
  text-align: right;
  opacity: 0;
  transition: opacity 0.15s;
}
.fab-msg:hover .fab-msg-time { opacity: 1; }

/* 우클릭 컨텍스트 메뉴 */
.fab-ctx-menu {
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.14);
  padding: 4px 0;
  z-index: 99999;
  min-width: 110px;
}
.fab-ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 7px 14px;
  color: var(--text-primary, #1a1d21);
  text-align: left;
  transition: background 0.1s;
}
.fab-ctx-item:hover { background: var(--bg-secondary, #f3f4f6); }
.fab-ctx-item:last-child { color: var(--color-danger, #e11d48); }
.fab-edit-input {
  width: 100%;
  padding: 6px 10px;
  border: 1.5px solid var(--color-primary, #1264a3);
  border-radius: 14px;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  background: var(--bg-primary, #fff);
  color: var(--text-primary, #1a1d21);
}
.fab-msg-mine .fab-msg-bubble {
  background: var(--color-primary, #1264a3);
  color: #fff;
}

.fab-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border-color, #e8eaed);
  flex-shrink: 0;
}
.fab-input {
  flex: 1;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border-color, #d0d7de);
  border-radius: 20px;
  font-size: 0.85rem;
  outline: none;
  background: var(--bg-secondary, #f3f4f6);
  color: var(--text-primary, #1a1d21);
  font-family: inherit;
  transition: border-color 0.15s;
}
.fab-input:focus {
  border-color: var(--color-primary, #1264a3);
  background: var(--bg-primary, #fff);
}
.fab-send-btn {
  background: var(--color-primary, #1264a3);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s;
}
.fab-send-btn:hover { background: #0d4f87; }

.fab-empty,
.fab-loading {
  text-align: center;
  color: var(--text-secondary, #9ca3af);
  font-size: 0.8rem;
  padding: 2rem 1rem;
  margin: 0;
}

/* ── 다크모드 ─────────────────────────────────── */
[data-theme="dark"] #chat-fab-popup {
  background: #1e2124;
  border-color: rgba(255,255,255,0.1);
}
[data-theme="dark"] .fab-popup-header {
  color: rgba(255,255,255,0.5);
  border-color: rgba(255,255,255,0.08);
}
[data-theme="dark"] .fab-rooms-view .fab-room-item {
  color: #c9d1d9;
  border-color: rgba(255,255,255,0.05);
}
[data-theme="dark"] .fab-rooms-view .fab-room-item:hover { background: rgba(255,255,255,0.06); }
[data-theme="dark"] .fab-chat-header {
  background: #1e2124;
  border-color: rgba(255,255,255,0.08);
}
[data-theme="dark"] .fab-chat-title { color: #fff; }
[data-theme="dark"] .fab-msg-bubble {
  background: rgba(255,255,255,0.08);
  color: #c9d1d9;
}
[data-theme="dark"] .fab-msg-mine .fab-msg-bubble {
  background: #1264a3;
  color: #fff;
}
[data-theme="dark"] .fab-input {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.15);
  color: #c9d1d9;
}
[data-theme="dark"] .fab-input:focus {
  border-color: #1264a3;
  background: rgba(255,255,255,0.12);
}
[data-theme="dark"] .fab-input-wrap {
  border-color: rgba(255,255,255,0.08);
}
[data-theme="dark"] .fab-room-type-icon { color: rgba(255,255,255,0.35); }
[data-theme="dark"] .fab-header-popup-btn { color: rgba(255,255,255,0.45); }
[data-theme="dark"] .fab-header-popup-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
[data-theme="dark"] .fab-header-type-icon { color: rgba(255,255,255,0.75); }
