/* 오른쪽 아래 채팅 */

/* 채팅 */
.chat-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .55);
  cursor: pointer;
  transition: transform .15s ease;
}

.chat-fab:hover { transform: scale(1.06); }
.chat-fab:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }
.chat-fab svg { width: 26px; height: 26px; fill: currentColor; }

.chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #e0475b;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  border: 2px solid var(--bg);
}

.chat-badge[hidden] { display: none; }

/* 새 메시지 알림: 아이콘 흔들기 */
.chat-fab.ring { animation: chat-ring .8s ease-in-out; }
@keyframes chat-ring {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(-16deg) scale(1.08); }
  30% { transform: rotate(13deg) scale(1.08); }
  45% { transform: rotate(-10deg) scale(1.05); }
  60% { transform: rotate(7deg); }
  75% { transform: rotate(-4deg); }
}
@media (prefers-reduced-motion: reduce) { .chat-fab.ring { animation: none; } }

.chat {
  position: fixed;
  right: 20px;
  bottom: 88px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 40px));
  height: min(580px, calc(100dvh - 120px));
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .6);
  overflow: hidden;
}

.chat[hidden] { display: none; }

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.chat-head h2 { margin: 0; font-size: 16px; }
.chat-online { margin-left: 4px; font-size: 12px; font-weight: 600; color: #2f9e5b; }
.chat-me { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.chat-close, .chat-picker-close {
  flex: none;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: var(--thumb);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.chat-log {
  flex: 1;
  margin: 0;
  padding: 12px 14px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-empty { margin: auto; color: var(--muted); font-size: 13px; text-align: center; }

.msg { max-width: 85%; align-self: flex-start; }
/* "~님이 ~에 같이 입장했어요" 안내 */
.msg-system { align-self: center; max-width: 92%; padding: 5px 12px; border-radius: 12px; background: var(--thumb); color: var(--muted); font-size: 12px; text-align: center; line-height: 1.5; }
.msg-system-site { color: var(--text); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.msg-system-site:hover { color: var(--accent); }
.msg-system .msg-time { margin-left: 4px; font-size: 11px; }
.msg.mine { align-self: flex-end; text-align: right; }
.msg-meta { margin: 0 0 3px; font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.msg.mine .msg-meta { justify-content: flex-end; }
.msg-nick { font-weight: 600; color: var(--text); }
.msg-time { opacity: .8; }

.msg-body {
  display: inline-block;
  margin: 0;
  padding: 8px 12px;
  border-radius: 14px 14px 14px 4px;
  background: var(--thumb);
  font-size: 14px;
  line-height: 1.5;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.mine .msg-body { border-radius: 14px 14px 4px 14px; background: var(--accent); color: #fff; }

.msg.invite { max-width: 92%; }
.msg-invite { padding: 10px; border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 14px; background: color-mix(in srgb, var(--accent) 8%, var(--surface)); text-align: left; }
.msg-invite-text { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
.msg-invite-gone { margin: 0; font-size: 13px; color: var(--muted); }

.msg-invite-site {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}

.msg-invite-site:hover { outline: 1px solid var(--accent); }
.msg-invite-site img { flex: none; width: 76px; aspect-ratio: 1200 / 630; object-fit: cover; border-radius: 7px; background: var(--thumb); }
.msg-invite-label { display: grid; gap: 2px; min-width: 0; font-size: 13px; }
.msg-invite-label strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-invite-go { color: var(--accent); font-weight: 700; font-size: 12px; }

.chat-status { margin: 0; padding: 6px 14px; font-size: 12px; color: var(--muted); background: var(--thumb); }
.chat-status[hidden] { display: none; }

.chat-picker {
  position: absolute;
  inset: 62px 0 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
}

.chat-picker[hidden] { display: none; }
.chat-picker-head { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }

.chat-picker input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.chat-picker ul { flex: 1; margin: 0; padding: 0; list-style: none; overflow-y: auto; display: grid; align-content: start; gap: 4px; }
.chat-picker li[hidden] { display: none; }

.chat-picker ul button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.chat-picker ul button:hover, .chat-picker ul button:focus-visible { background: var(--thumb); }
.chat-picker ul button.wanted { background: var(--thumb); box-shadow: inset 0 0 0 1.5px var(--accent); }
.chat-picker img, .chat-picker-noimg { flex: none; width: 64px; aspect-ratio: 1200 / 630; object-fit: cover; border-radius: 6px; background: var(--thumb); }

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.chat-form textarea {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
}

.chat-form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.chat-share, .chat-send {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.chat-share { padding: 0 10px; }
.chat-send { width: 38px; justify-content: center; background: var(--accent); border-color: var(--accent); color: #fff; }
.chat-share svg, .chat-send svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chat-send svg { fill: currentColor; stroke-width: 1.5; }

/* 모바일: 채팅창은 전체 화면 */
@media (max-width: 640px) {
  .chat-fab { right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: 52px; height: 52px; }
  .chat { inset: 0; width: auto; height: auto; border: 0; border-radius: 0; padding-bottom: env(safe-area-inset-bottom); }
  body.chat-open { overflow: hidden; }
  body.chat-open .chat-fab { display: none; }
  .chat-form textarea { font-size: 16px; } /* iOS 확대 방지 */
}

/* 채팅 '~님이 ~에 들어갔어요' 안내의 따라 들어가기 버튼 */
.msg-follow { display: inline-block; margin-left: 8px; padding: 2px 10px; border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; text-decoration: none; white-space: nowrap; vertical-align: 1px; }
.msg-follow:hover { filter: brightness(1.08); }

/* 채팅 의견 안내의 의견 앞부분 */
.msg-quote { display: block; margin: 3px 0 1px; color: var(--text); font-style: normal; }
.msg-quote::before, .msg-quote::after { content: "“"; color: var(--muted); }
.msg-quote::after { content: "”"; }
