/* AI 도우미 (chat dock) — from komap-ui ai_dowoomi.css, portal-adapted */

/* CSS variable fallbacks when page :root is incomplete */
:root {
  --navy: #15294d;
  --navy2: #1e3a5f;
  --blue: #2e6fd6;
  --blue-soft: #e8f0fc;
  --bg: #eef2f8;
  --card: #ffffff;
  --line: #e1e7f0;
  --text: #1a2233;
  --muted: #6b7790;
}

/* 플로팅 런처(FAB) */
.cp-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 52px;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 30px;
  background: linear-gradient(135deg, var(--blue), var(--navy2));
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(20, 41, 77, 0.28);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cp-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(20, 41, 77, 0.34);
}
.cp-fab .em {
  font-size: 18px;
}
body.panel-open .cp-fab {
  display: none;
}

/* 챗 패널 */
.chatpanel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 95;
  width: 360px;
  max-width: calc(100vw - 28px);
  height: 560px;
  max-height: calc(100vh - 44px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(20, 41, 77, 0.3);
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
body.panel-open .chatpanel {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.cp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 13px 16px;
  background: var(--navy);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
}
.cp-head .sub {
  font-weight: 600;
  font-size: 11px;
  color: #cdd8ea;
  margin-left: 2px;
}
.cp-head .cp-tools {
  display: flex;
  align-items: center;
  gap: 2px;
}
.cp-iconbtn {
  background: transparent;
  border: 0;
  color: #cdd8ea;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 7px;
  font-family: inherit;
}
.cp-iconbtn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}
.cp-close {
  font-size: 20px;
}

/* ── 임베딩(우측 고정) 모드 — 헤더는 그대로, 본문만 밀림 ── */
.bodywrap,
#wrapper,
.main_wrapper {
  transition: padding-right 0.18s ease;
}
body.dock-embedded.panel-open .bodywrap,
body.dock-embedded.panel-open #wrapper,
body.dock-embedded.panel-open .main_wrapper {
  padding-right: 380px;
}
body.dock-embedded .chatpanel {
  top: var(--cp-top, 116px);
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 42vw;
  height: auto;
  max-height: none;
  border-radius: 0;
  border: 0;
  border-left: 1px solid var(--line);
  box-shadow: -14px 0 40px rgba(20, 41, 77, 0.1);
  transform: translateX(16px);
}
body.dock-embedded.panel-open .chatpanel {
  transform: none;
}
.cp-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
}
.cp-msg {
  max-width: 84%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.cp-msg.bot {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.cp-msg.user {
  align-self: flex-end;
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.cp-dim {
  color: var(--muted);
  font-size: 12px;
}
.cp-msg.user .cp-dim {
  color: #dbe7fb;
}
/* 응답 대기 표시 — 타이핑 점 애니메이션 + 경과 시간 */
.cp-msg.cp-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.cp-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.cp-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue);
  opacity: 0.35;
  animation: cp-bounce 1.2s infinite ease-in-out both;
}
.cp-typing i:nth-child(1) {
  animation-delay: -0.24s;
}
.cp-typing i:nth-child(2) {
  animation-delay: -0.12s;
}
.cp-elapsed {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
@keyframes cp-bounce {
  0%,
  80%,
  100% {
    transform: scale(0.7);
    opacity: 0.35;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}
@media (prefers-reduced-motion: reduce) {
  .cp-typing i {
    animation: none;
  }
}
.cp-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}
.cp-pick {
  border: 1px solid #cfe0fb;
  background: var(--blue-soft, #e8f0fc);
  color: var(--blue);
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.cp-pick:hover {
  background: #dcebfd;
}
.cp-composer {
  display: flex;
  gap: 8px;
  padding: 11px;
  border-top: 1px solid var(--line);
  background: var(--card);
}
.cp-composer input {
  flex: 1;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 13.5px;
}
.cp-composer input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 111, 214, 0.12);
}
.cp-composer button {
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}
.cp-composer button:hover {
  background: var(--navy2);
}
/* 좁은 화면에서는 임베딩 인셋을 끄고 플로팅처럼 표시 */
@media (max-width: 880px) {
  body.dock-embedded.panel-open .bodywrap,
  body.dock-embedded.panel-open #wrapper,
  body.dock-embedded.panel-open .main_wrapper {
    padding-right: 0;
  }
  body.dock-embedded .chatpanel {
    top: auto;
    right: 22px;
    bottom: 22px;
    width: 360px;
    max-width: calc(100vw - 28px);
    height: 560px;
    max-height: calc(100vh - 44px);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 18px 50px rgba(20, 41, 77, 0.3);
  }
}
@media (max-width: 520px) {
  .chatpanel,
  body.dock-embedded .chatpanel {
    right: 14px;
    left: 14px;
    width: auto;
    max-width: none;
    bottom: 14px;
    top: auto;
    height: calc(100vh - 28px);
  }
}

.messages_chat .message.gpt ul,
.messages_chat .message.gpt ol { margin: 4px 0 4px 18px; }
.messages_chat .message.gpt strong { font-weight: 700; }
.messages_chat .message.gpt p { margin: 4px 0; }
