#om-chat-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  min-width: 100px;
  height: 48px;
  border-radius: 24px;
  border: none;
  cursor: pointer;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.om-chat-icon {
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
}

.om-chat-text {
  font-size: 14px;
  line-height: 1;
  font-weight: 500;
}

#om-chat-widget {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 340px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: 520px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(15,23,42,0.55);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, "Noto Sans KR", sans-serif;
  box-sizing: border-box;
  /* 모바일에서 화면을 넘지 않도록 보장 */
  left: auto;
  min-width: 0;
}

#om-chat-widget.dark {
  background: #0f172a;
  color: #e5e7eb;
}

.om-chat-header {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(148,163,184,0.4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #312e81, #4c1d95);
  color: #e5e7eb;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
}

.om-chat-header-title {
  font-size: 14px;
  font-weight: 600;
}

.om-chat-header-sub {
  font-size: 11px;
  opacity: 0.85;
}

.om-chat-header-close {
  cursor: pointer;
  font-size: 18px;
  margin-left: 8px;
}

.om-chat-messages {
  padding: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  background: #f8fafc;
  font-size: 13px;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
}

.om-chat-widget.dark .om-chat-messages {
  background: #020617;
}

.om-msg {
  margin-bottom: 8px;
  display: flex;
}

.om-msg.user {
  justify-content: flex-end;
}

.om-msg.assistant {
  justify-content: flex-start;
}

.om-bubble {
  max-width: 80%;
  padding: 7px 9px;
  border-radius: 12px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}

.om-msg.user .om-bubble {
  background: #4f46e5;
  color: #fff;
  border-bottom-right-radius: 2px;
}

.om-msg.assistant .om-bubble {
  background: #e5e7eb;
  color: #111827;
  border-bottom-left-radius: 2px;
}

#om-chat-widget.dark .om-msg.assistant .om-bubble {
  background: #1e293b;
  color: #e5e7eb;
}

.om-chat-input {
  border-top: 1px solid rgba(148,163,184,0.5);
  padding: 8px;
  background: #f9fafb;
  display: flex;
  gap: 6px;
  align-items: flex-end;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  flex-shrink: 0;
  /* 입력 영역이 늘어나도 챗봇창 크기에 영향 주지 않도록 */
  min-height: fit-content;
  max-height: 120px;
}

#om-chat-widget.dark .om-chat-input {
  background: #020617;
}

#om-chat-input-textarea {
  flex: 1;
  resize: none;
  border-radius: 10px;
  border: 1px solid rgba(148,163,184,0.8);
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  height: auto;
  min-height: 32px;
  max-height: 80px;
  overflow-y: auto;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  width: 100%;
  /* textarea가 자동으로 높이 조절되지만 최대 높이 제한 */
  line-height: 1.4;
  /* iOS Safari 자동 확대 방지 */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

  #om-chat-send-btn {
    border: none;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    background: #4f46e5;
    color: #fff;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: fit-content;
  }

.om-typing {
  font-size: 11px;
  color: #64748b;
  margin-bottom: 4px;
}

@media (max-width: 768px) {
  #om-chat-toggle {
    min-width: 90px;
    height: 44px;
    padding: 0 14px;
    font-size: 13px;
    gap: 5px;
  }
  
  .om-chat-icon {
    font-size: 18px;
  }
  
  .om-chat-text {
    font-size: 13px;
  }
  
  #om-chat-widget {
    /* 모바일에서 화면 너비를 넘지 않도록 안전하게 계산 */
    width: calc(100% - 32px) !important;
    max-width: calc(100% - 32px) !important;
    min-width: 0 !important;
    right: 16px !important;
    left: auto !important;
    bottom: 80px;
    /* 키보드가 올라올 때를 대비해 높이를 더 작게 설정 */
    height: auto !important;
    max-height: calc(100vh - 120px) !important;
    /* 패딩과 보더를 포함한 크기 계산 */
    box-sizing: border-box;
  }
  
  /* 입력창에 포커스가 있을 때 챗봇창 높이 제한 및 가로 크기 축소 */
  #om-chat-widget.keyboard-open {
    max-height: calc(50vh - 40px) !important;
    bottom: auto !important;
    top: 20px !important;
    width: calc(100% - 40px) !important;
    max-width: calc(100% - 40px) !important;
    right: 20px !important;
  }
  
  /* 키보드가 올라올 때 입력 영역 패딩 축소 */
  #om-chat-widget.keyboard-open .om-chat-input {
    padding: 6px !important;
    gap: 4px !important;
  }
  
  /* 키보드가 올라올 때 전송 버튼 크기 조정 */
  #om-chat-widget.keyboard-open #om-chat-send-btn {
    padding: 6px 8px !important;
    font-size: 12px !important;
    white-space: nowrap;
    flex-shrink: 0;
  }
  
  /* 키보드가 올라올 때 textarea 크기 보장 */
  #om-chat-widget.keyboard-open #om-chat-input-textarea {
    min-width: 0;
    max-width: 100%;
    flex: 1;
  }
  
  /* 챗봇 내부 요소들도 화면을 넘지 않도록 */
  #om-chat-widget * {
    box-sizing: border-box;
    max-width: 100%;
  }
  
  .om-chat-header {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex-shrink: 0;
  }
  
  .om-chat-messages {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    flex: 1;
    overflow-y: auto;
  }
  
  .om-chat-input {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex-shrink: 0;
    max-height: 100px;
    /* 입력 영역이 화면을 넘지 않도록 */
    padding-left: 6px !important;
    padding-right: 6px !important;
    gap: 4px !important;
  }
  
  #om-chat-input-textarea {
    max-height: 70px;
    /* 모바일에서 iOS Safari 자동 확대 방지를 위해 16px 이상 설정 */
    font-size: 16px !important;
    /* 입력 영역이 화면을 넘지 않도록 엄격한 제한 */
    max-width: calc(100% - 60px) !important;
    width: calc(100% - 60px) !important;
    min-width: 0 !important;
    /* 패딩 축소로 공간 확보 */
    padding: 5px 6px !important;
  }
  
  body {
    overflow-x: hidden !important;
    position: relative;
    /* 모바일에서 body가 화면을 넘지 않도록 */
    width: 100%;
    max-width: 100vw;
    /* iOS Safari 자동 확대 방지 */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* 터치 액션 제어 */
    touch-action: pan-y;
  }

  html {
    overflow-x: hidden !important;
    width: 100%;
    max-width: 100vw;
    /* iOS Safari 자동 확대 방지 */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  
  /* 챗봇 위젯이 화면을 넘지 않도록 추가 보장 */
  #om-chat-widget {
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
}

@media (max-width: 480px) {
  #om-chat-toggle {
    min-width: 85px;
    height: 42px;
    padding: 0 12px;
    font-size: 12px;
    gap: 4px;
    bottom: 16px;
    right: 16px;
  }
  
  .om-chat-icon {
    font-size: 17px;
  }
  
  .om-chat-text {
    font-size: 12px;
  }
  
  #om-chat-widget {
    /* 작은 모바일 화면에서 더 안전하게 계산 */
    width: calc(100% - 24px) !important;
    max-width: calc(100% - 24px) !important;
    min-width: 0 !important;
    right: 12px !important;
    left: auto !important;
    bottom: 80px;
    height: auto !important;
    max-height: calc(100vh - 120px) !important;
    box-sizing: border-box;
  }
  
  /* 작은 화면에서 입력창 포커스 시 */
  #om-chat-widget.keyboard-open {
    max-height: calc(45vh - 30px) !important;
    bottom: auto !important;
    top: 15px !important;
    width: calc(100% - 32px) !important;
    max-width: calc(100% - 32px) !important;
    right: 16px !important;
  }
  
  /* 작은 화면에서 키보드가 올라올 때 입력 영역 패딩 축소 */
  #om-chat-widget.keyboard-open .om-chat-input {
    padding: 5px !important;
    gap: 3px !important;
  }
  
  /* 작은 화면에서 전송 버튼 크기 조정 */
  #om-chat-widget.keyboard-open #om-chat-send-btn {
    padding: 5px 7px !important;
    font-size: 11px !important;
  }
  
  /* 작은 화면에서도 내부 요소들이 화면을 넘지 않도록 */
  .om-chat-header {
    padding-left: 8px;
    padding-right: 8px;
    flex-shrink: 0;
  }
  
  .om-chat-messages {
    padding-left: 8px;
    padding-right: 8px;
    min-height: 0;
    flex: 1;
    overflow-y: auto;
  }
  
  .om-chat-input {
    padding-left: 6px !important;
    padding-right: 6px !important;
    flex-shrink: 0;
    max-height: 90px;
    gap: 3px !important;
  }
  
  #om-chat-input-textarea {
    max-height: 60px;
    /* 작은 모바일 화면에서도 iOS Safari 자동 확대 방지 */
    font-size: 16px !important;
    /* 입력 영역이 화면을 넘지 않도록 더 엄격한 제한 */
    max-width: calc(100% - 55px) !important;
    width: calc(100% - 55px) !important;
    min-width: 0 !important;
    /* 패딩 더 축소 */
    padding: 4px 5px !important;
  }
  
  .om-bubble {
    max-width: 85%;
  }
}

