/* 플로팅 AI 상담 위젯 */
#chatbot-widget-root {
  --cw-primary: #1d8cf8;
  --cw-primary-dark: #1171d3;
  --cw-bg: #ffffff;
  --cw-text: #2c3e50;
  --cw-muted: #8898aa;
  --cw-border: rgba(0, 0, 0, 0.08);
  --cw-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  --cw-fab-size: 56px;
  --cw-panel-width: 380px;
  --cw-panel-height: 520px;
  font-family: "NanumSquare", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Malgun Gothic", sans-serif;
}

#chatbot-widget-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: var(--cw-fab-size);
  height: var(--cw-fab-size);
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary-dark));
  color: #fff;
  box-shadow: 0 4px 16px rgba(29, 140, 248, 0.45);
  cursor: pointer;
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#chatbot-widget-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(29, 140, 248, 0.55);
}

#chatbot-widget-fab .mdi {
  font-size: 28px;
  line-height: 1;
}

#chatbot-widget-fab.is-open .mdi-chat-processing {
  display: none;
}

#chatbot-widget-fab:not(.is-open) .mdi-close {
  display: none;
}

#chatbot-widget-panel {
  position: fixed;
  right: 24px;
  bottom: calc(24px + var(--cw-fab-size) + 12px);
  width: var(--cw-panel-width);
  height: var(--cw-panel-height);
  max-height: calc(100vh - 120px);
  background: var(--cw-bg);
  border-radius: 16px;
  box-shadow: var(--cw-shadow);
  border: 1px solid var(--cw-border);
  z-index: 1051;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s, width 0.3s ease, height 0.3s ease, bottom 0.3s ease, right 0.3s ease;
}

#chatbot-widget-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

#chatbot-widget-panel.is-expanded {
  width: calc(100vw - 48px);
  height: calc(100vh - 48px);
  max-width: 1400px;
  max-height: 1000px;
  right: 24px;
  bottom: 24px;
}

.cw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary-dark));
  color: #fff;
  flex-shrink: 0;
}

.cw-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  min-width: 0;
  flex: 1;
}

.cw-header-logo {
  height: 30px;
  width: auto;
  max-width: 110px;
  object-fit: contain;
  object-position: left center;
  display: block;
  flex-shrink: 0;
}

.cw-header-label {
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  padding-left: 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.35);
  line-height: 1.2;
}

.cw-header-actions {
  display: flex;
  gap: 4px;
}

.cw-header-actions button {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.cw-header-actions button:hover {
  background: rgba(255, 255, 255, 0.28);
}

.cw-messages {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8f9fb;
}

.cw-message {
  display: flex;
  gap: 8px;
  max-width: 92%;
  min-width: 0;
}

.cw-message.is-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.cw-message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.cw-message.is-bot .cw-message-avatar {
  background: #fff;
  border: 1px solid var(--cw-border);
  overflow: hidden;
  padding: 0;
}

.cw-bot-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cw-message.is-user .cw-message-avatar {
  background: #e9ecef;
  color: var(--cw-text);
}

.cw-message-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  min-width: 0;
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.cw-message.is-user .cw-message-bubble {
  white-space: pre-wrap;
}

.cw-message.is-bot .cw-message-bubble {
  white-space: normal;
}

/* 봇 마크다운 렌더링 */
.cw-message-bubble.cw-markdown p {
  margin: 0 0 0.55em;
}

.cw-message-bubble.cw-markdown p:last-child {
  margin-bottom: 0;
}

.cw-message-bubble.cw-markdown strong {
  font-weight: 600;
}

.cw-message-bubble.cw-markdown ul,
.cw-message-bubble.cw-markdown ol {
  margin: 0.35em 0;
  padding-left: 1.25em;
}

.cw-message-bubble.cw-markdown li {
  margin-bottom: 0.2em;
}

.cw-message-bubble.cw-markdown h1,
.cw-message-bubble.cw-markdown h2,
.cw-message-bubble.cw-markdown h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0.5em 0 0.35em;
}

.cw-message-bubble.cw-markdown code {
  font-size: 12px;
  background: #f1f3f5;
  padding: 1px 4px;
  border-radius: 4px;
  word-break: break-all;
}

.code-block-wrapper {
  position: relative;
  margin: 0.8em 0;
  background: #f1f3f5;
  border-radius: 8px;
  border: 1px solid var(--cw-border);
}

.code-block-wrapper .copy-code-button {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 4px 8px;
  background: transparent;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  font-family: inherit;
  color: #6c757d;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
  z-index: 2;
}

.code-block-wrapper .copy-code-button:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #212529;
}

.cw-message-bubble.cw-markdown .code-block-wrapper pre {
  margin: 0;
  padding: 28px 10px 10px;
  background: transparent;
  border-radius: 0;
}

.cw-message-bubble.cw-markdown > pre {
  margin: 0.5em 0;
  padding: 8px 10px;
  background: #f1f3f5;
  border-radius: 8px;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

.cw-message-bubble.cw-markdown pre code {
  background: none;
  padding: 0;
}

.cw-message-bubble.cw-markdown a {
  color: var(--cw-primary);
  text-decoration: underline;
}

.cw-message-bubble.cw-markdown table {
  display: block;
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 0.5em 0;
  overflow-x: auto;
}

.cw-message-bubble.cw-markdown th,
.cw-message-bubble.cw-markdown td {
  border: 1px solid var(--cw-border);
  padding: 4px 6px;
  word-break: break-word;
}

/* 마크다운 자식 요소가 말풍선 밖으로 삐져나가지 않도록 */
.cw-message-bubble.cw-markdown>* {
  max-width: 100%;
}

.cw-message.is-bot .cw-message-bubble {
  background: #fff;
  color: var(--cw-text);
  border: 1px solid var(--cw-border);
  border-top-left-radius: 4px;
}

.cw-message.is-user .cw-message-bubble {
  background: var(--cw-primary);
  color: #fff;
  border-top-right-radius: 4px;
}

.cw-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.cw-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cw-muted);
  animation: cw-bounce 1.2s infinite ease-in-out;
}

.cw-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.cw-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes cw-bounce {

  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.5;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.cw-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--cw-border);
  background: #fff;
  flex-shrink: 0;
}

.cw-input-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.cw-input-wrap textarea {
  flex: 1;
  border: 1px solid var(--cw-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  resize: none;
  max-height: 100px;
  line-height: 1.4;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.cw-input-wrap textarea:focus {
  border-color: var(--cw-primary);
}

.cw-send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--cw-primary);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.cw-send-btn:disabled {
  background: #c0d6f0;
  cursor: not-allowed;
}

.cw-send-btn:not(:disabled):hover {
  background: var(--cw-primary-dark);
}

.cw-welcome {
  text-align: center;
  color: var(--cw-muted);
  font-size: 13px;
  padding: 24px 12px;
  line-height: 1.6;
}

.cw-welcome .cw-bot-avatar-img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 0 auto 8px;
  border: 1px solid var(--cw-border);
}

.cw-welcome .mdi {
  font-size: 36px;
  color: var(--cw-primary);
  display: block;
  margin-bottom: 8px;
}

/* 모바일: 하단 네비 위에 배치 */
@media (max-width: 768px) {
  #chatbot-widget-fab {
    right: 16px;
    bottom: 80px;
    width: 52px;
    height: 52px;
  }

  #chatbot-widget-panel {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 72vh;
    max-height: none;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }

  #chatbot-widget-panel.is-open {
    transform: translateY(0);
  }

  #chatbot-widget-panel.is-expanded {
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }

  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    #chatbot-widget-fab {
      bottom: calc(80px + env(safe-area-inset-bottom));
      right: calc(16px + env(safe-area-inset-right));
    }

    #chatbot-widget-panel {
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}

/* 인쇄 시 플로팅 버튼·패널 숨김 */
@media print {
  #chatbot-widget-root {
    display: none !important;
    visibility: hidden !important;
  }
}