/**
 * 채팅: 오른쪽 목록 패널 + 오른쪽 하단 채팅창(최대 3개)
 * `app/globals.css` 의 `--app-header-height` 아래에서 시작 (고정 헤더와 겹치지 않음).
 */
#chat-wrap {
  position: fixed;
  top: var(--app-header-height, 5rem);
  right: 0;
  bottom: 0;
  z-index: 9000;
  display: flex;
  flex-direction: row;
  pointer-events: none;
}

#chat-wrap * {
  pointer-events: auto;
}

.chat-toggle {
  width: 44px;
  min-width: 44px;
  height: 44px;
  align-self: flex-start;
  margin: 12px 0 auto;
  border: 1px solid #ddd;
  border-right: none;
  border-radius: 12px 0 0 12px;
  background: #fff;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.08);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.chat-toggle:hover {
  background: #f8f8f8;
}

.chat-toggle .chat-toggle-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #e0245e;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
}

.chat-toggle .chat-toggle-badge[data-visible="true"] {
  display: flex;
}

#chat-wrap.collapsed .chat-panel {
  display: none;
}

#chat-wrap:not(.collapsed) .chat-toggle {
  border-radius: 0;
}

.chat-panel {
  width: 280px;
  max-width: calc(100vw - 60px);
  height: 100%;
  background: #fff;
  border-left: 1px solid #e0e0e0;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-panel-header {
  padding: 12px;
  border-bottom: 1px solid #eee;
}

.chat-search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 14px;
  box-sizing: border-box;
}

.chat-search:focus {
  outline: none;
  border-color: #ffcd38;
}

.chat-search-results {
  max-height: 200px;
  overflow-y: auto;
  border-bottom: 1px solid #eee;
  background: #fafafa;
}

.chat-search-results .chat-search-item {
  padding: 12px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-search-results .chat-search-item:hover {
  background: #f0f0f0;
}

.chat-room-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.chat-room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f5f5f5;
  position: relative;
}

.chat-room-item:hover {
  background: #f8f8f8;
}

.chat-room-item .chat-room-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e0e0e0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: #666;
  font-size: 14px;
}

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

.chat-room-item .chat-room-name {
  font-weight: 600;
  font-size: 14px;
  color: #333;
}

.chat-room-item .chat-room-preview {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-room-item .chat-room-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.chat-room-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-room-status.online {
  background: #22c55e;
}

.chat-room-status.offline {
  background: #d1d5db;
}

.chat-room-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  background: #e0245e;
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-room-item[data-pinned="true"] .chat-room-name::before {
  content: "📌 ";
}

#chat-windows-container {
  position: fixed;
  bottom: 0;
  right: 44px;
  z-index: 8999;
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-end;
  gap: 8px;
  padding: 0 12px 12px 0;
  max-width: 100vw;
  transition: right 0.2s ease;
}

.chat-window {
  width: 320px;
  height: 400px;
  max-height: 70vh;
  background: #fff;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.chat-window.minimized {
  height: 48px;
  min-height: 48px;
}

.chat-window.minimized .chat-window-body,
.chat-window.minimized .chat-window-footer {
  display: none !important;
}

.chat-window-header {
  padding: 12px 14px;
  background: #f8f8f8;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.chat-window-header .chat-window-title {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-window-header .chat-window-title .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d1d5db;
}

.chat-window-header .chat-window-title .status-dot.online {
  background: #22c55e;
}

.chat-window-header .chat-window-minimize {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  color: #666;
}

.chat-window-header .chat-window-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-window-header .chat-window-close {
  border: none;
  background: none;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  color: #666;
}

.chat-window-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fafafa;
}

.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg.mine {
  align-self: flex-end;
  background: #ffcd38;
  color: #1a1a1a;
}

.chat-msg.theirs {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e5e5e5;
}

.chat-msg-time {
  font-size: 11px;
  color: #999;
  margin-top: 4px;
}

.chat-window-footer {
  padding: 10px 12px;
  border-top: 1px solid #eee;
  background: #fff;
}

.chat-window-footer form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-window-footer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 100px;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 14px;
  resize: none;
  font-family: inherit;
}

.chat-window-footer textarea:focus {
  outline: none;
  border-color: #ffcd38;
}

.chat-window-footer button[type="submit"] {
  padding: 10px 14px;
  background: #ffcd38;
  border: none;
  border-radius: 10px;
  font-weight: bold;
  cursor: pointer;
  font-size: 14px;
}

.chat-window-footer button[type="submit"]:hover:not(:disabled) {
  background: #ffdd67;
}

.chat-window-footer button[type="submit"]:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-context-menu {
  position: fixed;
  z-index: 99999;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 4px 0;
  min-width: 140px;
}

.chat-context-menu button {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}

.chat-context-menu button:hover {
  background: #f5f5f5;
}

.chat-empty-list {
  padding: 24px 16px;
  text-align: center;
  color: #999;
  font-size: 14px;
}
