/* 칩스터 1:1 채팅 위젯 */
:root {
  --chat-primary: #5a4cf0;
  --chat-bg: #f4f5f7;
}

/* 페이지 버튼(메이커와 채팅/채팅 목록)에 붙는 안읽음 뱃지 */
.chat_btn_badge {
  display: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 6px;
  border-radius: 9px;
  background: #ff3b30;
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  vertical-align: middle;
}
.chat_btn_badge.show { display: inline-block; }

/* 채팅 패널 */
.chat_panel {
  position: fixed;
  /* 화면(앱 프레임) 정중앙 */
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 120px));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  z-index: 100000; /* common.css 의 헤더/팝업(z-index 999~9999) 위로 */
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.chat_panel.open { display: flex; }

.chat_head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--chat-primary);
  color: #fff;
  flex: 0 0 auto;
}
.chat_head .chat_back,
.chat_head .chat_close {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}
.chat_head .chat_back { display: none; }
.chat_head.has_back .chat_back { display: inline-block; }
.chat_head .chat_title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat_head .chat_avatar {
  width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: #fff;
}

.chat_body {
  flex: 1 1 auto;
  overflow-y: auto;
  background: var(--chat-bg);
}

/* 방 목록 (메이커) */
.chat_rooms { display: flex; flex-direction: column; }
.chat_room_item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  background: #fff;
}
.chat_room_item:hover { background: #fafafa; }
.chat_room_item .avatar { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 50%; background: #e0e0e0; overflow: hidden; display: inline-block; }
.chat_room_item .avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat_room_item .meta { flex: 1; min-width: 0; }
.chat_room_item .meta .nick { font-size: 14px; font-weight: 600; }
.chat_room_item .meta .last {
  font-size: 12px; color: #888; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat_room_item .unread {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: #ff3b30; color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.chat_empty { padding: 40px 20px; text-align: center; color: #999; font-size: 13px; }

/* 메시지 영역 */
.chat_messages { display: flex; flex-direction: column; gap: 8px; padding: 14px; }

/* 날짜 구분선 (가운데) */
.chat_date {
  align-self: center;
  margin: 8px 0;
  padding: 3px 12px;
  font-size: 12px;
  color: #777;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 12px;
}

/* 한 줄 = 말풍선 + 메타(읽음/시간) 컬럼 */
.chat_msg { display: flex; align-items: flex-end; gap: 4px; max-width: 85%; }
.chat_msg.mine { align-self: flex-end; }       /* 내가 보낸 건 오른쪽 */
.chat_msg.theirs { align-self: flex-start; }    /* 받은 건 왼쪽 */

.chat_msg .bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat_msg.mine .bubble { background: var(--chat-primary); color: #fff; border-bottom-right-radius: 4px; }
.chat_msg.theirs .bubble { background: #fff; color: #222; border: 1px solid #eee; border-bottom-left-radius: 4px; }

/* 메타: 읽음 + 시간을 세로(column)로. mine 은 말풍선 왼쪽, theirs 는 오른쪽 */
.chat_meta {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  font-size: 10px;
  color: #999;
  line-height: 1.3;
  white-space: nowrap;
}
.chat_msg.mine .chat_meta { align-items: flex-end; text-align: right; }   /* 말풍선 왼쪽 */
.chat_msg.theirs .chat_meta { align-items: flex-start; text-align: left; }/* 말풍선 오른쪽 */
.chat_meta .read { color: #999; }
.chat_meta .read.hidden { display: none; }
/* 같은 발신자+같은 분 연속 메시지: 시간만 마지막에 표시(병합).
   읽음은 모든 메시지에 유지. */
.chat_msg.mine .chat_meta.merged .time { display: none; } /* 내 메시지: 시간만 숨기고 읽음은 남김 */
.chat_msg.theirs .chat_meta.merged { display: none; }      /* 받은 메시지: 읽음 없으니 통째로 숨김 */

/* 입력 */
.chat_input {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 4px 6px;
  border-top: 1px solid #eee;
  background: #fff;
}
.chat_input.hidden { display: none; }
.chat_input textarea {
  flex: 1; resize: none; border: 1px solid #ddd; border-radius: 14px;
  padding: 3px 10px; font-size: 13px; max-height: 52px; line-height: 1.25; font-family: inherit;
}
.chat_input button {
  border: none; background: var(--chat-primary); color: #fff;
  border-radius: 14px; padding: 0 12px; font-size: 13px; cursor: pointer;
}
.chat_input button:disabled { opacity: 0.5; cursor: default; }

.chat_status { padding: 8px 14px; font-size: 12px; color: #c0392b; text-align: center; }
