/* AROMALL — 쇼핑 가이드 챗봇 */

#chat-fab {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 9990;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  box-shadow: 0 6px 20px rgba(0,76,153,0.35);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#chat-fab:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0,76,153,0.4); }
#chat-fab.dragging { transition: none; box-shadow: 0 10px 24px rgba(0,76,153,0.4); }
#chat-fab.open { background: var(--navy-d); }
#chat-fab .badge-dot {
  position: absolute; top: 6px; right: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--orange); border: 2px solid #fff;
}

#chat-panel {
  position: fixed;
  right: 1.5rem;
  bottom: 5.5rem;
  z-index: 9990;
  width: 380px;
  max-width: calc(100vw - 3rem);
  height: 560px;
  max-height: calc(100vh - 8rem);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.22);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(12px);
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
#chat-panel.open {
  display: flex;
  transform: translateY(0);
  opacity: 1;
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-d) 100%);
  color: #fff;
}
.chat-title { font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; gap: 8px; }
.chat-title i { font-size: 18px; }
.chat-sub {
  font-size: 11px;
  opacity: 0.85;
  font-weight: 500;
  margin-left: 6px;
}
.chat-close {
  background: transparent; border: none; color: #fff;
  width: 28px; height: 28px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 18px;
}
.chat-close:hover { background: rgba(255,255,255,0.12); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  background: var(--surface);
  display: flex; flex-direction: column; gap: 10px;
}
.chat-msg {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}
.chat-msg-user {
  align-self: flex-end;
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.chat-msg-assistant {
  align-self: flex-start;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.chat-msg-assistant.streaming::after {
  content: '▍';
  display: inline-block;
  color: var(--navy);
  animation: chat-caret 1s steps(2) infinite;
  margin-left: 2px;
}
@keyframes chat-caret {
  50% { opacity: 0; }
}

/* 마크다운 요소 스타일 */
.chat-msg-assistant p { margin: 0 0 8px; }
.chat-msg-assistant p:last-child { margin-bottom: 0; }
.chat-msg-assistant ul, .chat-msg-assistant ol {
  margin: 4px 0 8px; padding-left: 20px; list-style: revert;
}
.chat-msg-assistant li { margin: 2px 0; }
.chat-msg-assistant h1, .chat-msg-assistant h2, .chat-msg-assistant h3 {
  font-size: 14px; margin: 10px 0 6px; font-weight: 700;
}
.chat-msg-assistant strong { font-weight: 700; color: var(--ink); }
.chat-msg-assistant em { font-style: italic; }
.chat-msg-assistant code {
  background: #F3F4F6; padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.chat-msg-assistant pre {
  background: #0F172A; color: #E2E8F0;
  padding: 10px 12px; border-radius: 8px;
  overflow-x: auto; font-size: 12px; margin: 6px 0;
}
.chat-msg-assistant pre code { background: transparent; color: inherit; padding: 0; }
.chat-msg-assistant blockquote {
  border-left: 3px solid var(--line-strong);
  padding-left: 10px; color: var(--ink-2); margin: 6px 0;
}
.chat-msg-assistant a { color: var(--navy); text-decoration: underline; }
.chat-msg-assistant hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }

.chat-context-chip {
  align-self: center;
  font-size: 11px;
  color: var(--ink-3);
  background: var(--navy-l);
  padding: 3px 10px;
  border-radius: 999px;
  display: inline-flex; align-items: center; gap: 5px;
}

.chat-input {
  border-top: 1px solid var(--line);
  padding: 10px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #fff;
}
.chat-input textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  outline: none;
  min-height: 38px; max-height: 120px;
  color: var(--ink);
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.chat-input textarea::-webkit-scrollbar { display: none; }
.chat-input textarea:focus { border-color: var(--navy); }
.chat-send {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--navy);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.chat-send:disabled { background: var(--line-strong); cursor: not-allowed; }
.chat-send:not(:disabled):hover { background: var(--navy-d); }

@media (max-width: 540px) {
  #chat-panel {
    /* JS(syncPanelViewport)가 top/left/width/height 를 visualViewport 에 맞춰 제어한다.
       right/bottom 은 꺼서(auto) 데스크탑 기본값·인라인 top/height 와 충돌하지 않게 한다. */
    top: 0; left: 0; right: auto; bottom: auto;
    width: 100%; max-width: 100%;
    height: 100dvh; max-height: none;
    border-radius: 0;
  }
  #chat-fab { bottom: 1rem; right: 1rem; }
  /* 상품 상세 페이지는 탭바 위에 장바구니/구매 고정 바가 추가로 떠 있어 챗봇 버튼과 겹친다 —
     mobile/tabbar.css 의 #chat-fab !important 보다 우선하도록 동일하게 !important 로 그 위에 띄운다. */
  body[data-page="product"] #chat-fab { bottom: calc(64px + 62px + 16px) !important; }
  .chat-input textarea { font-size: 16px; }
  .chat-header {
    padding-top: calc(14px + env(safe-area-inset-top));
  }
  /* 키보드 없을 때만 홈 인디케이터만큼 하단 여백. 키보드가 뜨면(.kbd-open) 여백 제거. */
  .chat-input {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  #chat-panel.kbd-open .chat-input {
    padding-bottom: 10px;
  }
}
