/* fokm 실시간 채팅 위젯 */
#fokm-chat-btn {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #1c6dd0;
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  cursor: pointer;
  z-index: 9998;
  font-size: 28px;
  line-height: 60px;
  text-align: center;
  padding: 0;
  transition: transform .15s ease;
}
#fokm-chat-btn:hover { transform: scale(1.05); }
#fokm-chat-btn .fokm-chat-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: #e63946;
  color: #fff;
  font-size: 12px;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  border-radius: 10px;
  padding: 0 6px;
  display: none;
  font-weight: 600;
}

#fokm-chat-panel {
  position: fixed;
  right: 20px;
  bottom: 90px;
  width: 340px;
  max-width: calc(100vw - 24px);
  height: 480px;
  max-height: calc(100vh - 110px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  z-index: 9999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", sans-serif;
}
#fokm-chat-panel.open { display: flex; }

#fokm-chat-head {
  background: #1c6dd0;
  color: #fff;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#fokm-chat-head small { font-weight: 400; opacity: .85; font-size: 12px; }
.fokm-chat-online {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
  padding: 2px 8px;
  background: rgba(255,255,255,0.18);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  vertical-align: 1px;
}
.fokm-chat-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7);
  animation: fokm-chat-pulse 2s infinite;
}
@keyframes fokm-chat-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7); }
  70%  { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}
#fokm-chat-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

#fokm-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #f5f7fb;
  font-size: 14px;
  /* 메시지를 항상 하단(입력창 바로 위) 정렬 — 카톡처럼 */
  display: flex;
  flex-direction: column;
}
/* 비어있는 위쪽 공간을 ::before 가 차지해서 메시지를 아래로 밀어줌.
   메시지가 많아 overflow 되면 자동으로 0 으로 squeeze 되어 정상 스크롤로 동작 */
#fokm-chat-body::before {
  content: '';
  flex: 1 1 auto;
  min-height: 0;
}

.fokm-chat-msg { margin: 8px 0; display: flex; }
.fokm-chat-msg .fokm-chat-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 14px;
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.45;
}
.fokm-chat-msg.user { justify-content: flex-end; }
.fokm-chat-msg.user .fokm-chat-bubble {
  background: #1c6dd0;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.fokm-chat-msg.admin .fokm-chat-bubble {
  background: #fff;
  color: #222;
  border: 1px solid #e0e4ec;
  border-bottom-left-radius: 4px;
}
.fokm-chat-msg.system .fokm-chat-bubble {
  background: transparent;
  color: #888;
  font-size: 12px;
  text-align: center;
  margin: 0 auto;
}
.fokm-chat-time {
  font-size: 11px;
  color: #999;
  margin: 0 6px;
  align-self: flex-end;
}

#fokm-chat-name-row {
  display: flex;
  padding: 8px 10px;
  background: #fff;
  border-top: 1px solid #e8ebf2;
}
#fokm-chat-name {
  flex: 1;
  border: 1px solid #d6dae3;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}

#fokm-chat-input-row {
  display: flex;
  padding: 8px 10px;
  background: #fff;
  border-top: 1px solid #e8ebf2;
}
#fokm-chat-input {
  flex: 1;
  border: 1px solid #d6dae3;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
  resize: none;
  height: 38px;
  max-height: 100px;
  font-family: inherit;
}
#fokm-chat-input:focus { border-color: #1c6dd0; }
#fokm-chat-send {
  margin-left: 6px;
  background: #1c6dd0;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
#fokm-chat-send:disabled { opacity: .5; cursor: default; }

/* 모바일 — 작은 폰부터 태블릿 직전까지 전체 화면에 맞춤 + 카톡 스타일 키보드 추적 */
@media (max-width: 768px) {
  #fokm-chat-panel {
    right: max(8px, env(safe-area-inset-right));
    left: max(8px, env(safe-area-inset-left));
    /* --fokm-kb 는 widget.js 가 visualViewport 로 키보드 높이 주입 (기본 0) */
    top: calc(max(12px, env(safe-area-inset-top)));
    bottom: calc(var(--fokm-kb, 0px) + max(12px, env(safe-area-inset-bottom)));
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    border-radius: 14px;
    transition: bottom .18s ease;
  }
  /* 키보드 올라온 상태에서는 둥근 모서리 제거 (카톡처럼 키보드와 매끄럽게) */
  #fokm-chat-panel.kb-open { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
  #fokm-chat-btn {
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
  }
  #fokm-chat-head { padding: 14px 16px; font-size: 16px; }
  #fokm-chat-input { font-size: 16px; }  /* iOS 자동 줌 방지 */
  #fokm-chat-name { font-size: 16px; }
  /* 채팅 패널 열림 상태에서는 floating 버튼 숨김 (JS가 .hidden-by-chat 부여) */
  #fokm-chat-btn.hidden-by-chat { display: none; }
}
